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.fire = function(json) {
var koObservable = self.listeners[json.path] || null;
if (!koObservable)
return;
var value = json.value;
var listeners = self.listeners[json.path] || [];
listeners.forEach(function(koObservable) {
koObservable(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.getListener = function(pathOrAlias) {
if( pathOrAlias in self.listeners ) {
return self.listeners[pathOrAlias];
}
self.removeListener = function(pathOrAlias, koObservable) {
var path = resolvePropertyPath(self, 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) {
@ -92,29 +118,35 @@ require([
"prop" : alias,
"koObservable" : koObservable
});
return;
return self;
}
var path = this.aliases[alias] || "";
if (path.length == 0) {
if (alias.charAt(0) == '/') {
path = alias;
} else {
console.log("can't listen to " + alias + ": unknown alias.");
return;
}
var path = resolvePropertyPath(self, alias);
if (path == null) {
console.log("can't listen to " + alias + ": unknown alias or invalid path.");
return self;
}
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({
command : 'addListener',
node : path
}));
}
self.ws.send(JSON.stringify({
command : 'get',
node : path
}));
return self;
}
self.aliases = aliases || {};
@ -365,9 +397,9 @@ require([
update : function(element, valueAccessor, allBindings) {
var value = valueAccessor() || {};
var data = ko.unwrap( value.data );
var options = ko.unwrap( value.options );
jquery.plot(element, data, options );
var data = ko.unwrap(value.data);
var options = ko.unwrap(value.options);
jquery.plot(element, data, options);
},

View file

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

View file

@ -1,6 +1,10 @@
<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">
<caption class="ui-widget-header ui-corner-all" data-bind="text: helpTitle"></caption>
<tbody data-bind="foreach: helpContent">

View file

@ -6,6 +6,16 @@ define([
self.helpTitle = ko.observable("");
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) {

View file

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