1
0
Fork 0

Phi: initial work for plotting properties

This commit is contained in:
Torsten Dreyer 2015-03-02 15:48:09 +01:00
parent 59e0fa180a
commit f1170e3709
5 changed files with 97 additions and 39 deletions

View file

@ -67,22 +67,48 @@ require([
self.initWebsocket(); self.initWebsocket();
self.fire = function(json) { self.fire = function(json) {
var koObservable = self.listeners[json.path] || null; var value = json.value;
if (!koObservable) var listeners = self.listeners[json.path] || [];
return; listeners.forEach(function(koObservable) {
koObservable(value)
});
koObservable(json.value); koObservable(json.value);
} }
function resolvePropertyPath(self, pathOrAlias) {
if (pathOrAlias in self.aliases)
return self.aliases[pathOrAlias];
if (pathOrAlias.charAt(0) == '/')
return pathOrAlias;
return null;
}
self.listeners = {} self.listeners = {}
self.getListener = function(pathOrAlias) { self.removeListener = function(pathOrAlias, koObservable) {
if( pathOrAlias in self.listeners ) { var path = resolvePropertyPath(self, pathOrAlias);
return self.listeners[pathOrAlias]; if (path == null) {
} console.log("can't remove listener for " + pathOrAlias + ": unknown alias or invalid path.");
return self;
} }
self.removeListener = function(pathOrAlias) { var listeners = self.listeners[path] || [];
var idx = listeners.indexOf(koObservable);
if (idx == -1) {
console.log("can't remove listener for " + path + ": not a listener.");
return self;
}
listeners.splice(idx, 1);
if (0 == listeners.length) {
self.ws.send(JSON.stringify({
command : 'removeListener',
node : path
}));
}
return self;
} }
self.addListener = function(alias, koObservable) { self.addListener = function(alias, koObservable) {
@ -92,29 +118,35 @@ require([
"prop" : alias, "prop" : alias,
"koObservable" : koObservable "koObservable" : koObservable
}); });
return; return self;
} }
var path = this.aliases[alias] || ""; var path = resolvePropertyPath(self, alias);
if (path.length == 0) { if (path == null) {
if (alias.charAt(0) == '/') { console.log("can't listen to " + alias + ": unknown alias or invalid path.");
path = alias; return self;
} else {
console.log("can't listen to " + alias + ": unknown alias.");
return;
}
} }
self.listeners[path] = koObservable; var listeners = self.listeners[path] = (self.listeners[path] || []);
if (listeners.indexOf(koObservable) != -1) {
console.log("won't listen to " + path + ": duplicate.");
return self;
}
listeners.push(koObservable);
if (1 == listeners.length) {
self.ws.send(JSON.stringify({ self.ws.send(JSON.stringify({
command : 'addListener', command : 'addListener',
node : path node : path
})); }));
}
self.ws.send(JSON.stringify({ self.ws.send(JSON.stringify({
command : 'get', command : 'get',
node : path node : path
})); }));
return self;
} }
self.aliases = aliases || {}; self.aliases = aliases || {};
@ -365,9 +397,9 @@ require([
update : function(element, valueAccessor, allBindings) { update : function(element, valueAccessor, allBindings) {
var value = valueAccessor() || {}; var value = valueAccessor() || {};
var data = ko.unwrap( value.data ); var data = ko.unwrap(value.data);
var options = ko.unwrap( value.options ); var options = ko.unwrap(value.options);
jquery.plot(element, data, options ); jquery.plot(element, data, options);
}, },

View file

@ -17,6 +17,10 @@ define([
require : 'topics/Aircraft/Help' require : 'topics/Aircraft/Help'
}); });
ko.components.register('Aircraft/Panel', {
require : 'topics/Aircraft/Panel'
});
function ViewModel(params) { function ViewModel(params) {
var self = this; var self = this;

View file

@ -1,6 +1,10 @@
<style> <style>
</style> </style>
<div class="ui-widget-content ui-corner-all" data-bind="if: longDescription().length">
<div class="ui-widget-header ui-corner-all" data-bind="text: description"></div>
<div data-bind="text: longDescription"></div>
</div>
<table id="phi-aircraft-helptable" class="ui-widget-content ui-corner-all"> <table id="phi-aircraft-helptable" class="ui-widget-content ui-corner-all">
<caption class="ui-widget-header ui-corner-all" data-bind="text: helpTitle"></caption> <caption class="ui-widget-header ui-corner-all" data-bind="text: helpTitle"></caption>
<tbody data-bind="foreach: helpContent"> <tbody data-bind="foreach: helpContent">

View file

@ -6,6 +6,16 @@ define([
self.helpTitle = ko.observable(""); self.helpTitle = ko.observable("");
self.helpContent = ko.observableArray([]); self.helpContent = ko.observableArray([]);
self.description = ko.observable('');
self.longDescription = ko.observable('');
jquery.get('/json/sim/description', null, function(data) {
self.description(data.value);
});
jquery.get('/json/sim/long-description', null, function(data) {
self.longDescription(data.value);
});
jquery.get('/json/sim/help?d=2', null, function(data) { jquery.get('/json/sim/help?d=2', null, function(data) {

View file

@ -11,8 +11,10 @@ define([
this.samples = []; this.samples = [];
this.sample = function(timeStamp) { this.sample = function(timeStamp) {
while (this.samples.length >= this.maxSamples) console.log(this.samples.length,this.maxSamples);
while (this.samples.length >= this.maxSamples) {
this.samples.shift(); this.samples.shift();
}
this.samples.push([ this.samples.push([
timeStamp, this.source() timeStamp, this.source()
]); ]);
@ -42,8 +44,9 @@ define([
} }
this.removeSource = function(source) { this.removeSource = function(source) {
var s = this.sources[source].source;
delete this.sources[source]; delete this.sources[source];
return this; return s;
} }
this.containsSource = function(source) { this.containsSource = function(source) {
@ -242,19 +245,23 @@ define([
self.toggleProp = function(prop) { self.toggleProp = function(prop) {
if (self.propertySampler.containsSource(prop.path)) { if (self.propertySampler.containsSource(prop.path)) {
self.propertySampler.removeSource(prop.path); var obs = self.propertySampler.removeSource(prop.path);
ko.utils.knockprops.removeListener(prop.path, obs);
return; return;
} }
var obs = ko.utils.knockprops.getListener(prop.path); var obs = ko.observable(0);
if (obs) { ko.utils.knockprops.addListener(prop.path, obs);
self.propertySampler.addSource(new SampleSource(prop, obs, { self.propertySampler.addSource(new SampleSource(prop, obs, {
maxSamples : 1000, maxSamples : 300,
})); }));
} }
}
self.update = function() { self.updateId = 0;
self.update = function(id) {
if (self.updateId != id)
return;
var sources = self.propertySampler.sources; var sources = self.propertySampler.sources;
var data = []; var data = [];
@ -265,7 +272,7 @@ define([
data.push({ data.push({
// color : 'rgb(192, 128, 0)', // color : 'rgb(192, 128, 0)',
data : source.samples, data : source.samples,
label : key, label : "hallO",
lines : { lines : {
show : true show : true
}, },
@ -276,23 +283,24 @@ define([
show : false show : false
}, },
shadowSize : 0, shadowSize : 0,
yaxis: i++, yaxis : i++,
}); });
} }
self.flotData(data); self.flotData(data);
setTimeout(function() { setTimeout(function() {
self.update(); self.update(id);
}, 100); }, 100);
} }
self.update(); self.update(++self.updateId);
} }
ViewModel.prototype.dispose = function() { ViewModel.prototype.dispose = function() {
console.log("disposing pal"); console.log("disposing pal");
this.propertySampler.stop(); this.propertySampler.stop();
this.updateId++;
} }
// Return component definition // Return component definition