diff --git a/src/frontend/plotting/grid.c b/src/frontend/plotting/grid.c index aaeb3b829..52d4b6073 100644 --- a/src/frontend/plotting/grid.c +++ b/src/frontend/plotting/grid.c @@ -706,7 +706,7 @@ drawlingrid(GRAPH *graph, char *units, int spacing, int nsp, double dst, double j = (int)m; if (j == 0) SetLinestyle(0); - if (graph->grid.gridtype != GRID_NONE) { + if (graph->grid.gridtype != GRID_NONE && graph->grid.gridtype != GRID_DIGITAL_NONE) { if (axis == x_axis) DevDrawLine(graph->viewportxoff + i, graph->viewportyoff, graph->viewportxoff + i, @@ -726,7 +726,7 @@ drawlingrid(GRAPH *graph, char *units, int spacing, int nsp, double dst, double DevDrawText(buf, graph->viewportxoff + i - ((int) strlen(buf) * graph->fontwidth) / 2, (int) (graph->fontheight * 2.5), 0); - else + else if (graph->grid.gridtype != GRID_DIGITAL && graph->grid.gridtype != GRID_DIGITAL_NONE) DevDrawText(buf, graph->viewportxoff - 2 - graph->fontwidth * (int) strlen(buf), graph->viewportyoff + i - @@ -736,10 +736,12 @@ drawlingrid(GRAPH *graph, char *units, int spacing, int nsp, double dst, double if (nsp == 1) j += 1000; } + /* the x axis unit (bottom right) and the y axis unit (upper left) */ if (!graph->nounits) { if (axis == x_axis) DevDrawText(units, (int)(graph->absolute.width * RELPOSXUNIT + unitshift), graph->fontheight, 0); - else + /* y axis unit only when no digitop plot */ + else if (graph->grid.gridtype != GRID_DIGITAL && graph->grid.gridtype != GRID_DIGITAL_NONE) DevDrawText(units, graph->fontwidth, (int)(graph->absolute.height - 2 * graph->fontheight), 0); } diff --git a/src/frontend/plotting/plotit.c b/src/frontend/plotting/plotit.c index 44b9e9551..5d4d245bf 100644 --- a/src/frontend/plotting/plotit.c +++ b/src/frontend/plotting/plotit.c @@ -852,29 +852,43 @@ bool plotit(wordlist *wl, const char *hcopy, const char *devname) } } - /* Add n * spacing (e.g. 1.3) to digital event node based vectors */ + /* Add n * spacing (e.g. 1.5) to digital event node based vectors */ if (digitop) { double spacing = 1.5; double nn = 0.; - int ii = 0; + int ii = 0, jj = 0; + for (d = vecs; d; d = d->v_link2) { if (d->v_scale && eq(d->v_scale->v_name, "step") && (d->v_scale->v_type == SV_TIME) && (d->v_type == SV_VOLTAGE) && (d->v_length > 1)) { for (ii = 0; ii < d->v_length; ii++) { d->v_realdata[ii] += nn; } nn += spacing; + jj++ ; } } if (!ydelta) ydelta = TMALLOC(double, 1); *ydelta = spacing; + /* new plot */ if (!ylim) { ylim = TMALLOC(double, 2); ylim[0] = 0; - ylim[1] = nn; + /* make ylim[1] a multiple of 2*1.5 */ + if (jj % 2 == 0) + ylim[1] = nn; + else + ylim[1] = nn + 1.5; } + /* re-scaled plot */ else { - if (ylim[0] < 1.5) + /* just figure out that ylim[0] < ylim[1] */ + if (ylim[0] > ylim[1]) { + double interm = ylim[1]; + ylim[1] = ylim[0]; + ylim[0] = interm; + } + if (ylim[0] < 1.1) /* catch the bottom line */ ylim[0] = 0; else @@ -882,6 +896,11 @@ bool plotit(wordlist *wl, const char *hcopy, const char *devname) ylim[0] = ((int)(ylim[0] / spacing) + 1) * spacing; ylim[1] = ((int)(ylim[1] / spacing) + 1) * spacing; } + /* suppress y labeling */ + if (gtype == GRID_NONE) + gtype = GRID_DIGITAL_NONE; + else + gtype = GRID_DIGITAL; } /* If there are higher dimensional vectors, transform them into a diff --git a/src/include/ngspice/grid.h b/src/include/ngspice/grid.h index ffe44ffe4..ab7d6fb7b 100644 --- a/src/include/ngspice/grid.h +++ b/src/include/ngspice/grid.h @@ -7,8 +7,9 @@ Note: SMITHGRID is only a smith grid, SMITH transforms the data */ typedef enum { - GRID_NONE, GRID_LIN, GRID_LOGLOG, GRID_XLOG, - GRID_YLOG, GRID_POLAR, GRID_SMITH, GRID_SMITHGRID + GRID_NONE, GRID_LIN, GRID_LOGLOG, GRID_XLOG, GRID_YLOG, + GRID_POLAR, GRID_SMITH, GRID_SMITHGRID, GRID_DIGITAL_NONE, + GRID_DIGITAL } GRIDTYPE; void gr_fixgrid(GRAPH *graph, double xdelta, double ydelta, int xtype, int ytype);