X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=dygraph.js;h=f82285b73f56fd65f93d25e490545ab6be8b4b71;hb=1f0f434a67305ccb3d54a0bbd16a1b6d9421fffb;hp=3f311f69a464ed5a572c3fa2429a6f8fdaf98f26;hpb=25ca4e1c935157d4ab13aacd1b8dae327fa0b14e;p=dygraphs.git diff --git a/dygraph.js b/dygraph.js index 3f311f6..f82285b 100644 --- a/dygraph.js +++ b/dygraph.js @@ -190,7 +190,7 @@ Dygraph.numberValueFormatter = function(x, opts) { * @private */ Dygraph.numberAxisLabelFormatter = function(x, granularity, opts) { - return Dygraph.numberValueFormatter(x, opts); + return Dygraph.numberValueFormatter.call(this, x, opts); }; /** @@ -322,15 +322,11 @@ Dygraph.DEFAULT_ATTRS = { xLabelHeight: 18, yLabelWidth: 18, - drawXAxis: true, - drawYAxis: true, axisLineColor: "black", axisLineWidth: 0.3, gridLineWidth: 0.3, axisLabelColor: "black", axisLabelWidth: 50, - drawYGrid: true, - drawXGrid: true, gridLineColor: "rgb(128,128,128)", interactionModel: null, // will be set to Dygraph.Interaction.defaultModel @@ -426,7 +422,7 @@ Dygraph.prototype.__init__ = function(div, file, attrs) { // Support two-argument constructor if (attrs === null || attrs === undefined) { attrs = {}; } - attrs = Dygraph.mapLegacyOptions_(attrs); + attrs = Dygraph.copyUserAttrs_(attrs); if (typeof(div) == 'string') { div = document.getElementById(div); @@ -2023,6 +2019,14 @@ Dygraph.prototype.animateSelection_ = function(direction) { var thisId = ++this.animateId; var that = this; + var cleanupIfClearing = function() { + // if we haven't reached fadeLevel 0 in the max frame time, + // ensure that the clear happens and just go to 0 + if (that.fadeLevel !== 0 && direction < 0) { + that.fadeLevel = 0; + that.clearSelection(); + } + }; Dygraph.repeatAndCleanup( function(n) { // ignore simultaneous animations @@ -2035,7 +2039,7 @@ Dygraph.prototype.animateSelection_ = function(direction) { that.updateSelection_(that.fadeLevel / totalSteps); } }, - steps, millis, function() {}); + steps, millis, cleanupIfClearing); }; /** @@ -2046,6 +2050,7 @@ Dygraph.prototype.animateSelection_ = function(direction) { Dygraph.prototype.updateSelection_ = function(opt_animFraction) { /*var defaultPrevented = */ this.cascadeEvents_('select', { + selectedRow: this.lastRow_, selectedX: this.lastx_, selectedPoints: this.selPoints_ }); @@ -3461,9 +3466,9 @@ Dygraph.prototype.start_ = function() { Dygraph.prototype.updateOptions = function(input_attrs, block_redraw) { if (typeof(block_redraw) == 'undefined') block_redraw = false; - // mapLegacyOptions_ drops the "file" parameter as a convenience to us. + // copyUserAttrs_ drops the "file" parameter as a convenience to us. var file = input_attrs.file; - var attrs = Dygraph.mapLegacyOptions_(input_attrs); + var attrs = Dygraph.copyUserAttrs_(input_attrs); // TODO(danvk): this is a mess. Move these options into attr_. if ('rollPeriod' in attrs) { @@ -3512,50 +3517,15 @@ Dygraph.prototype.updateOptions = function(input_attrs, block_redraw) { }; /** - * Returns a copy of the options with deprecated names converted into current - * names. Also drops the (potentially-large) 'file' attribute. If the caller is - * interested in that, they should save a copy before calling this. - * @private + * Make a copy of input attributes, removing file as a convenience. */ -Dygraph.mapLegacyOptions_ = function(attrs) { +Dygraph.copyUserAttrs_ = function(attrs) { var my_attrs = {}; for (var k in attrs) { if (!attrs.hasOwnProperty(k)) continue; if (k == 'file') continue; if (attrs.hasOwnProperty(k)) my_attrs[k] = attrs[k]; } - - var set = function(axis, opt, value) { - if (!my_attrs.axes) my_attrs.axes = {}; - if (!my_attrs.axes[axis]) my_attrs.axes[axis] = {}; - my_attrs.axes[axis][opt] = value; - }; - var map = function(opt, axis, new_opt) { - if (typeof(attrs[opt]) != 'undefined') { - console.warn("Option " + opt + " is deprecated. Use the " + - new_opt + " option for the " + axis + " axis instead. " + - "(e.g. { axes : { " + axis + " : { " + new_opt + " : ... } } } " + - "(see http://dygraphs.com/per-axis.html for more information."); - set(axis, new_opt, attrs[opt]); - delete my_attrs[opt]; - } - }; - - // This maps, e.g., xValueFormater -> axes: { x: { valueFormatter: ... } } - map('xValueFormatter', 'x', 'valueFormatter'); - map('pixelsPerXLabel', 'x', 'pixelsPerLabel'); - map('xAxisLabelFormatter', 'x', 'axisLabelFormatter'); - map('xTicker', 'x', 'ticker'); - map('yValueFormatter', 'y', 'valueFormatter'); - map('pixelsPerYLabel', 'y', 'pixelsPerLabel'); - map('yAxisLabelFormatter', 'y', 'axisLabelFormatter'); - map('yTicker', 'y', 'ticker'); - map('drawXGrid', 'x', 'drawGrid'); - map('drawXAxis', 'x', 'drawAxis'); - map('drawYGrid', 'y', 'drawGrid'); - map('drawYAxis', 'y', 'drawAxis'); - map('xAxisLabelWidth', 'x', 'axisLabelWidth'); - map('yAxisLabelWidth', 'y', 'axisLabelWidth'); return my_attrs; }; @@ -3632,19 +3602,25 @@ Dygraph.prototype.visibility = function() { }; /** - * Changes the visiblity of a series. + * Changes the visibility of one or more series. * - * @param {number} num the series index + * @param {number|number[]} num the series index or an array of series indices * @param {boolean} value true or false, identifying the visibility. */ Dygraph.prototype.setVisibility = function(num, value) { var x = this.visibility(); - if (num < 0 || num >= x.length) { - console.warn("invalid series number in setVisibility: " + num); - } else { - x[num] = value; - this.predraw_(); + + if (num.constructor !== Array) num = [num]; + + for (var i = 0; i < num.length; i++) { + if (num[i] < 0 || num[i] >= x.length) { + console.warn("invalid series number in setVisibility: " + num[i]); + } else { + x[num[i]] = value; + } } + + this.predraw_(); }; /** @@ -3707,6 +3683,35 @@ Dygraph.prototype.indexFromSetName = function(name) { }; /** + * Find the row number corresponding to the given x-value. + * Returns null if there is no such x-value in the data. + * If there are multiple rows with the same x-value, this will return the + * first one. + * @param {number} xVal The x-value to look for (e.g. millis since epoch). + * @return {?number} The row number, which you can pass to getValue(), or null. + */ +Dygraph.prototype.getRowForX = function(xVal) { + var low = 0, + high = this.numRows() - 1; + + while (low <= high) { + var idx = (high + low) >> 1; + var x = this.getValue(idx, 0); + if (x < xVal) { + low = idx + 1; + } else if (x > xVal) { + high = idx - 1; + } else if (low != idx) { // equal, but there may be an earlier match. + high = idx; + } else { + return idx; + } + } + + return null; +}; + +/** * Trigger a callback when the dygraph has drawn itself and is ready to be * manipulated. This is primarily useful when dygraphs has to do an XHR for the * data (i.e. a URL is passed as the data source) and the chart is drawn