X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;ds=sidebyside;f=dygraph.js;h=7bcffd1fec05fb9e8cd4a6df1ae9060ec9589ebc;hb=ea4942ed6644e9ae7ce1e955ecbfb67666f051dc;hp=4d2d3d074a6fe07ddfa087b2ad72a2fd7e950e93;hpb=2ad87eaa004e722037fba951f4fe418d09c209cc;p=dygraphs.git
diff --git a/dygraph.js b/dygraph.js
index 4d2d3d0..7bcffd1 100644
--- a/dygraph.js
+++ b/dygraph.js
@@ -171,7 +171,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_ = [];
@@ -240,8 +239,13 @@ Dygraph.prototype.__init__ = function(div, file, attrs) {
this.start_();
};
-Dygraph.prototype.attr_ = function(name) {
- if (typeof(this.user_attrs_[name]) != 'undefined') {
+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') {
return this.attrs_[name];
@@ -352,6 +356,32 @@ Dygraph.prototype.toDataCoords = function(x, y) {
return ret;
};
+/**
+ * Returns the number of columns (including the independent variable).
+ */
+Dygraph.prototype.numColumns = function() {
+ return this.rawData_[0].length;
+};
+
+/**
+ * Returns the number of rows (excluding any header/label row).
+ */
+Dygraph.prototype.numRows = function() {
+ return this.rawData_.length;
+};
+
+/**
+ * Returns the value in the given row and column. If the row and column exceed
+ * the bounds on the data, returns null. Also returns null if the value is
+ * missing.
+ */
+Dygraph.prototype.getValue = function(row, col) {
+ if (row < 0 || row > this.rawData_.length) return null;
+ if (col < 0 || col > this.rawData_[row].length) return null;
+
+ return this.rawData_[row][col];
+};
+
Dygraph.addEvent = function(el, evt, fn) {
var normed_fn = function(e) {
if (!e) var e = window.event;
@@ -803,7 +833,8 @@ Dygraph.prototype.createDragInterface_ = function() {
var regionWidth = Math.abs(dragEndX - dragStartX);
var regionHeight = Math.abs(dragEndY - dragStartY);
- if (regionWidth < 2 && regionHeight < 2 && self.lastx_ != undefined) {
+ if (regionWidth < 2 && regionHeight < 2 &&
+ self.lastx_ != undefined && self.lastx_ != -1) {
// TODO(danvk): pass along more info about the points, e.g. 'x'
if (self.attr_('clickCallback') != null) {
self.attr_('clickCallback')(event, self.lastx_, self.selPoints_);
@@ -990,11 +1021,18 @@ Dygraph.prototype.mouseMove_ = function(event) {
*/
Dygraph.prototype.updateSelection_ = function() {
// Clear the previously drawn vertical, if there is one
- var circleSize = this.attr_('highlightCircleSize');
var ctx = this.canvas_.getContext("2d");
if (this.previousVerticalX_ >= 0) {
+ // Determine the maximum highlight circle size.
+ var maxCircleSize = 0;
+ 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_;
- ctx.clearRect(px - circleSize - 1, 0, 2 * circleSize + 2, this.height_);
+ ctx.clearRect(px - maxCircleSize - 1, 0,
+ 2 * maxCircleSize + 2, this.height_);
}
var isOK = function(x) { return x && !isNaN(x); };
@@ -1010,7 +1048,7 @@ Dygraph.prototype.updateSelection_ = function() {
if (this.attr_('showLabelsOnHighlight')) {
// Set the status message to indicate the selected point(s)
for (var i = 0; i < this.selPoints_.length; i++) {
- if (!this.attr_("labelsShowZeroValues") && this.selPoints_[i].yval == 0) continue;
+ if (!this.attr_("labelsShowZeroValues") && this.selPoints_[i].yval == 0) continue;
if (!isOK(this.selPoints_[i].canvasy)) continue;
if (this.attr_("labelsSeparateLines")) {
replace += "
";
@@ -1030,6 +1068,8 @@ Dygraph.prototype.updateSelection_ = function() {
ctx.save();
for (var i = 0; i < this.selPoints_.length; i++) {
if (!isOK(this.selPoints_[i].canvasy)) continue;
+ 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,
@@ -1414,22 +1454,25 @@ Dygraph.dateTicker = function(startDate, endDate, self) {
* @return {Array.