mirror of
https://github.com/nasa/openmct.git
synced 2025-04-12 13:47:55 +00:00
[Plot] Separate out positioning
Separate out pixel-to-plot-coordinate conversion into its own script, to simplify PlotController for testing and maintainability. WTD-533.
This commit is contained in:
parent
1b4286344d
commit
5bfa9c76a7
platform/features/plot/src
@ -8,9 +8,10 @@ define(
|
||||
"./PlotPreparer",
|
||||
"./PlotPalette",
|
||||
"./PlotPanZoomStack",
|
||||
"./PlotPosition",
|
||||
"../lib/moment.min.js"
|
||||
],
|
||||
function (PlotPreparer, PlotPalette, PlotPanZoomStack) {
|
||||
function (PlotPreparer, PlotPalette, PlotPanZoomStack, PlotPosition) {
|
||||
"use strict";
|
||||
|
||||
var AXIS_DEFAULTS = [
|
||||
@ -44,30 +45,15 @@ define(
|
||||
return (i ? formatRangeValue : formatDomainValue)(v);
|
||||
}
|
||||
|
||||
|
||||
function pixelToDomainRange(x, y, width, height, domainOffset) {
|
||||
var panZoom = panZoomStack.getPanZoom(),
|
||||
offset = [ domainOffset || 0, 0 ],
|
||||
origin = panZoom.origin,
|
||||
dimensions = panZoom.dimensions;
|
||||
|
||||
if (!dimensions || !origin) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [ x / width, (height - y) / height ].map(function (v, i) {
|
||||
return v * dimensions[i] + origin[i] + offset[i];
|
||||
});
|
||||
}
|
||||
|
||||
function mousePositionToDomainRange(mousePosition, domainOffset) {
|
||||
return pixelToDomainRange(
|
||||
return new PlotPosition(
|
||||
mousePosition.x,
|
||||
mousePosition.y,
|
||||
mousePosition.width,
|
||||
mousePosition.height,
|
||||
panZoomStack,
|
||||
domainOffset
|
||||
);
|
||||
).getPosition();
|
||||
}
|
||||
|
||||
function generateTicks(start, span, count, format) {
|
||||
|
39
platform/features/plot/src/PlotPosition.js
Normal file
39
platform/features/plot/src/PlotPosition.js
Normal file
@ -0,0 +1,39 @@
|
||||
/*global define*/
|
||||
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
"use strict";
|
||||
|
||||
function PlotPosition(x, y, width, height, panZoomStack, domainOffset) {
|
||||
var panZoom = panZoomStack.getPanZoom(),
|
||||
offset = [ domainOffset || 0, 0 ],
|
||||
origin = panZoom.origin,
|
||||
dimensions = panZoom.dimensions,
|
||||
position;
|
||||
|
||||
if (!dimensions || !origin) {
|
||||
position = [];
|
||||
} else {
|
||||
position = [ x / width, (height - y) / height ].map(function (v, i) {
|
||||
return v * dimensions[i] + origin[i] + offset[i];
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
getDomain: function () {
|
||||
return position[0];
|
||||
},
|
||||
getRange: function () {
|
||||
return position[1];
|
||||
},
|
||||
getPosition: function () {
|
||||
return position;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
return PlotPosition;
|
||||
}
|
||||
);
|
Loading…
x
Reference in New Issue
Block a user