| 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>DataSeries Test</title> |
| 19 |
|
| 20 |
<style> |
| 21 |
@import "../../../../dojo/resources/dojo.css"; |
| 22 |
@import "../../../../dijit/tests/css/dijitTests.css"; |
| 23 |
@import "../../../../dijit/themes/dijit.css"; |
| 24 |
@import "../../../../dijit/themes/tundra/tundra.css"; |
| 25 |
|
| 26 |
#spinners{ |
| 27 |
clear:both; |
| 28 |
} |
| 29 |
#spinners label{ |
| 30 |
width:60px; |
| 31 |
line-height:30px; |
| 32 |
margin-top:10px; |
| 33 |
} |
| 34 |
.tundra #spinners .dijitSpinner { |
| 35 |
width:70px !important; |
| 36 |
margin:5px !important; |
| 37 |
} |
| 38 |
.tundra #spinners .dijitSpinner{ |
| 39 |
width:80px !important; |
| 40 |
} |
| 41 |
.dijitSpinner{ |
| 42 |
padding:0px !important; |
| 43 |
} |
| 44 |
#spinners .dijitSpinnerButtonContainer{ |
| 45 |
line-height:23px; |
| 46 |
} |
| 47 |
.dj_ie #spinners .dijitSpinnerButtonContainer{ |
| 48 |
height:25px; |
| 49 |
} |
| 50 |
.dijitInputLayoutContainer .dijitInputField input{ |
| 51 |
padding:5px 0px 0px 5px; |
| 52 |
} |
| 53 |
.dj_webkit .dijitInputLayoutContainer .dijitInputField input{ |
| 54 |
padding:10px 0px 0px 5px; |
| 55 |
} |
| 56 |
|
| 57 |
.dojoxLegendNode {border: 1px solid #ccc; margin: 5px 10px 5px 10px; padding: 3px;} |
| 58 |
.dojoxLegendText {vertical-align: text-top; padding-right: 10px} |
| 59 |
|
| 60 |
#charts { |
| 61 |
clear: both; |
| 62 |
margin-bottom: 50px; |
| 63 |
} |
| 64 |
.chart-area { |
| 65 |
float: left; |
| 66 |
border: 1px solid #ccc; |
| 67 |
width: 450px; |
| 68 |
height: 350px; |
| 69 |
margin: 3px; |
| 70 |
} |
| 71 |
.chart { |
| 72 |
width: 450px; |
| 73 |
height: 300px; |
| 74 |
} |
| 75 |
</style> |
| 76 |
|
| 77 |
<script src="../../../../dojo/dojo.js" data-dojo-config="isDebug: false, parseOnLoad: true, has:{'dojo-bidi': true}"></script> |
| 78 |
|
| 79 |
<script> |
| 80 |
dojo.require("dojo.parser"); |
| 81 |
dojo.require("doh.runner"); |
| 82 |
|
| 83 |
dojo.require("dojox.charting.Chart2D"); |
| 84 |
dojo.require("dojox.charting.DataSeries"); |
| 85 |
dojo.require("dojox.charting.themes.ThreeD"); |
| 86 |
dojo.require("dojox.charting.widget.Legend"); |
| 87 |
|
| 88 |
dojo.require("dojox.charting.plot2d.Markers"); |
| 89 |
dojo.require("dojox.charting.plot2d.Columns"); |
| 90 |
dojo.require("dojox.charting.plot2d.Pie"); |
| 91 |
|
| 92 |
dojo.require("dojox.charting.action2d.Tooltip"); |
| 93 |
dojo.require("dojox.charting.action2d.MoveSlice"); |
| 94 |
dojo.require("dojox.charting.action2d.Magnify"); |
| 95 |
dojo.require("dojox.charting.action2d.Shake"); |
| 96 |
|
| 97 |
dojo.require("dojo.data.ItemFileWriteStore"); |
| 98 |
|
| 99 |
dojo.require("dijit.form.NumberSpinner"); |
| 100 |
|
| 101 |
var store = new dojo.data.ItemFileWriteStore({url: "stockHebrew.json"}); |
| 102 |
|
| 103 |
function addLegend(chart, node){ |
| 104 |
var legend = new dojox.charting.widget.Legend({chart: chart}, node); |
| 105 |
dojo.connect(chart, "render", legend, "refresh"); |
| 106 |
} |
| 107 |
|
| 108 |
var templates = { |
| 109 |
low: "<strong>{0}</strong>: <strong>low {1}</strong> – {2} – {3}", |
| 110 |
price: "<span dir='ltr'><strong>{0}</strong>: {1} – <strong>price {2}</strong> – {3}</span>", |
| 111 |
high: "<strong>{0}</strong>: {1} – {2} – <strong>high {3}</strong>" |
| 112 |
}; |
| 113 |
|
| 114 |
function valTrans(value, store, item){ |
| 115 |
return { |
| 116 |
y: store.getValue(item, value), |
| 117 |
tooltip: dojo.replace( |
| 118 |
templates[value], |
| 119 |
dojo.map(["symbol", "low", "price", "high"], function(field){ |
| 120 |
return store.getValue(item, field); |
| 121 |
}) |
| 122 |
) |
| 123 |
}; |
| 124 |
} |
| 125 |
|
| 126 |
var chartL, chartC, chartP; |
| 127 |
|
| 128 |
makeCharts = function(){ |
| 129 |
chartL = new dojox.charting.Chart2D("lines",{textDir:"auto", dir:"rtl"}). |
| 130 |
setTheme(dojox.charting.themes.ThreeD). |
| 131 |
addAxis("x", {fixLower: "major", fixUpper: "major", natural: true, majorTickStep: 5}). |
| 132 |
addAxis("y", {vertical: true, fixLower: "major", fixUpper: "major", includeZero: true}). |
| 133 |
addPlot("default", {type: dojox.charting.plot2d.Markers}). |
| 134 |
addSeries("Price.", new dojox.charting.DataSeries( |
| 135 |
store, {query: {symbol: "*"}}, "price")). |
| 136 |
render(); |
| 137 |
addLegend(chartL, "lines_legend"); |
| 138 |
new dojox.charting.action2d.Magnify(chartL); |
| 139 |
new dojox.charting.action2d.Tooltip(chartL); |
| 140 |
|
| 141 |
chartC = new dojox.charting.Chart2D("cols",{textDir:"rtl"}). |
| 142 |
setTheme(dojox.charting.themes.ThreeD). |
| 143 |
addAxis("x", {natural: true}). |
| 144 |
addAxis("y", {vertical: true, fixLower: "major", fixUpper: "major", includeZero: true}). |
| 145 |
addPlot("default", {type: dojox.charting.plot2d.Columns}). |
| 146 |
addSeries("Low.", new dojox.charting.DataSeries( |
| 147 |
store, {query: {symbol: "*"}}, dojo.hitch(null, valTrans, "low"))). |
| 148 |
addSeries("\u05de\u05d7\u05d9\u05e8.", new dojox.charting.DataSeries( |
| 149 |
store, {query: {symbol: "*"}}, dojo.hitch(null, valTrans, "price"))). |
| 150 |
addSeries("High.", new dojox.charting.DataSeries( |
| 151 |
store, {query: {symbol: "*"}}, dojo.hitch(null, valTrans, "high"))). |
| 152 |
render(); |
| 153 |
addLegend(chartC, "cols_legend"); |
| 154 |
new dojox.charting.action2d.Shake(chartC, "default", {shiftY: 0}); |
| 155 |
new dojox.charting.action2d.Tooltip(chartC); |
| 156 |
|
| 157 |
chartP = new dojox.charting.Chart2D("pie",{textDir:"auto",htmlLabels:true}). |
| 158 |
setTheme(dojox.charting.themes.ThreeD). |
| 159 |
addPlot("default", {type: dojox.charting.plot2d.Pie, radius: 125}). |
| 160 |
addSeries("Price", new dojox.charting.DataSeries( |
| 161 |
store, {query: {symbol: "*"}}, {y: "price", text: "symbol", tooltip: "price"})). |
| 162 |
render(); |
| 163 |
addLegend(chartP, "pie_legend"); |
| 164 |
new dojox.charting.action2d.Tooltip(chartP); |
| 165 |
new dojox.charting.action2d.MoveSlice(chartP); |
| 166 |
}; |
| 167 |
|
| 168 |
makeSpinners = function(items){ |
| 169 |
dojo.forEach(items, function(m){ |
| 170 |
var nm = store.getLabel(m); |
| 171 |
var num = store.getValue(m, "price"); |
| 172 |
console.log(nm, num); |
| 173 |
var w = new dijit.form.NumberSpinner({ |
| 174 |
onChange: function(val){ |
| 175 |
val = val===0 ? 0.01 : val; //HACKS the no label-when-zero bug |
| 176 |
console.log("OC:", nm, val); |
| 177 |
store.setValue(m, "price", val); |
| 178 |
//store.setValues(m, "historicPrice", store.getValues("historicPrice").push(val)); |
| 179 |
console.log("OC:", nm, val); |
| 180 |
}, |
| 181 |
value: num, |
| 182 |
constraints: {min:0, max:10,places:2}, |
| 183 |
className: "myField", |
| 184 |
intermediateChanges: true |
| 185 |
}); |
| 186 |
dojo.place('<label>'+nm+'</label>', dojo.byId("spinners"), "last") |
| 187 |
dojo.place(w.domNode, "spinners", "last") |
| 188 |
}); |
| 189 |
|
| 190 |
var labels = dojo.map(items, function(item, index){ |
| 191 |
return { |
| 192 |
value: index + 1, |
| 193 |
text: store.getLabel(item) |
| 194 |
} |
| 195 |
}); |
| 196 |
chartC.addAxis("x", {natural: true, labels: labels}).render(); |
| 197 |
} |
| 198 |
|
| 199 |
dojo.addOnLoad(function(){ |
| 200 |
makeCharts(); |
| 201 |
store.fetch({query:{symbol:"*"}, onComplete: makeSpinners, onError:function(err){console.error(err)}}) |
| 202 |
|
| 203 |
doh.register("parse", function(){ |
| 204 |
dojo.parser.parse(); |
| 205 |
}); |
| 206 |
|
| 207 |
doh.run(); |
| 208 |
}); |
| 209 |
</script> |
| 210 |
|
| 211 |
</head> |
| 212 |
|
| 213 |
<body class="tundra" dir ="ltr"> |
| 214 |
<h1>DataSeries Test</h1> |
| 215 |
<p> |
| 216 |
Use the spinner fields at the bottom to change the data. The charts listen to store changes an update automatically. |
| 217 |
</p> |
| 218 |
<div id="charts"> |
| 219 |
<div class="chart-area"> |
| 220 |
<div id="lines_legend"></div> |
| 221 |
<div id="lines" class="chart" dir="rtl"></div> |
| 222 |
</div> |
| 223 |
<div class="chart-area" data-dojo-textdir="rtl"> |
| 224 |
<div id="cols_legend"></div> |
| 225 |
<div id="cols" class="chart"></div> |
| 226 |
</div> |
| 227 |
<div class="chart-area"> |
| 228 |
<div id="pie_legend"></div> |
| 229 |
<div id="pie" class="chart"></div> |
| 230 |
</div> |
| 231 |
</div> |
| 232 |
<div id="spinners"></div> |
| 233 |
</body> |
| 234 |
</html> |