3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
15 Ext4.onReady(function() {
30 memoryArray = ['Wired', 'Active', 'Inactive', 'Free'];
31 processArray = ['explorer', 'monitor', 'charts', 'desktop', 'Ext3', 'Ext4'];
32 colors = ['rgb(244, 16, 0)',
37 Ext4.chart.theme.Memory = Ext4.extend(Ext4.chart.theme.Base, {
38 constructor: function(config) {
39 Ext4.chart.theme.Base.prototype.constructor.call(this, Ext4.apply({
45 function generateData(a) {
49 rest = a.length, total = rest, consume;
50 for (i = 0; i < a.length; i++) {
51 consume = Math.floor(Math.random() * rest * 100) / 100 + 2;
52 rest = rest - (consume - 5);
62 memoryStore = Ext4.create('store.json', {
63 fields: ['name', 'memory'],
64 data: generateData(memoryArray)
67 processesMemoryStore = Ext4.create('store.json', {
68 fields: ['name', 'memory'],
69 data: generateData(processArray)
72 cpuLoadStore = Ext4.create('store.json', { fields: ['core1', 'core2'] });
76 function generateCpuLoad() {
77 function generate(factor) {
78 var value = factor + ((Math.floor(Math.random() * 2) % 2) ? -1 : 1) * Math.floor(Math.random() * 9);
80 if (value < 0 || value > 100) {
87 if (data.length === 0) {
94 for (var i = 1; i < 100; i++) {
96 core1: generate(data[i - 1].core1),
97 core2: generate(data[i - 1].core2),
102 cpuLoadStore.loadData(data);
105 cpuLoadStore.data.removeAt(0);
106 cpuLoadStore.data.each(function(item, key) {
107 item.data.time = key;
110 var lastData = cpuLoadStore.last().data;
111 cpuLoadStore.loadData([{
112 core1: generate(lastData.core1),
113 core2: generate(lastData.core2),
114 time: lastData.time + 1
122 memoryPieChartConfig = {
135 theme: 'Memory:gradients',
145 renderer: function(storeItem, item) {
146 //calculate percentage.
148 memoryStore.each(function(rec) {
149 total += rec.get('memory');
151 this.setTitle(storeItem.get('name') + ': ' + Math.round(storeItem.get('memory') / total * 100) + '%');
175 store: processesMemoryStore,
177 easing: 'ease-in-out',
197 title: 'System Processes',
199 font: 'bold 14px Arial'
210 title: 'Memory Usage',
212 font: 'bold 14px Arial'
228 renderer: function(sprite, record, attr, index, store) {
229 var highColor = Ext4.draw.Color.fromString('#e84b67'),
230 lowColor = Ext4.draw.Color.fromString('#b1da5a'),
231 value = record.get('memory'),
235 color = lowColor.getDarker((value - 5) / 15).toString();
238 color = lowColor.getLighter(((5 - value) / 20)).toString();
245 return Ext.apply(attr, {
252 cpuLoadChartConfig = {
277 title: 'Core 1 (3.4GHz)',
291 cpuLoadChartConfig2 = {
316 title: 'Core 2 (3.4GHz)',
330 win = Ext4.createWidget('window', {
335 title: 'System Statistics',
336 renderTo: Ext4.getBody(),
368 memoryPieChartConfig,
376 function doGenerateCpuLoad() {
377 clearTimeout(cpuLoadTimer);
378 cpuLoadTimer = setTimeout(function() {
379 if (pass % 3 === 0) {
380 memoryStore.loadData(generateData(memoryArray));
383 if (pass % 5 === 0) {
384 processesMemoryStore.loadData(generateData(processArray));
393 Ext.get('chart-win-shortcut').on('click', function() {