Skip to content

Commit

Permalink
Added isUTCBased to TimeSystem interface
Browse files Browse the repository at this point in the history
  • Loading branch information
akhenry committed Aug 3, 2016
1 parent b9c4110 commit 6501e2e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
1 change: 1 addition & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ define([
'./platform/search/bundle',
'./platform/status/bundle',
'./platform/commonUI/regions/bundle'

], function (Main, legacyRegistry) {
return {
legacyRegistry: legacyRegistry,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,12 @@ define([], function () {
throw new Error('Not implemented');
};

/**
* @return {boolean}
*/
TimeSystem.prototype.isUTCBased = function () {
return true;
};

return TimeSystem;
});
40 changes: 26 additions & 14 deletions platform/features/conductor-v2/conductor/src/ui/MctConductorAxis.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,25 @@ define(
.append('svg:svg')
.attr('width', '100%')
.attr('height', height);
var xScale = d3.scaleUtc();
var xAxis = d3.axisTop();
// draw x axis with labels and move to the bottom of the chart area
var axisElement = vis.append("g")
.attr("transform", "translate(0," + (height - padding) + ")");

function setScale(start, end) {
function setScale() {
var xScale = undefined;
var width = target.offsetWidth;
xScale.domain([new Date(start), new Date(end)])
.range([padding, width - padding * 2]);
var timeSystem = conductor.timeSystem();
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);
axisElement.call(xAxis);
}
Expand All @@ -65,27 +74,30 @@ define(
var b = conductor.bounds();

//Define a custom format function
xAxis.tickFormat(function (date) {
return format.format(date.getTime(), {min: b.start, max: b.end});
xAxis.tickFormat(function (tickValue) {
// 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);
}
}

scope.resize = function () {
var b = conductor.bounds();
setScale(b.start, b.end);
};
scope.resize = setScale;

conductor.on('timeSystem', changeTimeSystem);

//On conductor bounds changes, redraw ticks
conductor.on('bounds', function (bounds) {
setScale(bounds.start, bounds.end);
setScale();
});
//Set initial scale.
var bounds = conductor.bounds();
setScale(bounds.start, bounds.end);

setScale();

if (conductor.timeSystem() !== undefined) {
changeTimeSystem(conductor.timeSystem());
Expand Down

0 comments on commit 6501e2e

Please sign in to comment.