Skip to content

Commit

Permalink
Correctly handle decimal display size (#4009)
Browse files Browse the repository at this point in the history
Fix the `readUsedSize` regular expression to correctly parse (truncate) pixel decimal values.
  • Loading branch information
simonbrunel authored Mar 18, 2017
1 parent 4b421a5 commit bd60fa2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/platforms/platform.dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = function(Chart) {
*/
function readUsedSize(element, property) {
var value = helpers.getStyle(element, property);
var matches = value && value.match(/(\d+)px/);
var matches = value && value.match(/^(\d+)(\.\d+)?px$/);
return matches? Number(matches[1]) : undefined;
}

Expand Down
18 changes: 18 additions & 0 deletions test/specs/platform.dom.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,24 @@ describe('Platform.dom', function() {
rw: 165, rh: 85,
});
});

// https://github.com/chartjs/Chart.js/issues/3860
it('should support decimal display width and/or height', function() {
var chart = acquireChart({
options: {
responsive: false
}
}, {
canvas: {
style: 'width: 345.42px; height: 125.42px;'
}
});

expect(chart).toBeChartOfSize({
dw: 345, dh: 125,
rw: 345, rh: 125,
});
});
});

describe('config.options.responsive: true (maintainAspectRatio: true)', function() {
Expand Down

0 comments on commit bd60fa2

Please sign in to comment.