this.layout_.addDataset(this.attr_("labels")[i], datasets[i]);
}
- // TODO(danvk): this method doesn't need to return anything.
- var out = this.computeYAxisRanges_(extremes);
- var axes = out[0];
- var seriesToAxisMap = out[1];
- this.layout_.updateOptions( { yAxes: axes,
- seriesToAxisMap: seriesToAxisMap
- } );
-
+ if (datasets.length > 0) {
+ // TODO(danvk): this method doesn't need to return anything.
+ var out = this.computeYAxisRanges_(extremes);
+ var axes = out[0];
+ var seriesToAxisMap = out[1];
+ this.layout_.updateOptions( { yAxes: axes,
+ seriesToAxisMap: seriesToAxisMap
+ } );
+ }
this.addXTicks_();
+ // Save the X axis zoomed status as the updateOptions call will tend to set it errorneously
+ var tmp_zoomed_x = this.zoomed_x_;
// Tell PlotKit to use this new data and render itself
this.layout_.updateOptions({dateWindow: this.dateWindow_});
+ this.zoomed_x_ = tmp_zoomed_x;
this.layout_.evaluateWithError();
this.plotter_.clear();
this.plotter_.render();
* indices are into the axes_ array.
*/
Dygraph.prototype.computeYAxes_ = function() {
- var valueWindow;
+ var valueWindows;
if (this.axes_ != undefined) {
// Preserve valueWindow settings.
- valueWindow = [];
+ valueWindows = [];
for (var index = 0; index < this.axes_.length; index++) {
- valueWindow.push(this.axes_[index].valueWindow);
+ valueWindows.push(this.axes_[index].valueWindow);
}
}
}
this.seriesToAxisMap_ = seriesToAxisFiltered;
- if (valueWindow != undefined) {
+ if (valueWindows != undefined) {
// Restore valueWindow settings.
- for (var index = 0; index < valueWindow.length; index++) {
- this.axes_[index].valueWindow = valueWindow[index];
+ for (var index = 0; index < valueWindows.length; index++) {
+ this.axes_[index].valueWindow = valueWindows[index];
}
}
};
}
if ('dateWindow' in attrs) {
this.dateWindow_ = attrs.dateWindow;
- this.zoomed_x_ = attrs.dateWindow != null;
+ if (!('noZoomFlagChange' in attrs)) {
+ this.zoomed_x_ = attrs.dateWindow != null;
+ }
}
- if ('valueRange' in attrs) {
+ if ('valueRange' in attrs && !('noZoomFlagChange' in attrs)) {
this.zoomed_y_ = attrs.valueRange != null;
}
--- /dev/null
+<html>
+ <head>
+ <title>zoom</title>
+ <!--[if IE]>
+ <script type="text/javascript" src="../excanvas.js"></script>
+ <![endif]-->
+ <script type="text/javascript" src="../strftime/strftime-min.js"></script>
+ <script type="text/javascript" src="../rgbcolor/rgbcolor.js"></script>
+ <script type="text/javascript" src="../dygraph-canvas.js"></script>
+ <script type="text/javascript" src="../dygraph.js"></script>
+ <script type="text/javascript" src="data.js"></script>
+ </head>
+ <body>
+ <h3>Click the buttons to change the date and value windows of the chart.</h3>
+ <h4>Window coordinates (in dates and values):</h4>
+ <div id="xdimensions"></div> <div id="ydimensions"></div>
+ <br />
+ <div>
+ <p>
+ Toggle the check box below to determine the difference in operation of the zoom flags
+ when the date and value windows of the chart are changed using the arrows underneath.
+ </p>
+ <input id="noZoomFlagChange" type="checkbox" checked=true>Do not change zoom
+ </div>
+
+ <div style="float: right">
+ <p>Zoomed: <span id="zoomed">False</span><p/>
+ <p>Zoomed X: <span id="zoomedX">False</span><p/>
+ <p>Zoomed Y: <span id="zoomedY">False</span><p/>
+ </div>
+ <div style="float: left">
+ <p><input type="button" value="↑" onclick="adjustTop(+1)"></p>
+ <p><input type="button" value="↓" onclick="adjustTop(-1)"></p>
+ <p>
+ <input type="button" value="←" onclick="adjustFirst(-100000000)">
+ <input type="button" value="→" onclick="adjustFirst(+100000000)">
+ </p>
+ <p><input type="button" value="↑" onclick="adjustBottom(+1)"></p>
+ <p><input type="button" value="↓" onclick="adjustBottom(-1)"></p>
+ </div>
+ <div id="div_g" style="width: 600px; height: 300px; float: left"></div>
+ <div style="float: left">
+ <p>
+ <input type="button" value="←" onclick="adjustLast(-100000000)">
+ <input type="button" value="→" onclick="adjustLast(+100000000)">
+ </p>
+ </div>
+ <script type="text/javascript">
+ g = new Dygraph(
+ document.getElementById("div_g"),
+ NoisyData,
+ {
+ errorBars: true,
+ zoomCallback : function(minDate, maxDate, yRange) {
+ showDimensions(minDate, maxDate, yRange);
+ },
+ drawCallback: function(me, initial) {
+ document.getElementById("zoomed").innerHTML = "" + me.isZoomed();
+ document.getElementById("zoomedX").innerHTML = "" + me.isZoomed("x");
+ document.getElementById("zoomedY").innerHTML = "" + me.isZoomed("y");
+ var x_range = me.xAxisRange()
+ var elem = document.getElementById("xdimensions")
+ elem.innerHTML = "dateWindow : [" + x_range[0] + ", "+ x_range[1] + "]"
+ }
+ }
+ )
+
+ // Pull an initial value for logging.
+ var minDate = g.xAxisRange()[0];
+ var maxDate = g.xAxisRange()[1];
+ var minValue = g.yAxisRange()[0];
+ var maxValue = g.yAxisRange()[1];
+ showDimensions(minDate, maxDate, [minValue, maxValue]);
+
+ function showDimensions(minDate, maxDate, yRanges) {
+ showXDimensions(minDate, maxDate);
+ showYDimensions(yRanges);
+ }
+
+ function getNoChange() {
+ var options = {}
+ var elem = document.getElementById("noZoomFlagChange")
+ if (elem.checked) {
+ options.noZoomFlagChange = true
+ }
+ return options
+ }
+
+ function adjustTop(value) {
+ options = getNoChange()
+ maxValue += value
+ options.valueRange = [minValue, maxValue]
+ console.log(options)
+ g.updateOptions(options)
+ }
+
+ function adjustBottom(value) {
+ options = getNoChange()
+ minValue += value
+ options.valueRange = [minValue, maxValue]
+ console.log(options)
+ g.updateOptions(options)
+ }
+
+ function adjustFirst(value) {
+ options = getNoChange()
+ minDate += value
+ options.dateWindow = [minDate, maxDate]
+ console.log(options)
+ g.updateOptions(options)
+ }
+
+ function adjustLast(value) {
+ options = getNoChange()
+ maxDate += value
+ options.dateWindow = [minDate, maxDate]
+ g.updateOptions(options)
+ }
+
+ function showXDimensions(first, second) {
+ var elem = document.getElementById("xdimensions");
+ elem.innerHTML = "dateWindow : [" + first + ", "+ second + "]";
+ }
+
+ function showYDimensions(ranges) {
+ var elem = document.getElementById("ydimensions");
+ elem.innerHTML = "valueRange : [" + ranges + "]";
+ }
+
+ </script>
+ </body>
+</html>