Skip to content

Commit

Permalink
Add support for tick.mode and tick.source
Browse files Browse the repository at this point in the history
- Replace getSampleSize() with getBarPixelsForIndex()
- Remove the ruler
- calculateBarIndexPixels() calls getBarPixelsForIndex() instead of using the ruler
- Add dataMin and dataMax to scale._model for scale adjustment in buildTick()
- Calculation of the bar size based on the tick interval for given time
  • Loading branch information
nagix committed Jul 28, 2017
1 parent 66d5502 commit 1ec3617
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions src/scales/scale.time.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,21 +517,31 @@ module.exports = function(Chart) {
}

// If the chart has bars, shift min and max based on the sample size
if (me.options.gridLines.offsetGridLines || me.chart.hasBar) {
var sampleSizeMs = moment.duration(me.options.sampleSize || 0).asMilliseconds();
var offsetGridLines = me.options.gridLines.offsetGridLines;
var minOffset, maxOffset;
if (sampleSizeMs) {
minOffset = offsetGridLines ? 0 : - sampleSizeMs / 2;
maxOffset = offsetGridLines ? sampleSizeMs : sampleSizeMs / 2;
} else {
var tickSizeMs = (ticks.length < 2) ? max - min :
(ticks[ticks.length - 1] - ticks[0]) / (ticks.length - 1);
minOffset = offsetGridLines ? 0 : - tickSizeMs / 2;
maxOffset = offsetGridLines ? tickSizeMs : tickSizeMs / 2;
if (offsetGridLines || me.chart.hasBar) {
dataMin = model.dataMin;
dataMax = model.dataMax;
duration = max - min;
sampleSizeMs = moment.duration(me.options.sampleSize || 0).asMilliseconds();

tickSizeMs = duration;
for (i = 0, ilen = ticks.length - 1; i < ilen; ++i) {
tickSizeMs = ticks[i + 1] - ticks[i];
if (dataMin < ticks[i + 1]) {
break;
}
}
min = Math.min(min, model.min + minOffset);
max = Math.max(max, model.max + maxOffset);
size = sampleSizeMs || tickSizeMs;
min = Math.min(min, dataMin - (offsetGridLines ? 0 : size / 2));

tickSizeMs = duration;
for (i = ticks.length - 1; i > 0; --i) {
tickSizeMs = ticks[i] - ticks[i - 1];
if (dataMin >= ticks[i - 1]) {
break;
}
}
size = sampleSizeMs || tickSizeMs;
max = Math.max(max, dataMax + (offsetGridLines ? size : size / 2));

// Disable zero line if min has been updated
if (min !== helpers.min(ticks)) {
Expand Down Expand Up @@ -618,7 +628,6 @@ module.exports = function(Chart) {

getPixelForValue: function(value, index, datasetIndex, includeOffset) {
var me = this;
var ticks = me.ticks;
var time = null;

if (index !== undefined && datasetIndex !== undefined) {
Expand Down

0 comments on commit 1ec3617

Please sign in to comment.