123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388 |
- Ext4.onReady(function() {
- var memoryArray,
- processArray,
- colors,
- memoryStore,
- processesMemoryStore,
- cpuLoadStore,
- data,
- memoryPieChartConfig,
- barChartConfig,
- cpuLoadChartConfig,
- cpuLoadChartConfig2,
- win,
- cpuLoadTimer, pass;
- memoryArray = ['Wired', 'Active', 'Inactive', 'Free'];
- processArray = ['explorer', 'monitor', 'charts', 'desktop', 'Ext3', 'Ext4'];
- colors = ['rgb(244, 16, 0)',
- 'rgb(248, 130, 1)',
- 'rgb(0, 7, 255)',
- 'rgb(84, 254, 0)'];
- Ext4.chart.theme.Memory = Ext4.extend(Ext4.chart.theme.Base, {
- constructor: function(config) {
- Ext4.chart.theme.Base.prototype.constructor.call(this, Ext4.apply({
- colors: colors
- }, config));
- }
- });
- function generateData(a) {
- var data = [],
- i,
- names = a,
- rest = a.length, total = rest, consume;
- for (i = 0; i < a.length; i++) {
- consume = Math.floor(Math.random() * rest * 100) / 100 + 2;
- rest = rest - (consume - 5);
- data.push({
- name: names[i],
- memory: consume
- });
- }
- return data;
- }
- memoryStore = Ext4.create('store.json', {
- fields: ['name', 'memory'],
- data: generateData(memoryArray)
- });
- processesMemoryStore = Ext4.create('store.json', {
- fields: ['name', 'memory'],
- data: generateData(processArray)
- });
- cpuLoadStore = Ext4.create('store.json', {
- fields: ['core1', 'core2', 'time']
- });
- data = [];
- function generateCpuLoad() {
- function generate(factor) {
- var value = factor + ((Math.floor(Math.random() * 2) % 2) ? -1 : 1) * Math.floor(Math.random() * 9);
- if (value < 0 || value > 100) {
- value = 50;
- }
- return value;
- }
- if (data.length === 0) {
- data.push({
- core1: 0,
- core2: 0,
- time: 0
- });
- for (var i = 1; i < 100; i++) {
- data.push({
- core1: generate(data[i - 1].core1),
- core2: generate(data[i - 1].core2),
- time: i
- });
- }
- cpuLoadStore.loadData(data);
- }
- else {
- cpuLoadStore.data.removeAt(0);
- cpuLoadStore.data.each(function(item, key) {
- item.data.time = key;
- });
- var lastData = cpuLoadStore.last().data;
- cpuLoadStore.loadData([{
- core1: generate(lastData.core1),
- core2: generate(lastData.core2),
- time: lastData.time + 1
- }], true);
- }
- }
- generateCpuLoad();
- memoryPieChartConfig = {
- flex: 1,
- xtype: 'chart',
- animate: {
- duration: 250
- },
- store: memoryStore,
- shadow: true,
- legend: {
- position: 'right',
- update: false
- },
- insetPadding: 40,
- theme: 'Memory:gradients',
- series: [{
- donut: 30,
- type: 'pie',
- field: 'memory',
- showInLegend: true,
- tips: {
- trackMouse: true,
- width: 140,
- height: 28,
- renderer: function(storeItem, item) {
- //calculate percentage.
- var total = 0;
- memoryStore.each(function(rec) {
- total += rec.get('memory');
- });
- this.setTitle(storeItem.get('name') + ': ' + Math.round(storeItem.get('memory') / total * 100) + '%');
- }
- },
- highlight: {
- segment: {
- margin: 20
- }
- },
- labelTitle: {
- font: '13px Arial'
- },
- label: {
- field: 'name',
- display: 'rotate',
- contrast: true,
- font: '12px Arial'
- }
- }]
- };
- barChartConfig = {
- flex: 1,
- xtype: 'chart',
- theme: 'Category1',
- store: processesMemoryStore,
- animate: {
- easing: 'ease-in-out',
- duration: 750
- },
- axes: [{
- type: 'Numeric',
- position: 'left',
- minimum: 0,
- maximum: 10,
- fields: ['memory'],
- title: 'Memory',
- labelTitle: {
- font: '13px Arial'
- },
- label: {
- font: '11px Arial'
- }
- },{
- type: 'Category',
- position: 'bottom',
- fields: ['name'],
- title: 'System Processes',
- labelTitle: {
- font: 'bold 14px Arial'
- },
- label: {
- rotation: {
- degrees: 45
- }
- }
- },{
- type: 'Numeric',
- position: 'top',
- fields: ['memory'],
- title: 'Memory Usage',
- labelTitle: {
- font: 'bold 14px Arial'
- },
- label: {
- fill: '#FFFFFF',
- stroke: '#FFFFFF'
- },
- axisStyle: {
- fill: '#FFFFFF',
- stroke: '#FFFFFF'
- }
- }],
- series: [{
- title: 'Processes',
- type: 'column',
- xField: 'name',
- yField: 'memory',
- renderer: function(sprite, record, attr, index, store) {
- var highColor = Ext4.draw.Color.fromString('#e84b67'),
- lowColor = Ext4.draw.Color.fromString('#b1da5a'),
- value = record.get('memory'),
- color;
- if (value > 5) {
- color = lowColor.getDarker((value - 5) / 15).toString();
- }
- else {
- color = lowColor.getLighter(((5 - value) / 20)).toString();
- }
- if (value >= 8) {
- color = '#CD0000';
- }
- return Ext.apply(attr, {
- fill: color
- });
- }
- }]
- };
- cpuLoadChartConfig = {
- flex: 1,
- xtype: 'chart',
- theme: 'Category1',
- animate: false,
- store: cpuLoadStore,
- legend: {
- position: 'bottom',
- update: false
- },
- axes: [{
- type: 'Numeric',
- position: 'left',
- minimum: 0,
- maximum: 100,
- fields: ['core1'],
- title: 'CPU Load',
- grid: true,
- labelTitle: {
- font: '13px Arial'
- },
- label: {
- font: '11px Arial'
- }
- }],
- series: [{
- title: 'Core 1 (3.4GHz)',
- type: 'line',
- lineWidth: 4,
- showMarkers: false,
- fill: true,
- axis: ['left'],
- xField: 'time',
- yField: 'core1',
- style: {
- 'stroke-width': 1
- }
- }]
- };
- cpuLoadChartConfig2 = {
- flex: 1,
- xtype: 'chart',
- theme: 'Category2',
- animate: false,
- store: cpuLoadStore,
- legend: {
- position: 'bottom',
- update: false
- },
- axes: [{
- type: 'Numeric',
- position: 'left',
- minimum: 0,
- maximum: 100,
- grid: true,
- fields: ['core2'],
- title: 'CPU Load',
- labelTitle: {
- font: '13px Arial'
- },
- label: {
- font: '11px Arial'
- }
- }],
- series: [{
- title: 'Core 2 (3.4GHz)',
- type: 'line',
- lineWidth: 4,
- showMarkers: false,
- fill: true,
- axis: ['left'],
- xField: 'time',
- yField: 'core2',
- style: {
- 'stroke-width': 1
- }
- }]
- };
- win = Ext4.widget('window', {
- x: 90,
- y: 50,
- width: 800,
- height: 600,
- title: 'System Statistics',
- renderTo: Ext4.getBody(),
- closeAction: 'hide',
- layout: 'fit',
- items: [{
- xtype: 'panel',
- layout: {
- type: 'hbox',
- align: 'stretch'
- },
- items: [{
- flex: 1,
- height: 600,
- width: 400,
- xtype: 'container',
- layout: {
- type: 'vbox',
- align: 'stretch'
- },
- items: [
- cpuLoadChartConfig,
- cpuLoadChartConfig2
- ]
- }, {
- flex: 1,
- width: 400,
- height: 600,
- xtype: 'container',
- layout: {
- type: 'vbox',
- align: 'stretch'
- },
- items: [
- memoryPieChartConfig,
- barChartConfig
- ]
- }]
- }]
- });
- pass = 0;
- function doGenerateCpuLoad() {
- clearTimeout(cpuLoadTimer);
- cpuLoadTimer = setTimeout(function() {
- if (pass % 3 === 0) {
- memoryStore.loadData(generateData(memoryArray));
- }
- if (pass % 5 === 0) {
- processesMemoryStore.loadData(generateData(processArray));
- }
- generateCpuLoad();
- doGenerateCpuLoad();
- pass++;
- }, 500);
- }
- Ext.get('chart-win-shortcut').on('click', function() {
- doGenerateCpuLoad();
- win.show();
- });
- });
|