mirror of
https://github.com/nasa/openmct.git
synced 2025-06-02 07:30:49 +00:00
Added isUTCBased to TimeSystem interface
This commit is contained in:
parent
b9c41107c1
commit
6501e2eb5f
1
main.js
1
main.js
@ -106,6 +106,7 @@ define([
|
|||||||
'./platform/search/bundle',
|
'./platform/search/bundle',
|
||||||
'./platform/status/bundle',
|
'./platform/status/bundle',
|
||||||
'./platform/commonUI/regions/bundle'
|
'./platform/commonUI/regions/bundle'
|
||||||
|
|
||||||
], function (Main, legacyRegistry) {
|
], function (Main, legacyRegistry) {
|
||||||
return {
|
return {
|
||||||
legacyRegistry: legacyRegistry,
|
legacyRegistry: legacyRegistry,
|
||||||
|
@ -66,5 +66,12 @@ define([], function () {
|
|||||||
throw new Error('Not implemented');
|
throw new Error('Not implemented');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {boolean}
|
||||||
|
*/
|
||||||
|
TimeSystem.prototype.isUTCBased = function () {
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
return TimeSystem;
|
return TimeSystem;
|
||||||
});
|
});
|
||||||
|
@ -44,16 +44,25 @@ define(
|
|||||||
.append('svg:svg')
|
.append('svg:svg')
|
||||||
.attr('width', '100%')
|
.attr('width', '100%')
|
||||||
.attr('height', height);
|
.attr('height', height);
|
||||||
var xScale = d3.scaleUtc();
|
|
||||||
var xAxis = d3.axisTop();
|
var xAxis = d3.axisTop();
|
||||||
// draw x axis with labels and move to the bottom of the chart area
|
// draw x axis with labels and move to the bottom of the chart area
|
||||||
var axisElement = vis.append("g")
|
var axisElement = vis.append("g")
|
||||||
.attr("transform", "translate(0," + (height - padding) + ")");
|
.attr("transform", "translate(0," + (height - padding) + ")");
|
||||||
|
|
||||||
function setScale(start, end) {
|
function setScale() {
|
||||||
|
var xScale = undefined;
|
||||||
var width = target.offsetWidth;
|
var width = target.offsetWidth;
|
||||||
xScale.domain([new Date(start), new Date(end)])
|
var timeSystem = conductor.timeSystem();
|
||||||
.range([padding, width - padding * 2]);
|
var bounds = conductor.bounds();
|
||||||
|
|
||||||
|
if (timeSystem.isUTCBased()) {
|
||||||
|
xScale = d3.scaleUtc();
|
||||||
|
xScale.domain([new Date(bounds.start), new Date(bounds.end)]);
|
||||||
|
} else {
|
||||||
|
xScale = d3.scaleLinear();
|
||||||
|
xScale.domain([bounds.start, bounds.end]);
|
||||||
|
}
|
||||||
|
xScale.range([padding, width - padding * 2]);
|
||||||
xAxis.scale(xScale);
|
xAxis.scale(xScale);
|
||||||
axisElement.call(xAxis);
|
axisElement.call(xAxis);
|
||||||
}
|
}
|
||||||
@ -65,27 +74,30 @@ define(
|
|||||||
var b = conductor.bounds();
|
var b = conductor.bounds();
|
||||||
|
|
||||||
//Define a custom format function
|
//Define a custom format function
|
||||||
xAxis.tickFormat(function (date) {
|
xAxis.tickFormat(function (tickValue) {
|
||||||
return format.format(date.getTime(), {min: b.start, max: b.end});
|
// Normalize date representations to numbers
|
||||||
|
if (tickValue instanceof Date){
|
||||||
|
tickValue = tickValue.getTime();
|
||||||
|
}
|
||||||
|
return format.format(tickValue, {
|
||||||
|
min: b.start,
|
||||||
|
max: b.end
|
||||||
|
});
|
||||||
});
|
});
|
||||||
axisElement.call(xAxis);
|
axisElement.call(xAxis);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
scope.resize = function () {
|
scope.resize = setScale;
|
||||||
var b = conductor.bounds();
|
|
||||||
setScale(b.start, b.end);
|
|
||||||
};
|
|
||||||
|
|
||||||
conductor.on('timeSystem', changeTimeSystem);
|
conductor.on('timeSystem', changeTimeSystem);
|
||||||
|
|
||||||
//On conductor bounds changes, redraw ticks
|
//On conductor bounds changes, redraw ticks
|
||||||
conductor.on('bounds', function (bounds) {
|
conductor.on('bounds', function (bounds) {
|
||||||
setScale(bounds.start, bounds.end);
|
setScale();
|
||||||
});
|
});
|
||||||
//Set initial scale.
|
|
||||||
var bounds = conductor.bounds();
|
setScale();
|
||||||
setScale(bounds.start, bounds.end);
|
|
||||||
|
|
||||||
if (conductor.timeSystem() !== undefined) {
|
if (conductor.timeSystem() !== undefined) {
|
||||||
changeTimeSystem(conductor.timeSystem());
|
changeTimeSystem(conductor.timeSystem());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user