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.
17 * Copyright(c) 2006-2011 Sencha Inc.
18 * licensing@sencha.com
19 * http://www.sencha.com/license
22 Ext.define('MyDesktop.SystemStatus', {
23 extend: 'Ext.ux.desktop.Module',
32 // No launcher means we don't appear on the Start Menu...
34 // text: 'SystemStatus',
35 // iconCls:'cpustats',
36 // handler : this.createWindow,
40 Ext.chart.theme.Memory = Ext.extend(Ext.chart.theme.Base, {
41 constructor: function(config) {
42 Ext.chart.theme.Memory.superclass.constructor.call(this, Ext.apply({
43 colors: [ 'rgb(244, 16, 0)',
52 createNewWindow: function () {
54 desktop = me.app.getDesktop();
57 me.cpuLoadStore = Ext.create('store.json', {
58 fields: ['core1', 'core2']
61 me.memoryArray = ['Wired', 'Active', 'Inactive', 'Free'];
62 me.memoryStore = Ext.create('store.json', {
63 fields: ['name', 'memory'],
64 data: me.generateData(me.memoryArray)
68 me.processArray = ['explorer', 'monitor', 'charts', 'desktop', 'Ext3', 'Ext4'];
69 me.processesMemoryStore = Ext.create('store.json', {
70 fields: ['name', 'memory'],
71 data: me.generateData(me.processArray)
76 return desktop.createWindow({
78 title: 'System Status',
90 destroy: function () {
91 clearTimeout(me.updateTimer);
92 me.updateTimer = null;
112 me.createCpu1LoadChart(),
113 me.createCpu2LoadChart()
125 me.createMemoryPieChart(),
126 me.createProcessChart()
133 createWindow : function() {
134 var win = this.app.getDesktop().getWindow(this.id);
136 win = this.createNewWindow();
142 createCpu1LoadChart: function () {
148 store: this.cpuLoadStore,
168 title: 'Core 1 (3.4GHz)',
183 createCpu2LoadChart: function () {
189 store: this.cpuLoadStore,
209 title: 'Core 2 (3.4GHz)',
224 createMemoryPieChart: function () {
233 store: this.memoryStore,
240 theme: 'Memory:gradients',
250 renderer: function(storeItem, item) {
251 //calculate percentage.
253 me.memoryStore.each(function(rec) {
254 total += rec.get('memory');
256 this.setTitle(storeItem.get('name') + ': ' +
257 Math.round(storeItem.get('memory') / total * 100) + '%');
278 createProcessChart: function () {
283 store: this.processesMemoryStore,
285 easing: 'ease-in-out',
305 title: 'System Processes',
307 font: 'bold 14px Arial'
318 title: 'Memory Usage',
320 font: 'bold 14px Arial'
336 renderer: function(sprite, record, attr, index, store) {
337 var lowColor = Ext.draw.Color.fromString('#b1da5a'),
338 value = record.get('memory'),
342 color = lowColor.getDarker((value - 5) / 15).toString();
344 color = lowColor.getLighter(((5 - value) / 20)).toString();
351 return Ext.apply(attr, {
359 generateCpuLoad: function () {
361 data = me.cpuLoadData;
363 function generate(factor) {
364 var value = factor + ((Math.floor(Math.random() * 2) % 2) ? -1 : 1) * Math.floor(Math.random() * 9);
366 if (value < 0 || value > 100) {
373 if (data.length === 0) {
380 for (var i = 1; i < 100; i++) {
382 core1: generate(data[i - 1].core1),
383 core2: generate(data[i - 1].core2),
388 me.cpuLoadStore.loadData(data);
390 me.cpuLoadStore.data.removeAt(0);
391 me.cpuLoadStore.data.each(function(item, key) {
392 item.data.time = key;
395 var lastData = me.cpuLoadStore.last().data;
396 me.cpuLoadStore.loadData([{
397 core1: generate(lastData.core1),
398 core2: generate(lastData.core2),
399 time: lastData.time + 1
405 generateData: function (names) {
408 rest = names.length, consume;
410 for (i = 0; i < names.length; i++) {
411 consume = Math.floor(Math.random() * rest * 100) / 100 + 2;
412 rest = rest - (consume - 5);
422 updateCharts: function () {
424 clearTimeout(me.updateTimer);
425 me.updateTimer = setTimeout(function() {
426 if (me.pass % 3 === 0) {
427 me.memoryStore.loadData(me.generateData(me.memoryArray));
430 if (me.pass % 5 === 0) {
431 me.processesMemoryStore.loadData(me.generateData(me.processArray));
434 me.generateCpuLoad();