Commits

Anonymous committed ff514ba

Added minor tick support to linear axis when used with default CanvasGridRenderer.

Comments (0)

Files changed (3)

src/jqplot.canvasGridRenderer.js

                         switch (name) {
                             case 'xaxis':
                                 // draw the grid line if we should
-                                if (t.showGridline && this.drawGridlines) {
+                                if (t.showGridline && this.drawGridlines && ((!t.isMinorTick && axis.drawMajorGridlines) || (t.isMinorTick && axis.drawMinorGridlines)) ) {
                                     drawLine(pos, this._top, pos, this._bottom);
                                 }
                                 // draw the mark
-                                if (t.showMark && t.mark) {
+                                if (t.showMark && t.mark && ((!t.isMinorTick && axis.drawMajorTickMarks) || (t.isMinorTick && axis.drawMinorTickMarks)) ) {
                                     s = t.markSize;
                                     m = t.mark;
                                     var pos = Math.round(axis.u2p(t.value)) + 0.5;
                                 break;
                             case 'yaxis':
                                 // draw the grid line
-                                if (t.showGridline && this.drawGridlines) {
+                                if (t.showGridline && this.drawGridlines && ((!t.isMinorTick && axis.drawMajorGridlines) || (t.isMinorTick && axis.drawMinorGridlines)) ) {
                                     drawLine(this._right, pos, this._left, pos);
                                 }
                                 // draw the mark
-                                if (t.showMark && t.mark) {
+                                if (t.showMark && t.mark && ((!t.isMinorTick && axis.drawMajorTickMarks) || (t.isMinorTick && axis.drawMinorTickMarks)) ) {
                                     s = t.markSize;
                                     m = t.mark;
                                     var pos = Math.round(axis.u2p(t.value)) + 0.5;
                                 break;
                             case 'x2axis':
                                 // draw the grid line
-                                if (t.showGridline && this.drawGridlines) {
+                                if (t.showGridline && this.drawGridlines && ((!t.isMinorTick && axis.drawMajorGridlines) || (t.isMinorTick && axis.drawMinorGridlines)) ) {
                                     drawLine(pos, this._bottom, pos, this._top);
                                 }
                                 // draw the mark
-                                if (t.showMark && t.mark) {
+                                if (t.showMark && t.mark && ((!t.isMinorTick && axis.drawMajorTickMarks) || (t.isMinorTick && axis.drawMinorTickMarks)) ) {
                                     s = t.markSize;
                                     m = t.mark;
                                     var pos = Math.round(axis.u2p(t.value)) + 0.5;
                                 break;
                             case 'y2axis':
                                 // draw the grid line
-                                if (t.showGridline && this.drawGridlines) {
+                                if (t.showGridline && this.drawGridlines && ((!t.isMinorTick && axis.drawMajorGridlines) || (t.isMinorTick && axis.drawMinorGridlines)) ) {
                                     drawLine(this._left, pos, this._right, pos);
                                 }
                                 // draw the mark
-                                if (t.showMark && t.mark) {
+                                if (t.showMark && t.mark && ((!t.isMinorTick && axis.drawMajorTickMarks) || (t.isMinorTick && axis.drawMinorTickMarks)) ) {
                                     s = t.markSize;
                                     m = t.mark;
                                     var pos = Math.round(axis.u2p(t.value)) + 0.5;

src/jqplot.core.js

         this.showLabel = true;
         // prop: min
         // minimum value of the axis (in data units, not pixels).
-        this.min=null;
+        this.min = null;
         // prop: max
         // maximum value of the axis (in data units, not pixels).
-        this.max=null;
+        this.max = null;
         // prop: autoscale
         // DEPRECATED
         // the default scaling algorithm produces superior results.
         this.showTickMarks = true;
         // prop: showMinorTicks
         // Wether or not to show minor ticks.  This is renderer dependent.
-        // The default <$.jqplot.LinearAxisRenderer> does not have minor ticks.
         this.showMinorTicks = true;
+        // prop: drawMajorGridlines
+        // True to draw gridlines for major axis ticks.
+        this.drawMajorGridlines = true;
+        // prop: drawMinorGridlines
+        // True to draw gridlines for minor ticks.
+        this.drawMinorGridlines = false;
+        // prop: drawMajorTickMarks
+        // True to draw tick marks for major axis ticks.
+        this.drawMajorTickMarks = true;
+        // prop: drawMinorTickMarks
+        // True to draw tick marks for minor ticks.  This is renderer dependent.
+        this.drawMinorTickMarks = true;
         // prop: useSeriesColor
         // Use the color of the first series associated with this axis for the
         // tick marks and line bordering this axis.

src/jqplot.linearAxisRenderer.js

         // 0 is no inset, 0.5 is one half a tick interval, 1 is a full
         // tick interval, etc.
         this.tickInset = 0;
+        // prop: minorTicks
+        // Number of ticks to add between "major" ticks.
+        // Major ticks are ticks supplied by user or auto computed.
+        // Minor ticks cannot be created by user.
+        this.minorTicks = 0;
         this._autoFormatString = '';
         this._overrideFormatString = false;
         $.extend(true, this, options);
                 this.tickOptions.formatString = this._autoFormatString;
             }
 
+            var t, to;
             for (var i=0; i<this.numberTicks; i++){
                 tt = this.min + i * this.tickInterval;
-                var t = new this.tickRenderer(this.tickOptions);
+                t = new this.tickRenderer(this.tickOptions);
                 // var t = new $.jqplot.AxisTickRenderer(this.tickOptions);
 
                 t.setTick(tt, this.name);
                 this._ticks.push(t);
+
+                if (i < this.numberTicks - 1) {
+                    for (var j=0; j<this.minorTicks; j++) {
+                        tt += this.tickInterval/(this.minorTicks+1);
+                        to = $.extend(true, {}, this.tickOptions, {name:this.name, value:tt, label:'', isMinorTick:true});
+                        t = new this.tickRenderer(to);
+                        this._ticks.push(t);
+                    }
+                }
                 t = null;
             }
         }