Debian Codegraph @

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