Embed Notice
HTML Code
Corresponding Notice
- Embed this notice@nach @tadano :bigbosssalute: That's the monitoring monitor. I patched the histogram program, I like it, your mileage may vary.
histogram.c:15,20 - phistogram.c:15,21
Bw = 2, /* border width */
};
+ /* "light" and "dark" are misnomers in this version; "min"/"max". */
Image *neutral;
Image *light;
Image *dark;
histogram.c:24,49 - phistogram.c:25,56
Rectangle hrect;
Point maxvloc;
double *data;
- double vmax = 100, scale = 1.0;
+ double vmax = 1, scale = 1.0;
uint nval;
int dontdie = 0, col = 1;
int colors[][3] = {
- { 0xFFAAAAFF, 0xFFAAAAFF, 0xBB5D5DFF }, /* Peach */
- { DPalebluegreen, DPalegreygreen, DPurpleblue }, /* Aqua */
- { DPaleyellow, DDarkyellow, DYellowgreen }, /* Yellow */
- { DPalegreen, DMedgreen, DDarkgreen }, /* Green */
- { 0x00AAFFFF, 0x00AAFFFF, 0x0088CCFF }, /* Blue */
- { 0xEEEEEEFF, 0xCCCCCCFF, 0x888888F }, /* Grey */
+ { 0xFFFAFAFF, 0xBB5D5DFF, 0xFFAAAAFF }, /* Peach */
+ { DWhite, DPalegreygreen, DPurpleblue }, /* Aqua */
+ { DWhite, DYellowgreen, DDarkyellow }, /* Yellow */
+ { 0xFFFFDCFF, DDarkgreen, DMedgreen }, /* Green */
+ { 0xBBEEFFFF, 0x00AAFFFF, 0x0088CCFF }, /* Blue */
+ { 0xFFFFFFFF, 0xCCCCCCFF, 0x0888888F }, /* Grey */
+
+ { 0x000000FF, 0x00E4FFFF, 0xFF4DA1FF },
+ { 0x000000FF, 0x004DA1FF, 0xFF4DA1FF },
+ { 0x000000FF, 0xFF00A1FF, 0xFFFFA1FF },
};
+ int *ccolor;
void
initcolor(int i)
{
- neutral = allocimagemix(display, colors[i][0], DWhite);
- light = allocimage(display, Rect(0,0,1,1), CMAP8, 1, colors[i][1]);
- dark = allocimage(display, Rect(0,0,1,1), CMAP8, 1, colors[i][2]);
- txtcolor = display->black;
+ ccolor = colors[i];
+ neutral = allocimage(display, Rect(0,0,1,1), RGB24, 1, colors[i][0]);
+ light = allocimage(display, Rect(0,0,1,1), RGB24, 1, colors[i][1]);
+ dark = allocimage(display, Rect(0,0,1,1), RGB24, 1, colors[i][2]);
+ txtcolor = allocimage(display, Rect(0,0,1,1), RGB24, 1, (~colors[i][0])|0xFF);
}
void*
histogram.c:73,99 - phistogram.c:80,117
return p;
}
+ int
+ blendc(ulong a, ulong b, double s)
+ {
+ uchar p;
+ p = floor(255.0*(s/vmax));
+ return setalpha(a, p) + setalpha(b, 255-p);
+ }
+
void
drawdatum(int x, double prev, double v)
{
Point p, q;
+ Image *vc;
+
p = datapoint(x, v);
q = datapoint(x, prev);
+ vc = allocimage(display, Rect(0,0,1,1), RGB24, 1, blendc(ccolor[2], ccolor[1], v));
+ if(vc == nil)
+ sysfatal("drawdatum: %r");
if(p.y < q.y){
draw(screen, Rect(p.x, hrect.min.y, p.x+1, p.y), neutral,
nil, ZP);
- draw(screen, Rect(p.x, p.y, p.x+1, q.y+Dot), dark, nil, ZP);
- draw(screen, Rect(p.x, q.y+Dot, p.x+1, hrect.max.y), light,
+ draw(screen, Rect(p.x, p.y, p.x+1, hrect.max.y), vc,
nil, ZP);
}else{
draw(screen, Rect(p.x, hrect.min.y, p.x+1, q.y), neutral,
nil, ZP);
- draw(screen, Rect(p.x, q.y, p.x+1, p.y+Dot), dark, nil, ZP);
- draw(screen, Rect(p.x, p.y+Dot, p.x+1, hrect.max.y), light,
+ draw(screen, Rect(p.x, q.y, p.x+1, hrect.max.y), vc,
nil, ZP);
}
-
+ freeimage(vc);
}
void
histogram.c:102,109 - phistogram.c:120,129
char buf[32];
draw(screen, hrect, screen, nil, Pt(hrect.min.x+1, hrect.min.y));
- if(v * scale > vmax)
+ if(v * scale > vmax) {
+ vmax = v / scale;
v = vmax / scale;
+ }
drawdatum(hrect.max.x-1, data[0], v);
memmove(&data[1], &data[0], (nval-1) * sizeof data[0]);
data[0] = v;
histogram.c:136,143 - phistogram.c:156,163
q = subpt(r.max, Pt(Lx, Ly));
hrect = Rpt(p, q);
- maxvloc = Pt(r.max.x - Lx - stringwidth(display->defaultfont,
- "999999999"), r.min.y + Ly);
+ maxvloc = Pt(4 + r.max.x - Lx - (stringwidth(display->defaultfont,
+ "999999999")), r.min.y + Ly);
nval = abs(Dx(hrect));
if(nval != onval){
histogram.c:146,152 - phistogram.c:166,172
memset(data+onval, 0, (nval - onval) * sizeof data[0]);
}
- border(screen, hrect, -Bw, dark, ZP);
+ border(screen, hrect, -Bw, txtcolor, ZP);
snprint(buf, sizeof buf, "%0.9f", data[0]);
stringbg(screen, maxvloc, txtcolor, ZP, display->defaultfont, buf,
neutral, ZP);