Skip to content

Commit

Permalink
Fix chartjs line chart autoskip/label overlap (#130)
Browse files Browse the repository at this point in the history
* Fixed autoskip/label overlap issue until chartjs is patched.
  • Loading branch information
Laurence Stant authored and dceejay committed Dec 22, 2016
1 parent e7f0199 commit 386b476
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/components/ui-chart-js/ui-chart-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ angular.module('ui').directive('uiChartJs', [ '$timeout', '$interpolate',
$timeout(function() {
var type = scope.$eval('me.item.look');
scope.config = loadConfiguration(type, scope);

// Fix autoskip so last two scale labels don't overlap
Chart.scaleService.updateScaleDefaults('time', {
afterBuildTicks: function(me){
var end = me.ticks.length-1;
if (end > 1) {
var lastDiff = me.parseTime(me.ticks[end]).diff(me.parseTime(me.ticks[end-1]));
var penulDiff = me.parseTime(me.ticks[end-1]).diff(me.parseTime(me.ticks[end-2]));
if (lastDiff < penulDiff) {
me.ticks.splice(end-1,1);
}
}
}
});

// When new values arrive, update the chart
scope.$watch('me.item.value', function (newValue) {
Expand Down

0 comments on commit 386b476

Please sign in to comment.