mirror of
https://github.com/chartjs/Chart.js.git
synced 2025-12-08 20:36:08 +00:00
The title plugin and scale title now accept lineHeight specified using unitless value (1.4), length ('1.4em' or '12px'), percentage ('200%') or keyword ('normal' === 1.2). The line height parsing has been refactored under the 'Chart.helpers.options' namespace. Also fix incorrect text positioning in the title plugin.
https://developer.mozilla.org/en-US/docs/Web/CSS/line-height
28 lines
1000 B
JavaScript
28 lines
1000 B
JavaScript
'use strict';
|
|
|
|
describe('Chart.helpers.options', function() {
|
|
var options = Chart.helpers.options;
|
|
|
|
describe('toLineHeight', function() {
|
|
it ('should support keyword values', function() {
|
|
expect(options.toLineHeight('normal', 16)).toBe(16 * 1.2);
|
|
});
|
|
it ('should support unitless values', function() {
|
|
expect(options.toLineHeight(1.4, 16)).toBe(16 * 1.4);
|
|
expect(options.toLineHeight('1.4', 16)).toBe(16 * 1.4);
|
|
});
|
|
it ('should support length values', function() {
|
|
expect(options.toLineHeight('42px', 16)).toBe(42);
|
|
expect(options.toLineHeight('1.4em', 16)).toBe(16 * 1.4);
|
|
});
|
|
it ('should support percentage values', function() {
|
|
expect(options.toLineHeight('140%', 16)).toBe(16 * 1.4);
|
|
});
|
|
it ('should fallback to default (1.2) for invalid values', function() {
|
|
expect(options.toLineHeight(null, 16)).toBe(16 * 1.2);
|
|
expect(options.toLineHeight(undefined, 16)).toBe(16 * 1.2);
|
|
expect(options.toLineHeight('foobar', 16)).toBe(16 * 1.2);
|
|
});
|
|
});
|
|
});
|