]>
Commit | Line | Data |
---|---|---|
b5494945 DC |
1 | Ext.define('PVE.widget.RRDChart', { |
2 | extend: 'Ext.chart.CartesianChart', | |
3 | alias: 'widget.pveRRDChart', | |
4 | ||
5 | ||
7ec884ca | 6 | width: 770, |
b5494945 | 7 | height: 300, |
87484017 | 8 | animation: false, |
dba34cd6 DC |
9 | interactions: [{ |
10 | type: 'crosszoom' | |
11 | }], | |
b5494945 DC |
12 | axes: [{ |
13 | type: 'numeric', | |
14 | position: 'left', | |
15 | grid: true, | |
16 | renderer: 'leftAxisRenderer', | |
22f2f9d6 | 17 | minimum: 0 |
b5494945 DC |
18 | }, { |
19 | type: 'time', | |
20 | position: 'bottom', | |
21 | grid: true, | |
22f2f9d6 | 22 | fields: ['time'] |
b5494945 DC |
23 | }], |
24 | legend: { | |
ed37370c | 25 | docked: 'bottom' |
b5494945 DC |
26 | }, |
27 | listeners: { | |
dba34cd6 DC |
28 | afterrender: 'onAfterRender', |
29 | animationend: 'onAfterAnimation' | |
b5494945 DC |
30 | }, |
31 | ||
32 | bytesArr : [ | |
33 | 'memtotal', | |
34 | 'memused', | |
35 | 'roottotal', | |
36 | 'rootused', | |
37 | 'swaptotal', | |
38 | 'swapused', | |
39 | 'maxmem', | |
40 | 'mem', | |
41 | 'disk', | |
921324b6 DC |
42 | 'maxdisk', |
43 | 'total', | |
22f2f9d6 | 44 | 'used' |
b5494945 DC |
45 | ], |
46 | bytespersArr: [ | |
47 | 'netin', | |
48 | 'netout', | |
49 | 'diskread', | |
50 | 'diskwrite' | |
51 | ], | |
52 | ||
53 | percentArr: [ | |
54 | 'cpu', | |
55 | 'iowait' | |
56 | ], | |
57 | ||
58 | convertToUnits: function(value) { | |
59 | var units = ['', 'k','M','G','T', 'P']; | |
60 | var si = 0; | |
61 | while(value >= 1000 && si < (units.length -1)){ | |
62 | value = value / 1000; | |
63 | si++; | |
64 | } | |
65 | // javascript floating point weirdness | |
66 | value = Ext.Number.correctFloat(value); | |
67 | ||
68 | // limit to 2 decimal points | |
69 | value = Ext.util.Format.number(value, "0.##"); | |
70 | ||
ec0bd652 | 71 | return value.toString() + " " + units[si]; |
b5494945 DC |
72 | }, |
73 | ||
74 | leftAxisRenderer: function(axis, label, layoutContext) { | |
75 | var me = this; | |
76 | return me.convertToUnits(label); | |
77 | }, | |
78 | ||
79 | onSeriesTooltipRender: function (tooltip, record, item) { | |
80 | var me = this; | |
81 | var suffix = ''; | |
82 | ||
83 | if (me.percentArr.indexOf(item.field) != -1) { | |
84 | suffix = '%'; | |
85 | } else if (me.bytesArr.indexOf(item.field) != -1) { | |
86 | suffix = 'B'; | |
87 | } else if (me.bytespersArr.indexOf(item.field) != -1) { | |
88 | suffix = 'B/s'; | |
89 | } | |
90 | ||
91 | var prefix = item.field; | |
92 | if (me.fieldTitles && me.fieldTitles[me.fields.indexOf(item.field)]) { | |
93 | prefix = me.fieldTitles[me.fields.indexOf(item.field)]; | |
94 | } | |
95 | tooltip.setHtml(prefix + ': ' + this.convertToUnits(record.get(item.field)) + suffix + | |
96 | '<br>' + new Date(record.get('time'))); | |
97 | }, | |
98 | ||
99 | onAfterRender: function(){ | |
100 | var me = this; | |
101 | ||
102 | // add correct label for left axis | |
103 | var axisTitle = ""; | |
104 | if (me.percentArr.indexOf(me.fields[0]) != -1) { | |
105 | axisTitle = "%"; | |
106 | } else if (me.bytesArr.indexOf(me.fields[0]) != -1) { | |
107 | axisTitle = "Bytes"; | |
108 | } else if (me.bytespersArr.indexOf(me.fields[0]) != -1) { | |
109 | axisTitle = "Bytes/s"; | |
110 | } | |
111 | me.axes[0].setTitle(axisTitle); | |
112 | ||
ed37370c | 113 | me.addTool([{ |
dba34cd6 DC |
114 | type: 'minus', |
115 | disabled: true, | |
116 | tooltip: gettext('Undo Zoom'), | |
117 | handler: function(){ | |
118 | var undoButton = me.interactions[0].getUndoButton(); | |
119 | if (undoButton.handler) { | |
120 | undoButton.handler(); | |
121 | } | |
122 | } | |
ed37370c DC |
123 | },{ |
124 | type: 'restore', | |
125 | tooltip: gettext('Toggle Legend'), | |
126 | handler: function(){ | |
127 | me.legend.setVisible(!me.legend.isVisible()); | |
128 | } | |
129 | }]); | |
b5494945 DC |
130 | // add a series for each field we get |
131 | me.fields.forEach(function(item, index){ | |
132 | var title = item; | |
133 | if (me.fieldTitles && me.fieldTitles[index]) { | |
134 | title = me.fieldTitles[index]; | |
135 | } | |
136 | me.addSeries({ | |
137 | type: 'line', | |
138 | xField: 'time', | |
139 | yField: item, | |
140 | title: title, | |
141 | fill: true, | |
142 | style: { | |
143 | lineWidth: 1.5, | |
22f2f9d6 | 144 | opacity: 0.60 |
b5494945 DC |
145 | }, |
146 | marker: { | |
147 | opacity: 0, | |
148 | scaling: 0.01, | |
149 | fx: { | |
150 | duration: 200, | |
151 | easing: 'easeOut' | |
152 | } | |
153 | }, | |
154 | highlightCfg: { | |
155 | opacity: 1, | |
156 | scaling: 1.5 | |
157 | }, | |
158 | tooltip: { | |
159 | trackMouse: true, | |
160 | renderer: 'onSeriesTooltipRender' | |
161 | } | |
162 | }); | |
163 | }); | |
164 | }, | |
165 | ||
dba34cd6 DC |
166 | onAfterAnimation: function(chart, eopts) { |
167 | // if the undobuton is disabled, | |
168 | // disable our tool | |
169 | var ourUndoZoomButton = chart.tools[0]; | |
170 | var undoButton = chart.interactions[0].getUndoButton(); | |
171 | ourUndoZoomButton.setDisabled(undoButton.isDisabled()); | |
172 | }, | |
173 | ||
b5494945 DC |
174 | initComponent: function() { |
175 | var me = this; | |
176 | ||
177 | if (!me.store) { | |
178 | throw "cannot work without store"; | |
179 | } | |
180 | ||
181 | if (!me.fields) { | |
182 | throw "cannot work without fields"; | |
183 | } | |
184 | ||
185 | me.callParent(); | |
87484017 DC |
186 | |
187 | // enable animation after the store is loaded | |
188 | me.store.onAfter('load', function() { | |
189 | me.setAnimation(true); | |
190 | }, this, {single: true}); | |
b5494945 DC |
191 | } |
192 | }); |