]> git.proxmox.com Git - extjs.git/blame - extjs/examples/kitchensink/modern/src/view/chart/ColumnController.js
add extjs 6.0.1 sources
[extjs.git] / extjs / examples / kitchensink / modern / src / view / chart / ColumnController.js
CommitLineData
6527f429
DM
1Ext.define('KitchenSink.view.chart.BasicController', {\r
2 extend: 'Ext.app.ViewController',\r
3 alias: 'controller.column-chart',\r
4\r
5 onDownload: function() {\r
6 var chart = this.lookupReference('chart');\r
7 if (Ext.os.is.Desktop) {\r
8 chart.download({\r
9 filename: 'Redwood City Climate Data Chart'\r
10 });\r
11 } else {\r
12 chart.preview();\r
13 }\r
14 },\r
15\r
16 onReloadData: function() {\r
17 var chart = this.lookupReference('chart');\r
18 chart.getStore().refreshData();\r
19 },\r
20\r
21 // The 'target' here is an object that contains information\r
22 // about the target value when the drag operation on the column ends.\r
23 onEditTipRender: function (tooltip, item, target, e) {\r
24 tooltip.setHtml('Temperature °F: ' + target.yValue.toFixed(1));\r
25 },\r
26\r
27 onColumnEdit: function (chart, data) {\r
28 var threshold = 65,\r
29 delta = 20,\r
30 yValue = data.target.yValue,\r
31 coldness;\r
32\r
33 if (yValue < threshold) {\r
34 coldness = Ext.Number.constrain((threshold - yValue) / delta, 0, 1);\r
35 return {\r
36 fillStyle: 'rgba(133, 231, 252, ' + coldness.toString() + ')'\r
37 };\r
38 } else {\r
39 return {\r
40 fillStyle: 'none'\r
41 };\r
42 }\r
43 },\r
44\r
45 onInitialize: function () {\r
46 Ext.Viewport.on('orientationchange', this.updateChartTitle, this);\r
47 this.updateChartTitle();\r
48 },\r
49\r
50 updateChartTitle: function (viewport, orientation, width, height) {\r
51 var chart = this.lookupReference('chart'),\r
52 chartSurface = chart.getSurface('chart'),\r
53 title = chartSurface.getItems()[0];\r
54\r
55 width = width || Ext.Viewport.getWindowWidth();\r
56\r
57 title.setAttributes({\r
58 hidden: width < 500\r
59 });\r
60 },\r
61\r
62 onAfterRender: function () {\r
63 var me = this,\r
64 chart = this.lookupReference('chart'),\r
65 axis = chart.getAxis(0),\r
66 store = chart.getStore();\r
67\r
68 function onAxisRangeChange() {\r
69 me.onAxisRangeChange(axis);\r
70 }\r
71\r
72 store.on({\r
73 datachanged: onAxisRangeChange,\r
74 update: onAxisRangeChange\r
75 });\r
76 },\r
77\r
78 onAxisRangeChange: function (axis, range) {\r
79 // this.lookupReference('chart') will fail here,\r
80 // as at the time of this call\r
81 // the chart is not yet in the component tree,\r
82 // so we have to use axis.getChart() instead.\r
83 var chart = axis.getChart(),\r
84 store = chart.getStore(),\r
85 sum = 0,\r
86 mean;\r
87\r
88 store.each(function (rec) {\r
89 sum += rec.get('highF');\r
90 });\r
91\r
92 mean = sum / store.getCount();\r
93\r
94 axis.setLimits({\r
95 value: mean,\r
96 line: {\r
97 title: {\r
98 text: 'Average high: ' + mean.toFixed(2) + '°F'\r
99 },\r
100 lineDash: [2,2]\r
101 }\r
102 });\r
103 },\r
104\r
105 itemAnimationDuration: 0,\r
106\r
107 // Disable item's animaton for editing.\r
108 onBeginItemEdit: function (chart, interaction, item) {\r
109 var itemsMarker = item.sprite.getMarker(item.category),\r
110 fx = itemsMarker.getTemplate().fx; // animation modifier\r
111\r
112 this.itemAnimationDuration = fx.getDuration();\r
113 fx.setDuration(0);\r
114 },\r
115\r
116 // Restore item's animation when editing is done.\r
117 onEndItemEdit: function (chart, interaction, item, target) {\r
118 var itemsMarker = item.sprite.getMarker(item.category),\r
119 fx = itemsMarker.getTemplate().fx;\r
120\r
121 fx.setDuration(this.itemAnimationDuration);\r
122 }\r
123\r
124});