Debian Codegraph @

dojox/charting/tests/BidiSupport/mirror_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, has:{'dojo-bidi': 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 dojo.require("dojox.charting.axis2d.Default");
53
54 dojo.require("dojox.charting.plot2d.Markers");
55 dojo.require("dojox.charting.plot2d.Columns");
56 dojo.require("dojox.charting.plot2d.Pie");
57
58 dojo.require("dojox.charting.action2d.Tooltip");
59 dojo.require("dojox.charting.action2d.MoveSlice");
60 dojo.require("dojox.charting.action2d.Magnify");
61 dojo.require("dojox.charting.action2d.Shake");
62
63 dojo.require("dojo.store.Memory");
64 dojo.require("dojo.store.Observable");
65
66 dojo.require("dijit.form.NumberSpinner");
67
68 dojo.xhrGet({
69 url: "stock.json",
70 sync: true,
71 handleAs: "json"
72 }).then(function(data){
73 store = dojo.store.Observable(new dojo.store.Memory({data:data}));
74 });
75
76 function addLegend(chart, node){
77 var legend = new dojox.charting.widget.Legend({chart: chart}, node);
78 dojo.connect(chart, "render", legend, "refresh");
79 }
80
81 var templates = {
82 low: "<strong>{0}</strong>: <strong>low {1}</strong> &ndash; {2} &ndash; {3}",
83 price: "<strong>{0}</strong>: {1} &ndash; <strong>price {2}</strong> &ndash; {3}",
84 high: "<strong>{0}</strong>: {1} &ndash; {2} &ndash; <strong>high {3}</strong>"
85 };
86
87 function valTrans(value, object){
88 return {
89 y: object[value],
90 tooltip: dojo.replace(
91 templates[value],
92 dojo.map(["symbol", "low", "price", "high"], function(field){
93 return object[field];
94 })
95 )
96 };
97 }
98
99 var chartL, chartC, chartP;
100
101 makeCharts = function(){
102 chartL = new dojox.charting.Chart("lines").
103 setTheme(dojox.charting.themes.ThreeD).
104 addAxis("x", {fixLower: "major", fixUpper: "major", natural: true, majorTickStep: 5}).
105 addAxis("y", {vertical: true, fixLower: "major", fixUpper: "major", includeZero: true}).
106 addPlot("default", {type: dojox.charting.plot2d.Markers}).
107 addSeries("Price", new dojox.charting.StoreSeries(
108 store, {query: {}}, "price")).setDir("rtl").
109 render();
110 addLegend(chartL, "lines_legend");
111 new dojox.charting.action2d.Magnify(chartL);
112 new dojox.charting.action2d.Tooltip(chartL);
113
114 chartC = new dojox.charting.Chart("cols").
115 setTheme(dojox.charting.themes.ThreeD).
116 addAxis("x", {natural: true}).
117 addAxis("y", {vertical: true, fixLower: "major", fixUpper: "major", includeZero: true}).
118 addPlot("default", {type: dojox.charting.plot2d.Columns}).
119 addSeries("Low", new dojox.charting.StoreSeries(
120 store, {query: {}}, dojo.hitch(null, valTrans, "low"))).
121 addSeries("Price", new dojox.charting.StoreSeries(
122 store, {query: {}}, dojo.hitch(null, valTrans, "price"))).
123 addSeries("High", new dojox.charting.StoreSeries(
124 store, {query: {}}, dojo.hitch(null, valTrans, "high"))).setDir("rtl").
125 render();
126 addLegend(chartC, "cols_legend");
127 new dojox.charting.action2d.Shake(chartC, "default", {shiftY: 0});
128 new dojox.charting.action2d.Tooltip(chartC);
129
130 chartP = new dojox.charting.Chart("pie").
131 setTheme(dojox.charting.themes.ThreeD).
132 addPlot("default", {type: dojox.charting.plot2d.Pie, radius: 125}).
133 addSeries("Price", new dojox.charting.StoreSeries(
134 store, {query: {}}, {y: "price", text: "symbol", tooltip: "price"})).setDir("rtl").
135 render();
136 addLegend(chartP, "pie_legend");
137 new dojox.charting.action2d.Tooltip(chartP);
138 new dojox.charting.action2d.MoveSlice(chartP);
139 };
140
141 makeSpinners = function(objects){
142 dojo.forEach(objects, function(m){
143 var nm = m.symbol;
144 var num = m.price;
145 console.log(nm, num);
146 var w = new dijit.form.NumberSpinner({
147 onChange: function(val){
148 val = val===0 ? 0.01 : val; //HACKS the no label-when-zero bug
149 console.log("OC:", nm, val);
150 m.price = val;
151 store.put(m);
152 //store.setValues(m, "historicPrice", store.getValues("historicPrice").push(val));
153 console.log("OC:", nm, val);
154 },
155 value: num,
156 constraints: {min:0, max:10,places:2},
157 className: "myField",
158 intermediateChanges: true
159 });
160 dojo.place('<label>'+nm+'</label>', dojo.byId("spinners"), "last")
161 dojo.place(w.domNode, "spinners", "last")
162 });
163
164 var labels = dojo.map(objects, function(object, index){
165 return {
166 value: index + 1,
167 text: object.symbol
168 }
169 });
170 chartC.addAxis("x", {natural: true, labels: labels}).render();
171 }
172
173 dojo.addOnLoad(function(){
174 makeCharts();
175 makeSpinners(store.query({}));
176 });
177 </script>
178
179 </head>
180
181 <body class="claro">
182 <h1>StoreSeries Test</h1>
183 <p>
184 Use the spinner fields at the bottom to change the data. The charts listen to store changes an update automatically.
185 </p>
186 <div id="charts">
187 <div class="chart-area">
188 <div id="lines_legend"></div>
189 <div id="lines" class="chart"></div>
190 </div>
191 <div class="chart-area">
192 <div id="cols_legend"></div>
193 <div id="cols" class="chart"></div>
194 </div>
195 <div class="chart-area">
196 <div id="pie_legend"></div>
197 <div id="pie" class="chart"></div>
198 </div>
199 </div>
200 <div id="spinners"></div>
201 </body>
202 </html>