markrcote / flot-tickrotor

Flot plugin to display angled X-axis tick labels. This repo is unmaintained in part due to flot being in a similar situation.
23 stars 39 forks source link

Vertical grid lines not displaying when tick labels are rotated. #11

Open dshenderson opened 10 years ago

dshenderson commented 10 years ago

When labels are rotated, the vertical grid lines for the ticks are not rendered on the chart. I believe this is because of opts.ticks = []; on line 77.

dshenderson commented 10 years ago

Since the original ticks are preserved in xaxis.rotatedTicks = ticks; on line 76, wouldn't it be possible to patch flot to check for the existence of xaxis.rotatedTicks in order to draw the vertical lines?

dshenderson commented 10 years ago

I have patched my copy flot as follows, which seems to take care of the issue:

/jquery.flot.js
Index: assets/javascript/lib/jquery/plugins/flot/jquery.flot.js
===================================================================
--- assets/javascript/lib/jquery/plugins/flot/jquery.flot.js    (revision 13829)
+++ assets/javascript/lib/jquery/plugins/flot/jquery.flot.js    (working copy)
@@ -2030,8 +2030,9 @@

             for (var j = 0; j < axes.length; ++j) {
                 var axis = axes[j], box = axis.box,
-                    t = axis.tickLength, x, y, xoff, yoff;
-                if (!axis.show || axis.ticks.length == 0)
+                    t = axis.tickLength, x, y, xoff, yoff,
+                    rTicks = axis.rotatedTicks || axis.ticks;
+                if (!axis.show || rTicks.length == 0)
                     continue;

                 ctx.lineWidth = 1;
@@ -2080,8 +2081,8 @@
                 ctx.strokeStyle = axis.options.tickColor;

                 ctx.beginPath();
-                for (i = 0; i < axis.ticks.length; ++i) {
-                    var v = axis.ticks[i].v;
+                for (i = 0; i < rTicks.length; ++i) {
+                    var v = rTicks[i].v;

                     xoff = yoff = 0;`
PlippiePlop commented 10 years ago

Seems to fix the issue.

waldofe commented 8 years ago

+1 also worked for me.

hobwell commented 6 years ago

+1 still works.