This commit is contained in:
parent
b54721a323
commit
ef7d745134
1 changed files with 275 additions and 236 deletions
|
|
@ -75,57 +75,29 @@ static void draw_line(MwWidget handle, const char* text, double x, double y, dou
|
|||
vmax += (double)width / r.height * (vmax - vmin); \
|
||||
}
|
||||
|
||||
static void draw(MwWidget handle) {
|
||||
static void bar_chart(MwWidget handle, MwRect* _r, double vmin, double vmax, int space, const char** colors, int n, MwLLColor border) {
|
||||
int ColorDiff = MwGetColorDifference(handle);
|
||||
MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground));
|
||||
MwLLColor border = MwParseColor(handle, MwGetText(handle, MwNforeground));
|
||||
MwRect r;
|
||||
MwChart c = handle->internal;
|
||||
int i;
|
||||
const char** colors = palette0;
|
||||
int n;
|
||||
int gap;
|
||||
int width;
|
||||
double vmin = 0xffffffff;
|
||||
double vmax = -0xffffffff;
|
||||
int space = MwTextHeight(handle, NULL, "M");
|
||||
MwPoint p[2];
|
||||
int type = MwGetInteger(handle, MwNtype);
|
||||
int modern = MwGetInteger(handle, MwNmodernLook);
|
||||
double ovmin;
|
||||
double ovmax;
|
||||
|
||||
for(n = 0; colors[n] != NULL; n++);
|
||||
|
||||
for(i = 0; i < arrlen(c->entries); i++) {
|
||||
if(vmin > c->entries[i].value) vmin = c->entries[i].value;
|
||||
if(vmax < c->entries[i].value) vmax = c->entries[i].value;
|
||||
}
|
||||
|
||||
if(MwGetInteger(handle, MwNminValue) != MwDEFAULT) vmin = MwGetInteger(handle, MwNminValue);
|
||||
if(MwGetInteger(handle, MwNmaxValue) != MwDEFAULT) vmax = MwGetInteger(handle, MwNmaxValue);
|
||||
|
||||
ovmin = vmin;
|
||||
ovmax = vmax;
|
||||
|
||||
r.x = 0;
|
||||
r.y = 0;
|
||||
r.width = MwGetInteger(handle, MwNwidth);
|
||||
r.height = MwGetInteger(handle, MwNheight);
|
||||
MwDrawRect(handle, &r, base);
|
||||
|
||||
if(type == MwCHART_BAR || type == MwCHART_3D_BAR) {
|
||||
double s = 1.5;
|
||||
double twidth;
|
||||
char buf[128];
|
||||
MwRect node;
|
||||
MwPoint p[2];
|
||||
int i;
|
||||
int width;
|
||||
int gap;
|
||||
MwRect r = *_r;
|
||||
double ovmin = vmin;
|
||||
double ovmax = vmax;
|
||||
int type = MwGetInteger(handle, MwNtype);
|
||||
int modern = MwGetInteger(handle, MwNmodernLook);
|
||||
|
||||
node.x = 0;
|
||||
|
||||
for(i = 0; i < arrlen(c->entries); i++) {
|
||||
int w;
|
||||
|
||||
sprintf(buf, NUMFMT, c->entries[i].value);
|
||||
MwStringPrintIntoBuffer(buf, sizeof(buf), NUMFMT, c->entries[i].value);
|
||||
|
||||
w = MwTextWidth(handle, NULL, buf);
|
||||
|
||||
|
|
@ -141,12 +113,12 @@ static void draw(MwWidget handle) {
|
|||
|
||||
twidth = (width + gap) * arrlen(c->entries) + gap;
|
||||
|
||||
sprintf(buf, NUMFMT, ovmax);
|
||||
MwStringPrintIntoBuffer(buf, sizeof(buf), NUMFMT, ovmax);
|
||||
draw_line(handle, buf, node.x, (r.height - space) - (ovmax - vmin) / (vmax - vmin) * (r.height - space), twidth, width / 2, border);
|
||||
|
||||
draw_line(handle, "0", node.x, (r.height - space) - (0 - vmin) / (vmax - vmin) * (r.height - space), twidth, width / 2, border);
|
||||
|
||||
sprintf(buf, NUMFMT, ovmin);
|
||||
MwStringPrintIntoBuffer(buf, sizeof(buf), NUMFMT, ovmin);
|
||||
draw_line(handle, buf, node.x, (r.height - space) - (ovmin - vmin) / (vmax - vmin) * (r.height - space), twidth, width / 2, border);
|
||||
|
||||
p[0].x = node.x;
|
||||
|
|
@ -247,12 +219,21 @@ static void draw(MwWidget handle) {
|
|||
MwLLFreeColor(colorl);
|
||||
MwLLFreeColor(color);
|
||||
}
|
||||
} else if(type == MwCHART_PIE || type == MwCHART_3D_PIE) {
|
||||
}
|
||||
|
||||
static void pie_chart(MwWidget handle, MwRect* _r, const char** colors, int n, MwLLColor border) {
|
||||
int ColorDiff = MwGetColorDifference(handle);
|
||||
MwChart c = handle->internal;
|
||||
double sum = 0;
|
||||
MwRect r = *_r;
|
||||
int radius = r.width < r.height ? r.width : r.height;
|
||||
double cangle = 0;
|
||||
int k;
|
||||
int type = MwGetInteger(handle, MwNtype);
|
||||
int modern = MwGetInteger(handle, MwNmodernLook);
|
||||
double vsquish = type == MwCHART_3D_PIE ? 2 : 1;
|
||||
int i;
|
||||
MwPoint p[2];
|
||||
MwPoint p2[360 + 1 + 1];
|
||||
|
||||
for(i = 0; i < arrlen(c->entries); i++) {
|
||||
|
|
@ -319,7 +300,7 @@ static void draw(MwWidget handle) {
|
|||
} else if(k == 3) {
|
||||
int j;
|
||||
|
||||
p[count] = p2[0];
|
||||
p2[count] = p2[0];
|
||||
for(j = 0; j < count; j++) {
|
||||
if(!modern) MwLLLine(handle->lowlevel, &p2[j], border);
|
||||
}
|
||||
|
|
@ -349,16 +330,25 @@ static void draw(MwWidget handle) {
|
|||
p[0].x = p[1].x = r.width / 2 + radius / 2;
|
||||
MwLLLine(handle->lowlevel, p, border);
|
||||
}
|
||||
} else if(type == MwCHART_LINE) {
|
||||
}
|
||||
|
||||
static void line_chart(MwWidget handle, MwRect* _r, double vmin, double vmax, int space, MwLLColor border) {
|
||||
MwChart c = handle->internal;
|
||||
char buf[128];
|
||||
MwRect node;
|
||||
double twidth;
|
||||
double x = 0;
|
||||
int j;
|
||||
MwPoint p[2];
|
||||
MwRect r = *_r;
|
||||
double ovmin = vmin;
|
||||
double ovmax = vmax;
|
||||
int i;
|
||||
int width;
|
||||
|
||||
for(i = 0; i < arrlen(c->entries); i++) {
|
||||
int w;
|
||||
|
||||
sprintf(buf, NUMFMT, c->entries[i].value);
|
||||
MwStringPrintIntoBuffer(buf, sizeof(buf), NUMFMT, c->entries[i].value);
|
||||
|
||||
w = MwTextWidth(handle, NULL, buf);
|
||||
|
||||
|
|
@ -370,12 +360,12 @@ static void draw(MwWidget handle) {
|
|||
|
||||
CALC_VMIN_VMAX;
|
||||
|
||||
sprintf(buf, NUMFMT, ovmax);
|
||||
MwStringPrintIntoBuffer(buf, sizeof(buf), NUMFMT, ovmax);
|
||||
draw_line(handle, buf, x, (r.height - space) - (ovmax - vmin) / (vmax - vmin) * (r.height - space), twidth, width / 2, border);
|
||||
|
||||
draw_line(handle, "0", x, (r.height - space) - (0 - vmin) / (vmax - vmin) * (r.height - space), twidth, width / 2, border);
|
||||
|
||||
sprintf(buf, NUMFMT, ovmin);
|
||||
MwStringPrintIntoBuffer(buf, sizeof(buf), NUMFMT, ovmin);
|
||||
draw_line(handle, buf, x, (r.height - space) - (ovmin - vmin) / (vmax - vmin) * (r.height - space), twidth, width / 2, border);
|
||||
|
||||
draw_line(handle, "", x, (r.height - space) - (vmin - vmin) / (vmax - vmin) * (r.height - space), twidth, width / 2, border);
|
||||
|
|
@ -388,15 +378,64 @@ static void draw(MwWidget handle) {
|
|||
|
||||
MwLLLine(handle->lowlevel, p, border);
|
||||
|
||||
for(i = 1; i < arrlen(c->entries); i++) {
|
||||
for(j = 0; j < 2; j++) {
|
||||
for(i = j == 0 ? 1 : 0; i < arrlen(c->entries); i++) {
|
||||
p[0].x = x + (r.width - x) / (arrlen(c->entries) + 1) * i;
|
||||
p[0].y = (r.height - space) - (c->entries[i - 1].value - vmin) / (vmax - vmin) * (r.height - space);
|
||||
p[1].x = x + (r.width - x) / (arrlen(c->entries) + 1) * (i + 1);
|
||||
p[1].y = (r.height - space) - (c->entries[i].value - vmin) / (vmax - vmin) * (r.height - space);
|
||||
|
||||
if(j == 0) {
|
||||
MwLLLine(handle->lowlevel, p, border);
|
||||
} else {
|
||||
MwDrawText(handle, NULL, &p[1], c->entries[i].name, MwALIGNMENT_CENTER, border);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void draw(MwWidget handle) {
|
||||
MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground));
|
||||
MwLLColor border = MwParseColor(handle, MwGetText(handle, MwNforeground));
|
||||
MwRect r;
|
||||
MwChart c = handle->internal;
|
||||
int i;
|
||||
const char** colors = palette0;
|
||||
int n;
|
||||
double vmin = 0xffffffff;
|
||||
double vmax = -0xffffffff;
|
||||
int space = MwTextHeight(handle, NULL, "M");
|
||||
int type = MwGetInteger(handle, MwNtype);
|
||||
|
||||
for(n = 0; colors[n] != NULL; n++);
|
||||
|
||||
for(i = 0; i < arrlen(c->entries); i++) {
|
||||
if(vmin > c->entries[i].value) vmin = c->entries[i].value;
|
||||
if(vmax < c->entries[i].value) vmax = c->entries[i].value;
|
||||
}
|
||||
|
||||
if(MwGetInteger(handle, MwNminValue) != MwDEFAULT) vmin = MwGetInteger(handle, MwNminValue);
|
||||
if(MwGetInteger(handle, MwNmaxValue) != MwDEFAULT) vmax = MwGetInteger(handle, MwNmaxValue);
|
||||
|
||||
r.x = 0;
|
||||
r.y = 0;
|
||||
r.width = MwGetInteger(handle, MwNwidth);
|
||||
r.height = MwGetInteger(handle, MwNheight);
|
||||
MwDrawRect(handle, &r, base);
|
||||
|
||||
switch(type) {
|
||||
case MwCHART_BAR:
|
||||
case MwCHART_3D_BAR:
|
||||
bar_chart(handle, &r, vmin, vmax, space, colors, n, border);
|
||||
break;
|
||||
case MwCHART_PIE:
|
||||
case MwCHART_3D_PIE:
|
||||
pie_chart(handle, &r, colors, n, border);
|
||||
break;
|
||||
case MwCHART_LINE:
|
||||
line_chart(handle, &r, vmin, vmax, space, border);
|
||||
break;
|
||||
}
|
||||
|
||||
MwLLFreeColor(border);
|
||||
MwLLFreeColor(base);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue