mirror of
https://github.com/chartjs/Chart.js.git
synced 2025-12-08 20:36:08 +00:00
Correctly handle decimal display size (#4009)
Fix the `readUsedSize` regular expression to correctly parse (truncate) pixel decimal values.
This commit is contained in:
parent
4b421a50bf
commit
bd60fa2dfd
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user