X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=dygraph.js;h=a266af05403128bd6c1bd36d5137067a4a395f01;hb=c1dbeb10b48e0f805be2cef09efebf5e35218c1a;hp=929a9ea09212457d2a2d234b0fea5b8741d14d41;hpb=de0445fc1b969ab85a3d985dbd1e6747f3ddac0b;p=dygraphs.git
diff --git a/dygraph.js b/dygraph.js
index 929a9ea..a266af0 100644
--- a/dygraph.js
+++ b/dygraph.js
@@ -126,7 +126,8 @@ Dygraph.DEFAULT_ATTRS = {
stackedGraph: false,
hideOverlayOnMouseOut: true,
- stepPlot: false
+ stepPlot: false,
+ avoidMinZero: false
};
// Various logging levels.
@@ -171,7 +172,6 @@ Dygraph.prototype.__init__ = function(div, file, attrs) {
this.previousVerticalX_ = -1;
this.fractions_ = attrs.fractions || false;
this.dateWindow_ = attrs.dateWindow || null;
- this.valueRange_ = attrs.valueRange || null;
this.wilsonInterval_ = attrs.wilsonInterval || true;
this.is_initial_draw_ = true;
this.annotations_ = [];
@@ -232,20 +232,18 @@ Dygraph.prototype.__init__ = function(div, file, attrs) {
// Make a note of whether labels will be pulled from the CSV file.
this.labelsFromCSV_ = (this.attr_("labels") == null);
- Dygraph.addAnnotationRule();
-
// Create the containing DIV and other interactive elements
this.createInterface_();
this.start_();
};
-Dygraph.prototype.attr_ = function(name, series) {
- if (series &&
- typeof(this.user_attrs_[series]) != 'undefined' &&
- this.user_attrs_[series] != null &&
- typeof(this.user_attrs_[series][name]) != 'undefined') {
- return this.user_attrs_[series][name];
+Dygraph.prototype.attr_ = function(name, seriesName) {
+ if (seriesName &&
+ typeof(this.user_attrs_[seriesName]) != 'undefined' &&
+ this.user_attrs_[seriesName] != null &&
+ typeof(this.user_attrs_[seriesName][name]) != 'undefined') {
+ return this.user_attrs_[seriesName][name];
} else if (typeof(this.user_attrs_[name]) != 'undefined') {
return this.user_attrs_[name];
} else if (typeof(this.attrs_[name]) != 'undefined') {
@@ -395,13 +393,6 @@ Dygraph.addEvent = function(el, evt, fn) {
}
};
-Dygraph.clipCanvas_ = function(cnv, clip) {
- var ctx = cnv.getContext("2d");
- ctx.beginPath();
- ctx.rect(clip.left, clip.top, clip.width, clip.height);
- ctx.clip();
-};
-
/**
* Generates interface elements for the Dygraph: a containing div, a div to
* display the current point, and a textbox to adjust the rolling average
@@ -417,15 +408,6 @@ Dygraph.prototype.createInterface_ = function() {
this.graphDiv.style.height = this.height_ + "px";
enclosing.appendChild(this.graphDiv);
- var clip = {
- top: 0,
- left: this.attr_("yAxisLabelWidth") + 2 * this.attr_("axisTickSize")
- };
- clip.width = this.width_ - clip.left - this.attr_("rightGap");
- clip.height = this.height_ - this.attr_("axisLabelFontSize")
- - 2 * this.attr_("axisTickSize");
- this.clippingArea_ = clip;
-
// Create the canvas for interactive parts of the chart.
this.canvas_ = Dygraph.createCanvas();
this.canvas_.style.position = "absolute";
@@ -442,10 +424,6 @@ Dygraph.prototype.createInterface_ = function() {
this.graphDiv.appendChild(this.canvas_);
this.mouseEventElement_ = this.canvas_;
- // Make sure we don't overdraw.
- Dygraph.clipCanvas_(this.hidden_, this.clippingArea_);
- Dygraph.clipCanvas_(this.canvas_, this.clippingArea_);
-
var dygraph = this;
Dygraph.addEvent(this.mouseEventElement_, 'mousemove', function(e) {
dygraph.mouseMove_(e);
@@ -470,12 +448,8 @@ Dygraph.prototype.createInterface_ = function() {
axisLineWidth: Dygraph.AXIS_LINE_WIDTH };
Dygraph.update(this.renderOptions_, this.attrs_);
Dygraph.update(this.renderOptions_, this.user_attrs_);
- this.plotter_ = new DygraphCanvasRenderer(this,
- this.hidden_, this.layout_,
- this.renderOptions_);
this.createStatusMessage_();
- this.createRollInterface_();
this.createDragInterface_();
};
@@ -686,6 +660,9 @@ Dygraph.prototype.createStatusMessage_ = function() {
* @private
*/
Dygraph.prototype.createRollInterface_ = function() {
+ // Destroy any existing roller.
+ if (this.roller_) this.graphDiv.removeChild(this.roller_);
+
var display = this.attr_('showRoller') ? "block" : "none";
var textAttr = { "position": "absolute",
"zIndex": 10,
@@ -778,7 +755,7 @@ Dygraph.prototype.createDragInterface_ = function() {
self.dateWindow_[0] = draggingDate - (dragEndX / self.width_) * dateRange;
self.dateWindow_[1] = self.dateWindow_[0] + dateRange;
- self.drawGraph_(self.rawData_);
+ self.drawGraph_();
}
});
@@ -886,7 +863,7 @@ Dygraph.prototype.createDragInterface_ = function() {
Dygraph.addEvent(this.mouseEventElement_, 'dblclick', function(event) {
if (self.dateWindow_ == null) return;
self.dateWindow_ = null;
- self.drawGraph_(self.rawData_);
+ self.drawGraph_();
var minDate = self.rawData_[0][0];
var maxDate = self.rawData_[self.rawData_.length - 1][0];
if (self.attr_("zoomCallback")) {
@@ -940,7 +917,7 @@ Dygraph.prototype.doZoom_ = function(lowX, highX) {
var maxDate = r[0];
this.dateWindow_ = [minDate, maxDate];
- this.drawGraph_(this.rawData_);
+ this.drawGraph_();
if (this.attr_("zoomCallback")) {
this.attr_("zoomCallback")(minDate, maxDate);
}
@@ -1026,9 +1003,9 @@ Dygraph.prototype.updateSelection_ = function() {
if (this.previousVerticalX_ >= 0) {
// Determine the maximum highlight circle size.
var maxCircleSize = 0;
- var num_series = this.attr_('labels').length;
- for (var i = 1; i < num_series; i++) {
- var r = this.attr_('highlightCircleSize', i);
+ var labels = this.attr_('labels');
+ for (var i = 1; i < labels.length; i++) {
+ var r = this.attr_('highlightCircleSize', labels[i]);
if (r > maxCircleSize) maxCircleSize = r;
}
var px = this.previousVerticalX_;
@@ -1055,7 +1032,7 @@ Dygraph.prototype.updateSelection_ = function() {
replace += "
";
}
var point = this.selPoints_[i];
- var c = new RGBColor(this.colors_[i%clen]);
+ var c = new RGBColor(this.plotter_.colors[point.name]);
var yval = fmtFunc(point.yval);
replace += " "
+ point.name + ":"
@@ -1069,8 +1046,8 @@ Dygraph.prototype.updateSelection_ = function() {
ctx.save();
for (var i = 0; i < this.selPoints_.length; i++) {
if (!isOK(this.selPoints_[i].canvasy)) continue;
- var setIdx = this.indexFromSetName(this.selPoints_[i].name);
- var circleSize = this.attr_('highlightCircleSize', setIdx);
+ var circleSize =
+ this.attr_('highlightCircleSize', this.selPoints_[i].name);
ctx.beginPath();
ctx.fillStyle = this.plotter_.colors[this.selPoints_[i].name];
ctx.arc(canvasx, this.selPoints_[i].canvasy, circleSize,
@@ -1101,7 +1078,13 @@ Dygraph.prototype.setSelection = function(row) {
if (row !== false && row >= 0) {
for (var i in this.layout_.datasets) {
if (row < this.layout_.datasets[i].length) {
- this.selPoints_.push(this.layout_.points[pos+row]);
+ var point = this.layout_.points[pos+row];
+
+ if (this.attr_("stackedGraph")) {
+ point = this.layout_.unstackPointAtIndex(pos+row);
+ }
+
+ this.selPoints_.push(point);
}
pos += this.layout_.datasets[i].length;
}
@@ -1249,7 +1232,7 @@ Dygraph.round_ = function(num, places) {
*/
Dygraph.prototype.loadedEvent_ = function(data) {
this.rawData_ = this.parseCSV_(data);
- this.drawGraph_(this.rawData_);
+ this.predraw_();
};
Dygraph.prototype.months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
@@ -1452,62 +1435,86 @@ Dygraph.dateTicker = function(startDate, endDate, self) {
* Add ticks when the x axis has numbers on it (instead of dates)
* @param {Number} startDate Start of the date window (millis since epoch)
* @param {Number} endDate End of the date window (millis since epoch)
+ * @param self
+ * @param {function} attribute accessor function.
* @return {Array.