X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=dygraph.js;h=19eccb24d7ee3cba5b2cffeafb8a66d5a18442aa;hb=bc7f1c971ee069c9d6621244c8ca7e6471040a30;hp=623acf7eee157d2f9774d4bb424709b5c9047799;hpb=e5152598cf72fb46c396f79edebc68e9fb4fec73;p=dygraphs.git diff --git a/dygraph.js b/dygraph.js index 623acf7..19eccb2 100644 --- a/dygraph.js +++ b/dygraph.js @@ -193,6 +193,11 @@ Dygraph.DEFAULT_ATTRS = { stepPlot: false, avoidMinZero: false, + // Sizes of the various chart labels. + titleHeight: 28, + xLabelHeight: 18, + yLabelWidth: 18, + interactionModel: null // will be set to Dygraph.defaultInteractionModel. }; @@ -959,8 +964,9 @@ Dygraph.prototype.createStatusMessage_ = function() { }; /** - * Position the labels div so that its right edge is flush with the right edge - * of the charting area. + * Position the labels div so that: + * - its right edge is flush with the right edge of the charting area + * - its top edge is flush with the top edge of the charting area */ Dygraph.prototype.positionLabelsDiv_ = function() { // Don't touch a user-specified labelsDiv. @@ -969,6 +975,7 @@ Dygraph.prototype.positionLabelsDiv_ = function() { var area = this.plotter_.area; var div = this.attr_("labelsDiv"); div.style.left = area.x + area.w - this.attr_("labelsDivWidth") - 1 + "px"; + div.style.top = area.y + "px"; }; /** @@ -986,10 +993,11 @@ Dygraph.prototype.createRollInterface_ = function() { var display = this.attr_('showRoller') ? 'block' : 'none'; + var area = this.plotter_.area; var textAttr = { "position": "absolute", "zIndex": 10, - "top": (this.plotter_.area.h - 25) + "px", - "left": (this.plotter_.area.x + 1) + "px", + "top": (area.y + area.h - 25) + "px", + "left": (area.x + 1) + "px", "display": display }; this.roller_.size = "2"; @@ -2112,7 +2120,7 @@ Dygraph.prototype.GetXAxis = function(start_time, end_time, granularity) { if (i % year_mod != 0) continue; for (var j = 0; j < months.length; j++) { var date_str = i + "/" + zeropad(1 + months[j]) + "/01"; - var t = Date.parse(date_str); + var t = Dygraph.dateStrToMillis(date_str); if (t < start_time || t > end_time) continue; ticks.push({ v:t, label: formatter(new Date(t), granularity) }); } @@ -2601,13 +2609,10 @@ Dygraph.prototype.drawGraph_ = function() { this.layout_.addDataset(this.attr_("labels")[i], datasets[i]); } - if (datasets.length > 0) { - // TODO(danvk): this method doesn't need to return anything. - this.computeYAxisRanges_(extremes); - this.layout_.updateOptions( { yAxes: this.axes_, - seriesToAxisMap: this.seriesToAxisMap_ - } ); - } + this.computeYAxisRanges_(extremes); + this.layout_.updateOptions( { yAxes: this.axes_, + seriesToAxisMap: this.seriesToAxisMap_ + } ); this.addXTicks_(); // Save the X axis zoomed status as the updateOptions call will tend to set it errorneously @@ -2765,25 +2770,14 @@ Dygraph.prototype.computeYAxisRanges_ = function(extremes) { seriesForAxis[idx].push(series); } - // If no series are defined or visible then fill in some reasonable defaults. - if (seriesForAxis.length == 0) { - var axis = this.axes_[0]; - axis.computedValueRange = [0, 1]; - var ret = - Dygraph.numericTicks(axis.computedValueRange[0], - axis.computedValueRange[1], - this, - axis); - axis.ticks = ret.ticks; - this.numYDigits_ = ret.numDigits; - return; - } - // Compute extreme values, a span and tick marks for each axis. for (var i = 0; i < this.axes_.length; i++) { var axis = this.axes_[i]; - { + if (!seriesForAxis[i]) { + // If no series are defined or visible then use a reasonable default + axis.extremeRange = [0, 1]; + } else { // Calculate the extremes of extremes. var series = seriesForAxis[i]; var minY = Infinity; // extremes[series[0]][0]; @@ -2793,23 +2787,18 @@ Dygraph.prototype.computeYAxisRanges_ = function(extremes) { // Only use valid extremes to stop null data series' from corrupting the scale. extremeMinY = extremes[series[j]][0]; if (extremeMinY != null) { - minY = Math.min(extremeMinY, minY); + minY = Math.min(extremeMinY, minY); } extremeMaxY = extremes[series[j]][1]; if (extremeMaxY != null) { - maxY = Math.max(extremeMaxY, maxY); + maxY = Math.max(extremeMaxY, maxY); } } if (axis.includeZero && minY > 0) minY = 0; // Ensure we have a valid scale, otherwise defualt to zero for safety. - if (minY == Infinity) { - minY = 0; - } - - if (maxY == -Infinity) { - maxY = 0; - } + if (minY == Infinity) minY = 0; + if (maxY == -Infinity) maxY = 0; // Add some padding and round up to an integer to be human-friendly. var span = maxY - minY; @@ -3035,16 +3024,16 @@ Dygraph.dateParser = function(dateStr, self) { while (dateStrSlashed.search("-") != -1) { dateStrSlashed = dateStrSlashed.replace("-", "/"); } - d = Date.parse(dateStrSlashed); + d = Dygraph.dateStrToMillis(dateStrSlashed); } else if (dateStr.length == 8) { // e.g. '20090712' // TODO(danvk): remove support for this format. It's confusing. dateStrSlashed = dateStr.substr(0,4) + "/" + dateStr.substr(4,2) + "/" + dateStr.substr(6,2); - d = Date.parse(dateStrSlashed); + d = Dygraph.dateStrToMillis(dateStrSlashed); } else { // Any format that Date.parse will accept, e.g. "2009/07/12" or // "2009/07/12 12:34:56" - d = Date.parse(dateStr); + d = Dygraph.dateStrToMillis(dateStr); } if (!d || isNaN(d)) { @@ -3431,6 +3420,13 @@ Dygraph.prototype.parseDataTable_ = function(data) { } } +// This is identical to JavaScript's built-in Date.parse() method, except that +// it doesn't get replaced with an incompatible method by aggressive JS +// libraries like MooTools or Joomla. +Dygraph.dateStrToMillis = function(str) { + return new Date(str).getTime(); +}; + // These functions are all based on MochiKit. Dygraph.update = function (self, o) { if (typeof(o) != 'undefined' && o !== null) { @@ -3526,11 +3522,6 @@ Dygraph.prototype.start_ = function() { *
dateWindow
or valueRange
options, the zoom flags are not changed to reflect a zoomed state. This is primarily useful for when the display area of a chart is changed programmatically and also where manual zooming is allowed and use is made of the isZoomed
method to determine this."
+ "description" : "When this option is passed to updateOptions() along with either the dateWindow
or valueRange
options, the zoom flags are not changed to reflect a zoomed state. This is primarily useful for when the display area of a chart is changed programmatically and also where manual zooming is allowed and use is made of the isZoomed
method to determine this."
}
}
; //