Skip to content

Commit a4f6f6f

Browse files
committedJul 25, 2016
Added license
1 parent 19fd63b commit a4f6f6f

File tree

3 files changed

+47
-45
lines changed

3 files changed

+47
-45
lines changed
 

‎platform/commonUI/formats/bundle.js

+11
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@ define([
6161
"key": "DEFAULT_TIME_FORMAT",
6262
"value": "utc"
6363
}
64+
],
65+
"licenses": [
66+
{
67+
"name": "d3",
68+
"version": "3.0.0",
69+
"description": "Incorporates modified code from d3 Time Scales",
70+
"author": "Mike Bostock",
71+
"copyright": "Copyright 2010-2016 Mike Bostock. " +
72+
"All rights reserved.",
73+
"link": "https://github.com/d3/d3/blob/master/LICENSE"
74+
}
6475
]
6576
}
6677
});

‎platform/commonUI/formats/src/UTCTimeFormat.js

+30-23
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ define([
4141
DAYS = 24 * HOURS,
4242
MONTHS = (365 / 12) * DAYS;
4343

44+
/**
45+
* @typedef Scale
46+
* @property {number} min the minimum scale value, in ms
47+
* @property {number} max the maximum scale value, in ms
48+
*/
49+
4450
/**
4551
* Formatter for UTC timestamps. Interprets numeric values as
4652
* milliseconds since the start of 1970.
@@ -57,42 +63,43 @@ define([
5763
* the threshold required.
5864
* @private
5965
*/
60-
function getScaledFormat (d, threshold) {
61-
//Adapted from D3 formatting rules
62-
if (!(d instanceof Date)){
63-
d = new Date(moment.utc(d));
64-
}
66+
function getScaledFormat (d) {
67+
var m = moment.utc(d);
68+
/**
69+
* Uses logic from d3 Time-Scales, v3 of the API. See
70+
* https://github.com/d3/d3-3.x-api-reference/blob/master/Time-Scales.md
71+
*
72+
* Licensed
73+
*/
6574
return [
66-
[".SSS", function(d) { return d.getMilliseconds() >= threshold; }],
67-
[":ss", function(d) { return d.getSeconds() * SECONDS >= threshold; }],
68-
["HH:mm", function(d) { return d.getMinutes() * MINUTES >= threshold; }],
69-
["HH", function(d) { return d.getHours() * HOURS >= threshold; }],
70-
["ddd DD", function(d) {
71-
return d.getDay() * DAYS >= threshold &&
72-
d.getDate() != 1;
75+
[".SSS", function(m) { return m.milliseconds(); }],
76+
[":ss", function(m) { return m.seconds(); }],
77+
["HH:mm", function(m) { return m.minutes(); }],
78+
["HH", function(m) { return m.hours(); }],
79+
["ddd DD", function(m) {
80+
return m.days() &&
81+
m.date() != 1;
7382
}],
74-
["MMM DD", function(d) { return d.getDate() != 1; }],
75-
["MMMM", function(d) {
76-
return d.getMonth() * MONTHS >= threshold;
83+
["MMM DD", function(m) { return m.date() != 1; }],
84+
["MMMM", function(m) {
85+
return m.month();
7786
}],
7887
["YYYY", function() { return true; }]
7988
].filter(function (row){
80-
return row[1](d);
89+
return row[1](m);
8190
})[0][0];
8291
};
8392

8493
/**
8594
*
8695
* @param value
87-
* @param {number} [threshold] Optionally provides context to the
88-
* format request, allowing for scale-appropriate formatting. This value
89-
* should be the minimum unit to be represented by this format, in ms. For
90-
* example, to display seconds, a threshold of 1 * 1000 should be provided.
96+
* @param {Scale} [scale] Optionally provides context to the
97+
* format request, allowing for scale-appropriate formatting.
9198
* @returns {string} the formatted date
9299
*/
93-
UTCTimeFormat.prototype.format = function (value, threshold) {
94-
if (threshold !== undefined){
95-
var scaledFormat = getScaledFormat(value, threshold);
100+
UTCTimeFormat.prototype.format = function (value, scale) {
101+
if (scale !== undefined){
102+
var scaledFormat = getScaledFormat(value, scale);
96103
if (scaledFormat) {
97104
return moment.utc(value).format(scaledFormat);
98105
}

‎platform/features/conductor-v2/src/ui/MctConductorAxis.js

+6-22
Original file line numberDiff line numberDiff line change
@@ -57,39 +57,23 @@ define(
5757
axisElement.call(xAxis);
5858
}
5959

60-
// Calculates the precision of date for formatting. Relies on
61-
// D3's behavior to tick on round units
62-
function threshold(date){
63-
var ms = date.getTime();
64-
return [
65-
365 * 24 * 60 * 60 * 1000, // years
66-
(365 / 12) * 24 * 60 * 60 * 1000, // months
67-
7 * 24 * 60 * 60 * 1000, // weeks
68-
24 * 60 * 60 * 1000, // days
69-
60 * 60 * 1000, // hours
70-
60 * 1000, // minutes
71-
1000, // seconds
72-
1 // ms
73-
].filter(function (boundary) {
74-
return ms % boundary === 0;
75-
})[0];
76-
}
77-
7860
function changeTimeSystem(timeSystem) {
7961
var key = timeSystem.formats()[0];
8062
if (key !== undefined) {
8163
var format = formatService.getFormat(key);
64+
var b = conductor.bounds();
8265

8366
//Define a custom format function
8467
xAxis.tickFormat(function (date) {
85-
return format.format(date, threshold(date));
68+
return format.format(date, {min: b.start, max: b.end});
8669
});
8770
axisElement.call(xAxis);
8871
}
8972
}
9073

9174
scope.resize = function () {
92-
setScale(conductor.bounds().start, conductor.bounds().end);
75+
var b = conductor.bounds();
76+
setScale(b.start, b.end);
9377
};
9478

9579
conductor.on('timeSystem', changeTimeSystem);
@@ -98,9 +82,9 @@ define(
9882
conductor.on('bounds', function (bounds) {
9983
setScale(bounds.start, bounds.end);
10084
});
101-
10285
//Set initial scale.
103-
setScale(conductor.bounds().start, conductor.bounds().end);
86+
var bounds = conductor.bounds();
87+
setScale(bounds.start, bounds.end);
10488

10589
if (conductor.timeSystem() !== undefined) {
10690
changeTimeSystem(conductor.timeSystem());

0 commit comments

Comments
 (0)