mirror of
https://github.com/nasa/openmct.git
synced 2025-06-22 17:08:57 +00:00
[Plot] Organize plot elements
Place elements of the PlotController into a separate directory inside of the source folder for the plot plug-in, in preparation for review and integration. Part of ongoing plot transition to Angular, WTD-533.
This commit is contained in:
92
platform/features/plot/src/elements/PlotPreparer.js
Normal file
92
platform/features/plot/src/elements/PlotPreparer.js
Normal file
@ -0,0 +1,92 @@
|
||||
/*global define,Float32Array*/
|
||||
|
||||
/**
|
||||
* Prepares data to be rendered in a GL Plot. Handles
|
||||
* the conversion from data API to displayable buffers.
|
||||
*/
|
||||
define(
|
||||
function () {
|
||||
'use strict';
|
||||
|
||||
function identity(x) { return x; }
|
||||
|
||||
function PlotPreparer(datas, domain, range) {
|
||||
var index,
|
||||
vertices = [],
|
||||
max = [Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY],
|
||||
min = [Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY],
|
||||
x,
|
||||
y,
|
||||
xLabels = {},
|
||||
yLabels = {},
|
||||
yUnits = {},
|
||||
domainOffset = Number.POSITIVE_INFINITY,
|
||||
buffers;
|
||||
|
||||
datas = datas || [];
|
||||
|
||||
datas.filter(identity).forEach(function (data) {
|
||||
domainOffset = Math.min(data.getDomainValue(0, domain), domainOffset);
|
||||
});
|
||||
|
||||
datas.forEach(function (data, i) {
|
||||
if (!data) {
|
||||
return; // skip null data
|
||||
}
|
||||
|
||||
vertices.push([]);
|
||||
for (index = 0; index < data.getPointCount(); index = index + 1) {
|
||||
x = data.getDomainValue(index, domain);
|
||||
y = data.getRangeValue(index, range);
|
||||
vertices[i].push(x - domainOffset);
|
||||
vertices[i].push(y);
|
||||
min[0] = Math.min(min[0], x);
|
||||
min[1] = Math.min(min[1], y);
|
||||
max[0] = Math.max(max[0], x);
|
||||
max[1] = Math.max(max[1], y);
|
||||
}
|
||||
|
||||
if (data.getDomainLabel) {
|
||||
xLabels[data.getDomainLabel(domain)] = true;
|
||||
}
|
||||
|
||||
if (data.getRangeLabel) {
|
||||
yLabels[data.getRangeLabel(range)] = true;
|
||||
}
|
||||
|
||||
if (data.getRangeUnits) {
|
||||
yUnits[data.getRangeUnits(range)] = true;
|
||||
}
|
||||
});
|
||||
|
||||
if (max[1] === min[1]) {
|
||||
max[1] = max[1] + 1.0;
|
||||
min[1] = min[1] - 1.0;
|
||||
}
|
||||
|
||||
xLabels = Object.keys(xLabels).sort();
|
||||
yLabels = Object.keys(yLabels).sort();
|
||||
yUnits = Object.keys(yUnits).sort();
|
||||
|
||||
buffers = vertices.map(function (v) { return new Float32Array(v); });
|
||||
|
||||
return {
|
||||
getDimensions: function () {
|
||||
return [max[0] - min[0], max[1] - min[1]];
|
||||
},
|
||||
getOrigin: function () {
|
||||
return min;
|
||||
},
|
||||
getDomainOffset: function () {
|
||||
return domainOffset;
|
||||
},
|
||||
getBuffers: function () {
|
||||
return buffers;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return PlotPreparer;
|
||||
|
||||
}
|
||||
);
|
Reference in New Issue
Block a user