2020-11-10 09:18:06 +00:00
|
|
|
Ext.define('PBS.widget.UsageChart', {
|
|
|
|
extend: 'Ext.container.Container',
|
|
|
|
alias: 'widget.pbsUsageChart',
|
|
|
|
|
|
|
|
layout: {
|
|
|
|
type: 'hbox',
|
|
|
|
align: 'center',
|
|
|
|
},
|
|
|
|
|
|
|
|
items: [
|
|
|
|
{
|
|
|
|
width: 80,
|
|
|
|
xtype: 'box',
|
|
|
|
itemId: 'title',
|
|
|
|
data: {
|
|
|
|
title: '',
|
|
|
|
},
|
|
|
|
tpl: '<h3>{title}:</h3>',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
flex: 1,
|
|
|
|
xtype: 'cartesian',
|
2021-05-26 09:12:00 +00:00
|
|
|
downloadServerUrl: '-',
|
2020-11-10 09:18:06 +00:00
|
|
|
height: '100%',
|
|
|
|
itemId: 'chart',
|
|
|
|
border: false,
|
|
|
|
axes: [
|
|
|
|
{
|
|
|
|
type: 'numeric',
|
|
|
|
position: 'right',
|
2020-11-10 10:46:00 +00:00
|
|
|
hidden: false,
|
2020-11-10 09:18:06 +00:00
|
|
|
minimum: 0,
|
2020-11-10 10:46:00 +00:00
|
|
|
// TODO: make this configurable?!
|
|
|
|
maximum: 1,
|
|
|
|
renderer: (axis, label) => `${label*100}%`,
|
2020-11-10 09:18:06 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'time',
|
|
|
|
position: 'bottom',
|
|
|
|
hidden: true,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
|
|
|
|
store: {
|
|
|
|
trackRemoved: false,
|
|
|
|
data: {},
|
|
|
|
},
|
|
|
|
|
|
|
|
series: [{
|
|
|
|
type: 'line',
|
|
|
|
xField: 'time',
|
|
|
|
yField: 'val',
|
|
|
|
fill: 'true',
|
|
|
|
colors: ['#cfcfcf'],
|
|
|
|
tooltip: {
|
|
|
|
trackMouse: true,
|
|
|
|
renderer: function(tooltip, record, ctx) {
|
|
|
|
if (!record || !record.data) return;
|
|
|
|
let date = new Date(record.data.time);
|
2020-11-10 10:46:22 +00:00
|
|
|
date = Ext.Date.format(date, 'c');
|
2020-11-10 09:18:06 +00:00
|
|
|
let value = (100*record.data.val).toFixed(2);
|
|
|
|
tooltip.setHtml(
|
|
|
|
`${value} %<br />
|
|
|
|
${date}`,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
style: {
|
|
|
|
lineWidth: 1.5,
|
|
|
|
opacity: 0.60,
|
|
|
|
},
|
|
|
|
marker: {
|
|
|
|
opacity: 0,
|
|
|
|
scaling: 0.01,
|
|
|
|
fx: {
|
|
|
|
duration: 200,
|
|
|
|
easing: 'easeOut',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
highlightCfg: {
|
|
|
|
opacity: 1,
|
|
|
|
scaling: 1.5,
|
|
|
|
},
|
|
|
|
}],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
|
|
|
|
setData: function(data) {
|
|
|
|
let me = this;
|
|
|
|
let chart = me.chart;
|
|
|
|
chart.store.setData(data);
|
|
|
|
chart.redraw();
|
|
|
|
},
|
|
|
|
|
|
|
|
// the renderer for the tooltip and last value, default just the value
|
|
|
|
renderer: Ext.identityFn,
|
|
|
|
|
|
|
|
setTitle: function(title) {
|
|
|
|
let me = this;
|
|
|
|
me.title = title;
|
|
|
|
me.getComponent('title').update({ title: title });
|
|
|
|
},
|
|
|
|
|
|
|
|
initComponent: function() {
|
|
|
|
var me = this;
|
|
|
|
me.callParent();
|
|
|
|
|
|
|
|
if (me.title) {
|
|
|
|
me.getComponent('title').update({ title: me.title });
|
|
|
|
}
|
|
|
|
me.chart = me.getComponent('chart');
|
|
|
|
me.chart.timeaxis = me.chart.getAxes()[1];
|
|
|
|
if (me.color) {
|
|
|
|
me.chart.series[0].setStyle({
|
|
|
|
fill: me.color,
|
|
|
|
stroke: me.color,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|