| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
<![if gte IE 9]> |
| 13 |
<!DOCTYPE HTML> |
| 14 |
<html lang="en"> |
| 15 |
<head> |
| 16 |
<![endif]> |
| 17 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| 18 |
<title>Scaling, scrolling, and panning.</title> |
| 19 |
<style type="text/css"> |
| 20 |
@import "../../../dojo/resources/dojo.css"; |
| 21 |
@import "../../../dijit/themes/tundra/tundra.css"; |
| 22 |
@import "../../../dijit/tests/css/dijitTests.css"; |
| 23 |
</style> |
| 24 |
<script type="text/javascript" src="../../../dojo/dojo.js" data-dojo-config="isDebug: true, parseOnLoad: true"></script> |
| 25 |
<script type="text/javascript"> |
| 26 |
|
| 27 |
dojo.require("dijit.form.HorizontalSlider"); |
| 28 |
dojo.require("dijit.form.HorizontalRule"); |
| 29 |
dojo.require("dijit.form.HorizontalRuleLabels"); |
| 30 |
dojo.require("dojo.parser"); // scan page for widgets |
| 31 |
|
| 32 |
dojo.require("dojox.charting.Chart"); |
| 33 |
dojo.require("dojox.charting.axis2d.Default"); |
| 34 |
dojo.require("dojox.charting.plot2d.Areas"); |
| 35 |
dojo.require("dojox.charting.plot2d.Grid"); |
| 36 |
dojo.require("dojox.charting.themes.PlotKit.orange"); |
| 37 |
|
| 38 |
dojo.require("dojox.lang.functional.object"); |
| 39 |
|
| 40 |
var df = dojox.lang.functional; |
| 41 |
var chart, moveable, scaleX = 1, scaleY = 1, offsetX = 0, offsetY = 0; |
| 42 |
|
| 43 |
var reflect = function(){ |
| 44 |
df.forIn(chart.axes, function(axis){ |
| 45 |
var scale = axis.getWindowScale(), |
| 46 |
offset = Math.round(axis.getWindowOffset() * axis.getScaler().bounds.scale); |
| 47 |
if(axis.vertical){ |
| 48 |
scaleY = scale; |
| 49 |
offsetY = offset; |
| 50 |
}else{ |
| 51 |
scaleX = scale; |
| 52 |
offsetX = offset; |
| 53 |
} |
| 54 |
}); |
| 55 |
setTimeout(function(){ |
| 56 |
dijit.byId("scaleXSlider").set("value",scaleX); |
| 57 |
dijit.byId("offsetXSlider").set("value",offsetX); |
| 58 |
dijit.byId("scaleYSlider").set("value",scaleY); |
| 59 |
dijit.byId("offsetYSlider").set("value",offsetY); |
| 60 |
}, 25); |
| 61 |
}; |
| 62 |
|
| 63 |
var update = function(){ |
| 64 |
chart.setWindow(scaleX, scaleY, offsetX, offsetY, {duration: 1500}).render(); |
| 65 |
reflect(); |
| 66 |
}; |
| 67 |
|
| 68 |
var scaleXEvent = function(value){ |
| 69 |
scaleX = value; |
| 70 |
dojo.byId("scaleXValue").innerHTML = value; |
| 71 |
update(); |
| 72 |
}; |
| 73 |
|
| 74 |
var scaleYEvent = function(value){ |
| 75 |
scaleY = value; |
| 76 |
dojo.byId("scaleYValue").innerHTML = value; |
| 77 |
update(); |
| 78 |
}; |
| 79 |
|
| 80 |
var offsetXEvent = function(value){ |
| 81 |
offsetX = value; |
| 82 |
dojo.byId("offsetXValue").innerHTML = value; |
| 83 |
update(); |
| 84 |
}; |
| 85 |
|
| 86 |
var offsetYEvent = function(value){ |
| 87 |
offsetY = value; |
| 88 |
dojo.byId("offsetYValue").innerHTML = value; |
| 89 |
update(); |
| 90 |
}; |
| 91 |
|
| 92 |
var _init = null; |
| 93 |
var onMouseDown = function(e){ |
| 94 |
_init = {x: e.clientX, y: e.clientY, ox: offsetX, oy: offsetY}; |
| 95 |
dojo.stopEvent(e); |
| 96 |
}; |
| 97 |
|
| 98 |
var onMouseUp = function(e){ |
| 99 |
if(_init){ |
| 100 |
_init = null; |
| 101 |
reflect(); |
| 102 |
dojo.stopEvent(e); |
| 103 |
} |
| 104 |
}; |
| 105 |
|
| 106 |
var onMouseMove = function(e){ |
| 107 |
if(_init){ |
| 108 |
var dx = e.clientX - _init.x, |
| 109 |
dy = e.clientY - _init.y; |
| 110 |
offsetX = _init.ox - dx; |
| 111 |
offsetY = _init.oy + dy; |
| 112 |
chart.setWindow(scaleX, scaleY, offsetX, offsetY).render(); |
| 113 |
dojo.stopEvent(e); |
| 114 |
} |
| 115 |
}; |
| 116 |
|
| 117 |
makeObjects = function(){ |
| 118 |
chart = new dojox.charting.Chart("test"); |
| 119 |
chart.setTheme(dojox.charting.themes.PlotKit.orange); |
| 120 |
chart.addAxis("x", {fixLower: "minor", natural: true, stroke: "grey", |
| 121 |
majorTick: {stroke: "black", length: 4}, minorTick: {stroke: "gray", length: 2}}); |
| 122 |
chart.addAxis("y", {vertical: true, min: 0, max: 30, majorTickStep: 5, minorTickStep: 1, stroke: "grey", |
| 123 |
majorTick: {stroke: "black", length: 4}, minorTick: {stroke: "gray", length: 2}}); |
| 124 |
chart.addPlot("default", {type: "Areas", animate: {duration: 1800}}); |
| 125 |
chart.addSeries("Series A", [0, 25, 5, 20, 10, 15, 5, 20, 0, 25]); |
| 126 |
chart.addAxis("x2", {fixLower: "minor", natural: true, leftBottom: false, stroke: "grey", |
| 127 |
majorTick: {stroke: "black", length: 4}, minorTick: {stroke: "gray", length: 2}}); |
| 128 |
chart.addAxis("y2", {vertical: true, min: 0, max: 20, leftBottom: false, stroke: "grey", |
| 129 |
majorTick: {stroke: "black", length: 4}, minorTick: {stroke: "gray", length: 2}}); |
| 130 |
chart.addPlot("plot2", {type: "Areas", hAxis: "x2", vAxis: "y2", animate: {duration: 1800}}); |
| 131 |
chart.addSeries("Series B", [15, 0, 15, 0, 15, 0, 15, 0, 15, 0, 15, 0, 15, 0, 15, 0, 15], {plot: "plot2"}); |
| 132 |
chart.addPlot("grid", {type: "Grid", hMinorLines: true}); |
| 133 |
chart.render(); |
| 134 |
|
| 135 |
dojo.connect(dijit.byId("scaleXSlider"), "onChange", scaleXEvent); |
| 136 |
dojo.connect(dijit.byId("scaleYSlider"), "onChange", scaleYEvent); |
| 137 |
dojo.connect(dijit.byId("offsetXSlider"), "onChange", offsetXEvent); |
| 138 |
dojo.connect(dijit.byId("offsetYSlider"), "onChange", offsetYEvent); |
| 139 |
|
| 140 |
dojo.connect(dojo.byId("test"), "onmousedown", onMouseDown); |
| 141 |
dojo.connect(dojo.byId("test"), "onmousemove", onMouseMove); |
| 142 |
dojo.connect(dojo.byId("test"), "onmouseup", onMouseUp); |
| 143 |
}; |
| 144 |
|
| 145 |
dojo.addOnLoad(makeObjects); |
| 146 |
|
| 147 |
</script> |
| 148 |
</head> |
| 149 |
<body class="tundra"> |
| 150 |
<h1>Scaling, scrolling, and panning.</h1> |
| 151 |
|
| 152 |
<p>UI explained:</p> |
| 153 |
<ul> |
| 154 |
<li>Use Scale X and Scale Y to zoom in the chart. You can scale the chart anisotropically.</li> |
| 155 |
<li>Use Offset X and Offset Y to move the origin of the chart.</li> |
| 156 |
<li>You cannot move the chart outside its boundaries. |
| 157 |
<ul> |
| 158 |
<li>Example: if both scale factors are 1, you cannot move the origin — you should zoom in first.</li> |
| 159 |
</ul> |
| 160 |
</li> |
| 161 |
<li>After applying scale/offset to the chart, sliders' positions change to reflect actual values.</li> |
| 162 |
<li>When you zoomed in, you can grab chart with mouse and move around (pan). |
| 163 |
<ul> |
| 164 |
<li>Warning: can be slow on some browsers.</li> |
| 165 |
</ul> |
| 166 |
</li> |
| 167 |
</ul> |
| 168 |
<table> |
| 169 |
<tr><td align="center" class="pad">Scale X (<span id="scaleXValue">1</span>)</td></tr> |
| 170 |
<tr><td> |
| 171 |
<div id="scaleXSlider" dojoType="dijit.form.HorizontalSlider" |
| 172 |
value="1" minimum="1" maximum="10" discreteValues="10" showButtons="false" |
| 173 |
style="width: 600px;"> |
| 174 |
<div dojoType="dijit.form.HorizontalRule" container="bottomDecoration" count="10" style="height:5px;"></div> |
| 175 |
<div dojoType="dijit.form.HorizontalRuleLabels" container="bottomDecoration" minimum="1" maximum="10" count="10" |
| 176 |
constraints="{pattern: '##'}" style="height:1.2em;font-size:75%;color:gray;"></div> |
| 177 |
</div> |
| 178 |
</td></tr> |
| 179 |
<tr><td align="center" class="pad">Scale Y (<span id="scaleYValue">1</span>)</td></tr> |
| 180 |
<tr><td> |
| 181 |
<div id="scaleYSlider" dojoType="dijit.form.HorizontalSlider" |
| 182 |
value="1" minimum="1" maximum="10" discreteValues="10" showButtons="false" |
| 183 |
style="width: 600px;"> |
| 184 |
<div dojoType="dijit.form.HorizontalRule" container="bottomDecoration" count="10" style="height:5px;"></div> |
| 185 |
<div dojoType="dijit.form.HorizontalRuleLabels" container="bottomDecoration" minimum="1" maximum="10" count="10" |
| 186 |
constraints="{pattern: '##'}" style="height:1.2em;font-size:75%;color:gray;"></div> |
| 187 |
</div> |
| 188 |
</td></tr> |
| 189 |
<tr><td align="center" class="pad">Offset X (<span id="offsetXValue">0</span>)</td></tr> |
| 190 |
<tr><td> |
| 191 |
<div id="offsetXSlider" dojoType="dijit.form.HorizontalSlider" |
| 192 |
value="1" minimum="0" maximum="1000" discreteValues="1001" showButtons="false" |
| 193 |
style="width: 600px;"> |
| 194 |
<div dojoType="dijit.form.HorizontalRule" container="bottomDecoration" count="11" style="height:5px;"></div> |
| 195 |
<div dojoType="dijit.form.HorizontalRuleLabels" container="bottomDecoration" minimum="0" maximum="1000" count="11" |
| 196 |
constraints="{pattern: '####'}" style="height:1.2em;font-size:75%;color:gray;"></div> |
| 197 |
</div> |
| 198 |
</td></tr> |
| 199 |
<tr><td align="center" class="pad">Offset Y (<span id="offsetYValue">0</span>)</td></tr> |
| 200 |
<tr><td> |
| 201 |
<div id="offsetYSlider" dojoType="dijit.form.HorizontalSlider" |
| 202 |
value="1" minimum="0" maximum="1000" discreteValues="1001" showButtons="false" |
| 203 |
style="width: 600px;"> |
| 204 |
<div dojoType="dijit.form.HorizontalRule" container="bottomDecoration" count="11" style="height:5px;"></div> |
| 205 |
<div dojoType="dijit.form.HorizontalRuleLabels" container="bottomDecoration" minimum="0" maximum="1000" count="11" |
| 206 |
constraints="{pattern: '####'}" style="height:1.2em;font-size:75%;color:gray;"></div> |
| 207 |
</div> |
| 208 |
</td></tr> |
| 209 |
</table> |
| 210 |
<div id="test" style="width: 500px; height: 300px;"></div> |
| 211 |
<p>That's all Folks!</p> |
| 212 |
</body> |
| 213 |
</html> |