Commits

cleonello  committed 59c0e46

Update to replot method to allow passing in axes options so can control which axes parameters are reset. Update to example.

  • Participants
  • Parent commits 2735e35

Comments (0)

Files changed (2)

File examples/canvasOverlay.html

 				objects: [
 					{horizontalLine: {
 						name: 'barney',
-						y: 4,
+						y: 14,
 						lineWidth: 6,
 						color: 'rgb(100, 55, 124)',
 						shadow: false
 					}},
 					{horizontalLine: {
 						name: 'fred',
-						y: 8,
+						y: 10,
 						lineWidth: 12,
 						xminOffset: '8px',
 						xmaxOffset: '29px',
 					}},
 					{horizontalLine: {
 						name: 'wilma',
-						y: 11,
+						y: 7,
 						lineWidth: 2,
-						xOffset: '44',
+						xOffset: '54',
 						color: 'rgb(133, 120, 24)',
 						shadow: false
 					}},
 		var co = plot1.plugins.canvasOverlay;
 		var line = co.get('barney');
 		line.options.y += 0.5;
-		co.draw(plot1);
+		if (line.options.y >= plot1.axes.yaxis.max) {
+			var newmax = plot1.axes.yaxis.max + 4;
+			plot1.replot({resetAxes:['yaxis'], axes:{yaxis:{max:newmax}}});
+		}
+		else {
+			co.draw(plot1);
+		}
 	}
 	
 	function linedown() {

File src/jqplot.core.js

         this.renderer.reset.call(this);
     };
     
-    Axis.prototype.resetScale = function() {
-        this.min = null;
-        this.max = null;
-        this.numberTicks = null;
-        this.tickInterval = null;
-		this._ticks = [];
-		this.ticks = [];
+    Axis.prototype.resetScale = function(opts) {
+		$.extend(true, this, {min: null, max: null, numberTicks: null, tickInterval: null, _ticks: [], ticks: []}, opts);
 		this.resetDataBounds();
     };
 	
         //
         // Parameters:
         // axes - Boolean to reset or not reset all axes or an array or object of axis names to reset.
-        this.resetAxesScale = function(axes) {
-            var ax = (axes != undefined) ? axes : this.axes;
+        this.resetAxesScale = function(axes, options) {
+			var opts = options || {};
+            var ax = axes || this.axes;
             if (ax === true) {
                 ax = this.axes;
             }
             if (jQuery.isArray(ax)) {
                 for (var i = 0; i < ax.length; i++) {
-                    this.axes[ax[i]].resetScale();
+                    this.axes[ax[i]].resetScale(opts[ax[i]]);
                 }
             }
             else if (typeof(ax) === 'object') {
                 for (var name in ax) {
-                    this.axes[name].resetScale();
+                    this.axes[name].resetScale(opts[name]);
                 }
             }
         };
         // resetAxes - true to reset all axes min, max, numberTicks and tickInterval setting so axes will rescale themselves.
         //             optionally pass in list of axes to reset (e.g. ['xaxis', 'y2axis']) (default: false).
         this.replot = function(options) {
-            var opts = (options != undefined) ? options : {};
-            var clear = (opts.clear != undefined) ? opts.clear : true;
-            var resetAxes = (opts.resetAxes != undefined) ? opts.resetAxes : false;
+            var opts =  options || {};
+            var clear = opts.clear || true;
+            var resetAxes = opts.resetAxes || false;
             this.target.trigger('jqplotPreReplot');
             if (clear) {
             	// Couple of posts on Stack Overflow indicate that empty() doesn't
                 this.target.empty();
             }
             if (resetAxes) {
-                this.resetAxesScale(resetAxes);
+                this.resetAxesScale(resetAxes, opts.axes);
             }
             this.reInitialize();
             this.draw();