Debian Codegraph @

dojox/charting/tests/test_StoreSeries.html

raw symbols SCIP
1 <!--[if IE 7]>
2 <!DOCTYPE>
3 <html lang="en">
4 <head>
5 <![endif]-->
6 <!--[if IE 8]>
7 <!DOCTYPE>
8 <html lang="en">
9 <head>
10 <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"/>
11 <![endif]-->
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>StoreSeries Test</title>
19 <link rel="stylesheet" href="../../../dijit/themes/claro/document.css"/>
20 <link rel="stylesheet" href="../../../dijit/themes/claro/claro.css"/>
21 <link rel="stylesheet" href="../../../dijit/tests/css/dijitTests.css"/>
22
23 <style>
24 .dojoxLegendNode {border: 1px solid #ccc; margin: 5px 10px 5px 10px; padding: 3px;}
25 .dojoxLegendText {vertical-align: text-top; padding-right: 10px}
26
27 #charts {
28 clear: both;
29 margin-bottom: 50px;
30 }
31 .chart-area {
32 float: left;
33 border: 1px solid #ccc;
34 width: 450px;
35 height: 350px;
36 margin: 3px;
37 }
38 .chart {
39 width: 450px;
40 height: 300px;
41 }
42 </style>
43
44 <script src="../../../dojo/dojo.js" data-dojo-config="isDebug: false, parseOnLoad: true"></script>
45
46 <script>
47
48 dojo.require("dojox.charting.Chart");
49 dojo.require("dojox.charting.StoreSeries");
50 dojo.require("dojox.charting.themes.ThreeD");
51 dojo.require("dojox.charting.widget.Legend");
52
53 dojo.require("dojox.charting.axis2d.Default");
54
55 dojo.require("dojox.charting.plot2d.Markers");
56 dojo.require("dojox.charting.plot2d.Columns");
57 dojo.require("dojox.charting.plot2d.Pie");
58
59 dojo.require("dojox.charting.action2d.Tooltip");
60 dojo.require("dojox.charting.action2d.MoveSlice");
61 dojo.require("dojox.charting.action2d.Magnify");
62 dojo.require("dojox.charting.action2d.Shake");
63
64 dojo.require("dojo.store.Memory");
65 dojo.require("dojo.store.Observable");
66
67 dojo.require("dijit.form.NumberSpinner");
68
69 dojo.xhrGet({
70 url: "stock.json",
71 sync: true,
72 handleAs: "json"
73 }).then(function(data){
74 store = dojo.store.Observable(new dojo.store.Memory({data:data}));
75 });
76
77 function addLegend(chart, node){
78 var legend = new dojox.charting.widget.Legend({chart: chart}, node);
79 dojo.connect(chart, "render", legend, "refresh");
80 }
81
82 var templates = {
83 low: "<strong>{0}</strong>: <strong>low {1}</strong> &ndash; {2} &ndash; {3}",
84 price: "<strong>{0}</strong>: {1} &ndash; <strong>price {2}</strong> &ndash; {3}",
85 high: "<strong>{0}</strong>: {1} &ndash; {2} &ndash; <strong>high {3}</strong>"
86 };
87
88 function valTrans(value, object){
89 return {
90 y: object[value],
91 tooltip: dojo.replace(
92 templates[value],
93 dojo.map(["symbol", "low", "price", "high"], function(field){
94 return object[field];
95 })
96 )
97 };
98 }
99
100 var chartL, chartC, chartP;
101
102 makeCharts = function(){
103 chartL = new dojox.charting.Chart("lines").
104 setTheme(dojox.charting.themes.ThreeD).
105 addAxis("x", {fixLower: "major", fixUpper: "major", natural: true, majorTickStep: 5}).
106 addAxis("y", {vertical: true, fixLower: "major", fixUpper: "major", includeZero: true}).
107 addPlot("default", {type: dojox.charting.plot2d.Markers}).
108 addSeries("Price", new dojox.charting.StoreSeries(
109 store, {query: {}}, "price")).
110 render();
111 addLegend(chartL, "lines_legend");
112 new dojox.charting.action2d.Magnify(chartL);
113 new dojox.charting.action2d.Tooltip(chartL);
114
115 chartC = new dojox.charting.Chart("cols").
116 setTheme(dojox.charting.themes.ThreeD).
117 addAxis("x", {natural: true}).
118 addAxis("y", {vertical: true, fixLower: "major", fixUpper: "major", includeZero: true}).
119 addPlot("default", {type: dojox.charting.plot2d.Columns}).
120 addSeries("Low", new dojox.charting.StoreSeries(
121 store, {query: {}}, dojo.hitch(null, valTrans, "low"))).
122 addSeries("Price", new dojox.charting.StoreSeries(
123 store, {query: {}}, dojo.hitch(null, valTrans, "price"))).
124 addSeries("High", new dojox.charting.StoreSeries(
125 store, {query: {}}, dojo.hitch(null, valTrans, "high"))).
126 render();
127 addLegend(chartC, "cols_legend");
128 new dojox.charting.action2d.Shake(chartC, "default", {shiftY: 0});
129 new dojox.charting.action2d.Tooltip(chartC);
130
131 chartP = new dojox.charting.Chart("pie").
132 setTheme(dojox.charting.themes.ThreeD).
133 addPlot("default", {type: dojox.charting.plot2d.Pie, radius: 125}).
134 addSeries("Price", new dojox.charting.StoreSeries(
135 store, {query: {}}, {y: "price", text: "symbol", tooltip: "price"})).
136 render();
137 addLegend(chartP, "pie_legend");
138 new dojox.charting.action2d.Tooltip(chartP);
139 new dojox.charting.action2d.MoveSlice(chartP);
140 };
141
142 makeSpinners = function(objects){
143 dojo.forEach(objects, function(m){
144 var nm = m.symbol;
145 var num = m.price;
146 console.log(nm, num);
147 var w = new dijit.form.NumberSpinner({
148 onChange: function(val){
149 val = val===0 ? 0.01 : val; //HACKS the no label-when-zero bug
150 console.log("OC:", nm, val);
151 m.price = val;
152 store.put(m);
153 //store.setValues(m, "historicPrice", store.getValues("historicPrice").push(val));
154 console.log("OC:", nm, val);
155 },
156 value: num,
157 constraints: {min:0, max:10,places:2},
158 className: "myField",
159 intermediateChanges: true
160 });
161 dojo.place('<label>'+nm+'</label>', dojo.byId("spinners"), "last")
162 dojo.place(w.domNode, "spinners", "last")
163 });
164
165 var labels = dojo.map(objects, function(object, index){
166 return {
167 value: index + 1,
168 text: object.symbol
169 }
170 });
171 chartC.addAxis("x", {natural: true, labels: labels}).render();
172 }
173
174 dojo.addOnLoad(function(){
175 makeCharts();
176 makeSpinners(store.query({}));
177 });
178 </script>
179
180 </head>
181
182 <body class="claro">
183 <h1>StoreSeries Test</h1>
184 <p>
185 Use the spinner fields at the bottom to change the data. The charts listen to store changes an update automatically.
186 </p>
187 <div id="charts">
188 <div class="chart-area">
189 <div id="lines_legend"></div>
190 <div id="lines" class="chart"></div>
191 </div>
192 <div class="chart-area">
193 <div id="cols_legend"></div>
194 <div id="cols" class="chart"></div>
195 </div>
196 <div class="chart-area">
197 <div id="pie_legend"></div>
198 <div id="pie" class="chart"></div>
199 </div>
200 </div>
201 <div id="spinners"></div>
202 </body>
203 </html>