Skip to content

Commit

Permalink
Many minor fixes
Browse files Browse the repository at this point in the history
Fix tooltip
Fix color type
Use shorter time label
  • Loading branch information
fanthos committed Dec 29, 2017
1 parent e6659bf commit 0ef5327
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,21 @@ var TimelineConfig = {
displayFormat: false, // DEPRECATED
isoWeekday: false, // override week start day - see http://momentjs.com/docs/#/get-set/iso-weekday/
minUnit: 'millisecond',
distribution: 'linear',
bounds: 'data',

// defaults to unit's corresponding unitFormat below or override using pattern string from http://momentjs.com/docs/#/displaying/format/
displayFormats: {
millisecond: 'h:mm:ss.SSS a', // 11:20:01.123 AM,
second: 'h:mm:ss a', // 11:20:01 AM
minute: 'h:mm:ss a', // 11:20:01 AM
quarter: '[Q]Q - YYYY', // Q3
year: 'YYYY', // 2015
hour: 'MMM D, hA', // Sept 4, 5PM
day: 'll', // Sep 4 2015
minute: 'h:mm a', // 11:20 AM
hour: 'hA', // 5PM
day: 'MMM D', // Sep 4
week: 'll', // Week 46, or maybe "[W]WW - YYYY" ?
month: 'MMM YYYY', // Sept 2015
}
quarter: '[Q]Q - YYYY', // Q3
year: 'YYYY' // 2015
},
},
ticks: {
autoSkip: false
Expand Down Expand Up @@ -118,10 +120,12 @@ var TimelineScale = Chart.scaleService.getScaleConstructor('time').extend({
var timeOpts = me.options.time;
var min = MAX_INTEGER;
var max = MIN_INTEGER;
var timestampset = new Set();
var timestamps = [];
var timestampobj = {};
var datasets = [];
var i, j, ilen, jlen, data, timestamp0, timestamp1;


// Convert data to timestamps
for (i = 0, ilen = (chart.data.datasets || []).length; i < ilen; ++i) {
if (chart.isDatasetVisible(i)) {
Expand All @@ -141,18 +145,22 @@ var TimelineScale = Chart.scaleService.getScaleConstructor('time').extend({
max = timestamp1;
}
datasets[i][j] = [timestamp0, timestamp1, data[j][2]];
timestampset.add(timestamp0);
timestampset.add(timestamp1);
if (timestampobj.hasOwnProperty(timestamp0)) {
timestampobj[timestamp0] = true;
timestamps.push(timestamp0);
}
if (timestampobj.hasOwnProperty(timestamp1)) {
timestampobj[timestamp1] = true;
timestamps.push(timestamp1);
}
}
} else {
datasets[i] = [];
}
}

if (timestampset.size) {
timestamps = Array.from(timestampset).sort(sorter);
} else {
timestamps = [];
if (timestamps.size) {
timestamps.sort(sorter);
}

min = parse(timeOpts.min, me) || min;
Expand Down Expand Up @@ -231,7 +239,7 @@ Chart.controllers.timeline = Chart.controllers.bar.extend({
var y = yScale.getPixelForValue(data, datasetIndex, datasetIndex);
var width = end - x;
var height = me.calculateBarHeight(ruler);
var color = me.chart.options.colorFunction(data);
var color = me.chart.options.colorFunction(data[2]);

// This one has in account the size of the tick and the height of the bar, so we just
// divide both of them by two and subtract the height part and add the tick part
Expand All @@ -245,7 +253,7 @@ Chart.controllers.timeline = Chart.controllers.bar.extend({
width: width,
height: height,
base: x + width,
backgroundColor: color,
backgroundColor: color.rgbaString(),
borderSkipped: custom.borderSkipped ? custom.borderSkipped : rectangleElementOptions.borderSkipped,
borderColor: custom.borderColor ? custom.borderColor : helpers.getValueAtIndexOrDefault(dataset.borderColor, index, rectangleElementOptions.borderColor),
borderWidth: custom.borderWidth ? custom.borderWidth : helpers.getValueAtIndexOrDefault(dataset.borderWidth, index, rectangleElementOptions.borderWidth),
Expand Down

0 comments on commit 0ef5327

Please sign in to comment.