]>
git.proxmox.com Git - proxmox-widget-toolkit.git/blob - panel/RRDChart.js
1 Ext
.define('Proxmox.widget.RRDChart', {
2 extend
: 'Ext.chart.CartesianChart',
3 alias
: 'widget.proxmoxRRDChart',
5 unit
: undefined, // bytes, bytespersecond, percent
8 xclass
: 'Ext.app.ViewController',
10 convertToUnits: function(value
) {
11 var units
= ['', 'k','M','G','T', 'P'];
13 while(value
>= 1000 && si
< (units
.length
-1)){
18 // javascript floating point weirdness
19 value
= Ext
.Number
.correctFloat(value
);
21 // limit to 2 decimal points
22 value
= Ext
.util
.Format
.number(value
, "0.##");
24 return value
.toString() + " " + units
[si
];
27 leftAxisRenderer: function(axis
, label
, layoutContext
) {
30 return me
.convertToUnits(label
);
33 onSeriesTooltipRender: function(tooltip
, record
, item
) {
34 var me
= this.getView();
38 if (me
.unit
=== 'percent') {
40 } else if (me
.unit
=== 'bytes') {
42 } else if (me
.unit
=== 'bytespersecond') {
46 var prefix
= item
.field
;
47 if (me
.fieldTitles
&& me
.fieldTitles
[me
.fields
.indexOf(item
.field
)]) {
48 prefix
= me
.fieldTitles
[me
.fields
.indexOf(item
.field
)];
50 tooltip
.setHtml(prefix
+ ': ' + this.convertToUnits(record
.get(item
.field
)) + suffix
+
51 '<br>' + new Date(record
.get('time')));
54 onAfterAnimation: function(chart
, eopts
) {
55 // if the undobuton is disabled,
58 var ourUndoZoomButton
= chart
.tools
[0];
59 var undoButton
= chart
.interactions
[0].getUndoButton();
60 ourUndoZoomButton
.setDisabled(undoButton
.isDisabled());
74 renderer
: 'leftAxisRenderer',
75 //renderer: function(axis, label) { return label; },
87 animationend
: 'onAfterAnimation'
91 initComponent: function() {
96 throw "cannot work without store";
100 throw "cannot work without fields";
105 // add correct label for left axis
107 if (me
.unit
=== 'percent') {
109 } else if (me
.unit
=== 'bytes') {
111 } else if (me
.unit
=== 'bytespersecond') {
112 axisTitle
= "Bytes/s";
113 } else if (me
.fieldTitles
&& me
.fieldTitles
.length
=== 1) {
114 axisTitle
= me
.fieldTitles
[0];
115 } else if (me
.fields
.length
=== 1) {
116 axisTitle
= me
.fields
[0];
119 me
.axes
[0].setTitle(axisTitle
);
125 tooltip
: gettext('Undo Zoom'),
127 var undoButton
= me
.interactions
[0].getUndoButton();
128 if (undoButton
.handler
) {
129 undoButton
.handler();
134 tooltip
: gettext('Toggle Legend'),
137 me
.legend
.setVisible(!me
.legend
.isVisible());
143 // add a series for each field we get
144 me
.fields
.forEach(function(item
, index
){
146 if (me
.fieldTitles
&& me
.fieldTitles
[index
]) {
147 title
= me
.fieldTitles
[index
];
149 me
.addSeries(Ext
.apply(
174 renderer
: 'onSeriesTooltipRender'
181 // enable animation after the store is loaded
182 me
.store
.onAfter('load', function() {
183 me
.setAnimation(true);
184 }, this, {single
: true});