Commit 44936a9b authored by Claes Sjofors's avatar Claes Sjofors

Ge barchart, negative bars added

parent ca126d0d
...@@ -360,8 +360,10 @@ void GrowBarChart::draw(GlowWind* w, GlowTransform* t, int highlight, int hot, ...@@ -360,8 +360,10 @@ void GrowBarChart::draw(GlowWind* w, GlowTransform* t, int highlight, int hot,
int skip; int skip;
int bar_ll_x, bar_ur_x; int bar_ll_x, bar_ur_x;
int bar_ll_y, bar_ur_y; int bar_up_ll_y, bar_up_ur_y;
double f_bar_ll_y; double f_bar_up_ll_y;
int bar_down_ll_y, bar_down_ur_y, border_bar_down_ur_y;
double f_bar_down_ur_y;
double width; double width;
int brect_ll_x = 0, brect_ll_y = 0, brect_width = 0, brect_height = 0; int brect_ll_x = 0, brect_ll_y = 0, brect_width = 0, brect_height = 0;
...@@ -375,84 +377,153 @@ void GrowBarChart::draw(GlowWind* w, GlowTransform* t, int highlight, int hot, ...@@ -375,84 +377,153 @@ void GrowBarChart::draw(GlowWind* w, GlowTransform* t, int highlight, int hot,
else else
bar_ur_x = ll_x + (j + 1) * width; bar_ur_x = ll_x + (j + 1) * width;
bar_ll_y = ur_y; if ( min_value >= 0) {
f_bar_ll_y = ur_y; bar_up_ll_y = ur_y;
f_bar_up_ll_y = ur_y;
} else {
bar_up_ll_y = ur_y + min_value * (ur_y - ll_y) / (max_value - min_value);
f_bar_up_ll_y = bar_up_ll_y;
bar_down_ur_y = ur_y + min_value * (ur_y - ll_y) / (max_value - min_value);
f_bar_down_ur_y = bar_down_ur_y;
}
for (int i = 0; i < barsegments + 1; i++) { for (int i = 0; i < barsegments + 1; i++) {
glow_eDrawType fillcolor = glow_eDrawType_Line; glow_eDrawType fillcolor = glow_eDrawType_Line;
skip = 0; if ( min_value > 0 || bar_values[i][j] > 0) {
bar_ur_y = bar_ll_y; skip = 0;
bar_up_ur_y = bar_up_ll_y;
if (i == barsegments) {
if (bar_ll_y <= ll_y) if (i == barsegments) {
skip = 1; if (bar_up_ll_y <= ll_y)
else skip = 1;
bar_ll_y = ll_y; else
fillcolor = ctx->get_drawtype(fill_drawtype, bar_up_ll_y = ll_y;
glow_eDrawType_FillHighlight, highlight, (GrowNode*)colornode, 1); fillcolor = ctx->get_drawtype(fill_drawtype,
} else {
if (bar_values[i][j] <= min_value)
skip = 1;
else if (bar_ur_y <= ll_y)
skip = 1;
else {
f_bar_ll_y
-= (bar_values[i][j] - min_value) * (ur_y - ll_y) / (max_value - min_value);
bar_ll_y = f_bar_ll_y;
if (bar_ll_y < ll_y)
bar_ll_y = ll_y;
fillcolor = ctx->get_drawtype(bar_color[i],
glow_eDrawType_FillHighlight, highlight, (GrowNode*)colornode, 1); glow_eDrawType_FillHighlight, highlight, (GrowNode*)colornode, 1);
} else {
if (bar_values[i][j] <= min_value)
skip = 1;
else if (bar_up_ur_y <= ll_y)
skip = 1;
else {
f_bar_up_ll_y
-= bar_values[i][j] * (ur_y - ll_y) / (max_value - min_value);
bar_up_ll_y = f_bar_up_ll_y;
if (bar_up_ll_y < ll_y)
bar_up_ll_y = ll_y;
fillcolor = ctx->get_drawtype(bar_color[i],
glow_eDrawType_FillHighlight, highlight, (GrowNode*)colornode, 1);
}
} }
} if (!skip) {
if (grad == glow_eGradient_No || fillcolor == glow_eDrawType_ColorRed
if (!skip) { || i == barsegments) {
if (grad == glow_eGradient_No || fillcolor == glow_eDrawType_ColorRed if (chot)
|| i == barsegments) { drawtype = GlowColor::shift_drawtype(fillcolor, chot, 0);
if (chot) else
drawtype = GlowColor::shift_drawtype(fillcolor, chot, 0); drawtype = fillcolor;
ctx->gdraw->fill_rect(w, bar_ll_x, bar_up_ll_y, bar_ur_x - bar_ll_x,
bar_up_ur_y - bar_up_ll_y, drawtype);
} else {
glow_eDrawType f1, f2;
if (gradient_contrast >= 0) {
f2 = GlowColor::shift_drawtype(
fillcolor, -gradient_contrast / 2 + chot, 0);
f1 = GlowColor::shift_drawtype(
fillcolor, int(float(gradient_contrast) / 2 + 0.6) + chot, 0);
} else {
f2 = GlowColor::shift_drawtype(
fillcolor, -int(float(gradient_contrast) / 2 - 0.6) + chot, 0);
f1 = GlowColor::shift_drawtype(
fillcolor, gradient_contrast / 2 + chot, 0);
}
ctx->gdraw->gradient_fill_rect(w, bar_ll_x, bar_up_ll_y,
bar_ur_x - bar_ll_x, bar_up_ur_y - bar_up_ll_y, fillcolor, f1, f2,
grad);
}
}
} else {
// negative value, draw bar downwards
skip = 0;
bar_down_ll_y = bar_down_ur_y;
if (i == barsegments) {
border_bar_down_ur_y = bar_down_ur_y;
if (bar_down_ur_y >= ur_y)
skip = 1;
else else
drawtype = fillcolor; bar_down_ur_y = ur_y;
ctx->gdraw->fill_rect(w, bar_ll_x, bar_ll_y, bar_ur_x - bar_ll_x, fillcolor = ctx->get_drawtype(fill_drawtype,
bar_ur_y - bar_ll_y, drawtype); glow_eDrawType_FillHighlight, highlight, (GrowNode*)colornode, 1);
} else { } else {
glow_eDrawType f1, f2; if (bar_values[i][j] >= 0)
if (gradient_contrast >= 0) { skip = 1;
f2 = GlowColor::shift_drawtype( else if (bar_down_ll_y >= ur_y)
fillcolor, -gradient_contrast / 2 + chot, 0); skip = 1;
f1 = GlowColor::shift_drawtype( else {
fillcolor, int(float(gradient_contrast) / 2 + 0.6) + chot, 0); f_bar_down_ur_y
-= bar_values[i][j] * (ur_y - ll_y) / (max_value - min_value);
bar_down_ur_y = f_bar_down_ur_y;
if (bar_down_ur_y > ur_y)
bar_down_ur_y = ur_y;
fillcolor = ctx->get_drawtype(bar_color[i],
glow_eDrawType_FillHighlight, highlight, (GrowNode*)colornode, 1);
}
}
if (!skip) {
if (grad == glow_eGradient_No || fillcolor == glow_eDrawType_ColorRed
|| i == barsegments) {
if (chot)
drawtype = GlowColor::shift_drawtype(fillcolor, chot, 0);
else
drawtype = fillcolor;
ctx->gdraw->fill_rect(w, bar_ll_x, bar_down_ll_y, bar_ur_x - bar_ll_x,
bar_down_ur_y - bar_down_ll_y, drawtype);
} else { } else {
f2 = GlowColor::shift_drawtype( glow_eDrawType f1, f2;
fillcolor, -int(float(gradient_contrast) / 2 - 0.6) + chot, 0); if (gradient_contrast >= 0) {
f1 = GlowColor::shift_drawtype( f2 = GlowColor::shift_drawtype(
fillcolor, gradient_contrast / 2 + chot, 0); fillcolor, -gradient_contrast / 2 + chot, 0);
f1 = GlowColor::shift_drawtype(
fillcolor, int(float(gradient_contrast) / 2 + 0.6) + chot, 0);
} else {
f2 = GlowColor::shift_drawtype(
fillcolor, -int(float(gradient_contrast) / 2 - 0.6) + chot, 0);
f1 = GlowColor::shift_drawtype(
fillcolor, gradient_contrast / 2 + chot, 0);
}
ctx->gdraw->gradient_fill_rect(w, bar_ll_x, bar_down_ll_y,
bar_ur_x - bar_ll_x, bar_down_ur_y - bar_down_ll_y, fillcolor, f1, f2,
grad);
} }
ctx->gdraw->gradient_fill_rect(w, bar_ll_x, bar_ll_y,
bar_ur_x - bar_ll_x, bar_ur_y - bar_ll_y, fillcolor, f1, f2,
grad);
} }
} }
if (border && i == barsegments) { if (border && i == barsegments) {
// Draw previous bar border // Draw previous bar border
if (j > 0) { if (j > 0) {
drawtype = ctx->get_drawtype(draw_type, glow_eDrawType_LineHighlight, drawtype = ctx->get_drawtype(draw_type, glow_eDrawType_LineHighlight,
highlight, (GrowNode*)colornode, 0); highlight, (GrowNode*)colornode, 0);
ctx->gdraw->rect(w, brect_ll_x, brect_ll_y, brect_width, brect_height, ctx->gdraw->rect(w, brect_ll_x, brect_ll_y, brect_width, brect_height,
drawtype, idx, 0); drawtype, idx, 0);
} }
if (!skip) { if ( min_value >= 0) {
brect_ll_x = bar_ll_x; brect_ll_x = bar_ll_x;
brect_ll_y = bar_ur_y; brect_ll_y = bar_up_ll_y;
brect_width = bar_ur_x - bar_ll_x; brect_width = bar_ur_x - bar_ll_x;
brect_height = ur_y - bar_ur_y; brect_height = ur_y - bar_up_ll_y;
} else { } else {
brect_ll_x = bar_ll_x; brect_ll_x = bar_ll_x;
brect_ll_y = ll_y; brect_ll_y = bar_up_ll_y;
brect_width = bar_ur_x - bar_ll_x; brect_width = bar_ur_x - bar_ll_x;
brect_height = ur_y - ll_y; brect_height = ur_y + min_value * (ur_y - ll_y) / (max_value - min_value) - bar_up_ll_y;
} }
if (j == bars - 1) { if (j == bars - 1) {
// Draw last bar border // Draw last bar border
...@@ -462,7 +533,32 @@ void GrowBarChart::draw(GlowWind* w, GlowTransform* t, int highlight, int hot, ...@@ -462,7 +533,32 @@ void GrowBarChart::draw(GlowWind* w, GlowTransform* t, int highlight, int hot,
ctx->gdraw->rect(w, brect_ll_x, brect_ll_y, brect_width, brect_height, ctx->gdraw->rect(w, brect_ll_x, brect_ll_y, brect_width, brect_height,
drawtype, idx, 0); drawtype, idx, 0);
} }
// Draw negative bar border
if ( min_value < 0) {
if (j > 0) {
drawtype = ctx->get_drawtype(draw_type, glow_eDrawType_LineHighlight,
highlight, (GrowNode*)colornode, 0);
ctx->gdraw->rect(w, brect_ll_x, brect_ll_y, brect_width, brect_height,
drawtype, idx, 0);
}
brect_ll_x = bar_ll_x;
brect_ll_y = ur_y + min_value * (ur_y - ll_y) / (max_value - min_value);
brect_width = bar_ur_x - bar_ll_x;
brect_height = border_bar_down_ur_y - brect_ll_y;
if (j == bars - 1) {
// Draw last bar border
drawtype = ctx->get_drawtype(draw_type, glow_eDrawType_LineHighlight,
highlight, (GrowNode*)colornode, 0);
ctx->gdraw->rect(w, brect_ll_x, brect_ll_y, brect_width, brect_height,
drawtype, idx, 0);
}
}
} }
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment