summaryrefslogtreecommitdiffstats
path: root/web-gui/plot/source/class/plot/Application.js
blob: 23dc842a78ef3075fb29d95ba1cc3bce6f764a89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/* ************************************************************************

	 Copyright:

	 License:

	 Authors:

************************************************************************ */

/* ************************************************************************

#asset(plot/*)

************************************************************************ */

/**
 * This is the main application class of your custom application "plot"
 */
qx.Class.define("plot.Application",
{
extend : qx.application.Standalone,



/*
*****************************************************************************
	 MEMBERS
*****************************************************************************
*/

members :
{
	__rpc: null,
	__call: null,
	__plot: null,
	__data: null,
	__flot: null,
	__loadLabel: null,
	/**
	 * This method contains the initial application code and gets called 
	 * during startup of the application
	 * 
	 * @lint ignoreDeprecated(alert)
	 */
	main : function()
	{
		// Call super class
		this.base(arguments);

		// Enable logging in debug variant
		if (qx.core.Variant.isSet("qx.debug", "on"))
		{
			// support native logging capabilities, e.g. Firebug for Firefox
			qx.log.appender.Native;
			// support additional cross-browser console. Press F7 to toggle visibility
			qx.log.appender.Console;
		}

		/*
		-------------------------------------------------------------------------
			Below is your actual application code...
		-------------------------------------------------------------------------
		*/

		// Document is the application root
		var doc = this.getRoot();
		doc.setBackgroundColor("#ffffff");

		var back = new qx.ui.basic.Image("hello_world/back.png");
		back.setScale(true);
		doc.add(back, {left:0, top: 0});

		this.__rpc = new qx.io.remote.Rpc("http://localhost:8080/rpc", "com.pengutronix.jdb.systeminfo|/");

		this.__data = [];
		this.__plot = new qx.ui.core.Widget();
		this.__plot.addListener("appear", this.__showPlot, this);
		doc.add(this.__plot, {left: 100, top: 100});
		this.__plot.setHeight(200);
		this.__plot.setWidth(400);

		this.__loadLabel = new qx.ui.basic.Label("-");
		doc.add(this.__loadLabel, {left: 100, top: 80 });

		var timer = new qx.event.Timer(500);
		timer.addListener("interval", this.__tick, this);
		timer.start();

	},
	__showPlot: function() {
		var e = this.__plot.getContainerElement().getDomElement();
		qx.bom.element.Attribute.set(e, 'id', 'infoPlot');

		this.__flot = jQuery.plot(jQuery("#infoPlot"),
			[],
			{
			xaxis: {ticks: 0, min: 0, max: 100},
			yaxis: {ticks: 10, min: 0, max: 100},
			grid: {borderWidth: 1}
			});
		this.__updatePlot();
	},
	__updatePlot: function() {
		this.__flot.setData(
			[{
			data: this.__data
			}]);
		this.__flot.setupGrid();
		this.__flot.draw();
	},
	__tick: function() {
		if (this.__call != null) {
			this.__rpc.abort(this.__call);
		}
		this.__call = this.__rpc.callAsync(
			qx.lang.Function.bind(this.__callback, this),
			"com.pengutronix.jdb.SystemInfo.CpuLoad");
	},
	__callback: function(ret, err, id) {
		this.__call = null;
		if (err != null) {
			return;
		}
		var data = [];
		var start = this.__data.length - 99;
		if (start < 0)
			start = 0;
		var i;
		for (i = start; i < this.__data.length; ++i)
			data.push([i-start, this.__data[i][1]]);
		data.push([i-start, ret])
		this.__data = data;
		this.__loadLabel.setValue(this.tr("CPU Load: %1%", ret));
		this.__updatePlot();
	}
}
});