mirror of
https://github.com/nasa/openmct.git
synced 2025-06-14 13:18:15 +00:00
[Plot] Avoid displaying bad labels
Avoid displaying bad labels for tick marks, or in the coordinates shown on hover. Done in the context of refactoring to support WTD-625.
This commit is contained in:
@ -33,6 +33,7 @@ define(
|
||||
domainOffset,
|
||||
mousePosition,
|
||||
marqueeStart,
|
||||
hoverCoordinates,
|
||||
isHovering = false;
|
||||
|
||||
// Utility, for map/forEach loops. Index 0 is domain,
|
||||
@ -43,6 +44,11 @@ define(
|
||||
formatter.formatDomainValue)(v);
|
||||
}
|
||||
|
||||
// Utility function for filtering out empty strings.
|
||||
function isNonEmpty(v) {
|
||||
return typeof v === 'string' && v !== "";
|
||||
}
|
||||
|
||||
// Converts from pixel coordinates to domain-range,
|
||||
// to interpret mouse gestures.
|
||||
function mousePositionToDomainRange(mousePosition) {
|
||||
@ -79,6 +85,16 @@ define(
|
||||
return [ position[0] - domainOffset, position[1] ];
|
||||
}
|
||||
|
||||
|
||||
// Update the currnet hover coordinates
|
||||
function updateHoverCoordinates() {
|
||||
hoverCoordinates = mousePosition &&
|
||||
mousePositionToDomainRange(mousePosition)
|
||||
.map(formatValue)
|
||||
.filter(isNonEmpty)
|
||||
.join(", ");
|
||||
}
|
||||
|
||||
// Update the drawable marquee area to reflect current
|
||||
// mouse position (or don't show it at all, if no marquee
|
||||
// zoom is in progress)
|
||||
@ -191,10 +207,7 @@ define(
|
||||
* coordinates over which the mouse is hovered
|
||||
*/
|
||||
getHoverCoordinates: function () {
|
||||
return mousePosition ?
|
||||
mousePositionToDomainRange(
|
||||
mousePosition
|
||||
).map(formatValue) : [];
|
||||
return hoverCoordinates;
|
||||
},
|
||||
/**
|
||||
* Handle mouse movement over the chart area.
|
||||
@ -203,6 +216,7 @@ define(
|
||||
hover: function ($event) {
|
||||
isHovering = true;
|
||||
mousePosition = toMousePosition($event);
|
||||
updateHoverCoordinates();
|
||||
if (marqueeStart) {
|
||||
updateMarqueeBox();
|
||||
}
|
||||
|
Reference in New Issue
Block a user