- /* find grid spaceing */
- pixpex= (double)im->ysize / (log10(im->maxval) - log10(im->minval));
-
- if (isnan(pixpex)) {
- return 0;
- }
-
- for(i=0;yloglab[i][0] > 0;i++){
- minstep = log10(yloglab[i][0]);
- for(ii=1;yloglab[i][ii+1] > 0;ii++){
- if(yloglab[i][ii+2]==0){
- minstep = log10(yloglab[i][ii+1])-log10(yloglab[i][ii]);
- break;
- }
- }
- pixperstep = pixpex * minstep;
- if(pixperstep > 5){minoridx = i;}
- if(pixperstep > 2 * im->text_prop[TEXT_PROP_LEGEND].size){majoridx = i;}
- }
-
- X0=im->xorigin;
- X1=im->xorigin+im->xsize;
- /* paint minor grid */
- for (value = pow((double)10, log10(im->minval)
- - fmod(log10(im->minval),log10(yloglab[minoridx][0])));
- value <= im->maxval;
- value *= yloglab[minoridx][0]){
- if (value < im->minval) continue;
- i=0;
- while(yloglab[minoridx][++i] > 0){
- Y0 = ytr(im,value * yloglab[minoridx][i]);
- if (Y0 <= im->yorigin - im->ysize) break;
- gfx_new_dashed_line ( im->canvas,
- X0-1,Y0,
- X1+1,Y0,
- GRIDWIDTH, im->graph_col[GRC_GRID],
- im->grid_dash_on, im->grid_dash_off);
- }
- }
-
- /* paint major grid and labels*/
- for (value = pow((double)10, log10(im->minval)
- - fmod(log10(im->minval),log10(yloglab[majoridx][0])));
- value <= im->maxval;
- value *= yloglab[majoridx][0]){
- if (value < im->minval) continue;
- i=0;
- while(yloglab[majoridx][++i] > 0){
- Y0 = ytr(im,value * yloglab[majoridx][i]);
- if (Y0 <= im->yorigin - im->ysize) break;
- gfx_new_dashed_line ( im->canvas,
- X0-2,Y0,
- X1+2,Y0,
- MGRIDWIDTH, im->graph_col[GRC_MGRID],
- im->grid_dash_on, im->grid_dash_off);
-
- if (im->extra_flags & FORCE_UNITS_SI) {
- double pvalue = value * yloglab[majoridx][i];
- double scale = floor( log10( fabs(pvalue)) / 3);
- char symbol;
-
- pvalue /= pow(10, 3*scale);
-
- if ( ((scale+si_symbcenter) < sizeof(si_symbol)) &&
- ((scale+si_symbcenter) >= 0) )
- symbol = si_symbol[(int)scale+si_symbcenter];
- else
- symbol = '?';
-
- sprintf(graph_label,"%3.0f %c", pvalue, symbol);
- } else
- sprintf(graph_label,"%3.0e",value * yloglab[majoridx][i]);
-
- gfx_new_text ( im->canvas,
- X0-im->text_prop[TEXT_PROP_AXIS].size, Y0,
- im->graph_col[GRC_FONT],
- im->text_prop[TEXT_PROP_AXIS].font,
- im->text_prop[TEXT_PROP_AXIS].size,
- im->tabwidth,0.0, GFX_H_RIGHT, GFX_V_CENTER,
- graph_label );
- }
- }
- return 1;
+ /* major spacing for less dynamic data */
+ do {
+ /* search best row in yloglab */
+ mid++;
+ for (i = 0; yloglab[mid][i + 1] < 10.0; i++);
+ mspac = logscale * log10(10.0 / yloglab[mid][i]);
+ }
+ while (mspac >
+ 2 * im->text_prop[TEXT_PROP_LEGEND].size && yloglab[mid][0] > 0);
+ if (mid)
+ mid--;
+ /* find first value in yloglab */
+ for (flab = 0;
+ yloglab[mid][flab] < 10
+ && frexp10(im->minval, &tmp) > yloglab[mid][flab]; flab++);
+ if (yloglab[mid][flab] == 10.0) {
+ tmp += 1.0;
+ flab = 0;
+ }
+ val_exp = tmp;
+ if (val_exp % exfrac)
+ val_exp += abs(-val_exp % exfrac);
+ X0 = im->xorigin;
+ X1 = im->xorigin + im->xsize;
+ /* draw grid */
+ pre_value = DNAN;
+ while (1) {
+
+ value = yloglab[mid][flab] * pow(10.0, val_exp);
+ if (AlmostEqual2sComplement(value, pre_value, 4))
+ break; /* it seems we are not converging */
+ pre_value = value;
+ Y0 = ytr(im, value);
+ if (floor(Y0 + 0.5) <= im->yorigin - im->ysize)
+ break;
+ /* major grid line */
+ gfx_line(im,
+ X0 - 2, Y0, X0, Y0, MGRIDWIDTH, im->graph_col[GRC_MGRID]);
+ gfx_line(im, X1, Y0, X1 + 2, Y0,
+ MGRIDWIDTH, im->graph_col[GRC_MGRID]);
+ gfx_dashed_line(im, X0 - 2, Y0,
+ X1 + 2, Y0,
+ MGRIDWIDTH,
+ im->
+ graph_col
+ [GRC_MGRID], im->grid_dash_on, im->grid_dash_off);
+ /* label */
+ if (im->extra_flags & FORCE_UNITS_SI) {
+ int scale;
+ double pvalue;
+ char symbol;
+
+ scale = floor(val_exp / 3.0);
+ if (value >= 1.0)
+ pvalue = pow(10.0, val_exp % 3);
+ else
+ pvalue = pow(10.0, ((val_exp + 1) % 3) + 2);
+ pvalue *= yloglab[mid][flab];
+ if (((scale + si_symbcenter) < (int) sizeof(si_symbol))
+ && ((scale + si_symbcenter) >= 0))
+ symbol = si_symbol[scale + si_symbcenter];
+ else
+ symbol = '?';
+ sprintf(graph_label, "%3.0f %c", pvalue, symbol);
+ } else
+ sprintf(graph_label, "%3.0e", value);
+ gfx_text(im,
+ X0 -
+ im->
+ text_prop[TEXT_PROP_AXIS].
+ size, Y0,
+ im->graph_col[GRC_FONT],
+ im->
+ text_prop[TEXT_PROP_AXIS].
+ font,
+ im->
+ text_prop[TEXT_PROP_AXIS].
+ size, im->tabwidth, 0.0,
+ GFX_H_RIGHT, GFX_V_CENTER, graph_label);
+ /* minor grid */
+ if (mid < 4 && exfrac == 1) {
+ /* find first and last minor line behind current major line
+ * i is the first line and j tha last */
+ if (flab == 0) {
+ min_exp = val_exp - 1;
+ for (i = 1; yloglab[mid][i] < 10.0; i++);
+ i = yloglab[mid][i - 1] + 1;
+ j = 10;
+ } else {
+ min_exp = val_exp;
+ i = yloglab[mid][flab - 1] + 1;
+ j = yloglab[mid][flab];
+ }
+
+ /* draw minor lines below current major line */
+ for (; i < j; i++) {
+
+ value = i * pow(10.0, min_exp);
+ if (value < im->minval)
+ continue;
+ Y0 = ytr(im, value);
+ if (floor(Y0 + 0.5) <= im->yorigin - im->ysize)
+ break;
+ /* draw lines */
+ gfx_line(im,
+ X0 - 2, Y0,
+ X0, Y0, GRIDWIDTH, im->graph_col[GRC_GRID]);
+ gfx_line(im, X1, Y0, X1 + 2, Y0,
+ GRIDWIDTH, im->graph_col[GRC_GRID]);
+ gfx_dashed_line(im, X0 - 1, Y0,
+ X1 + 1, Y0,
+ GRIDWIDTH,
+ im->
+ graph_col[GRC_GRID],
+ im->grid_dash_on, im->grid_dash_off);
+ }
+ } else if (exfrac > 1) {
+ for (i = val_exp - exfrac / 3 * 2; i < val_exp; i += exfrac / 3) {
+ value = pow(10.0, i);
+ if (value < im->minval)
+ continue;
+ Y0 = ytr(im, value);
+ if (floor(Y0 + 0.5) <= im->yorigin - im->ysize)
+ break;
+ /* draw lines */
+ gfx_line(im,
+ X0 - 2, Y0,
+ X0, Y0, GRIDWIDTH, im->graph_col[GRC_GRID]);
+ gfx_line(im, X1, Y0, X1 + 2, Y0,
+ GRIDWIDTH, im->graph_col[GRC_GRID]);
+ gfx_dashed_line(im, X0 - 1, Y0,
+ X1 + 1, Y0,
+ GRIDWIDTH,
+ im->
+ graph_col[GRC_GRID],
+ im->grid_dash_on, im->grid_dash_off);
+ }
+ }
+
+ /* next decade */
+ if (yloglab[mid][++flab] == 10.0) {
+ flab = 0;
+ val_exp += exfrac;
+ }
+ }
+
+ /* draw minor lines after highest major line */
+ if (mid < 4 && exfrac == 1) {
+ /* find first and last minor line below current major line
+ * i is the first line and j tha last */
+ if (flab == 0) {
+ min_exp = val_exp - 1;
+ for (i = 1; yloglab[mid][i] < 10.0; i++);
+ i = yloglab[mid][i - 1] + 1;
+ j = 10;
+ } else {
+ min_exp = val_exp;
+ i = yloglab[mid][flab - 1] + 1;
+ j = yloglab[mid][flab];
+ }
+
+ /* draw minor lines below current major line */
+ for (; i < j; i++) {
+
+ value = i * pow(10.0, min_exp);
+ if (value < im->minval)
+ continue;
+ Y0 = ytr(im, value);
+ if (floor(Y0 + 0.5) <= im->yorigin - im->ysize)
+ break;
+ /* draw lines */
+ gfx_line(im,
+ X0 - 2, Y0, X0, Y0, GRIDWIDTH, im->graph_col[GRC_GRID]);
+ gfx_line(im, X1, Y0, X1 + 2, Y0,
+ GRIDWIDTH, im->graph_col[GRC_GRID]);
+ gfx_dashed_line(im, X0 - 1, Y0,
+ X1 + 1, Y0,
+ GRIDWIDTH,
+ im->
+ graph_col[GRC_GRID],
+ im->grid_dash_on, im->grid_dash_off);
+ }
+ }
+ /* fancy minor gridlines */
+ else if (exfrac > 1) {
+ for (i = val_exp - exfrac / 3 * 2; i < val_exp; i += exfrac / 3) {
+ value = pow(10.0, i);
+ if (value < im->minval)
+ continue;
+ Y0 = ytr(im, value);
+ if (floor(Y0 + 0.5) <= im->yorigin - im->ysize)
+ break;
+ /* draw lines */
+ gfx_line(im,
+ X0 - 2, Y0, X0, Y0, GRIDWIDTH, im->graph_col[GRC_GRID]);
+ gfx_line(im, X1, Y0, X1 + 2, Y0,
+ GRIDWIDTH, im->graph_col[GRC_GRID]);
+ gfx_dashed_line(im, X0 - 1, Y0,
+ X1 + 1, Y0,
+ GRIDWIDTH,
+ im->
+ graph_col[GRC_GRID],
+ im->grid_dash_on, im->grid_dash_off);
+ }
+ }
+
+ return 1;