Skip to content

Commit

Permalink
Upgrade to Chart.js 2.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Sep 10, 2017
1 parent 8390dc8 commit 0d47e06
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 526 deletions.
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@
"url": "https://github.com/chartjs/chartjs-chart-financial.git"
},
"dependencies": {
"chart.js": "^2.6.0"
"chart.js": "^2.7.0"
},
"devDependencies": {
"browserify": "^14.3.0",
"check-dependencies": "^1.0.1",
"browserify": "^14.4.0",
"check-dependencies": "^1.1.0",
"gulp": ">=3.9.1",
"gulp-concat": ">=2.6.1",
"gulp-insert": "^0.5.0",
"gulp-jshint": "^2.0.4",
"gulp-replace": ">=0.5.4",
"gulp-replace": ">=0.6.1",
"gulp-streamify": "^1.0.2",
"gulp-uglify": "^3.0.0",
"jasmine": "^2.6.0",
"jshint": "^2.9.4",
"karma": "^1.7.0",
"jasmine": "^2.8.0",
"jshint": "^2.9.5",
"karma": "^1.7.1",
"karma-browserify": "^5.1.1",
"karma-chrome-launcher": "^2.1.1",
"karma-chrome-launcher": "^2.2.0",
"karma-coverage": "^1.1.1",
"karma-firefox-launcher": "^1.0.1",
"karma-jasmine": "^1.1.0",
Expand Down
10 changes: 5 additions & 5 deletions src/controller.financial.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ module.exports = function(Chart) {

scales: {
xAxes: [{
type: 'timeseries',
// grid line settings
gridLines: {
offsetGridLines: true
},
type: 'time',
distribution: 'series',
time: {
format: 'll'
},
ticks: {
source: 'data'
}
}],
yAxes: [{
Expand Down
1 change: 0 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ Chart = typeof(Chart) === 'function' ? Chart : window.Chart;

require('./element.candlestick.js')(Chart);
require('./scale.financialLinear.js')(Chart);
require('./scale.timeseries.js')(Chart);
require('./controller.financial.js')(Chart);
27 changes: 26 additions & 1 deletion src/scale.financialLinear.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,32 @@ module.exports = function(Chart) {
var defaultConfig = {
position: 'left',
ticks: {
callback: Chart.Ticks.formatters.linear
// Copied from Ticks.formatters.linear
callback: function(tickValue, index, ticks) {
// If we have lots of ticks, don't use the ones
var delta = ticks.length > 3 ? ticks[2] - ticks[1] : ticks[1] - ticks[0];

// If we have a number like 2.5 as the delta, figure out how many decimal places we need
if (Math.abs(delta) > 1) {
if (tickValue !== Math.floor(tickValue)) {
// not an integer
delta = tickValue - Math.floor(tickValue);
}
}

var logDelta = helpers.log10(Math.abs(delta));
var tickString = '';

if (tickValue !== 0) {
var numDecimal = -1 * Math.floor(logDelta);
numDecimal = Math.max(Math.min(numDecimal, 20), 0); // toFixed has a max of 20 decimal places
tickString = tickValue.toFixed(numDecimal);
} else {
tickString = '0'; // never show decimal places for 0
}

return tickString;
}
}
};

Expand Down
Loading

0 comments on commit 0d47e06

Please sign in to comment.