/* ************************************************************************ 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(); } } });