language stringclasses 1
value | owner stringlengths 2 15 | repo stringlengths 2 21 | sha stringlengths 45 45 | message stringlengths 7 36.3k | path stringlengths 1 199 | patch stringlengths 15 102k | is_multipart bool 2
classes |
|---|---|---|---|---|---|---|---|
Other | chartjs | Chart.js | c8bdca62e89b4d6d9f334cec7a8bfa673725014c.json | Move all helpers to src/helpers (#6841)
* Move all helpers into src/helpers
* Move curve helpers to their own file
* DOM helpers moved to their own file
* Update migration docs
* Remove migration docs on new functions | src/index.js | @@ -4,10 +4,6 @@
var Chart = require('./core/core.controller');
Chart.helpers = require('./helpers/index');
-
-// @todo dispatch these helpers into appropriated helpers/helpers.* file and write unit tests!
-require('./core/core.helpers')(Chart);
-
Chart._adapters = require('./core/core.adapters');
Chart.Animation = require('./core/core.animation');
Chart.animationService = require('./core/core.animations'); | true |
Other | chartjs | Chart.js | c8bdca62e89b4d6d9f334cec7a8bfa673725014c.json | Move all helpers to src/helpers (#6841)
* Move all helpers into src/helpers
* Move curve helpers to their own file
* DOM helpers moved to their own file
* Update migration docs
* Remove migration docs on new functions | src/platforms/platform.dom.js | @@ -41,7 +41,7 @@ var EVENT_TYPES = {
* @returns {number} Size in pixels or undefined if unknown.
*/
function readUsedSize(element, property) {
- var value = helpers.getStyle(element, property);
+ var value = helpers.dom.getStyle(element, property);
var matches = value && value.match(/^(\d+)(\.\d+)?px$/);
return matches ? Number(matches[1]) : undefined;
}
@@ -146,7 +146,7 @@ function createEvent(type, chart, x, y, nativeEvent) {
function fromNativeEvent(event, chart) {
var type = EVENT_TYPES[event.type] || event.type;
- var pos = helpers.getRelativePosition(event, chart);
+ var pos = helpers.dom.getRelativePosition(event, chart);
return createEvent(type, chart, pos.x, pos.y, event);
}
| true |
Other | chartjs | Chart.js | c8bdca62e89b4d6d9f334cec7a8bfa673725014c.json | Move all helpers to src/helpers (#6841)
* Move all helpers into src/helpers
* Move curve helpers to their own file
* DOM helpers moved to their own file
* Update migration docs
* Remove migration docs on new functions | src/scales/scale.linearbase.js | @@ -1,6 +1,7 @@
'use strict';
import helpers from '../helpers/index';
+import {almostEquals, almostWhole, _decimalPlaces, _setMinAndMaxByKey, sign} from '../helpers/helpers.math';
import Scale from '../core/core.scale';
const isNullOrUndef = helpers.isNullOrUndef;
@@ -43,7 +44,7 @@ function generateTicks(generationOptions, dataRange) {
if (stepSize || isNullOrUndef(precision)) {
// If a precision is not specified, calculate factor based on spacing
- factor = Math.pow(10, helpers._decimalPlaces(spacing));
+ factor = Math.pow(10, _decimalPlaces(spacing));
} else {
// If the user specified a precision, round to that number of decimal places
factor = Math.pow(10, precision);
@@ -56,17 +57,17 @@ function generateTicks(generationOptions, dataRange) {
// If min, max and stepSize is set and they make an evenly spaced scale use it.
if (stepSize) {
// If very close to our whole number, use it.
- if (!isNullOrUndef(min) && helpers.almostWhole(min / spacing, spacing / 1000)) {
+ if (!isNullOrUndef(min) && almostWhole(min / spacing, spacing / 1000)) {
niceMin = min;
}
- if (!isNullOrUndef(max) && helpers.almostWhole(max / spacing, spacing / 1000)) {
+ if (!isNullOrUndef(max) && almostWhole(max / spacing, spacing / 1000)) {
niceMax = max;
}
}
numSpaces = (niceMax - niceMin) / spacing;
// If very close to our rounded value, use it.
- if (helpers.almostEquals(numSpaces, Math.round(numSpaces), spacing / 1000)) {
+ if (almostEquals(numSpaces, Math.round(numSpaces), spacing / 1000)) {
numSpaces = Math.round(numSpaces);
} else {
numSpaces = Math.ceil(numSpaces);
@@ -103,8 +104,8 @@ class LinearScaleBase extends Scale {
// do nothing since that would make the chart weird. If the user really wants a weird chart
// axis, they can manually override it
if (opts.beginAtZero) {
- var minSign = helpers.sign(me.min);
- var maxSign = helpers.sign(me.max);
+ var minSign = sign(me.min);
+ var maxSign = sign(me.max);
if (minSign < 0 && maxSign < 0) {
// move the top up to 0
@@ -215,7 +216,7 @@ class LinearScaleBase extends Scale {
// At this point, we need to update our max and min given the tick values since we have expanded the
// range of the scale
- helpers._setMinAndMaxByKey(ticks, me, 'value');
+ _setMinAndMaxByKey(ticks, me, 'value');
if (opts.reverse) {
ticks.reverse(); | true |
Other | chartjs | Chart.js | c8bdca62e89b4d6d9f334cec7a8bfa673725014c.json | Move all helpers to src/helpers (#6841)
* Move all helpers into src/helpers
* Move curve helpers to their own file
* DOM helpers moved to their own file
* Update migration docs
* Remove migration docs on new functions | src/scales/scale.logarithmic.js | @@ -2,6 +2,7 @@
import defaults from '../core/core.defaults';
import helpers from '../helpers/index';
+import {_setMinAndMaxByKey} from '../helpers/helpers.math';
import Scale from '../core/core.scale';
import LinearScaleBase from './scale.linearbase';
import Ticks from '../core/core.ticks';
@@ -132,7 +133,7 @@ class LogarithmicScale extends Scale {
// At this point, we need to update our max and min given the tick values since we have expanded the
// range of the scale
- helpers._setMinAndMaxByKey(ticks, me, 'value');
+ _setMinAndMaxByKey(ticks, me, 'value');
if (opts.reverse) {
reverse = !reverse; | true |
Other | chartjs | Chart.js | c8bdca62e89b4d6d9f334cec7a8bfa673725014c.json | Move all helpers to src/helpers (#6841)
* Move all helpers into src/helpers
* Move curve helpers to their own file
* DOM helpers moved to their own file
* Update migration docs
* Remove migration docs on new functions | src/scales/scale.radialLinear.js | @@ -2,6 +2,7 @@
import defaults from '../core/core.defaults';
import helpers from '../helpers/index';
+import {isNumber, toDegrees} from '../helpers/helpers.math';
import LinearScaleBase from './scale.linearbase';
import Ticks from '../core/core.ticks';
@@ -156,7 +157,7 @@ function fitWithPointLabels(scale) {
// Add quarter circle to make degree 0 mean top of circle
var angleRadians = scale.getIndexAngle(i);
- var angle = helpers.toDegrees(angleRadians) % 360;
+ var angle = toDegrees(angleRadians) % 360;
var hLimits = determineLimits(angle, pointPosition.x, textSize.w, 0, 180);
var vLimits = determineLimits(angle, pointPosition.y, textSize.h, 90, 270);
@@ -239,7 +240,7 @@ function drawPointLabels(scale) {
ctx.fillStyle = pointLabelFontColor;
var angleRadians = scale.getIndexAngle(i);
- var angle = helpers.toDegrees(angleRadians);
+ var angle = toDegrees(angleRadians);
ctx.textAlign = getTextAlignForAngle(angle);
adjustPointPositionForLabelHeight(angle, scale._pointLabelSizes[i], pointLabelPosition);
fillText(ctx, scale.pointLabels[i], pointLabelPosition, plFont.lineHeight);
@@ -287,7 +288,7 @@ function drawRadiusLine(scale, gridLineOpts, radius, index) {
}
function numberOrZero(param) {
- return helpers.isNumber(param) ? param : 0;
+ return isNumber(param) ? param : 0;
}
class RadialLinearScale extends LinearScaleBase { | true |
Other | chartjs | Chart.js | c8bdca62e89b4d6d9f334cec7a8bfa673725014c.json | Move all helpers to src/helpers (#6841)
* Move all helpers into src/helpers
* Move curve helpers to their own file
* DOM helpers moved to their own file
* Update migration docs
* Remove migration docs on new functions | src/scales/scale.time.js | @@ -3,6 +3,7 @@
import adapters from '../core/core.adapters';
import defaults from '../core/core.defaults';
import helpers from '../helpers/index';
+import {toRadians} from '../helpers/helpers.math';
import Scale from '../core/core.scale';
const resolve = helpers.options.resolve;
@@ -731,7 +732,7 @@ class TimeScale extends Scale {
const me = this;
const ticksOpts = me.options.ticks;
const tickLabelWidth = me.ctx.measureText(label).width;
- const angle = helpers.toRadians(me.isHorizontal() ? ticksOpts.maxRotation : ticksOpts.minRotation);
+ const angle = toRadians(me.isHorizontal() ? ticksOpts.maxRotation : ticksOpts.minRotation);
const cosRotation = Math.cos(angle);
const sinRotation = Math.sin(angle);
const tickFontSize = valueOrDefault(ticksOpts.fontSize, defaults.global.defaultFontSize); | true |
Other | chartjs | Chart.js | c8bdca62e89b4d6d9f334cec7a8bfa673725014c.json | Move all helpers to src/helpers (#6841)
* Move all helpers into src/helpers
* Move curve helpers to their own file
* DOM helpers moved to their own file
* Update migration docs
* Remove migration docs on new functions | test/specs/core.helpers.tests.js | @@ -20,26 +20,6 @@ describe('Core helper tests', function() {
expect(helpers.findPreviousWhere(data, callback, 0)).toBe(undefined);
});
- it('should get the correct sign', function() {
- expect(helpers.sign(0)).toBe(0);
- expect(helpers.sign(10)).toBe(1);
- expect(helpers.sign(-5)).toBe(-1);
- });
-
- it('should correctly determine if two numbers are essentially equal', function() {
- expect(helpers.almostEquals(0, Number.EPSILON, 2 * Number.EPSILON)).toBe(true);
- expect(helpers.almostEquals(1, 1.1, 0.0001)).toBe(false);
- expect(helpers.almostEquals(1e30, 1e30 + Number.EPSILON, 0)).toBe(false);
- expect(helpers.almostEquals(1e30, 1e30 + Number.EPSILON, 2 * Number.EPSILON)).toBe(true);
- });
-
- it('should correctly determine if a numbers are essentially whole', function() {
- expect(helpers.almostWhole(0.99999, 0.0001)).toBe(true);
- expect(helpers.almostWhole(0.9, 0.0001)).toBe(false);
- expect(helpers.almostWhole(1234567890123, 0.0001)).toBe(true);
- expect(helpers.almostWhole(1234567890123.001, 0.0001)).toBe(false);
- });
-
it('should generate integer ids', function() {
var uid = helpers.uid();
expect(uid).toEqual(jasmine.any(Number));
@@ -48,270 +28,6 @@ describe('Core helper tests', function() {
expect(helpers.uid()).toBe(uid + 3);
});
- it('should detect a number', function() {
- expect(helpers.isNumber(123)).toBe(true);
- expect(helpers.isNumber('123')).toBe(true);
- expect(helpers.isNumber(null)).toBe(false);
- expect(helpers.isNumber(NaN)).toBe(false);
- expect(helpers.isNumber(undefined)).toBe(false);
- expect(helpers.isNumber('cbc')).toBe(false);
- });
-
- it('should convert between radians and degrees', function() {
- expect(helpers.toRadians(180)).toBe(Math.PI);
- expect(helpers.toRadians(90)).toBe(0.5 * Math.PI);
- expect(helpers.toDegrees(Math.PI)).toBe(180);
- expect(helpers.toDegrees(Math.PI * 3 / 2)).toBe(270);
- });
-
- it('should get the correct number of decimal places', function() {
- expect(helpers._decimalPlaces(100)).toBe(0);
- expect(helpers._decimalPlaces(1)).toBe(0);
- expect(helpers._decimalPlaces(0)).toBe(0);
- expect(helpers._decimalPlaces(0.01)).toBe(2);
- expect(helpers._decimalPlaces(-0.01)).toBe(2);
- expect(helpers._decimalPlaces('1')).toBe(undefined);
- expect(helpers._decimalPlaces('')).toBe(undefined);
- expect(helpers._decimalPlaces(undefined)).toBe(undefined);
- expect(helpers._decimalPlaces(12345678.1234)).toBe(4);
- expect(helpers._decimalPlaces(1234567890.1234567)).toBe(7);
- });
-
- it('should get an angle from a point', function() {
- var center = {
- x: 0,
- y: 0
- };
-
- expect(helpers.getAngleFromPoint(center, {
- x: 0,
- y: 10
- })).toEqual({
- angle: Math.PI / 2,
- distance: 10,
- });
-
- expect(helpers.getAngleFromPoint(center, {
- x: Math.sqrt(2),
- y: Math.sqrt(2)
- })).toEqual({
- angle: Math.PI / 4,
- distance: 2
- });
-
- expect(helpers.getAngleFromPoint(center, {
- x: -1.0 * Math.sqrt(2),
- y: -1.0 * Math.sqrt(2)
- })).toEqual({
- angle: Math.PI * 1.25,
- distance: 2
- });
- });
-
- it('should spline curves', function() {
- expect(helpers.splineCurve({
- x: 0,
- y: 0
- }, {
- x: 1,
- y: 1
- }, {
- x: 2,
- y: 0
- }, 0)).toEqual({
- previous: {
- x: 1,
- y: 1,
- },
- next: {
- x: 1,
- y: 1,
- }
- });
-
- expect(helpers.splineCurve({
- x: 0,
- y: 0
- }, {
- x: 1,
- y: 1
- }, {
- x: 2,
- y: 0
- }, 1)).toEqual({
- previous: {
- x: 0,
- y: 1,
- },
- next: {
- x: 2,
- y: 1,
- }
- });
- });
-
- it('should spline curves with monotone cubic interpolation', function() {
- var dataPoints = [
- {_model: {x: 0, y: 0, skip: false}},
- {_model: {x: 3, y: 6, skip: false}},
- {_model: {x: 9, y: 6, skip: false}},
- {_model: {x: 12, y: 60, skip: false}},
- {_model: {x: 15, y: 60, skip: false}},
- {_model: {x: 18, y: 120, skip: false}},
- {_model: {x: null, y: null, skip: true}},
- {_model: {x: 21, y: 180, skip: false}},
- {_model: {x: 24, y: 120, skip: false}},
- {_model: {x: 27, y: 125, skip: false}},
- {_model: {x: 30, y: 105, skip: false}},
- {_model: {x: 33, y: 110, skip: false}},
- {_model: {x: 33, y: 110, skip: false}},
- {_model: {x: 36, y: 170, skip: false}}
- ];
- helpers.splineCurveMonotone(dataPoints);
- expect(dataPoints).toEqual([{
- _model: {
- x: 0,
- y: 0,
- skip: false,
- controlPointNextX: 1,
- controlPointNextY: 2
- }
- },
- {
- _model: {
- x: 3,
- y: 6,
- skip: false,
- controlPointPreviousX: 2,
- controlPointPreviousY: 6,
- controlPointNextX: 5,
- controlPointNextY: 6
- }
- },
- {
- _model: {
- x: 9,
- y: 6,
- skip: false,
- controlPointPreviousX: 7,
- controlPointPreviousY: 6,
- controlPointNextX: 10,
- controlPointNextY: 6
- }
- },
- {
- _model: {
- x: 12,
- y: 60,
- skip: false,
- controlPointPreviousX: 11,
- controlPointPreviousY: 60,
- controlPointNextX: 13,
- controlPointNextY: 60
- }
- },
- {
- _model: {
- x: 15,
- y: 60,
- skip: false,
- controlPointPreviousX: 14,
- controlPointPreviousY: 60,
- controlPointNextX: 16,
- controlPointNextY: 60
- }
- },
- {
- _model: {
- x: 18,
- y: 120,
- skip: false,
- controlPointPreviousX: 17,
- controlPointPreviousY: 100
- }
- },
- {
- _model: {
- x: null,
- y: null,
- skip: true
- }
- },
- {
- _model: {
- x: 21,
- y: 180,
- skip: false,
- controlPointNextX: 22,
- controlPointNextY: 160
- }
- },
- {
- _model: {
- x: 24,
- y: 120,
- skip: false,
- controlPointPreviousX: 23,
- controlPointPreviousY: 120,
- controlPointNextX: 25,
- controlPointNextY: 120
- }
- },
- {
- _model: {
- x: 27,
- y: 125,
- skip: false,
- controlPointPreviousX: 26,
- controlPointPreviousY: 125,
- controlPointNextX: 28,
- controlPointNextY: 125
- }
- },
- {
- _model: {
- x: 30,
- y: 105,
- skip: false,
- controlPointPreviousX: 29,
- controlPointPreviousY: 105,
- controlPointNextX: 31,
- controlPointNextY: 105
- }
- },
- {
- _model: {
- x: 33,
- y: 110,
- skip: false,
- controlPointPreviousX: 32,
- controlPointPreviousY: 110,
- controlPointNextX: 33,
- controlPointNextY: 110
- }
- },
- {
- _model: {
- x: 33,
- y: 110,
- skip: false,
- controlPointPreviousX: 33,
- controlPointPreviousY: 110,
- controlPointNextX: 34,
- controlPointNextY: 110
- }
- },
- {
- _model: {
- x: 36,
- y: 170,
- skip: false,
- controlPointPreviousX: 35,
- controlPointPreviousY: 150
- }
- }]);
- });
-
it('should return the width of the longest text in an Array and 2D Array', function() {
var context = window.createMockContext();
var font = "normal 12px 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif";
@@ -363,257 +79,6 @@ describe('Core helper tests', function() {
}]);
});
- it ('should get the maximum width and height for a node', function() {
- // Create div with fixed size as a test bed
- var div = document.createElement('div');
- div.style.width = '200px';
- div.style.height = '300px';
-
- document.body.appendChild(div);
-
- // Create the div we want to get the max size for
- var innerDiv = document.createElement('div');
- div.appendChild(innerDiv);
-
- expect(helpers.getMaximumWidth(innerDiv)).toBe(200);
- expect(helpers.getMaximumHeight(innerDiv)).toBe(300);
-
- document.body.removeChild(div);
- });
-
- it ('should get the maximum width and height for a node in a ShadowRoot', function() {
- // Create div with fixed size as a test bed
- var div = document.createElement('div');
- div.style.width = '200px';
- div.style.height = '300px';
-
- document.body.appendChild(div);
-
- if (!div.attachShadow) {
- // Shadow DOM is not natively supported
- return;
- }
-
- var shadow = div.attachShadow({mode: 'closed'});
-
- // Create the div we want to get the max size for
- var innerDiv = document.createElement('div');
- shadow.appendChild(innerDiv);
-
- expect(helpers.getMaximumWidth(innerDiv)).toBe(200);
- expect(helpers.getMaximumHeight(innerDiv)).toBe(300);
-
- document.body.removeChild(div);
- });
-
- it ('should get the maximum width of a node that has a max-width style', function() {
- // Create div with fixed size as a test bed
- var div = document.createElement('div');
- div.style.width = '200px';
- div.style.height = '300px';
-
- document.body.appendChild(div);
-
- // Create the div we want to get the max size for and set a max-width style
- var innerDiv = document.createElement('div');
- innerDiv.style.maxWidth = '150px';
- div.appendChild(innerDiv);
-
- expect(helpers.getMaximumWidth(innerDiv)).toBe(150);
-
- document.body.removeChild(div);
- });
-
- it ('should get the maximum height of a node that has a max-height style', function() {
- // Create div with fixed size as a test bed
- var div = document.createElement('div');
- div.style.width = '200px';
- div.style.height = '300px';
-
- document.body.appendChild(div);
-
- // Create the div we want to get the max size for and set a max-height style
- var innerDiv = document.createElement('div');
- innerDiv.style.maxHeight = '150px';
- div.appendChild(innerDiv);
-
- expect(helpers.getMaximumHeight(innerDiv)).toBe(150);
-
- document.body.removeChild(div);
- });
-
- it ('should get the maximum width of a node when the parent has a max-width style', function() {
- // Create div with fixed size as a test bed
- var div = document.createElement('div');
- div.style.width = '200px';
- div.style.height = '300px';
-
- document.body.appendChild(div);
-
- // Create an inner wrapper around our div we want to size and give that a max-width style
- var parentDiv = document.createElement('div');
- parentDiv.style.maxWidth = '150px';
- div.appendChild(parentDiv);
-
- // Create the div we want to get the max size for
- var innerDiv = document.createElement('div');
- parentDiv.appendChild(innerDiv);
-
- expect(helpers.getMaximumWidth(innerDiv)).toBe(150);
-
- document.body.removeChild(div);
- });
-
- it ('should get the maximum height of a node when the parent has a max-height style', function() {
- // Create div with fixed size as a test bed
- var div = document.createElement('div');
- div.style.width = '200px';
- div.style.height = '300px';
-
- document.body.appendChild(div);
-
- // Create an inner wrapper around our div we want to size and give that a max-height style
- var parentDiv = document.createElement('div');
- parentDiv.style.maxHeight = '150px';
- div.appendChild(parentDiv);
-
- // Create the div we want to get the max size for
- var innerDiv = document.createElement('div');
- innerDiv.style.height = '300px'; // make it large
- parentDiv.appendChild(innerDiv);
-
- expect(helpers.getMaximumHeight(innerDiv)).toBe(150);
-
- document.body.removeChild(div);
- });
-
- it ('should get the maximum width of a node that has a percentage max-width style', function() {
- // Create div with fixed size as a test bed
- var div = document.createElement('div');
- div.style.width = '200px';
- div.style.height = '300px';
-
- document.body.appendChild(div);
-
- // Create the div we want to get the max size for and set a max-width style
- var innerDiv = document.createElement('div');
- innerDiv.style.maxWidth = '50%';
- div.appendChild(innerDiv);
-
- expect(helpers.getMaximumWidth(innerDiv)).toBe(100);
-
- document.body.removeChild(div);
- });
-
- it ('should get the maximum height of a node that has a percentage max-height style', function() {
- // Create div with fixed size as a test bed
- var div = document.createElement('div');
- div.style.width = '200px';
- div.style.height = '300px';
-
- document.body.appendChild(div);
-
- // Create the div we want to get the max size for and set a max-height style
- var innerDiv = document.createElement('div');
- innerDiv.style.maxHeight = '50%';
- div.appendChild(innerDiv);
-
- expect(helpers.getMaximumHeight(innerDiv)).toBe(150);
-
- document.body.removeChild(div);
- });
-
- it ('should get the maximum width of a node when the parent has a percentage max-width style', function() {
- // Create div with fixed size as a test bed
- var div = document.createElement('div');
- div.style.width = '200px';
- div.style.height = '300px';
-
- document.body.appendChild(div);
-
- // Create an inner wrapper around our div we want to size and give that a max-width style
- var parentDiv = document.createElement('div');
- parentDiv.style.maxWidth = '50%';
- div.appendChild(parentDiv);
-
- // Create the div we want to get the max size for
- var innerDiv = document.createElement('div');
- parentDiv.appendChild(innerDiv);
-
- expect(helpers.getMaximumWidth(innerDiv)).toBe(100);
-
- document.body.removeChild(div);
- });
-
- it ('should get the maximum height of a node when the parent has a percentage max-height style', function() {
- // Create div with fixed size as a test bed
- var div = document.createElement('div');
- div.style.width = '200px';
- div.style.height = '300px';
-
- document.body.appendChild(div);
-
- // Create an inner wrapper around our div we want to size and give that a max-height style
- var parentDiv = document.createElement('div');
- parentDiv.style.maxHeight = '50%';
- div.appendChild(parentDiv);
-
- var innerDiv = document.createElement('div');
- innerDiv.style.height = '300px'; // make it large
- parentDiv.appendChild(innerDiv);
-
- expect(helpers.getMaximumHeight(innerDiv)).toBe(150);
-
- document.body.removeChild(div);
- });
-
- it ('should leave styled height and width on canvas if explicitly set', function() {
- var chart = window.acquireChart({}, {
- canvas: {
- height: 200,
- width: 200,
- style: 'height: 400px; width: 400px;'
- }
- });
-
- helpers.retinaScale(chart, true);
-
- var canvas = chart.canvas;
-
- expect(canvas.style.height).toBe('400px');
- expect(canvas.style.width).toBe('400px');
- });
-
- it ('Should get padding of parent as number (pixels) when defined as percent (returns incorrectly in IE11)', function() {
-
- // Create div with fixed size as a test bed
- var div = document.createElement('div');
- div.style.width = '300px';
- div.style.height = '300px';
- document.body.appendChild(div);
-
- // Inner DIV to have 5% padding of parent
- var innerDiv = document.createElement('div');
-
- div.appendChild(innerDiv);
-
- var canvas = document.createElement('canvas');
- innerDiv.appendChild(canvas);
-
- // No padding
- expect(helpers.getMaximumWidth(canvas)).toBe(300);
-
- // test with percentage
- innerDiv.style.padding = '5%';
- expect(helpers.getMaximumWidth(canvas)).toBe(270);
-
- // test with pixels
- innerDiv.style.padding = '10px';
- expect(helpers.getMaximumWidth(canvas)).toBe(280);
-
- document.body.removeChild(div);
- });
-
describe('Color helper', function() {
function isColorInstance(obj) {
return typeof obj === 'object' && Object.prototype.hasOwnProperty.call(obj, 'values') && Object.prototype.hasOwnProperty.call(obj.values, 'rgb');
@@ -622,13 +87,6 @@ describe('Core helper tests', function() {
it('should return a color when called with a color', function() {
expect(isColorInstance(helpers.color('rgb(1, 2, 3)'))).toBe(true);
});
-
- it('should return a color when called with a CanvasGradient instance', function() {
- var context = document.createElement('canvas').getContext('2d');
- var gradient = context.createLinearGradient(0, 1, 2, 3);
-
- expect(isColorInstance(helpers.color(gradient))).toBe(true);
- });
});
describe('Background hover color helper', function() { | true |
Other | chartjs | Chart.js | c8bdca62e89b4d6d9f334cec7a8bfa673725014c.json | Move all helpers to src/helpers (#6841)
* Move all helpers into src/helpers
* Move curve helpers to their own file
* DOM helpers moved to their own file
* Update migration docs
* Remove migration docs on new functions | test/specs/helpers.curve.tests.js | @@ -0,0 +1,211 @@
+describe('Curve helper tests', function() {
+ let helpers;
+
+ beforeAll(function() {
+ helpers = window.Chart.helpers.curve;
+ });
+
+ it('should spline curves', function() {
+ expect(helpers.splineCurve({
+ x: 0,
+ y: 0
+ }, {
+ x: 1,
+ y: 1
+ }, {
+ x: 2,
+ y: 0
+ }, 0)).toEqual({
+ previous: {
+ x: 1,
+ y: 1,
+ },
+ next: {
+ x: 1,
+ y: 1,
+ }
+ });
+
+ expect(helpers.splineCurve({
+ x: 0,
+ y: 0
+ }, {
+ x: 1,
+ y: 1
+ }, {
+ x: 2,
+ y: 0
+ }, 1)).toEqual({
+ previous: {
+ x: 0,
+ y: 1,
+ },
+ next: {
+ x: 2,
+ y: 1,
+ }
+ });
+ });
+
+ it('should spline curves with monotone cubic interpolation', function() {
+ var dataPoints = [
+ {_model: {x: 0, y: 0, skip: false}},
+ {_model: {x: 3, y: 6, skip: false}},
+ {_model: {x: 9, y: 6, skip: false}},
+ {_model: {x: 12, y: 60, skip: false}},
+ {_model: {x: 15, y: 60, skip: false}},
+ {_model: {x: 18, y: 120, skip: false}},
+ {_model: {x: null, y: null, skip: true}},
+ {_model: {x: 21, y: 180, skip: false}},
+ {_model: {x: 24, y: 120, skip: false}},
+ {_model: {x: 27, y: 125, skip: false}},
+ {_model: {x: 30, y: 105, skip: false}},
+ {_model: {x: 33, y: 110, skip: false}},
+ {_model: {x: 33, y: 110, skip: false}},
+ {_model: {x: 36, y: 170, skip: false}}
+ ];
+ helpers.splineCurveMonotone(dataPoints);
+ expect(dataPoints).toEqual([{
+ _model: {
+ x: 0,
+ y: 0,
+ skip: false,
+ controlPointNextX: 1,
+ controlPointNextY: 2
+ }
+ },
+ {
+ _model: {
+ x: 3,
+ y: 6,
+ skip: false,
+ controlPointPreviousX: 2,
+ controlPointPreviousY: 6,
+ controlPointNextX: 5,
+ controlPointNextY: 6
+ }
+ },
+ {
+ _model: {
+ x: 9,
+ y: 6,
+ skip: false,
+ controlPointPreviousX: 7,
+ controlPointPreviousY: 6,
+ controlPointNextX: 10,
+ controlPointNextY: 6
+ }
+ },
+ {
+ _model: {
+ x: 12,
+ y: 60,
+ skip: false,
+ controlPointPreviousX: 11,
+ controlPointPreviousY: 60,
+ controlPointNextX: 13,
+ controlPointNextY: 60
+ }
+ },
+ {
+ _model: {
+ x: 15,
+ y: 60,
+ skip: false,
+ controlPointPreviousX: 14,
+ controlPointPreviousY: 60,
+ controlPointNextX: 16,
+ controlPointNextY: 60
+ }
+ },
+ {
+ _model: {
+ x: 18,
+ y: 120,
+ skip: false,
+ controlPointPreviousX: 17,
+ controlPointPreviousY: 100
+ }
+ },
+ {
+ _model: {
+ x: null,
+ y: null,
+ skip: true
+ }
+ },
+ {
+ _model: {
+ x: 21,
+ y: 180,
+ skip: false,
+ controlPointNextX: 22,
+ controlPointNextY: 160
+ }
+ },
+ {
+ _model: {
+ x: 24,
+ y: 120,
+ skip: false,
+ controlPointPreviousX: 23,
+ controlPointPreviousY: 120,
+ controlPointNextX: 25,
+ controlPointNextY: 120
+ }
+ },
+ {
+ _model: {
+ x: 27,
+ y: 125,
+ skip: false,
+ controlPointPreviousX: 26,
+ controlPointPreviousY: 125,
+ controlPointNextX: 28,
+ controlPointNextY: 125
+ }
+ },
+ {
+ _model: {
+ x: 30,
+ y: 105,
+ skip: false,
+ controlPointPreviousX: 29,
+ controlPointPreviousY: 105,
+ controlPointNextX: 31,
+ controlPointNextY: 105
+ }
+ },
+ {
+ _model: {
+ x: 33,
+ y: 110,
+ skip: false,
+ controlPointPreviousX: 32,
+ controlPointPreviousY: 110,
+ controlPointNextX: 33,
+ controlPointNextY: 110
+ }
+ },
+ {
+ _model: {
+ x: 33,
+ y: 110,
+ skip: false,
+ controlPointPreviousX: 33,
+ controlPointPreviousY: 110,
+ controlPointNextX: 34,
+ controlPointNextY: 110
+ }
+ },
+ {
+ _model: {
+ x: 36,
+ y: 170,
+ skip: false,
+ controlPointPreviousX: 35,
+ controlPointPreviousY: 150
+ }
+ }]);
+ });
+}); | true |
Other | chartjs | Chart.js | c8bdca62e89b4d6d9f334cec7a8bfa673725014c.json | Move all helpers to src/helpers (#6841)
* Move all helpers into src/helpers
* Move curve helpers to their own file
* DOM helpers moved to their own file
* Update migration docs
* Remove migration docs on new functions | test/specs/helpers.dom.tests.js | @@ -0,0 +1,259 @@
+describe('DOM helpers tests', function() {
+ let helpers;
+
+ beforeAll(function() {
+ helpers = window.Chart.helpers.dom;
+ });
+
+ it ('should get the maximum width and height for a node', function() {
+ // Create div with fixed size as a test bed
+ var div = document.createElement('div');
+ div.style.width = '200px';
+ div.style.height = '300px';
+
+ document.body.appendChild(div);
+
+ // Create the div we want to get the max size for
+ var innerDiv = document.createElement('div');
+ div.appendChild(innerDiv);
+
+ expect(helpers.getMaximumWidth(innerDiv)).toBe(200);
+ expect(helpers.getMaximumHeight(innerDiv)).toBe(300);
+
+ document.body.removeChild(div);
+ });
+
+ it ('should get the maximum width and height for a node in a ShadowRoot', function() {
+ // Create div with fixed size as a test bed
+ var div = document.createElement('div');
+ div.style.width = '200px';
+ div.style.height = '300px';
+
+ document.body.appendChild(div);
+
+ if (!div.attachShadow) {
+ // Shadow DOM is not natively supported
+ return;
+ }
+
+ var shadow = div.attachShadow({mode: 'closed'});
+
+ // Create the div we want to get the max size for
+ var innerDiv = document.createElement('div');
+ shadow.appendChild(innerDiv);
+
+ expect(helpers.getMaximumWidth(innerDiv)).toBe(200);
+ expect(helpers.getMaximumHeight(innerDiv)).toBe(300);
+
+ document.body.removeChild(div);
+ });
+
+ it ('should get the maximum width of a node that has a max-width style', function() {
+ // Create div with fixed size as a test bed
+ var div = document.createElement('div');
+ div.style.width = '200px';
+ div.style.height = '300px';
+
+ document.body.appendChild(div);
+
+ // Create the div we want to get the max size for and set a max-width style
+ var innerDiv = document.createElement('div');
+ innerDiv.style.maxWidth = '150px';
+ div.appendChild(innerDiv);
+
+ expect(helpers.getMaximumWidth(innerDiv)).toBe(150);
+
+ document.body.removeChild(div);
+ });
+
+ it ('should get the maximum height of a node that has a max-height style', function() {
+ // Create div with fixed size as a test bed
+ var div = document.createElement('div');
+ div.style.width = '200px';
+ div.style.height = '300px';
+
+ document.body.appendChild(div);
+
+ // Create the div we want to get the max size for and set a max-height style
+ var innerDiv = document.createElement('div');
+ innerDiv.style.maxHeight = '150px';
+ div.appendChild(innerDiv);
+
+ expect(helpers.getMaximumHeight(innerDiv)).toBe(150);
+
+ document.body.removeChild(div);
+ });
+
+ it ('should get the maximum width of a node when the parent has a max-width style', function() {
+ // Create div with fixed size as a test bed
+ var div = document.createElement('div');
+ div.style.width = '200px';
+ div.style.height = '300px';
+
+ document.body.appendChild(div);
+
+ // Create an inner wrapper around our div we want to size and give that a max-width style
+ var parentDiv = document.createElement('div');
+ parentDiv.style.maxWidth = '150px';
+ div.appendChild(parentDiv);
+
+ // Create the div we want to get the max size for
+ var innerDiv = document.createElement('div');
+ parentDiv.appendChild(innerDiv);
+
+ expect(helpers.getMaximumWidth(innerDiv)).toBe(150);
+
+ document.body.removeChild(div);
+ });
+
+ it ('should get the maximum height of a node when the parent has a max-height style', function() {
+ // Create div with fixed size as a test bed
+ var div = document.createElement('div');
+ div.style.width = '200px';
+ div.style.height = '300px';
+
+ document.body.appendChild(div);
+
+ // Create an inner wrapper around our div we want to size and give that a max-height style
+ var parentDiv = document.createElement('div');
+ parentDiv.style.maxHeight = '150px';
+ div.appendChild(parentDiv);
+
+ // Create the div we want to get the max size for
+ var innerDiv = document.createElement('div');
+ innerDiv.style.height = '300px'; // make it large
+ parentDiv.appendChild(innerDiv);
+
+ expect(helpers.getMaximumHeight(innerDiv)).toBe(150);
+
+ document.body.removeChild(div);
+ });
+
+ it ('should get the maximum width of a node that has a percentage max-width style', function() {
+ // Create div with fixed size as a test bed
+ var div = document.createElement('div');
+ div.style.width = '200px';
+ div.style.height = '300px';
+
+ document.body.appendChild(div);
+
+ // Create the div we want to get the max size for and set a max-width style
+ var innerDiv = document.createElement('div');
+ innerDiv.style.maxWidth = '50%';
+ div.appendChild(innerDiv);
+
+ expect(helpers.getMaximumWidth(innerDiv)).toBe(100);
+
+ document.body.removeChild(div);
+ });
+
+ it ('should get the maximum height of a node that has a percentage max-height style', function() {
+ // Create div with fixed size as a test bed
+ var div = document.createElement('div');
+ div.style.width = '200px';
+ div.style.height = '300px';
+
+ document.body.appendChild(div);
+
+ // Create the div we want to get the max size for and set a max-height style
+ var innerDiv = document.createElement('div');
+ innerDiv.style.maxHeight = '50%';
+ div.appendChild(innerDiv);
+
+ expect(helpers.getMaximumHeight(innerDiv)).toBe(150);
+
+ document.body.removeChild(div);
+ });
+
+ it ('should get the maximum width of a node when the parent has a percentage max-width style', function() {
+ // Create div with fixed size as a test bed
+ var div = document.createElement('div');
+ div.style.width = '200px';
+ div.style.height = '300px';
+
+ document.body.appendChild(div);
+
+ // Create an inner wrapper around our div we want to size and give that a max-width style
+ var parentDiv = document.createElement('div');
+ parentDiv.style.maxWidth = '50%';
+ div.appendChild(parentDiv);
+
+ // Create the div we want to get the max size for
+ var innerDiv = document.createElement('div');
+ parentDiv.appendChild(innerDiv);
+
+ expect(helpers.getMaximumWidth(innerDiv)).toBe(100);
+
+ document.body.removeChild(div);
+ });
+
+ it ('should get the maximum height of a node when the parent has a percentage max-height style', function() {
+ // Create div with fixed size as a test bed
+ var div = document.createElement('div');
+ div.style.width = '200px';
+ div.style.height = '300px';
+
+ document.body.appendChild(div);
+
+ // Create an inner wrapper around our div we want to size and give that a max-height style
+ var parentDiv = document.createElement('div');
+ parentDiv.style.maxHeight = '50%';
+ div.appendChild(parentDiv);
+
+ var innerDiv = document.createElement('div');
+ innerDiv.style.height = '300px'; // make it large
+ parentDiv.appendChild(innerDiv);
+
+ expect(helpers.getMaximumHeight(innerDiv)).toBe(150);
+
+ document.body.removeChild(div);
+ });
+
+ it ('Should get padding of parent as number (pixels) when defined as percent (returns incorrectly in IE11)', function() {
+
+ // Create div with fixed size as a test bed
+ var div = document.createElement('div');
+ div.style.width = '300px';
+ div.style.height = '300px';
+ document.body.appendChild(div);
+
+ // Inner DIV to have 5% padding of parent
+ var innerDiv = document.createElement('div');
+
+ div.appendChild(innerDiv);
+
+ var canvas = document.createElement('canvas');
+ innerDiv.appendChild(canvas);
+
+ // No padding
+ expect(helpers.getMaximumWidth(canvas)).toBe(300);
+
+ // test with percentage
+ innerDiv.style.padding = '5%';
+ expect(helpers.getMaximumWidth(canvas)).toBe(270);
+
+ // test with pixels
+ innerDiv.style.padding = '10px';
+ expect(helpers.getMaximumWidth(canvas)).toBe(280);
+
+ document.body.removeChild(div);
+ });
+
+ it ('should leave styled height and width on canvas if explicitly set', function() {
+ var chart = window.acquireChart({}, {
+ canvas: {
+ height: 200,
+ width: 200,
+ style: 'height: 400px; width: 400px;'
+ }
+ });
+
+ helpers.retinaScale(chart, true);
+
+ var canvas = chart.canvas;
+
+ expect(canvas.style.height).toBe('400px');
+ expect(canvas.style.width).toBe('400px');
+ });
+
+}); | true |
Other | chartjs | Chart.js | c8bdca62e89b4d6d9f334cec7a8bfa673725014c.json | Move all helpers to src/helpers (#6841)
* Move all helpers into src/helpers
* Move curve helpers to their own file
* DOM helpers moved to their own file
* Update migration docs
* Remove migration docs on new functions | test/specs/helpers.math.tests.js | @@ -4,6 +4,7 @@
describe('Chart.helpers.math', function() {
var math = Chart.helpers.math;
var factorize = math._factorize;
+ var decimalPlaces = math._decimalPlaces;
it('should factorize', function() {
expect(factorize(1000)).toEqual([1, 2, 4, 5, 8, 10, 20, 25, 40, 50, 100, 125, 200, 250, 500]);
@@ -25,4 +26,84 @@ describe('Chart.helpers.math', function() {
expect(math.log10(Math.pow(10, i))).toBe(i);
}
});
+
+ it('should get the correct number of decimal places', function() {
+ expect(decimalPlaces(100)).toBe(0);
+ expect(decimalPlaces(1)).toBe(0);
+ expect(decimalPlaces(0)).toBe(0);
+ expect(decimalPlaces(0.01)).toBe(2);
+ expect(decimalPlaces(-0.01)).toBe(2);
+ expect(decimalPlaces('1')).toBe(undefined);
+ expect(decimalPlaces('')).toBe(undefined);
+ expect(decimalPlaces(undefined)).toBe(undefined);
+ expect(decimalPlaces(12345678.1234)).toBe(4);
+ expect(decimalPlaces(1234567890.1234567)).toBe(7);
+ });
+
+ it('should get an angle from a point', function() {
+ var center = {
+ x: 0,
+ y: 0
+ };
+
+ expect(math.getAngleFromPoint(center, {
+ x: 0,
+ y: 10
+ })).toEqual({
+ angle: Math.PI / 2,
+ distance: 10,
+ });
+
+ expect(math.getAngleFromPoint(center, {
+ x: Math.sqrt(2),
+ y: Math.sqrt(2)
+ })).toEqual({
+ angle: Math.PI / 4,
+ distance: 2
+ });
+
+ expect(math.getAngleFromPoint(center, {
+ x: -1.0 * Math.sqrt(2),
+ y: -1.0 * Math.sqrt(2)
+ })).toEqual({
+ angle: Math.PI * 1.25,
+ distance: 2
+ });
+ });
+
+ it('should convert between radians and degrees', function() {
+ expect(math.toRadians(180)).toBe(Math.PI);
+ expect(math.toRadians(90)).toBe(0.5 * Math.PI);
+ expect(math.toDegrees(Math.PI)).toBe(180);
+ expect(math.toDegrees(Math.PI * 3 / 2)).toBe(270);
+ });
+
+ it('should correctly determine if two numbers are essentially equal', function() {
+ expect(math.almostEquals(0, Number.EPSILON, 2 * Number.EPSILON)).toBe(true);
+ expect(math.almostEquals(1, 1.1, 0.0001)).toBe(false);
+ expect(math.almostEquals(1e30, 1e30 + Number.EPSILON, 0)).toBe(false);
+ expect(math.almostEquals(1e30, 1e30 + Number.EPSILON, 2 * Number.EPSILON)).toBe(true);
+ });
+
+ it('should get the correct sign', function() {
+ expect(math.sign(0)).toBe(0);
+ expect(math.sign(10)).toBe(1);
+ expect(math.sign(-5)).toBe(-1);
+ });
+
+ it('should correctly determine if a numbers are essentially whole', function() {
+ expect(math.almostWhole(0.99999, 0.0001)).toBe(true);
+ expect(math.almostWhole(0.9, 0.0001)).toBe(false);
+ expect(math.almostWhole(1234567890123, 0.0001)).toBe(true);
+ expect(math.almostWhole(1234567890123.001, 0.0001)).toBe(false);
+ });
+
+ it('should detect a number', function() {
+ expect(math.isNumber(123)).toBe(true);
+ expect(math.isNumber('123')).toBe(true);
+ expect(math.isNumber(null)).toBe(false);
+ expect(math.isNumber(NaN)).toBe(false);
+ expect(math.isNumber(undefined)).toBe(false);
+ expect(math.isNumber('cbc')).toBe(false);
+ });
}); | true |
Other | chartjs | Chart.js | dc4cff748f8ed36c29731b43aa7a9494ed1b4fc4.json | Convert line controller to use const/let (#6820) | src/controllers/controller.line.js | @@ -1,13 +1,13 @@
'use strict';
-var DatasetController = require('../core/core.datasetController');
-var defaults = require('../core/core.defaults');
-var elements = require('../elements/index');
-var helpers = require('../helpers/index');
+const DatasetController = require('../core/core.datasetController');
+const defaults = require('../core/core.defaults');
+const elements = require('../elements/index');
+const helpers = require('../helpers/index');
-var valueOrDefault = helpers.valueOrDefault;
-var resolve = helpers.options.resolve;
-var isPointInArea = helpers.canvas._isPointInArea;
+const valueOrDefault = helpers.valueOrDefault;
+const resolve = helpers.options.resolve;
+const isPointInArea = helpers.canvas._isPointInArea;
defaults._set('line', {
showLines: true,
@@ -101,7 +101,7 @@ module.exports = DatasetController.extend({
updateElements: function(points, start, count, reset) {
const me = this;
const {xScale, yScale, _stacked} = me._cachedMeta;
- var i;
+ let i;
for (i = start; i < start + count; ++i) {
const point = points[i];
@@ -135,11 +135,11 @@ module.exports = DatasetController.extend({
* @private
*/
_resolveDatasetElementOptions: function() {
- var me = this;
- var config = me._config;
- var options = me.chart.options;
- var lineOptions = options.elements.line;
- var values = DatasetController.prototype._resolveDatasetElementOptions.apply(me, arguments);
+ const me = this;
+ const config = me._config;
+ const options = me.chart.options;
+ const lineOptions = options.elements.line;
+ const values = DatasetController.prototype._resolveDatasetElementOptions.apply(me, arguments);
// The default behavior of lines is to break at null values, according
// to https://github.com/chartjs/Chart.js/issues/2435#issuecomment-216718158
@@ -155,26 +155,26 @@ module.exports = DatasetController.extend({
* @private
*/
_getMaxOverflow: function() {
- var me = this;
- var meta = me._cachedMeta;
- var data = meta.data || [];
+ const me = this;
+ const meta = me._cachedMeta;
+ const data = meta.data || [];
if (!data.length) {
return false;
}
- var border = me._showLine ? meta.dataset._model.borderWidth : 0;
- var firstPoint = data[0].size();
- var lastPoint = data[data.length - 1].size();
+ const border = me._showLine ? meta.dataset._model.borderWidth : 0;
+ const firstPoint = data[0].size();
+ const lastPoint = data[data.length - 1].size();
return Math.max(border, firstPoint, lastPoint) / 2;
},
updateBezierControlPoints: function() {
- var me = this;
- var chart = me.chart;
- var meta = me._cachedMeta;
- var lineModel = meta.dataset._model;
- var area = chart.chartArea;
- var points = meta.data || [];
- var i, ilen, model, controlPoints;
+ const me = this;
+ const chart = me.chart;
+ const meta = me._cachedMeta;
+ const lineModel = meta.dataset._model;
+ const area = chart.chartArea;
+ let points = meta.data || [];
+ let i, ilen;
// Only consider points that are drawn in case the spanGaps option is used
if (lineModel.spanGaps) {
@@ -191,8 +191,8 @@ module.exports = DatasetController.extend({
helpers.splineCurveMonotone(points);
} else {
for (i = 0, ilen = points.length; i < ilen; ++i) {
- model = points[i]._model;
- controlPoints = helpers.splineCurve(
+ const model = points[i]._model;
+ const controlPoints = helpers.splineCurve(
points[Math.max(0, i - 1)]._model,
model,
points[Math.min(i + 1, ilen - 1)]._model,
@@ -207,7 +207,7 @@ module.exports = DatasetController.extend({
if (chart.options.elements.line.capBezierPoints) {
for (i = 0, ilen = points.length; i < ilen; ++i) {
- model = points[i]._model;
+ const model = points[i]._model;
if (isPointInArea(model, area)) {
if (i > 0 && isPointInArea(points[i - 1]._model, area)) {
model.controlPointPreviousX = capControlPoint(model.controlPointPreviousX, area.left, area.right);
@@ -223,14 +223,14 @@ module.exports = DatasetController.extend({
},
draw: function() {
- var me = this;
- var ctx = me._ctx;
- var chart = me.chart;
- var meta = me._cachedMeta;
- var points = meta.data || [];
- var area = chart.chartArea;
- var i = 0;
- var ilen = points.length;
+ const me = this;
+ const ctx = me._ctx;
+ const chart = me.chart;
+ const meta = me._cachedMeta;
+ const points = meta.data || [];
+ const area = chart.chartArea;
+ const ilen = points.length;
+ let i = 0;
if (me._showLine) {
meta.dataset.draw(ctx);
@@ -246,9 +246,9 @@ module.exports = DatasetController.extend({
* @protected
*/
setHoverStyle: function(point) {
- var model = point._model;
- var options = point._options;
- var getHoverColor = helpers.getHoverColor;
+ const model = point._model;
+ const options = point._options;
+ const getHoverColor = helpers.getHoverColor;
point.$previousStyle = {
backgroundColor: model.backgroundColor, | false |
Other | chartjs | Chart.js | 53c6c618c6fc8b30efdb1e7e75a1c4673fe179d2.json | Allow pre-parsed data (to scale id's) (#6768)
* Allow pre-parsed data (to scale id's)
* Only update `count` references in pre-parsed mode
* Documentation | docs/SUMMARY.md | @@ -8,6 +8,7 @@
* [Usage](getting-started/usage.md)
* [Migration Guide](getting-started/v3-migration.md)
* [General](general/README.md)
+ * [Data structures](general/data-structures.md)
* [Accessibility](general/accessibility.md)
* [Responsive](general/responsive.md)
* [Pixel Ratio](general/device-pixel-ratio.md)
@@ -17,7 +18,7 @@
* [Options](general/options.md)
* [Colors](general/colors.md)
* [Fonts](general/fonts.md)
- * [Performance](general/performance.md)
+ * [Performance](general/performance.md)
* [Configuration](configuration/README.md)
* [Animations](configuration/animations.md)
* [Layout](configuration/layout.md) | true |
Other | chartjs | Chart.js | 53c6c618c6fc8b30efdb1e7e75a1c4673fe179d2.json | Allow pre-parsed data (to scale id's) (#6768)
* Allow pre-parsed data (to scale id's)
* Only update `count` references in pre-parsed mode
* Documentation | docs/axes/cartesian/category.md | @@ -17,6 +17,7 @@ let chart = new Chart(ctx, {
}
});
```
+
As part of axis definition:
```javascript
@@ -41,11 +42,12 @@ The category scale provides the following options for configuring tick marks. Th
| Name | Type | Default | Description
| ---- | ---- | ------- | -----------
| `labels` | `string[]` | - | An array of labels to display.
-| `min` | `string` | | The minimum item to display. [more...](#min-max-configuration)
-| `max` | `string` | | The maximum item to display. [more...](#min-max-configuration)
+| `min` | <code>string|number</code> | | The minimum item to display. [more...](#min-max-configuration)
+| `max` | <code>string|number</code> | | The maximum item to display. [more...](#min-max-configuration)
## Min Max Configuration
-For both the `min` and `max` properties, the value must be in the `labels` array. In the example below, the x axis would only display "March" through "June".
+
+For both the `min` and `max` properties, the value must be `string` in the `labels` array or `numeric` value as an index of a label in that array. In the example below, the x axis would only display "March" through "June".
```javascript
let chart = new Chart(ctx, {
@@ -65,3 +67,7 @@ let chart = new Chart(ctx, {
}
});
```
+
+## Internal data format
+
+Internally category scale uses label indices | true |
Other | chartjs | Chart.js | 53c6c618c6fc8b30efdb1e7e75a1c4673fe179d2.json | Allow pre-parsed data (to scale id's) (#6768)
* Allow pre-parsed data (to scale id's)
* Only update `count` references in pre-parsed mode
* Documentation | docs/axes/cartesian/linear.md | @@ -75,3 +75,7 @@ let options = {
}
};
```
+
+## Internal data format
+
+Internally, linear scale uses numeric data | true |
Other | chartjs | Chart.js | 53c6c618c6fc8b30efdb1e7e75a1c4673fe179d2.json | Allow pre-parsed data (to scale id's) (#6768)
* Allow pre-parsed data (to scale id's)
* Only update `count` references in pre-parsed mode
* Documentation | docs/axes/cartesian/logarithmic.md | @@ -5,3 +5,7 @@ The logarithmic scale is use to chart numerical data. It can be placed on either
## Tick Configuration Options
The logarithmic scale options extend the [common tick configuration](README.md#tick-configuration). This scale does not define any options that are unique to it.
+
+## Internal data format
+
+Internally logarithmic scale uses numeric data | true |
Other | chartjs | Chart.js | 53c6c618c6fc8b30efdb1e7e75a1c4673fe179d2.json | Allow pre-parsed data (to scale id's) (#6768)
* Allow pre-parsed data (to scale id's)
* Only update `count` references in pre-parsed mode
* Documentation | docs/axes/cartesian/time.md | @@ -155,6 +155,11 @@ The `ticks.source` property controls the ticks generation.
* `'labels'`: generates ticks from user given `labels` ONLY
### Parser
+
If this property is defined as a string, it is interpreted as a custom format to be used by Moment.js to parse the date.
If this is a function, it must return a Moment.js object given the appropriate data value.
+
+### Internal data format
+
+Internally time scale uses milliseconds since epoch | true |
Other | chartjs | Chart.js | 53c6c618c6fc8b30efdb1e7e75a1c4673fe179d2.json | Allow pre-parsed data (to scale id's) (#6768)
* Allow pre-parsed data (to scale id's)
* Only update `count` references in pre-parsed mode
* Documentation | docs/axes/radial/linear.md | @@ -69,6 +69,7 @@ let chart = new Chart(ctx, {
In contrast to the `suggested*` settings, the `min` and `max` settings set explicit ends to the axes. When these are set, some data points may not be visible.
## Step Size
+
If set, the scale ticks will be enumerated by multiple of `stepSize`, having one tick per increment. If not set, the ticks are labeled automatically using the nice numbers algorithm.
This example sets up a chart with a y axis that creates ticks at `0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5`.
@@ -110,3 +111,7 @@ The following options are used to configure the point labels that are shown on t
| `fontSize` | `number` | `10` | font size in pixels.
| `fontStyle` | `string` | `'normal'` | Font style to use when rendering point labels.
| `lineHeight` | <code>number|string</code> | `1.2` | Height of an individual line of text (see [MDN](https://developer.mozilla.org/en-US/docs/Web/CSS/line-height)).
+
+## Internal data format
+
+Internally linear radial scale uses numeric data | true |
Other | chartjs | Chart.js | 53c6c618c6fc8b30efdb1e7e75a1c4673fe179d2.json | Allow pre-parsed data (to scale id's) (#6768)
* Allow pre-parsed data (to scale id's)
* Only update `count` references in pre-parsed mode
* Documentation | docs/charts/bar.md | @@ -1,4 +1,5 @@
# Bar
+
A bar chart provides a way of showing data values represented as vertical bars. It is sometimes used to show trend data, and the comparison of multiple data sets side by side.
{% chartjs %}
@@ -114,6 +115,7 @@ that derive from a bar chart.
**Note:** for negative bars in vertical chart, `top` and `bottom` are flipped. Same goes for `left` and `right` in horizontal chart.
Options are:
+
* `'bottom'`
* `'left'`
* `'top'`
@@ -137,6 +139,7 @@ The interaction with each bar can be controlled with the following properties:
All these values, if `undefined`, fallback to the associated [`elements.rectangle.*`](../configuration/elements.md#rectangle-configuration) options.
## Dataset Configuration
+
The bar chart accepts the following configuration from the associated dataset options:
| Name | Type | Default | Description
@@ -226,22 +229,7 @@ Sample: |==============|
## Data Structure
-The `data` property of a dataset for a bar chart is specified as an array of numbers. Each point in the data array corresponds to the label at the same index on the x axis.
-
-```javascript
-data: [20, 10]
-```
-
-You can also specify the dataset as x/y coordinates when using the [time scale](../axes/cartesian/time.md#time-cartesian-axis).
-
-```javascript
-data: [{x:'2016-12-25', y:20}, {x:'2016-12-26', y:10}]
-```
-
-You can also specify the dataset for a bar chart as arrays of two numbers. This will force rendering of bars with gaps between them (floating-bars). First and second numbers in array will correspond the start and the end point of a bar respectively.
-```javascript
-data: [[5,6], [-3,-6]]
-```
+All of the supported [data structures](../general/data-structures.md) can be used with bar charts.
## Stacked Bar Chart
@@ -328,3 +316,7 @@ var myBarChart = new Chart(ctx, {
The configuration options for the horizontal bar chart are the same as for the [bar chart](#scale-configuration). However, any options specified on the x axis in a bar chart, are applied to the y axis in a horizontal bar chart.
The default horizontal bar configuration is specified in `Chart.defaults.horizontalBar`.
+
+## Internal data format
+
+`{x, y, _custom}` where `_custom` is optional object defining stacked bar properties: `{start, end, barStart, barEnd, min, max}`. `start` and `end` are the input values. Those two are repeated in `barStart` (closer to origin), `barEnd` (further from origin), `min` and `max`. | true |
Other | chartjs | Chart.js | 53c6c618c6fc8b30efdb1e7e75a1c4673fe179d2.json | Allow pre-parsed data (to scale id's) (#6768)
* Allow pre-parsed data (to scale id's)
* Only update `count` references in pre-parsed mode
* Documentation | docs/charts/bubble.md | @@ -115,3 +115,7 @@ Bubble chart datasets need to contain a `data` array of points, each points repr
```
**Important:** the radius property, `r` is **not** scaled by the chart, it is the raw radius in pixels of the bubble that is drawn on the canvas.
+
+## Internal data format
+
+`{x, y, _custom}` where `_custom` is the radius. | true |
Other | chartjs | Chart.js | 53c6c618c6fc8b30efdb1e7e75a1c4673fe179d2.json | Allow pre-parsed data (to scale id's) (#6768)
* Allow pre-parsed data (to scale id's)
* Only update `count` references in pre-parsed mode
* Documentation | docs/charts/line.md | @@ -1,4 +1,5 @@
# Line
+
A line chart is a way of plotting data points on a line. Often, it is used to show trend data, or the comparison of two data sets.
{% chartjs %}
@@ -29,6 +30,7 @@ A line chart is a way of plotting data points on a line. Often, it is used to sh
{% endchartjs %}
## Example Usage
+
```javascript
var myLineChart = new Chart(ctx, {
type: 'line',
@@ -138,7 +140,9 @@ The interaction with each point can be controlled with the following properties:
| `pointHoverRadius` | The radius of the point when hovered.
### cubicInterpolationMode
+
The following interpolation modes are supported.
+
* `'default'`
* `'monotone'`
@@ -149,7 +153,9 @@ The `'monotone'` algorithm is more suited to `y = f(x)` datasets : it preserves
If left untouched (`undefined`), the global `options.elements.line.cubicInterpolationMode` property is used.
### Stepped Line
+
The following values are supported for `steppedLine`.
+
* `false`: No Step Interpolation (default)
* `true`: Step-before Interpolation (eq. `'before'`)
* `'before'`: Step-before Interpolation
@@ -172,34 +178,14 @@ The line chart defines the following configuration options. These options are me
It is common to want to apply a configuration setting to all created line charts. The global line chart settings are stored in `Chart.defaults.line`. Changing the global options only affects charts created after the change. Existing charts are not changed.
For example, to configure all line charts with `spanGaps = true` you would do:
+
```javascript
Chart.defaults.line.spanGaps = true;
```
## Data Structure
-The `data` property of a dataset for a line chart can be passed in two formats.
-
-### number[]
-```javascript
-data: [20, 10]
-```
-
-When the `data` array is an array of numbers, the x axis is generally a [category](../axes/cartesian/category.md#category-cartesian-axis). The points are placed onto the axis using their position in the array. When a line chart is created with a category axis, the `labels` property of the data object must be specified.
-
-### Point[]
-
-```javascript
-data: [{
- x: 10,
- y: 20
-}, {
- x: 15,
- y: 10
-}]
-```
-
-This alternate is used for sparse datasets, such as those in [scatter charts](./scatter.md#scatter-chart). Each data point is specified using an object containing `x` and `y` properties.
+See [`Data structures`](../general/data-structures.md)
## Stacked Area Chart
@@ -218,3 +204,7 @@ var stackedLine = new Chart(ctx, {
}
});
```
+
+## Internal data format
+
+`{x, y}` | true |
Other | chartjs | Chart.js | 53c6c618c6fc8b30efdb1e7e75a1c4673fe179d2.json | Allow pre-parsed data (to scale id's) (#6768)
* Allow pre-parsed data (to scale id's)
* Only update `count` references in pre-parsed mode
* Documentation | docs/charts/radar.md | @@ -200,3 +200,7 @@ data: {
}]
}
```
+
+## Internal data format
+
+`{x, y}` | true |
Other | chartjs | Chart.js | 53c6c618c6fc8b30efdb1e7e75a1c4673fe179d2.json | Allow pre-parsed data (to scale id's) (#6768)
* Allow pre-parsed data (to scale id's)
* Only update `count` references in pre-parsed mode
* Documentation | docs/charts/scatter.md | @@ -48,3 +48,7 @@ data: [{
y: 10
}]
```
+
+## Internal data format
+
+`{x, y}` | true |
Other | chartjs | Chart.js | 53c6c618c6fc8b30efdb1e7e75a1c4673fe179d2.json | Allow pre-parsed data (to scale id's) (#6768)
* Allow pre-parsed data (to scale id's)
* Only update `count` references in pre-parsed mode
* Documentation | docs/general/data-structures.md | @@ -0,0 +1,39 @@
+# Data structures
+
+The `data` property of a dataset can be passed in various formats. By default, that `data` is parsed using the associated chart type and scales.
+
+## Primitive[]
+
+```javascript
+data: [20, 10],
+labels: ['a', 'b']
+```
+
+When the `data` is an array of numbers, values from `labels` array at the same index are used for the index axis (`x` for vertical, `y` for horizontal charts).
+
+## Object[]
+
+```javascript
+data: [{x: 10, y: 20}, {x: 15, y: 10}]
+```
+
+```javascript
+data: [{x:'2016-12-25', y:20}, {x:'2016-12-26', y:10}]
+```
+
+```javascript
+data: [{x:'Sales', y:20}, {x:'Revenue', y:10}]
+```
+
+This is also the internal format used for parsed data. Property names are matched to scale-id. In this mode, parsing can be disabled by specifying `parsing: false` at chart options or dataset. If parsing is disabled, data must be in the formats the associated chart type and scales use internally.
+
+## Object
+
+```javascript
+data: {
+ January: 10,
+ February: 20
+}
+```
+
+In this mode, property name is used for `index` scale and value for `value` scale. For vertical charts, index scale is `x` and value scale is `y`. | true |
Other | chartjs | Chart.js | 53c6c618c6fc8b30efdb1e7e75a1c4673fe179d2.json | Allow pre-parsed data (to scale id's) (#6768)
* Allow pre-parsed data (to scale id's)
* Only update `count` references in pre-parsed mode
* Documentation | docs/general/performance.md | @@ -59,6 +59,10 @@ new Chart(ctx, {
});
```
+## Data structure and format
+
+Provide prepared data in the internal format accepted by the dataset and scales and set `parsing: false`. See [Data structures](data-structures.md) for more information.
+
## Data Decimation
Decimating your data will achieve the best results. When there is a lot of data to display on the graph, it doesn't make sense to show tens of thousands of data points on a graph that is only a few hundred pixels wide. | true |
Other | chartjs | Chart.js | 53c6c618c6fc8b30efdb1e7e75a1c4673fe179d2.json | Allow pre-parsed data (to scale id's) (#6768)
* Allow pre-parsed data (to scale id's)
* Only update `count` references in pre-parsed mode
* Documentation | src/core/core.datasetController.js | @@ -473,18 +473,23 @@ helpers.extend(DatasetController.prototype, {
const me = this;
const {_cachedMeta: meta, _data: data} = me;
const {iScale, vScale, _stacked} = meta;
- let i, ilen, parsed;
-
- if (helpers.isArray(data[start])) {
+ const parsing = resolve([me.getDataset().parsing, me.chart.options.parsing, true]);
+ let offset = 0;
+ let i, parsed;
+
+ if (parsing === false) {
+ parsed = data;
+ offset = start;
+ } else if (helpers.isArray(data[start])) {
parsed = me._parseArrayData(meta, data, start, count);
} else if (helpers.isObject(data[start])) {
parsed = me._parseObjectData(meta, data, start, count);
} else {
parsed = me._parsePrimitiveData(meta, data, start, count);
}
- for (i = 0, ilen = parsed.length; i < ilen; ++i) {
- meta.data[start + i]._parsed = parsed[i];
+ for (i = 0; i < count; ++i) {
+ meta.data[i + start]._parsed = parsed[i + offset];
}
if (_stacked) { | true |
Other | chartjs | Chart.js | 99596b04345ab79fc2bca9016779b2671db87bd7.json | Reduce duplication in drawGrid (#8647) | src/core/core.scale.js | @@ -1617,41 +1617,46 @@ export default class Scale extends Element {
const items = me._gridLineItems || (me._gridLineItems = me._computeGridLineItems(chartArea));
let i, ilen;
+ const drawLine = (p1, p2, style) => {
+ if (!style.width || !style.color) {
+ return;
+ }
+ ctx.save();
+ ctx.lineWidth = style.width;
+ ctx.strokeStyle = style.color;
+ ctx.setLineDash(style.borderDash || []);
+ ctx.lineDashOffset = style.borderDashOffset;
+
+ ctx.beginPath();
+ ctx.moveTo(p1.x, p1.y);
+ ctx.lineTo(p2.x, p2.y);
+ ctx.stroke();
+ ctx.restore();
+ };
+
if (grid.display) {
for (i = 0, ilen = items.length; i < ilen; ++i) {
const item = items[i];
- const {color, tickColor, tickWidth, width} = item;
-
- if (width && color && grid.drawOnChartArea) {
- ctx.save();
- ctx.lineWidth = width;
- ctx.strokeStyle = color;
- if (ctx.setLineDash) {
- ctx.setLineDash(item.borderDash);
- ctx.lineDashOffset = item.borderDashOffset;
- }
- ctx.beginPath();
- ctx.moveTo(item.x1, item.y1);
- ctx.lineTo(item.x2, item.y2);
- ctx.stroke();
- ctx.restore();
+ if (grid.drawOnChartArea) {
+ drawLine(
+ {x: item.x1, y: item.y1},
+ {x: item.x2, y: item.y2},
+ item
+ );
}
- if (tickWidth && tickColor && grid.drawTicks) {
- ctx.save();
- ctx.lineWidth = tickWidth;
- ctx.strokeStyle = tickColor;
- if (ctx.setLineDash) {
- ctx.setLineDash(item.tickBorderDash);
- ctx.lineDashOffset = item.tickBorderDashOffset;
- }
-
- ctx.beginPath();
- ctx.moveTo(item.tx1, item.ty1);
- ctx.lineTo(item.tx2, item.ty2);
- ctx.stroke();
- ctx.restore();
+ if (grid.drawTicks) {
+ drawLine(
+ {x: item.tx1, y: item.ty1},
+ {x: item.tx2, y: item.ty2},
+ {
+ color: item.tickColor,
+ width: item.tickWidth,
+ borderDash: item.tickBorderDash,
+ borderDashOffset: item.tickBorderDashOffset
+ }
+ );
}
}
}
@@ -1672,13 +1677,10 @@ export default class Scale extends Element {
y2 = _alignPixel(chart, me.bottom, lastLineWidth) + lastLineWidth / 2;
x1 = x2 = borderValue;
}
-
- ctx.lineWidth = axisWidth;
- ctx.strokeStyle = edgeOpts.borderColor;
- ctx.beginPath();
- ctx.moveTo(x1, y1);
- ctx.lineTo(x2, y2);
- ctx.stroke();
+ drawLine(
+ {x: x1, y: y1},
+ {x: x2, y: y2},
+ {width: axisWidth, color: edgeOpts.borderColor});
}
}
| false |
Other | chartjs | Chart.js | f744c3bde63cd74e598dabf4f59ea7ff96777e79.json | Add x/y shorthand for padding options (#8637) | docs/docs/axes/labelling.md | @@ -15,7 +15,7 @@ Namespace: `options.scales[scaleId].title`, it defines options for the scale tit
| `text` | `string`\|`string[]` | `''` | The text for the title. (i.e. "# of People" or "Response Choices").
| `color` | [`Color`](../general/colors.md) | `Chart.defaults.color` | Color of label.
| `font` | `Font` | `Chart.defaults.font` | See [Fonts](../general/fonts.md)
-| `padding` | `number`\|`object` | `4` | Padding to apply around scale labels. Only `top` and `bottom` are implemented.
+| `padding` | [`Padding`](../general/padding.md) | `4` | Padding to apply around scale labels. Only `top` and `bottom` are implemented.
## Creating Custom Tick Formats
| true |
Other | chartjs | Chart.js | f744c3bde63cd74e598dabf4f59ea7ff96777e79.json | Add x/y shorthand for padding options (#8637) | docs/docs/axes/radial/linear.mdx | @@ -34,11 +34,11 @@ Namespace: `options.scales[scaleId].ticks`
| Name | Type | Scriptable | Default | Description
| ---- | ---- | ------- | ------- | -----------
| `backdropColor` | [`Color`](../../general/colors.md) | Yes | `'rgba(255, 255, 255, 0.75)'` | Color of label backdrops.
-| `backdropPadding` | `number`\|`{top: number, bottom: number}` | | `2` | Padding of label backdrop.
-| `format` | `object` | | | The [`Intl.NumberFormat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat) options used by the default label formatter
-| `maxTicksLimit` | `number` | | `11` | Maximum number of ticks and gridlines to show.
-| `precision` | `number` | | | if defined and `stepSize` is not specified, the step size will be rounded to this many decimal places.
-| `stepSize` | `number` | | | User defined fixed step size for the scale. [more...](#step-size)
+| `backdropPadding` | [`Padding`](../../general/padding.md) | Yes | `2` | Padding of label backdrop.
+| `format` | `object` | Yes | | The [`Intl.NumberFormat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat) options used by the default label formatter
+| `maxTicksLimit` | `number` | Yes | `11` | Maximum number of ticks and gridlines to show.
+| `precision` | `number` | Yes | | if defined and `stepSize` is not specified, the step size will be rounded to this many decimal places.
+| `stepSize` | `number` | Yes | | User defined fixed step size for the scale. [more...](#step-size)
| `showLabelBackdrop` | `boolean` | Yes | `true` | If true, draw a background behind the tick labels.
<CommonTicksAll />
@@ -126,7 +126,7 @@ Namespace: `options.scales[scaleId].pointLabels`
| Name | Type | Scriptable | Default | Description
| ---- | ---- | ------- | ------- | -----------
| `backdropColor` | [`Color`](../../general/colors.md) | `true` | `undefined` | Background color of the point label.
-| `backdropPadding` | `number`\|`{top: number, bottom: number}` | | `2` | Padding of label backdrop.
+| `backdropPadding` | [`Padding`](../../general/padding.md) | | `2` | Padding of label backdrop.
| `display` | `boolean` | | `true` | if true, point labels are shown.
| `callback` | `function` | | | Callback function to transform data labels to point labels. The default implementation simply returns the current string.
| `color` | [`Color`](../../general/colors.md) | Yes | `Chart.defaults.color` | Color of label. | true |
Other | chartjs | Chart.js | f744c3bde63cd74e598dabf4f59ea7ff96777e79.json | Add x/y shorthand for padding options (#8637) | docs/docs/configuration/layout.md | @@ -6,27 +6,4 @@ Namespace: `options.layout`, the global options for the chart layout is defined
| Name | Type | Default | [Scriptable](../general/options.md#scriptable-options) | Description
| ---- | ---- | ------- | :----: | -----------
-| `padding` | `number`\|`object` | `0` | Yes | The padding to add inside the chart. [more...](#padding)
-
-## Padding
-
-If this value is a number, it is applied to all sides of the chart (left, top, right, bottom). If this value is an object, the `left` property defines the left padding. Similarly the `right`, `top` and `bottom` properties can also be specified.
-
-Lets say you wanted to add 50px of padding to the left side of the chart canvas, you would do:
-
-```javascript
-let chart = new Chart(ctx, {
- type: 'line',
- data: data,
- options: {
- layout: {
- padding: {
- left: 50,
- right: 0,
- top: 0,
- bottom: 0
- }
- }
- }
-});
-```
+| `padding` | [`Padding`](../general/padding.md) | `0` | Yes | The padding to add inside the chart. | true |
Other | chartjs | Chart.js | f744c3bde63cd74e598dabf4f59ea7ff96777e79.json | Add x/y shorthand for padding options (#8637) | docs/docs/configuration/legend.md | @@ -73,7 +73,7 @@ Namespace: `options.plugins.legend.title`
| `color` | [`Color`](../general/colors.md) | `Chart.defaults.color` | Color of text.
| `display` | `boolean` | `false` | Is the legend title displayed.
| `font` | `Font` | `Chart.defaults.font` | See [Fonts](../general/fonts.md)
-| `padding` | `number`\|`object` | `0` | Padding around the title. If specified as a number, it applies evenly to all sides.
+| `padding` | [`Padding`](../general/padding.md) | `0` | Padding around the title.
| `text` | `string` | | The string title.
## Legend Item Interface | true |
Other | chartjs | Chart.js | f744c3bde63cd74e598dabf4f59ea7ff96777e79.json | Add x/y shorthand for padding options (#8637) | docs/docs/configuration/title.md | @@ -16,7 +16,7 @@ Namespace: `options.plugins.title`, the global options for the chart title is de
| `fullSize` | `boolean` | `true` | Marks that this box should take the full width/height of the canvas. If `false`, the box is sized and placed above/beside the chart area.
| `position` | `string` | `'top'` | Position of title. [more...](#position)
| `font` | `Font` | `{style: 'bold'}` | See [Fonts](../general/fonts.md)
-| `padding` | `number`\|`{top: number, bottom: number}` | `10` | Adds padding above and below the title text if a single number is specified. It is also possible to change top and bottom padding separately.
+| `padding` | [`Padding`](../general/padding.md) | `10` | Padding to apply around the title. Only `top` and `bottom` are implemented.
| `text` | `string`\|`string[]` | `''` | Title text to display. If specified as an array, text is rendered on multiple lines.
### Position | true |
Other | chartjs | Chart.js | f744c3bde63cd74e598dabf4f59ea7ff96777e79.json | Add x/y shorthand for padding options (#8637) | docs/docs/configuration/tooltip.md | @@ -31,7 +31,7 @@ Namespace: `options.plugins.tooltip`, the global options for the chart tooltips
| `footerAlign` | `string` | `'left'` | Horizontal alignment of the footer text lines. [more...](#alignment)
| `footerSpacing` | `number` | `2` | Spacing to add to top and bottom of each footer line.
| `footerMarginTop` | `number` | `6` | Margin to add before drawing the footer.
-| `padding` | | `6` | Padding inside the tooltip on the 4 sides
+| `padding` | [`Padding`](../general/padding.md) | `6` | Padding inside the tooltip.
| `caretPadding` | `number` | `2` | Extra distance to move the end of the tooltip arrow away from the tooltip point.
| `caretSize` | `number` | `5` | Size, in px, of the tooltip arrow.
| `cornerRadius` | `number` | `6` | Radius of tooltip corner curves. | true |
Other | chartjs | Chart.js | f744c3bde63cd74e598dabf4f59ea7ff96777e79.json | Add x/y shorthand for padding options (#8637) | docs/docs/general/padding.md | @@ -0,0 +1,68 @@
+---
+title: Padding
+---
+
+Padding values in Chart options can be supplied in couple of different formats.
+
+### Number
+
+If this value is a number, it is applied to all sides (left, top, right, bottom).
+
+For exmaple, defining a 20px padding to all sides of chart:
+
+```javascript
+let chart = new Chart(ctx, {
+ type: 'line',
+ data: data,
+ options: {
+ layout:
+ padding: 20
+ }
+ }
+});
+```
+
+### {top, left, bottom, right} object
+
+If this value is an object, the `left` property defines the left padding. Similarly the `right`, `top` and `bottom` properties can also be specified.
+Omitted properties default to `0`.
+
+Lets say you wanted to add 50px of padding to the left side of the chart canvas, you would do:
+
+```javascript
+let chart = new Chart(ctx, {
+ type: 'line',
+ data: data,
+ options: {
+ layout: {
+ padding: {
+ left: 50
+ }
+ }
+ }
+});
+```
+
+### {x, y} object
+
+This is a shorthand for defining left/right and top/bottom to same values.
+
+For example, 10px left / right and 4px top / bottom padding on a Radial Linear Axis [tick backdropPadding](../axes/radial/linear#tick-configuration):
+
+```javascript
+let chart = new Chart(ctx, {
+ type: 'radar',
+ data: data,
+ options: {
+ scales: {
+ r: {
+ ticks: {
+ backdropPadding: {
+ x: 10,
+ y: 4
+ }
+ }
+ }
+ }
+});
+``` | true |
Other | chartjs | Chart.js | f744c3bde63cd74e598dabf4f59ea7ff96777e79.json | Add x/y shorthand for padding options (#8637) | docs/sidebars.js | @@ -17,6 +17,7 @@ module.exports = {
'general/options',
'general/colors',
'general/fonts',
+ 'general/padding',
'general/performance'
],
Configuration: [ | true |
Other | chartjs | Chart.js | f744c3bde63cd74e598dabf4f59ea7ff96777e79.json | Add x/y shorthand for padding options (#8637) | src/helpers/helpers.options.js | @@ -38,22 +38,25 @@ export function toLineHeight(value, size) {
}
const numberOrZero = v => +v || 0;
+const numberOrZero2 = (v1, v2) => numberOrZero(valueOrDefault(v1, v2));
/**
* Converts the given value into a TRBL object.
* @param {number|object} value - If a number, set the value to all TRBL component,
* else, if an object, use defined properties and sets undefined ones to 0.
+ * x / y are shorthands for same value for left/right and top/bottom.
* @returns {object} The padding values (top, right, bottom, left)
* @since 3.0.0
*/
export function toTRBL(value) {
let t, r, b, l;
if (isObject(value)) {
- t = numberOrZero(value.top);
- r = numberOrZero(value.right);
- b = numberOrZero(value.bottom);
- l = numberOrZero(value.left);
+ const {x, y} = value;
+ t = numberOrZero2(value.top, y);
+ r = numberOrZero2(value.right, x);
+ b = numberOrZero2(value.bottom, y);
+ l = numberOrZero2(value.left, x);
} else {
t = r = b = l = numberOrZero(value);
}
@@ -97,6 +100,7 @@ export function toTRBLCorners(value) {
* Converts the given value into a padding object with pre-computed width/height.
* @param {number|object} value - If a number, set the value to all TRBL component,
* else, if an object, use defined properties and sets undefined ones to 0.
+ * x / y are shorthands for same value for left/right and top/bottom.
* @returns {object} The padding values (top, right, bottom, left, width, height)
* @since 2.7.0
*/ | true |
Other | chartjs | Chart.js | f744c3bde63cd74e598dabf4f59ea7ff96777e79.json | Add x/y shorthand for padding options (#8637) | test/specs/helpers.options.tests.js | @@ -95,6 +95,14 @@ describe('Chart.helpers.options', function() {
expect(toPadding(undefined)).toEqual(
{top: 0, right: 0, bottom: 0, left: 0, height: 0, width: 0});
});
+ it('should support x / y shorthands', function() {
+ expect(toPadding({x: 1, y: 2})).toEqual(
+ {top: 2, right: 1, bottom: 2, left: 1, height: 4, width: 2});
+ expect(toPadding({x: 1, left: 0})).toEqual(
+ {top: 0, right: 1, bottom: 0, left: 0, height: 0, width: 1});
+ expect(toPadding({y: 5, bottom: 0})).toEqual(
+ {top: 5, right: 0, bottom: 0, left: 0, height: 5, width: 0});
+ });
});
describe('toFont', function() { | true |
Other | chartjs | Chart.js | f744c3bde63cd74e598dabf4f59ea7ff96777e79.json | Add x/y shorthand for padding options (#8637) | types/helpers/helpers.options.d.ts | @@ -28,7 +28,7 @@ export function toLineHeight(value: string, size: number): number;
* @since 2.7.0
*/
export function toPadding(
- value?: number | { top?: number; left?: number; right?: number; bottom?: number }
+ value?: number | { top?: number; left?: number; right?: number; bottom?: number; x?:number, y?: number }
): { top: number; left: number; right: number; bottom: number; width: number; height: number };
/** | true |
Other | chartjs | Chart.js | 96f6b42c57a57e71f84c73cbaa208afb4949f736.json | Use font lineHeight for tooltip alignment (#8631)
* Use font lineHeight for tooltip alignment
* Remove toFontString usage from tooltip | src/plugins/plugin.tooltip.js | @@ -1,10 +1,10 @@
import Animations from '../core/core.animations';
import Element from '../core/core.element';
import {each, noop, isNullOrUndef, isArray, _elementsEqual} from '../helpers/helpers.core';
-import {toPadding} from '../helpers/helpers.options';
+import {toFont, toPadding} from '../helpers/helpers.options';
import {getRtlAdapter, overrideTextDirection, restoreTextDirection} from '../helpers/helpers.rtl';
import {distanceBetweenPoints} from '../helpers/helpers.math';
-import {drawPoint, toFontString} from '../helpers';
+import {drawPoint} from '../helpers';
/**
* @typedef { import("../platform/platform.base").ChartEvent } ChartEvent
@@ -139,7 +139,10 @@ function createTooltipItem(chart, item) {
function getTooltipSize(tooltip, options) {
const ctx = tooltip._chart.ctx;
const {body, footer, title} = tooltip;
- const {bodyFont, footerFont, titleFont, boxWidth, boxHeight} = options;
+ const {boxWidth, boxHeight} = options;
+ const bodyFont = toFont(options.bodyFont);
+ const titleFont = toFont(options.titleFont);
+ const footerFont = toFont(options.footerFont);
const titleLineCount = title.length;
const footerLineCount = footer.length;
const bodyLineItemCount = body.length;
@@ -153,20 +156,20 @@ function getTooltipSize(tooltip, options) {
combinedBodyLength += tooltip.beforeBody.length + tooltip.afterBody.length;
if (titleLineCount) {
- height += titleLineCount * titleFont.size
+ height += titleLineCount * titleFont.lineHeight
+ (titleLineCount - 1) * options.titleSpacing
+ options.titleMarginBottom;
}
if (combinedBodyLength) {
// Body lines may include some extra height depending on boxHeight
- const bodyLineHeight = options.displayColors ? Math.max(boxHeight, bodyFont.size) : bodyFont.size;
+ const bodyLineHeight = options.displayColors ? Math.max(boxHeight, bodyFont.lineHeight) : bodyFont.lineHeight;
height += bodyLineItemCount * bodyLineHeight
- + (combinedBodyLength - bodyLineItemCount) * bodyFont.size
+ + (combinedBodyLength - bodyLineItemCount) * bodyFont.lineHeight
+ (combinedBodyLength - 1) * options.bodySpacing;
}
if (footerLineCount) {
height += options.footerMarginTop
- + footerLineCount * footerFont.size
+ + footerLineCount * footerFont.lineHeight
+ (footerLineCount - 1) * options.footerSpacing;
}
@@ -178,11 +181,11 @@ function getTooltipSize(tooltip, options) {
ctx.save();
- ctx.font = toFontString(titleFont);
+ ctx.font = titleFont.string;
each(tooltip.title, maxLineWidth);
// Body width
- ctx.font = toFontString(bodyFont);
+ ctx.font = bodyFont.string;
each(tooltip.beforeBody.concat(tooltip.afterBody), maxLineWidth);
// Body lines may include some extra width due to the color box
@@ -197,7 +200,7 @@ function getTooltipSize(tooltip, options) {
widthPadding = 0;
// Footer width
- ctx.font = toFontString(footerFont);
+ ctx.font = footerFont.string;
each(tooltip.footer, maxLineWidth);
ctx.restore();
@@ -652,15 +655,15 @@ export class Tooltip extends Element {
ctx.textAlign = rtlHelper.textAlign(options.titleAlign);
ctx.textBaseline = 'middle';
- titleFont = options.titleFont;
+ titleFont = toFont(options.titleFont);
titleSpacing = options.titleSpacing;
ctx.fillStyle = options.titleColor;
- ctx.font = toFontString(titleFont);
+ ctx.font = titleFont.string;
for (i = 0; i < length; ++i) {
- ctx.fillText(title[i], rtlHelper.x(pt.x), pt.y + titleFont.size / 2);
- pt.y += titleFont.size + titleSpacing; // Line Height and spacing
+ ctx.fillText(title[i], rtlHelper.x(pt.x), pt.y + titleFont.lineHeight / 2);
+ pt.y += titleFont.lineHeight + titleSpacing; // Line Height and spacing
if (i + 1 === length) {
pt.y += options.titleMarginBottom - titleSpacing; // If Last, add margin, remove spacing
@@ -676,10 +679,11 @@ export class Tooltip extends Element {
const me = this;
const labelColors = me.labelColors[i];
const labelPointStyle = me.labelPointStyles[i];
- const {boxHeight, boxWidth, bodyFont} = options;
+ const {boxHeight, boxWidth} = options;
+ const bodyFont = toFont(options.bodyFont);
const colorX = getAlignedX(me, 'left', options);
const rtlColorX = rtlHelper.x(colorX);
- const yOffSet = boxHeight < bodyFont.size ? (bodyFont.size - boxHeight) / 2 : 0;
+ const yOffSet = boxHeight < bodyFont.lineHeight ? (bodyFont.lineHeight - boxHeight) / 2 : 0;
const colorY = pt.y + yOffSet;
if (options.usePointStyle) {
@@ -725,8 +729,9 @@ export class Tooltip extends Element {
drawBody(pt, ctx, options) {
const me = this;
const {body} = me;
- const {bodyFont, bodySpacing, bodyAlign, displayColors, boxHeight, boxWidth} = options;
- let bodyLineHeight = bodyFont.size;
+ const {bodySpacing, bodyAlign, displayColors, boxHeight, boxWidth} = options;
+ const bodyFont = toFont(options.bodyFont);
+ let bodyLineHeight = bodyFont.lineHeight;
let xLinePadding = 0;
const rtlHelper = getRtlAdapter(options.rtl, me.x, me.width);
@@ -741,7 +746,7 @@ export class Tooltip extends Element {
ctx.textAlign = bodyAlign;
ctx.textBaseline = 'middle';
- ctx.font = toFontString(bodyFont);
+ ctx.font = bodyFont.string;
pt.x = getAlignedX(me, bodyAlignForCalculation, options);
@@ -765,21 +770,21 @@ export class Tooltip extends Element {
// Draw Legend-like boxes if needed
if (displayColors && lines.length) {
me._drawColorBox(ctx, pt, i, rtlHelper, options);
- bodyLineHeight = Math.max(bodyFont.size, boxHeight);
+ bodyLineHeight = Math.max(bodyFont.lineHeight, boxHeight);
}
for (j = 0, jlen = lines.length; j < jlen; ++j) {
fillLineOfText(lines[j]);
// Reset for any lines that don't include colorbox
- bodyLineHeight = bodyFont.size;
+ bodyLineHeight = bodyFont.lineHeight;
}
each(bodyItem.after, fillLineOfText);
}
// Reset back to 0 for after body
xLinePadding = 0;
- bodyLineHeight = bodyFont.size;
+ bodyLineHeight = bodyFont.lineHeight;
// After body lines
each(me.afterBody, fillLineOfText);
@@ -801,14 +806,14 @@ export class Tooltip extends Element {
ctx.textAlign = rtlHelper.textAlign(options.footerAlign);
ctx.textBaseline = 'middle';
- footerFont = options.footerFont;
+ footerFont = toFont(options.footerFont);
ctx.fillStyle = options.footerColor;
- ctx.font = toFontString(footerFont);
+ ctx.font = footerFont.string;
for (i = 0; i < length; ++i) {
- ctx.fillText(footer[i], rtlHelper.x(pt.x), pt.y + footerFont.size / 2);
- pt.y += footerFont.size + options.footerSpacing;
+ ctx.fillText(footer[i], rtlHelper.x(pt.x), pt.y + footerFont.lineHeight / 2);
+ pt.y += footerFont.lineHeight + options.footerSpacing;
}
}
} | true |
Other | chartjs | Chart.js | 96f6b42c57a57e71f84c73cbaa208afb4949f736.json | Use font lineHeight for tooltip alignment (#8631)
* Use font lineHeight for tooltip alignment
* Remove toFontString usage from tooltip | test/specs/plugin.tooltip.tests.js | @@ -163,8 +163,8 @@ describe('Plugin.Tooltip', function() {
}]
}));
- expect(tooltip.x).toBeCloseToPixel(267);
- expect(tooltip.y).toBeCloseToPixel(155);
+ expect(tooltip.x).toBeCloseToPixel(266);
+ expect(tooltip.y).toBeCloseToPixel(150);
});
it('Should only display if intersecting if intersect is set', async function() {
@@ -311,7 +311,7 @@ describe('Plugin.Tooltip', function() {
}]);
expect(tooltip.x).toBeCloseToPixel(267);
- expect(tooltip.y).toBeCloseToPixel(312);
+ expect(tooltip.y).toBeCloseToPixel(308);
});
it('Should display information from user callbacks', async function() {
@@ -475,7 +475,7 @@ describe('Plugin.Tooltip', function() {
}));
expect(tooltip.x).toBeCloseToPixel(267);
- expect(tooltip.y).toBeCloseToPixel(75);
+ expect(tooltip.y).toBeCloseToPixel(58);
});
it('Should provide context object to user callbacks', async function() {
@@ -581,7 +581,7 @@ describe('Plugin.Tooltip', function() {
}));
expect(tooltip.x).toBeCloseToPixel(267);
- expect(tooltip.y).toBeCloseToPixel(155);
+ expect(tooltip.y).toBeCloseToPixel(150);
});
it('Should allow reversing items', async function() {
@@ -649,7 +649,7 @@ describe('Plugin.Tooltip', function() {
}));
expect(tooltip.x).toBeCloseToPixel(267);
- expect(tooltip.y).toBeCloseToPixel(155);
+ expect(tooltip.y).toBeCloseToPixel(150);
});
it('Should follow dataset order', async function() {
@@ -718,7 +718,7 @@ describe('Plugin.Tooltip', function() {
}));
expect(tooltip.x).toBeCloseToPixel(267);
- expect(tooltip.y).toBeCloseToPixel(155);
+ expect(tooltip.y).toBeCloseToPixel(150);
});
it('should filter items from the tooltip using the callback', async function() {
@@ -1393,18 +1393,18 @@ describe('Plugin.Tooltip', function() {
{name: 'setTextBaseline', args: ['middle']},
{name: 'setFillStyle', args: ['#fff']},
{name: 'setFont', args: ["bold 12px 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif"]},
- {name: 'fillText', args: ['title', 105, 111]},
+ {name: 'fillText', args: ['title', 105, 112.2]},
{name: 'setTextAlign', args: ['left']},
{name: 'setTextBaseline', args: ['middle']},
{name: 'setFont', args: ["normal 12px 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif"]},
{name: 'setFillStyle', args: ['#fff']},
{name: 'setFillStyle', args: ['#fff']},
- {name: 'fillText', args: ['label', 105, 129]},
+ {name: 'fillText', args: ['label', 105, 132.6]},
{name: 'setTextAlign', args: ['left']},
{name: 'setTextBaseline', args: ['middle']},
{name: 'setFillStyle', args: ['#fff']},
{name: 'setFont', args: ["bold 12px 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif"]},
- {name: 'fillText', args: ['footer', 105, 147]},
+ {name: 'fillText', args: ['footer', 105, 153]},
{name: 'restore', args: []}
]));
});
@@ -1419,18 +1419,18 @@ describe('Plugin.Tooltip', function() {
{name: 'setTextBaseline', args: ['middle']},
{name: 'setFillStyle', args: ['#fff']},
{name: 'setFont', args: ["bold 12px 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif"]},
- {name: 'fillText', args: ['title', 195, 111]},
+ {name: 'fillText', args: ['title', 195, 112.2]},
{name: 'setTextAlign', args: ['right']},
{name: 'setTextBaseline', args: ['middle']},
{name: 'setFont', args: ["normal 12px 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif"]},
{name: 'setFillStyle', args: ['#fff']},
{name: 'setFillStyle', args: ['#fff']},
- {name: 'fillText', args: ['label', 195, 129]},
+ {name: 'fillText', args: ['label', 195, 132.6]},
{name: 'setTextAlign', args: ['right']},
{name: 'setTextBaseline', args: ['middle']},
{name: 'setFillStyle', args: ['#fff']},
{name: 'setFont', args: ["bold 12px 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif"]},
- {name: 'fillText', args: ['footer', 195, 147]},
+ {name: 'fillText', args: ['footer', 195, 153]},
{name: 'restore', args: []}
]));
});
@@ -1445,18 +1445,18 @@ describe('Plugin.Tooltip', function() {
{name: 'setTextBaseline', args: ['middle']},
{name: 'setFillStyle', args: ['#fff']},
{name: 'setFont', args: ["bold 12px 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif"]},
- {name: 'fillText', args: ['title', 150, 111]},
+ {name: 'fillText', args: ['title', 150, 112.2]},
{name: 'setTextAlign', args: ['center']},
{name: 'setTextBaseline', args: ['middle']},
{name: 'setFont', args: ["normal 12px 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif"]},
{name: 'setFillStyle', args: ['#fff']},
{name: 'setFillStyle', args: ['#fff']},
- {name: 'fillText', args: ['label', 150, 129]},
+ {name: 'fillText', args: ['label', 150, 132.6]},
{name: 'setTextAlign', args: ['center']},
{name: 'setTextBaseline', args: ['middle']},
{name: 'setFillStyle', args: ['#fff']},
{name: 'setFont', args: ["bold 12px 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif"]},
- {name: 'fillText', args: ['footer', 150, 147]},
+ {name: 'fillText', args: ['footer', 150, 153]},
{name: 'restore', args: []}
]));
});
@@ -1471,18 +1471,18 @@ describe('Plugin.Tooltip', function() {
{name: 'setTextBaseline', args: ['middle']},
{name: 'setFillStyle', args: ['#fff']},
{name: 'setFont', args: ["bold 12px 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif"]},
- {name: 'fillText', args: ['title', 195, 111]},
+ {name: 'fillText', args: ['title', 195, 112.2]},
{name: 'setTextAlign', args: ['center']},
{name: 'setTextBaseline', args: ['middle']},
{name: 'setFont', args: ["normal 12px 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif"]},
{name: 'setFillStyle', args: ['#fff']},
{name: 'setFillStyle', args: ['#fff']},
- {name: 'fillText', args: ['label', 150, 129]},
+ {name: 'fillText', args: ['label', 150, 132.6]},
{name: 'setTextAlign', args: ['left']},
{name: 'setTextBaseline', args: ['middle']},
{name: 'setFillStyle', args: ['#fff']},
{name: 'setFont', args: ["bold 12px 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif"]},
- {name: 'fillText', args: ['footer', 105, 147]},
+ {name: 'fillText', args: ['footer', 105, 153]},
{name: 'restore', args: []}
]));
}); | true |
Other | chartjs | Chart.js | a026b6065324fe8967de7789b091996a30557ed6.json | Change default autoSkipPadding to 3 (#8629) | docs/docs/axes/cartesian/_common_ticks.md | @@ -8,7 +8,7 @@ Namespace: `options.scales[scaleId].ticks`
| `crossAlign` | `string` | `'near'` | The tick alignment perpendicular to the axis. Can be `'near'`, `'center'`, or `'far'`. See [Tick Alignment](./index#tick-alignment)
| `sampleSize` | `number` | `ticks.length` | The number of ticks to examine when deciding how many labels will fit. Setting a smaller value will be faster, but may be less accurate when there is large variability in label length.
| `autoSkip` | `boolean` | `true` | If true, automatically calculates how many labels can be shown and hides labels accordingly. Labels will be rotated up to `maxRotation` before skipping any. Turn `autoSkip` off to show all labels no matter what.
-| `autoSkipPadding` | `number` | `0` | Padding between the ticks on the horizontal axis when `autoSkip` is enabled.
+| `autoSkipPadding` | `number` | `3` | Padding between the ticks on the horizontal axis when `autoSkip` is enabled.
| `labelOffset` | `number` | `0` | Distance in pixels to offset the label from the centre point of the tick (in the x-direction for the x-axis, and the y-direction for the y-axis). *Note: this can cause labels at the edges to be cropped by the edge of the canvas*
| `maxRotation` | `number` | `50` | Maximum rotation for tick labels when rotating to condense labels. Note: Rotation doesn't occur until necessary. *Note: Only applicable to horizontal scales.*
| `minRotation` | `number` | `0` | Minimum rotation for tick labels. *Note: Only applicable to horizontal scales.* | true |
Other | chartjs | Chart.js | a026b6065324fe8967de7789b091996a30557ed6.json | Change default autoSkipPadding to 3 (#8629) | src/core/core.scale.js | @@ -78,7 +78,7 @@ defaults.set('scale', {
padding: 0,
display: true,
autoSkip: true,
- autoSkipPadding: 0,
+ autoSkipPadding: 3,
labelOffset: 0,
// We pass through arrays to be rendered as multiline labels, we convert Others to strings here.
callback: Ticks.formatters.values, | true |
Other | chartjs | Chart.js | a026b6065324fe8967de7789b091996a30557ed6.json | Change default autoSkipPadding to 3 (#8629) | test/specs/scale.time.tests.js | @@ -1096,6 +1096,7 @@ describe('Time scale tests', function() {
ticks: {
source: 'data',
autoSkip: true,
+ autoSkipPadding: 0,
maxRotation: 0
}
}, | true |
Other | chartjs | Chart.js | aae8a06c37c0fd9ae60ae76c50735bcdcbef77da.json | Update context documentation (#8626) | docs/docs/general/options.md | @@ -70,6 +70,8 @@ A plugin can provide `additionalOptionScopes` array of paths to additionally loo
Scriptable options also accept a function which is called for each of the underlying data values and that takes the unique argument `context` representing contextual information (see [option context](options.md#option-context)).
A resolver is passed as second parameter, that can be used to access other options in the same context.
+> **Note:** the `context` argument should be validated in the scriptable function, because the function can be invoked in different contexts. The `type` field is a good candidate for this validation.
+
Example:
```javascript
@@ -132,7 +134,7 @@ In addition to [chart](#chart)
* `active`: true if element is active (hovered)
* `dataset`: dataset at index `datasetIndex`
* `datasetIndex`: index of the current dataset
-* `index`: getter for `datasetIndex`
+* `index`: same as `datasetIndex`
* `mode`: the update mode
* `type`: `'dataset'`
@@ -145,8 +147,7 @@ In addition to [dataset](#dataset)
* `parsed`: the parsed data values for the given `dataIndex` and `datasetIndex`
* `raw`: the raw data values for the given `dataIndex` and `datasetIndex`
* `element`: the element (point, arc, bar, etc.) for this data
-* `index`: getter for `dataIndex`
-* `mode`: the update mode
+* `index`: same as `dataIndex`
* `type`: `'data'`
### scale | true |
Other | chartjs | Chart.js | aae8a06c37c0fd9ae60ae76c50735bcdcbef77da.json | Update context documentation (#8626) | src/core/core.datasetController.js | @@ -158,6 +158,7 @@ function createDatasetContext(parent, index, dataset) {
dataset,
datasetIndex: index,
index,
+ mode: 'default',
type: 'dataset'
}
); | true |
Other | chartjs | Chart.js | b98974f5b2be666a6510b29e98f78994ce757704.json | Fix some animation issues (#8616)
* Fix some animation issues
* Stop animating shared options on reset
* cc | samples/advanced/progress-bar.html | @@ -6,9 +6,7 @@
<script src="../utils.js"></script>
<style>
canvas {
- -moz-user-select: none;
- -webkit-user-select: none;
- -ms-user-select: none;
+ user-select: none;
}
</style>
</head>
@@ -58,23 +56,26 @@
}]
},
options: {
- plugins: {
- title: {
- display: true,
- text: 'Chart.js Line Chart - Animation Progress Bar'
- }
- },
animation: {
duration: 2000,
onProgress: function(animation) {
progress.value = animation.currentStep / animation.numSteps;
},
onComplete: function() {
- window.setTimeout(function() {
- progress.value = 0;
- }, 2000);
+ //
+ }
+ },
+ interaction: {
+ mode: 'nearest',
+ axis: 'x',
+ intersect: false
+ },
+ plugins: {
+ title: {
+ display: true,
+ text: 'Chart.js Line Chart - Animation Progress Bar'
}
- }
+ },
}
};
| true |
Other | chartjs | Chart.js | b98974f5b2be666a6510b29e98f78994ce757704.json | Fix some animation issues (#8616)
* Fix some animation issues
* Stop animating shared options on reset
* cc | src/core/core.animation.js | @@ -30,7 +30,7 @@ export default class Animation {
this._fn = cfg.fn || interpolators[cfg.type || typeof from];
this._easing = effects[cfg.easing] || effects.linear;
this._start = Math.floor(Date.now() + (cfg.delay || 0));
- this._duration = Math.floor(cfg.duration);
+ this._duration = this._total = Math.floor(cfg.duration);
this._loop = !!cfg.loop;
this._target = target;
this._prop = prop;
@@ -53,6 +53,7 @@ export default class Animation {
const remain = me._duration - elapsed;
me._start = date;
me._duration = Math.floor(Math.max(remain, cfg.duration));
+ me._total += elapsed;
me._loop = !!cfg.loop;
me._to = resolve([cfg.to, to, currentValue, cfg.from]);
me._from = resolve([cfg.from, currentValue, to]); | true |
Other | chartjs | Chart.js | b98974f5b2be666a6510b29e98f78994ce757704.json | Fix some animation issues (#8616)
* Fix some animation issues
* Stop animating shared options on reset
* cc | src/core/core.animator.js | @@ -72,6 +72,11 @@ export class Animator {
item = items[i];
if (item._active) {
+ if (item._total > anims.duration) {
+ // if the animation has been updated and its duration prolonged,
+ // update to total duration of current animations run (for progress event)
+ anims.duration = item._total;
+ }
item.tick(date);
draw = true;
} else { | true |
Other | chartjs | Chart.js | b98974f5b2be666a6510b29e98f78994ce757704.json | Fix some animation issues (#8616)
* Fix some animation issues
* Stop animating shared options on reset
* cc | src/core/core.config.js | @@ -167,31 +167,35 @@ export default class Config {
* Returns the option scope keys for resolving dataset options.
* These keys do not include the dataset itself, because it is not under options.
* @param {string} datasetType
- * @return {string[]}
+ * @return {string[][]}
*/
datasetScopeKeys(datasetType) {
return cachedKeys(datasetType,
- () => [
+ () => [[
`datasets.${datasetType}`,
''
- ]);
+ ]]);
}
/**
* Returns the option scope keys for resolving dataset animation options.
* These keys do not include the dataset itself, because it is not under options.
* @param {string} datasetType
* @param {string} transition
- * @return {string[]}
+ * @return {string[][]}
*/
datasetAnimationScopeKeys(datasetType, transition) {
return cachedKeys(`${datasetType}.transition.${transition}`,
() => [
- `datasets.${datasetType}.transitions.${transition}`,
- `transitions.${transition}`,
+ [
+ `datasets.${datasetType}.transitions.${transition}`,
+ `transitions.${transition}`,
+ ],
// The following are used for looking up the `animations` and `animation` keys
- `datasets.${datasetType}`,
- ''
+ [
+ `datasets.${datasetType}`,
+ ''
+ ]
]);
}
@@ -201,65 +205,76 @@ export default class Config {
* is not under options.
* @param {string} datasetType
* @param {string} elementType
- * @return {string[]}
+ * @return {string[][]}
*/
datasetElementScopeKeys(datasetType, elementType) {
return cachedKeys(`${datasetType}-${elementType}`,
- () => [
+ () => [[
`datasets.${datasetType}.elements.${elementType}`,
`datasets.${datasetType}`,
`elements.${elementType}`,
''
- ]);
+ ]]);
}
/**
* Returns the options scope keys for resolving plugin options.
* @param {{id: string, additionalOptionScopes?: string[]}} plugin
- * @return {string[]}
+ * @return {string[][]}
*/
pluginScopeKeys(plugin) {
const id = plugin.id;
const type = this.type;
return cachedKeys(`${type}-plugin-${id}`,
- () => [
+ () => [[
`plugins.${id}`,
...plugin.additionalOptionScopes || [],
- ]);
+ ]]);
}
/**
- * Resolves the objects from options and defaults for option value resolution.
- * @param {object} mainScope - The main scope object for options
- * @param {string[]} scopeKeys - The keys in resolution order
- * @param {boolean} [resetCache] - reset the cache for this mainScope
+ * @private
*/
- getOptionScopes(mainScope, scopeKeys, resetCache) {
- const {_scopeCache, options, type} = this;
+ _cachedScopes(mainScope, resetCache) {
+ const _scopeCache = this._scopeCache;
let cache = _scopeCache.get(mainScope);
if (!cache || resetCache) {
cache = new Map();
_scopeCache.set(mainScope, cache);
}
- const cached = cache.get(scopeKeys);
+ return cache;
+ }
+
+ /**
+ * Resolves the objects from options and defaults for option value resolution.
+ * @param {object} mainScope - The main scope object for options
+ * @param {string[][]} keyLists - The arrays of keys in resolution order
+ * @param {boolean} [resetCache] - reset the cache for this mainScope
+ */
+ getOptionScopes(mainScope, keyLists, resetCache) {
+ const {options, type} = this;
+ const cache = this._cachedScopes(mainScope, resetCache);
+ const cached = cache.get(keyLists);
if (cached) {
return cached;
}
const scopes = new Set();
- if (mainScope) {
- scopes.add(mainScope);
- scopeKeys.forEach(key => addIfFound(scopes, mainScope, key));
- }
- scopeKeys.forEach(key => addIfFound(scopes, options, key));
- scopeKeys.forEach(key => addIfFound(scopes, overrides[type] || {}, key));
- scopeKeys.forEach(key => addIfFound(scopes, defaults, key));
- scopeKeys.forEach(key => addIfFound(scopes, descriptors, key));
+ keyLists.forEach(keys => {
+ if (mainScope) {
+ scopes.add(mainScope);
+ keys.forEach(key => addIfFound(scopes, mainScope, key));
+ }
+ keys.forEach(key => addIfFound(scopes, options, key));
+ keys.forEach(key => addIfFound(scopes, overrides[type] || {}, key));
+ keys.forEach(key => addIfFound(scopes, defaults, key));
+ keys.forEach(key => addIfFound(scopes, descriptors, key));
+ });
const array = [...scopes];
- if (keysCached.has(scopeKeys)) {
- cache.set(scopeKeys, array);
+ if (keysCached.has(keyLists)) {
+ cache.set(keyLists, array);
}
return array;
} | true |
Other | chartjs | Chart.js | b98974f5b2be666a6510b29e98f78994ce757704.json | Fix some animation issues (#8616)
* Fix some animation issues
* Stop animating shared options on reset
* cc | src/core/core.datasetController.js | @@ -830,7 +830,7 @@ export default class DatasetController {
* @protected
*/
updateSharedOptions(sharedOptions, mode, newOptions) {
- if (sharedOptions) {
+ if (sharedOptions && !isDirectUpdateMode(mode)) {
this._resolveAnimations(undefined, mode).update(sharedOptions, newOptions);
}
} | true |
Other | chartjs | Chart.js | b98974f5b2be666a6510b29e98f78994ce757704.json | Fix some animation issues (#8616)
* Fix some animation issues
* Stop animating shared options on reset
* cc | src/helpers/helpers.core.js | @@ -306,11 +306,8 @@ export function resolveObjectKey(obj, key) {
}
let pos = 0;
let idx = indexOfDotOrLength(key, pos);
- while (idx > pos) {
+ while (obj && idx > pos) {
obj = obj[key.substr(pos, idx - pos)];
- if (!obj) {
- break;
- }
pos = idx + 1;
idx = indexOfDotOrLength(key, pos);
} | true |
Other | chartjs | Chart.js | e513a904278530a08ca0995e5bd1ee8bda229f0f.json | Fix typo in animations.mdx (#8615)
transtion -> transition | docs/docs/configuration/animations.mdx | @@ -175,7 +175,7 @@ These default animations are overridden by most of the dataset controllers.
## transitions
The core transitions are `'active'`, `'hide'`, `'reset'`, `'resize'`, `'show'`.
-A custom transtion can be used by passing a custom `mode` to [update](../developers/api.md#updatemode).
+A custom transition can be used by passing a custom `mode` to [update](../developers/api.md#updatemode).
Transition extends the main [animation configuration](#animation-configuration) and [animations configuration](#animations-configuration).
### Default transitions | false |
Other | chartjs | Chart.js | 7dce94e8203703eba02cc7dad9cb451f0e2e6e30.json | Fix typo in linear.mdx (#8605)
minumum -> minimum | docs/docs/axes/cartesian/linear.mdx | @@ -62,7 +62,7 @@ let options = {
## Grace
If the value is string ending with `%`, its treat as percentage. If number, its treat as value.
-The value is added to the maximum data value and subtracted from the minumum data. This extends the scale range as if the data values were that much greater.
+The value is added to the maximum data value and subtracted from the minimum data. This extends the scale range as if the data values were that much greater.
import { useEffect, useRef } from 'react';
| false |
Other | chartjs | Chart.js | c27c27a081cc27f85f15a7f7b017fe7ef1ceb23d.json | Fix typo in auto package (#8601) | auto/auto.esm.js | @@ -1,5 +1,5 @@
-import {Chart, registrables} from '../dist/chart.esm';
+import {Chart, registerables} from '../dist/chart.esm';
-Chart.register(...registrables);
+Chart.register(...registerables);
export default Chart; | false |
Other | chartjs | Chart.js | 9a042672a74d71fb0238bfaa2310b237d106604e.json | Update scriptable tooltip context docs (#8599) | docs/docs/general/options.md | @@ -114,6 +114,7 @@ There are multiple levels of context objects:
* `data`
* `scale`
* `tick`
+ * `tooltip`
Each level inherits its parent(s) and any contextual information stored in the parent is available through the child.
@@ -162,3 +163,10 @@ In addition to [scale](#scale)
* `tick`: the associated tick object
* `index`: tick index
* `type`: `'tick'`
+
+### tooltip
+
+In addition to [chart](#chart)
+
+* `tooltip`: the tooltip object
+* `tooltipItems`: the items the tooltip is displaying | false |
Other | chartjs | Chart.js | 7ec99c38c1b41b16cf7cad433569af56c2544d63.json | Move startAngle to scale options (#8593) | docs/docs/axes/radial/linear.mdx | @@ -21,6 +21,7 @@ Namespace: `options.scales[scaleId]`
| `angleLines` | `object` | | Angle line configuration. [more...](#angle-line-options)
| `beginAtZero` | `boolean` | `false` | if true, scale will include 0 if it is not already included.
| `pointLabels` | `object` | | Point label configuration. [more...](#point-label-options)
+| `startAngle` | `number` | `0` | Starting angle of the scale. In degrees, 0 is at top.
<CommonAll />
| true |
Other | chartjs | Chart.js | 7ec99c38c1b41b16cf7cad433569af56c2544d63.json | Move startAngle to scale options (#8593) | docs/docs/charts/polar.mdx | @@ -112,7 +112,6 @@ These are the customisation options specific to Polar Area charts. These options
| Name | Type | Default | Description
| ---- | ---- | ------- | -----------
-| `startAngle` | `number` | `0` | Starting angle to draw arcs for the first item in a dataset. In degrees, 0 is at top.
| `animation.animateRotate` | `boolean` | `true` | If true, the chart will animate in with a rotation animation. This property is in the `options.animation` object.
| `animation.animateScale` | `boolean` | `true` | If true, will animate scaling the chart from the center outwards.
| true |
Other | chartjs | Chart.js | 7ec99c38c1b41b16cf7cad433569af56c2544d63.json | Move startAngle to scale options (#8593) | docs/docs/getting-started/v3-migration.md | @@ -101,6 +101,7 @@ A number of changes were made to the configuration options passed to the `Chart`
* `scales.[x/y]Axes.zeroLine*` options of axes were removed. Use scriptable scale options instead.
* The dataset option `steppedLine` was removed. Use `stepped`
* The chart option `showLines` was renamed to `showLine` to match the dataset option.
+* The chart option `startAngle` was moved to `radial` scale options.
* To override the platform class used in a chart instance, pass `platform: PlatformClass` in the config object. Note that the class should be passed, not an instance of the class.
* `aspectRatio` defaults to 1 for doughnut, pie, polarArea, and radar charts
* `TimeScale` does not read `t` from object data by default anymore. The default property is `x` or `y`, depending on the orientation. See [data structures](../general/data-structures.md) for details on how to change the default. | true |
Other | chartjs | Chart.js | 7ec99c38c1b41b16cf7cad433569af56c2544d63.json | Move startAngle to scale options (#8593) | src/controllers/controller.polarArea.js | @@ -1,12 +1,6 @@
import DatasetController from '../core/core.datasetController';
import {toRadians, PI} from '../helpers/index';
-function getStartAngleRadians(deg) {
- // radialLinear scale draws angleLines using startAngle. 0 is expected to be at top.
- // Here we adjust to standard unit circle used in drawing, where 0 is at right.
- return toRadians(deg) - 0.5 * PI;
-}
-
export default class PolarAreaController extends DatasetController {
constructor(chart, datasetIndex) {
@@ -51,7 +45,7 @@ export default class PolarAreaController extends DatasetController {
const scale = me._cachedMeta.rScale;
const centerX = scale.xCenter;
const centerY = scale.yCenter;
- const datasetStartAngle = getStartAngleRadians(opts.startAngle);
+ const datasetStartAngle = scale.getIndexAngle(0) - 0.5 * PI;
let angle = datasetStartAngle;
let i;
@@ -198,7 +192,8 @@ PolarAreaController.overrides = {
},
pointLabels: {
display: false
- }
+ },
+ startAngle: 0
}
}
}; | true |
Other | chartjs | Chart.js | 7ec99c38c1b41b16cf7cad433569af56c2544d63.json | Move startAngle to scale options (#8593) | src/scales/scale.radialLinear.js | @@ -368,11 +368,8 @@ export default class RadialLinearScale extends LinearScaleBase {
}
getIndexAngle(index) {
- const chart = this.chart;
- const angleMultiplier = TAU / chart.data.labels.length;
- const options = chart.options || {};
- const startAngle = options.startAngle || 0;
-
+ const angleMultiplier = TAU / this.getLabels().length;
+ const startAngle = this.options.startAngle || 0;
return _normalizeAngle(index * angleMultiplier + toRadians(startAngle));
}
@@ -564,6 +561,8 @@ RadialLinearScale.defaults = {
circular: false
},
+ startAngle: 0,
+
// label settings
ticks: {
// Boolean - Show a backdrop to the scale label | true |
Other | chartjs | Chart.js | 7ec99c38c1b41b16cf7cad433569af56c2544d63.json | Move startAngle to scale options (#8593) | test/specs/controller.polarArea.tests.js | @@ -160,7 +160,11 @@ describe('Chart.controllers.polarArea', function() {
legend: false,
title: false,
},
- startAngle: 90, // default is 0
+ scales: {
+ r: {
+ startAngle: 90, // default is 0
+ }
+ },
elements: {
arc: {
backgroundColor: 'rgb(255, 0, 0)', | true |
Other | chartjs | Chart.js | 7ec99c38c1b41b16cf7cad433569af56c2544d63.json | Move startAngle to scale options (#8593) | test/specs/scale.radialLinear.tests.js | @@ -31,6 +31,8 @@ describe('Test the radial linear scale', function() {
circular: false
},
+ startAngle: 0,
+
ticks: {
color: Chart.defaults.color,
showLabelBackdrop: true,
@@ -500,14 +502,14 @@ describe('Test the radial linear scale', function() {
options: {
scales: {
r: {
+ startAngle: 15,
pointLabels: {
callback: function(value, index) {
return index.toString();
}
}
}
},
- startAngle: 15
}
});
@@ -521,7 +523,7 @@ describe('Test the radial linear scale', function() {
expect(radToNearestDegree(chart.scales.r.getIndexAngle(i))).toBe(15 + (slice * i));
}
- chart.options.startAngle = 0;
+ chart.scales.r.options.startAngle = 0;
chart.update();
for (var x = 0; x < 5; x++) {
@@ -569,7 +571,7 @@ describe('Test the radial linear scale', function() {
textAlign: ['right', 'right', 'left', 'left', 'left'],
y: [82, 366, 506, 319, 53]
}].forEach(function(expected) {
- chart.options.startAngle = expected.startAngle;
+ scale.options.startAngle = expected.startAngle;
chart.update();
scale.ctx = window.createMockContext(); | true |
Other | chartjs | Chart.js | e3cdd7323a2a0813ac8d544f71410b2a2d452e4e.json | Move niceNum to helpers.math, cleanup IE fallbacks (#8570) | src/helpers/helpers.math.js | @@ -1,5 +1,10 @@
import {isFinite as isFiniteNumber} from './helpers.core';
+/**
+ * @alias Chart.helpers.math
+ * @namespace
+ */
+
export const PI = Math.PI;
export const TAU = 2 * PI;
export const PITAU = TAU + PI;
@@ -9,10 +14,19 @@ export const HALF_PI = PI / 2;
export const QUARTER_PI = PI / 4;
export const TWO_THIRDS_PI = PI * 2 / 3;
+export const log10 = Math.log10;
+export const sign = Math.sign;
+
/**
- * @alias Chart.helpers.math
- * @namespace
+ * Implementation of the nice number algorithm used in determining where axis labels will go
+ * @return {number}
*/
+export function niceNum(range) {
+ const niceRange = Math.pow(10, Math.floor(log10(range)));
+ const fraction = range / niceRange;
+ const niceFraction = fraction <= 1 ? 1 : fraction <= 2 ? 2 : fraction <= 5 ? 5 : 10;
+ return niceFraction * niceRange;
+}
/**
* Returns an array of factors sorted from 1 to sqrt(value)
@@ -37,16 +51,6 @@ export function _factorize(value) {
return result;
}
-export const log10 = Math.log10 || function(x) {
- const exponent = Math.log(x) * Math.LOG10E; // Math.LOG10E = 1 / Math.LN10.
- // Check for whole powers of 10,
- // which due to floating point rounding error should be corrected.
- const powerOf10 = Math.round(exponent);
- const isPowerOf10 = x === Math.pow(10, powerOf10);
-
- return isPowerOf10 ? powerOf10 : exponent;
-};
-
export function isNumber(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
@@ -75,18 +79,6 @@ export function _setMinAndMaxByKey(array, target, property) {
}
}
-export const sign = Math.sign ?
- function(x) {
- return Math.sign(x);
- } :
- function(x) {
- x = +x; // convert to a number
- if (x === 0 || isNaN(x)) {
- return x;
- }
- return x > 0 ? 1 : -1;
- };
-
export function toRadians(degrees) {
return degrees * (PI / 180);
} | true |
Other | chartjs | Chart.js | e3cdd7323a2a0813ac8d544f71410b2a2d452e4e.json | Move niceNum to helpers.math, cleanup IE fallbacks (#8570) | src/scales/scale.linearbase.js | @@ -1,30 +1,8 @@
import {isNullOrUndef} from '../helpers/helpers.core';
-import {almostEquals, almostWhole, log10, _decimalPlaces, _setMinAndMaxByKey, sign} from '../helpers/helpers.math';
+import {almostEquals, almostWhole, niceNum, _decimalPlaces, _setMinAndMaxByKey, sign} from '../helpers/helpers.math';
import Scale from '../core/core.scale';
import {formatNumber} from '../core/core.intl';
-/**
- * Implementation of the nice number algorithm used in determining where axis labels will go
- * @return {number}
- */
-function niceNum(range) {
- const exponent = Math.floor(log10(range));
- const fraction = range / Math.pow(10, exponent);
- let niceFraction;
-
- if (fraction <= 1.0) {
- niceFraction = 1;
- } else if (fraction <= 2) {
- niceFraction = 2;
- } else if (fraction <= 5) {
- niceFraction = 5;
- } else {
- niceFraction = 10;
- }
-
- return niceFraction * Math.pow(10, exponent);
-}
-
/**
* Generate a set of linear ticks
* @param generationOptions the options used to generate the ticks | true |
Other | chartjs | Chart.js | 118cff7cfc7f4a856b99415901a824aa69bca321.json | Remove distribution option from fixtures (#8559) | test/fixtures/scale.time/bar-large-gap-between-data.js | @@ -36,7 +36,6 @@ module.exports = {
x: {
display: false,
type: 'time',
- distribution: 'linear',
ticks: {
source: 'auto'
}, | true |
Other | chartjs | Chart.js | 118cff7cfc7f4a856b99415901a824aa69bca321.json | Remove distribution option from fixtures (#8559) | test/fixtures/scale.time/source-auto-linear.js | @@ -16,8 +16,7 @@ module.exports = {
},
ticks: {
source: 'auto'
- },
- distribution: 'linear'
+ }
},
y: {
display: false | true |
Other | chartjs | Chart.js | 118cff7cfc7f4a856b99415901a824aa69bca321.json | Remove distribution option from fixtures (#8559) | test/fixtures/scale.time/source-data-linear.js | @@ -16,8 +16,7 @@ module.exports = {
},
ticks: {
source: 'data'
- },
- distribution: 'linear'
+ }
},
y: {
display: false | true |
Other | chartjs | Chart.js | 118cff7cfc7f4a856b99415901a824aa69bca321.json | Remove distribution option from fixtures (#8559) | test/fixtures/scale.time/source-labels-linear-offset-min-max.js | @@ -18,8 +18,7 @@ module.exports = {
},
ticks: {
source: 'labels'
- },
- distribution: 'linear'
+ }
},
y: {
display: false | true |
Other | chartjs | Chart.js | 118cff7cfc7f4a856b99415901a824aa69bca321.json | Remove distribution option from fixtures (#8559) | test/fixtures/scale.time/source-labels-linear.js | @@ -16,8 +16,7 @@ module.exports = {
},
ticks: {
source: 'labels'
- },
- distribution: 'linear'
+ }
},
y: {
display: false | true |
Other | chartjs | Chart.js | 118cff7cfc7f4a856b99415901a824aa69bca321.json | Remove distribution option from fixtures (#8559) | test/fixtures/scale.time/ticks-reverse-linear-min-max.js | @@ -15,7 +15,6 @@ module.exports = {
time: {
parser: 'YYYY'
},
- distribution: 'linear',
reverse: true,
ticks: {
source: 'labels' | true |
Other | chartjs | Chart.js | 118cff7cfc7f4a856b99415901a824aa69bca321.json | Remove distribution option from fixtures (#8559) | test/fixtures/scale.time/ticks-reverse-linear.js | @@ -13,7 +13,6 @@ module.exports = {
time: {
parser: 'YYYY'
},
- distribution: 'linear',
reverse: true,
ticks: {
source: 'labels' | true |
Other | chartjs | Chart.js | 118cff7cfc7f4a856b99415901a824aa69bca321.json | Remove distribution option from fixtures (#8559) | test/fixtures/scale.timeseries/normalize.js | @@ -22,7 +22,6 @@ module.exports = {
time: {
parser: 'YYYY'
},
- distribution: 'linear',
ticks: {
source: 'data'
} | true |
Other | chartjs | Chart.js | 78d3d30d5684b26773bb2c46b8a972908e110cf3.json | Add _allKeys descriptor for Object.keys behavior (#8553) | src/core/core.config.js | @@ -316,7 +316,7 @@ export default class Config {
* @param {object[]} scopes
* @param {object} [context]
* @param {string[]} [prefixes]
- * @param {{scriptable: boolean, indexable: boolean}} [descriptorDefaults]
+ * @param {{scriptable: boolean, indexable: boolean, allKeys?: boolean}} [descriptorDefaults]
*/
createResolver(scopes, context, prefixes = [''], descriptorDefaults) {
const {resolver} = getResolver(this._resolverCache, scopes, prefixes); | true |
Other | chartjs | Chart.js | 78d3d30d5684b26773bb2c46b8a972908e110cf3.json | Add _allKeys descriptor for Object.keys behavior (#8553) | src/core/core.plugins.js | @@ -166,5 +166,5 @@ function createDescriptors(chart, plugins, options, all) {
function pluginOpts(config, plugin, opts, context) {
const keys = config.pluginScopeKeys(plugin);
const scopes = config.getOptionScopes(opts, keys);
- return config.createResolver(scopes, context, [''], {scriptable: false, indexable: false});
+ return config.createResolver(scopes, context, [''], {scriptable: false, indexable: false, allKeys: true});
} | true |
Other | chartjs | Chart.js | 78d3d30d5684b26773bb2c46b8a972908e110cf3.json | Add _allKeys descriptor for Object.keys behavior (#8553) | src/helpers/helpers.config.js | @@ -86,7 +86,7 @@ export function _createResolver(scopes, prefixes = [''], rootScopes = scopes, fa
* @param {object} proxy - The Proxy returned by `_createResolver`
* @param {object} context - Context object for scriptable/indexable options
* @param {object} [subProxy] - The proxy provided for scriptable options
- * @param {{scriptable: boolean, indexable: boolean}} [descriptorDefaults] - Defaults for descriptors
+ * @param {{scriptable: boolean, indexable: boolean, allKeys?: boolean}} [descriptorDefaults] - Defaults for descriptors
* @private
*/
export function _attachContext(proxy, context, subProxy, descriptorDefaults) {
@@ -123,7 +123,9 @@ export function _attachContext(proxy, context, subProxy, descriptorDefaults) {
* Also used by Object.hasOwnProperty.
*/
getOwnPropertyDescriptor(target, prop) {
- return Reflect.getOwnPropertyDescriptor(proxy, prop);
+ return target._descriptors.allKeys
+ ? Reflect.has(proxy, prop) ? {enumerable: true, configurable: true} : undefined
+ : Reflect.getOwnPropertyDescriptor(proxy, prop);
},
/**
@@ -162,8 +164,9 @@ export function _attachContext(proxy, context, subProxy, descriptorDefaults) {
* @private
*/
export function _descriptors(proxy, defaults = {scriptable: true, indexable: true}) {
- const {_scriptable = defaults.scriptable, _indexable = defaults.indexable} = proxy;
+ const {_scriptable = defaults.scriptable, _indexable = defaults.indexable, _allKeys = defaults.allKeys} = proxy;
return {
+ allKeys: _allKeys,
scriptable: _scriptable,
indexable: _indexable,
isScriptable: isFunction(_scriptable) ? _scriptable : () => _scriptable, | true |
Other | chartjs | Chart.js | 78d3d30d5684b26773bb2c46b8a972908e110cf3.json | Add _allKeys descriptor for Object.keys behavior (#8553) | test/specs/core.plugin.tests.js | @@ -274,7 +274,8 @@ describe('Chart.plugins', function() {
chart.notifyPlugins('hook');
expect(plugin.hook).toHaveBeenCalled();
- expect(plugin.hook.calls.first().args[2]).toEqualOptions({a: 42});
+ expect(Object.keys(plugin.hook.calls.first().args[2])).toEqual(['a']);
+ expect(plugin.hook.calls.first().args[2]).toEqual(jasmine.objectContaining({a: 42}));
Chart.unregister(plugin);
}); | true |
Other | chartjs | Chart.js | e2a50b957ec636df795c4be56d8e792a007c6d12.json | Remove empty dependencies block from package.json (#8550) | package.json | @@ -87,6 +87,5 @@
"typedoc": "^0.20.27",
"typescript": "^4.1.5",
"yargs": "^16.2.0"
- },
- "dependencies": {}
+ }
} | false |
Other | chartjs | Chart.js | ae95a8221d0145945c42026def788dda5c171c8f.json | Fix function support on _fallback (#8545) | src/helpers/helpers.config.js | @@ -245,14 +245,15 @@ function resolveFallback(fallback, prop, value) {
return isFunction(fallback) ? fallback(prop, value) : fallback;
}
-const getScope = (key, parent) => key === true ? parent : resolveObjectKey(parent, key);
+const getScope = (key, parent) => key === true ? parent
+ : typeof key === 'string' ? resolveObjectKey(parent, key) : undefined;
function addScopes(set, parentScopes, key, parentFallback) {
for (const parent of parentScopes) {
const scope = getScope(key, parent);
if (scope) {
set.add(scope);
- const fallback = scope._fallback;
+ const fallback = resolveFallback(scope._fallback, key, scope);
if (defined(fallback) && fallback !== key && fallback !== parentFallback) {
// When we reach the descriptor that defines a new _fallback, return that.
// The fallback will resume to that new scope. | true |
Other | chartjs | Chart.js | ae95a8221d0145945c42026def788dda5c171c8f.json | Fix function support on _fallback (#8545) | test/specs/helpers.config.tests.js | @@ -128,6 +128,37 @@ describe('Chart.helpers.config', function() {
});
});
+ it('should support _fallback as function', function() {
+ const descriptors = {
+ _fallback: (prop, value) => prop === 'hover' && value.shouldFall && 'interaction',
+ };
+ const defaults = {
+ interaction: {
+ mode: 'test',
+ priority: 'fall'
+ },
+ hover: {
+ priority: 'main'
+ }
+ };
+ const options = {
+ interaction: {
+ a: 1
+ },
+ hover: {
+ shouldFall: true,
+ b: 2
+ }
+ };
+ const resolver = _createResolver([options, defaults, descriptors]);
+ expect(resolver.hover).toEqualOptions({
+ mode: 'test',
+ priority: 'main',
+ a: 1,
+ b: 2
+ });
+ });
+
it('should not fallback by default', function() {
const defaults = {
hover: { | true |
Other | chartjs | Chart.js | aebbb5afff8c330f53568d269e8d3518903fa828.json | fix: allow colors as array (#10075)
* fix: allow colors as array
* Revert "fix: allow colors as array"
This reverts commit 632e2ee917ad58061b4ec39dda5f43f593b0b3c1.
* fix: allow colors as array
* Update types/index.esm.d.ts
Co-authored-by: Jacco van den Berg <39033624+LeeLenaleee@users.noreply.github.com>
Co-authored-by: Jacco van den Berg <39033624+LeeLenaleee@users.noreply.github.com> | types/index.esm.d.ts | @@ -2902,7 +2902,7 @@ export interface TickOptions {
* Color of tick
* @see Defaults.color
*/
- color: Scriptable<Color, ScriptableScaleContext>;
+ color: ScriptableAndArray<Color, ScriptableScaleContext>;
/**
* see Fonts
*/ | false |
Other | chartjs | Chart.js | cc807b22d3dd654ee57afab1e97a5b6f9d7589dc.json | add SubTitle to ts test register (#10117) | types/tests/register.ts | @@ -22,6 +22,7 @@ import {
Filler,
Legend,
Title,
+ SubTitle,
Tooltip
} from '../index.esm';
@@ -48,5 +49,6 @@ Chart.register(
Filler,
Legend,
Title,
+ SubTitle,
Tooltip
); | false |
Other | chartjs | Chart.js | a7d98fb1a0c0496cf87705351eb5995fd0e950af.json | Fix typos found by codespell (#10103) | docs/charts/doughnut.md | @@ -111,7 +111,7 @@ The doughnut/pie chart allows a number of properties to be specified for each da
| [`circumference`](#general) | `number` | - | - | `undefined`
| [`clip`](#general) | `number`\|`object` | - | - | `undefined`
| [`data`](#data-structure) | `number[]` | - | - | **required**
-| [`hoverBackgroundColor`](#interations) | [`Color`](../general/colors.md) | Yes | Yes | `undefined`
+| [`hoverBackgroundColor`](#interactions) | [`Color`](../general/colors.md) | Yes | Yes | `undefined`
| [`hoverBorderColor`](#interactions) | [`Color`](../general/colors.md) | Yes | Yes | `undefined`
| [`hoverBorderJoinStyle`](#interactions) | `'round'`\|`'bevel'`\|`'miter'` | Yes | Yes | `undefined`
| [`hoverBorderWidth`](#interactions) | `number` | Yes | Yes | `undefined` | true |
Other | chartjs | Chart.js | a7d98fb1a0c0496cf87705351eb5995fd0e950af.json | Fix typos found by codespell (#10103) | docs/charts/polar.md | @@ -62,7 +62,7 @@ The following options can be included in a polar area chart dataset to configure
| [`borderWidth`](#styling) | `number` | Yes | Yes | `2`
| [`clip`](#general) | `number`\|`object` | - | - | `undefined`
| [`data`](#data-structure) | `number[]` | - | - | **required**
-| [`hoverBackgroundColor`](#interations) | [`Color`](../general/colors.md) | Yes | Yes | `undefined`
+| [`hoverBackgroundColor`](#interactions) | [`Color`](../general/colors.md) | Yes | Yes | `undefined`
| [`hoverBorderColor`](#interactions) | [`Color`](../general/colors.md) | Yes | Yes | `undefined`
| [`hoverBorderJoinStyle`](#interactions) | `'round'`\|`'bevel'`\|`'miter'` | Yes | Yes | `undefined`
| [`hoverBorderWidth`](#interactions) | `number` | Yes | Yes | `undefined` | true |
Other | chartjs | Chart.js | a7d98fb1a0c0496cf87705351eb5995fd0e950af.json | Fix typos found by codespell (#10103) | docs/configuration/animations.md | @@ -123,7 +123,7 @@ These keys can be configured in following paths:
* `datasets[type]` - dataset type options
* `overrides[type]` - chart type options
-These paths are valid under `defaults` for global confuguration and `options` for instance configuration.
+These paths are valid under `defaults` for global configuration and `options` for instance configuration.
## animation
@@ -183,7 +183,7 @@ Namespace: `options.transitions[mode]`
| `'active'` | animation.duration | 400 | Override default duration to 400ms for hover animations
| `'resize'` | animation.duration | 0 | Override default duration to 0ms (= no animation) for resize
| `'show'` | animations.colors | `{ type: 'color', properties: ['borderColor', 'backgroundColor'], from: 'transparent' }` | Colors are faded in from transparent when dataset is shown using legend / [api](../developers/api.md#showdatasetIndex).
-| `'show'` | animations.visible | `{ type: 'boolean', duration: 0 }` | Dataset visiblity is immediately changed to true so the color transition from transparent is visible.
+| `'show'` | animations.visible | `{ type: 'boolean', duration: 0 }` | Dataset visibility is immediately changed to true so the color transition from transparent is visible.
| `'hide'` | animations.colors | `{ type: 'color', properties: ['borderColor', 'backgroundColor'], to: 'transparent' }` | Colors are faded to transparent when dataset id hidden using legend / [api](../developers/api.md#hidedatasetIndex).
| `'hide'` | animations.visible | `{ type: 'boolean', easing: 'easeInExpo' }` | Visibility is changed to false at a very late phase of animation
| true |
Other | chartjs | Chart.js | a7d98fb1a0c0496cf87705351eb5995fd0e950af.json | Fix typos found by codespell (#10103) | docs/configuration/subtitle.md | @@ -6,7 +6,7 @@ Subtitle is a second title placed under the main title, by default. It has exact
Namespace: `options.plugins.subtitle`. The global defaults for subtitle are configured in `Chart.defaults.plugins.subtitle`.
-Excactly the same configuration options with [title](./title.md) are available for subtitle, the namespaces only differ.
+Exactly the same configuration options with [title](./title.md) are available for subtitle, the namespaces only differ.
## Example Usage
| true |
Other | chartjs | Chart.js | a7d98fb1a0c0496cf87705351eb5995fd0e950af.json | Fix typos found by codespell (#10103) | docs/getting-started/v3-migration.md | @@ -75,7 +75,7 @@ A number of changes were made to the configuration options passed to the `Chart`
* Polar area `startAngle` option is now consistent with `Radar`, 0 is at top and value is in degrees. Default is changed from `-½π` to `0`.
* Doughnut `rotation` option is now in degrees and 0 is at top. Default is changed from `-½π` to `0`.
* Doughnut `circumference` option is now in degrees. Default is changed from `2π` to `360`.
-* Doughnut `cutoutPercentage` was renamed to `cutout`and accepts pixels as numer and percent as string ending with `%`.
+* Doughnut `cutoutPercentage` was renamed to `cutout`and accepts pixels as number and percent as string ending with `%`.
* `scale` option was removed in favor of `options.scales.r` (or any other scale id, with `axis: 'r'`)
* `scales.[x/y]Axes` arrays were removed. Scales are now configured directly to `options.scales` object with the object key being the scale Id.
* `scales.[x/y]Axes.barPercentage` was moved to dataset option `barPercentage` | true |
Other | chartjs | Chart.js | a7d98fb1a0c0496cf87705351eb5995fd0e950af.json | Fix typos found by codespell (#10103) | docs/samples/information.md | @@ -2,10 +2,10 @@
## Out of the box working samples
These samples are made for demonstration purposes only. They won't work out of the box if you copy paste them into your own website. This is because of how the docs are getting built. Some boilerplate code gets hidden.
-For a sample that can be copyed and pasted and used directly you can check the [usage page](../getting-started/usage.md).
+For a sample that can be copied and pasted and used directly you can check the [usage page](../getting-started/usage.md).
## Autogenerated data
The data used in the samples is autogenerated using custom functions. These functions do not ship with the library, for more information about this you can check the [utils page](./utils.md).
## Actions block
-The samples have an `actions` code block. These actions are not part of chart.js. They are internally transformed to seperate buttons together with onClick listeners by a plugin we use in the documentation. To implement such actions yourself you can make some buttons and add onClick event listeners to them. Then in these event listeners you can call your variable in which you made the chart and do the logic that the button is supposed to do.
+The samples have an `actions` code block. These actions are not part of chart.js. They are internally transformed to separate buttons together with onClick listeners by a plugin we use in the documentation. To implement such actions yourself you can make some buttons and add onClick event listeners to them. Then in these event listeners you can call your variable in which you made the chart and do the logic that the button is supposed to do. | true |
Other | chartjs | Chart.js | a7d98fb1a0c0496cf87705351eb5995fd0e950af.json | Fix typos found by codespell (#10103) | src/helpers/helpers.config.js | @@ -203,7 +203,7 @@ function _resolveWithContext(target, prop, receiver) {
value = _resolveArray(prop, value, target, descriptors.isIndexable);
}
if (needsSubResolver(prop, value)) {
- // if the resolved value is an object, crate a sub resolver for it
+ // if the resolved value is an object, create a sub resolver for it
value = _attachContext(value, _context, _subProxy && _subProxy[prop], descriptors);
}
return value; | true |
Other | chartjs | Chart.js | a7d98fb1a0c0496cf87705351eb5995fd0e950af.json | Fix typos found by codespell (#10103) | src/helpers/helpers.extras.js | @@ -17,7 +17,7 @@ export const requestAnimFrame = (function() {
/**
* Throttles calling `fn` once per animation frame
- * Latest argments are used on the actual call
+ * Latest arguments are used on the actual call
* @param {function} fn
* @param {*} thisArg
* @param {function} [updateFn] | true |
Other | chartjs | Chart.js | a7d98fb1a0c0496cf87705351eb5995fd0e950af.json | Fix typos found by codespell (#10103) | src/plugins/plugin.tooltip.js | @@ -1013,7 +1013,7 @@ export class Tooltip extends Element {
* Handle an event
* @param {ChartEvent} e - The event to handle
* @param {boolean} [replay] - This is a replayed event (from update)
- * @param {boolean} [inChartArea] - The event is indide chartArea
+ * @param {boolean} [inChartArea] - The event is inside chartArea
* @returns {boolean} true if the tooltip changed
*/
handleEvent(e, replay, inChartArea = true) {
@@ -1054,11 +1054,11 @@ export class Tooltip extends Element {
/**
* Helper for determining the active elements for event
* @param {ChartEvent} e - The event to handle
- * @param {Element[]} lastActive - Previously active elements
+ * @param {Element[]} lastActive - Previously active elements
* @param {boolean} [replay] - This is a replayed event (from update)
- * @param {boolean} [inChartArea] - The event is indide chartArea
+ * @param {boolean} [inChartArea] - The event is inside chartArea
* @returns {Element[]} - Active elements
- * @private
+ * @private
*/
_getActiveElements(e, lastActive, replay, inChartArea) {
const options = this.options; | true |
Other | chartjs | Chart.js | a7d98fb1a0c0496cf87705351eb5995fd0e950af.json | Fix typos found by codespell (#10103) | test/specs/controller.line.tests.js | @@ -603,7 +603,7 @@ describe('Chart.controllers.line', function() {
expect(options.cubicInterpolationMode).toBe('monotone');
});
- it('should be overriden by user-supplied values', function() {
+ it('should be overridden by user-supplied values', function() {
Chart.helpers.merge(Chart.defaults.datasets.line, {
spanGaps: true,
tension: 0.231 | true |
Other | chartjs | Chart.js | a7d98fb1a0c0496cf87705351eb5995fd0e950af.json | Fix typos found by codespell (#10103) | test/specs/core.animations.tests.js | @@ -44,7 +44,7 @@ describe('Chart.animations', function() {
})).toBeUndefined();
});
- it('should assing options directly, if target does not have previous options', function() {
+ it('should assign options directly, if target does not have previous options', function() {
const chart = {};
const anims = new Chart.Animations(chart, {option: {duration: 200}});
const target = {}; | true |
Other | chartjs | Chart.js | a7d98fb1a0c0496cf87705351eb5995fd0e950af.json | Fix typos found by codespell (#10103) | test/specs/core.controller.tests.js | @@ -252,7 +252,7 @@ describe('Chart', function() {
expect(chart.options.hover).toBeFalse();
});
- it('when options.interation=false and options.hover is not defined', function() {
+ it('when options.interaction=false and options.hover is not defined', function() {
var chart = acquireChart({
type: 'line',
options: {
@@ -262,7 +262,7 @@ describe('Chart', function() {
expect(chart.options.hover).toBeFalse();
});
- it('when options.interation=false and options.hover is defined', function() {
+ it('when options.interaction=false and options.hover is defined', function() {
var chart = acquireChart({
type: 'line',
options: { | true |
Other | chartjs | Chart.js | a7d98fb1a0c0496cf87705351eb5995fd0e950af.json | Fix typos found by codespell (#10103) | test/specs/helpers.interpolation.tests.js | @@ -7,7 +7,7 @@ describe('helpers.interpolation', function() {
expect(_pointInLine({x: 10, y: 10}, {x: 20, y: 20}, 1)).toEqual({x: 20, y: 20});
});
- it('Should intepolate a point in stepped line', function() {
+ it('Should interpolate a point in stepped line', function() {
expect(_steppedInterpolation({x: 10, y: 10}, {x: 20, y: 20}, 0, 'before')).toEqual({x: 10, y: 10});
expect(_steppedInterpolation({x: 10, y: 10}, {x: 20, y: 20}, 0.4, 'before')).toEqual({x: 14, y: 20});
expect(_steppedInterpolation({x: 10, y: 10}, {x: 20, y: 20}, 0.5, 'before')).toEqual({x: 15, y: 20}); | true |
Other | chartjs | Chart.js | a7d98fb1a0c0496cf87705351eb5995fd0e950af.json | Fix typos found by codespell (#10103) | test/specs/scale.time.tests.js | @@ -286,7 +286,7 @@ describe('Time scale tests', function() {
it('should have ticks with accurate labels', function() {
var scale = this.scale;
var ticks = scale.getTicks();
- // pixelsPerTick is an aproximation which assumes same number of milliseconds per year (not true)
+ // pixelsPerTick is an approximation which assumes same number of milliseconds per year (not true)
// we use a threshold of 1 day so that we still match these values
var pixelsPerTick = scale.width / (ticks.length - 1);
| true |
Other | chartjs | Chart.js | a7d98fb1a0c0496cf87705351eb5995fd0e950af.json | Fix typos found by codespell (#10103) | types/helpers/helpers.extras.d.ts | @@ -7,7 +7,7 @@ export function requestAnimFrame(cb: () => void): void;
/**
* Throttles calling `fn` once per animation frame
- * Latest argments are used on the actual call
+ * Latest arguments are used on the actual call
* @param {function} fn
* @param {*} thisArg
* @param {function} [updateFn] | true |
Other | chartjs | Chart.js | a7d98fb1a0c0496cf87705351eb5995fd0e950af.json | Fix typos found by codespell (#10103) | types/index.esm.d.ts | @@ -927,7 +927,7 @@ export interface Plugin<TType extends ChartType = ChartType, O = AnyObject> exte
*/
afterDataLimits?(chart: Chart, args: { scale: Scale }, options: O): void;
/**
- * @desc Called before scale bulds its ticks. This hook is called separately for each scale in the chart.
+ * @desc Called before scale builds its ticks. This hook is called separately for each scale in the chart.
* @param {Chart} chart - The chart instance.
* @param {object} args - The call arguments.
* @param {Scale} args.scale - The scale. | true |
Other | chartjs | Chart.js | 4d918f5afa6f3392201761c4c299bbe093bb96e8.json | add typing and docs for maxTicksLimit all scales (#10057)
* add typing and docs for maxTicksLimit time scale
* change maxTicksLimit to base instead of each scale seperatly since its done in the core.scale | docs/axes/cartesian/_common_ticks.md | @@ -15,3 +15,4 @@ Namespace: `options.scales[scaleId].ticks`
| `minRotation` | `number` | `0` | Minimum rotation for tick labels. *Note: Only applicable to horizontal scales.*
| `mirror` | `boolean` | `false` | Flips tick labels around axis, displaying the labels inside the chart instead of outside. *Note: Only applicable to vertical scales.*
| `padding` | `number` | `0` | Padding between the tick label and the axis. When set on a vertical axis, this applies in the horizontal (X) direction. When set on a horizontal axis, this applies in the vertical (Y) direction.
+| `maxTicksLimit` | `number` | `11` | Maximum number of ticks and gridlines to show. | true |
Other | chartjs | Chart.js | 4d918f5afa6f3392201761c4c299bbe093bb96e8.json | add typing and docs for maxTicksLimit all scales (#10057)
* add typing and docs for maxTicksLimit time scale
* change maxTicksLimit to base instead of each scale seperatly since its done in the core.scale | docs/axes/cartesian/linear.md | @@ -27,7 +27,6 @@ Namespace: `options.scales[scaleId].ticks`
| ---- | ---- | ------- | ------- | -----------
| `count` | `number` | Yes | `undefined` | The number of ticks to generate. If specified, this overrides the automatic generation.
| `format` | `object` | Yes | | The [`Intl.NumberFormat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat) options used by the default label formatter
-| `maxTicksLimit` | `number` | Yes | `11` | Maximum number of ticks and gridlines to show.
| `precision` | `number` | Yes | | if defined and `stepSize` is not specified, the step size will be rounded to this many decimal places.
| `stepSize` | `number` | Yes | | User-defined fixed step size for the scale. [more...](#step-size)
| true |
Other | chartjs | Chart.js | 4d918f5afa6f3392201761c4c299bbe093bb96e8.json | add typing and docs for maxTicksLimit all scales (#10057)
* add typing and docs for maxTicksLimit time scale
* change maxTicksLimit to base instead of each scale seperatly since its done in the core.scale | types/index.esm.d.ts | @@ -3078,6 +3078,11 @@ export interface CartesianScaleOptions extends CoreScaleOptions {
* @default 0
*/
padding: number;
+ /**
+ * Maximum number of ticks and gridlines to show.
+ * @default 11
+ */
+ maxTicksLimit: number;
};
}
@@ -3120,11 +3125,6 @@ export type LinearScaleOptions = CartesianScaleOptions & {
*/
format: Intl.NumberFormatOptions;
- /**
- * Maximum number of ticks and gridlines to show.
- * @default 11
- */
- maxTicksLimit: number;
/**
* if defined and stepSize is not specified, the step size will be rounded to this many decimal places.
*/ | true |
Other | chartjs | Chart.js | 51b051f766c309fd04fbd94556ec5c738c6d153f.json | Improve issue templates (#10038)
* Make issue templates fancier
* should be valid yml now
* remove title field
* remove reproducable sample for docs
* add example back to docs, change link for plugin and add TS link for TS issues
* wrong labels, forgot type: in front of it
* implement feedback
* gramar, missing word | .github/ISSUE_TEMPLATE/BUG.md | @@ -1,50 +0,0 @@
----
-name: Bug Report
-about: Something went awry
-labels: 'type: bug'
----
-
-<!--
- Need help or support? Please don't open an issue!
- Head to https://stackoverflow.com/questions/tagged/chart.js
-
- Bug reports MUST be submitted with an interactive example:
- https://codepen.io/pen?template=BapRepQ
-
- Chart.js versions lower then 3.x are NOT supported anymore, new issues will be disregarded.
--->
-
-## Expected Behavior
-<!-- Tell us what should happen -->
-
-## Current Behavior
-<!-- Tell us what happens instead of the expected behavior -->
-
-## Possible Solution
-<!--
- Not obligatory, but suggest a fix/reason for the bug,
- or ideas how to implement the addition or change
--->
-
-## Steps to Reproduce
-<!--
- Provide a link to a live example. Bug reports MUST be submitted with an
- interactive example (https://codepen.io/pen/?template=BapRepQ).
-
- If filing a bug against `master`, you may reference the latest code via
- https://www.chartjs.org/dist/master/chart.min.js (changing the filename to
- point at the file you need as appropriate). Do not rely on these files for
- production purposes as they may be removed at any time.
--->
-
-## Context
-<!--
- How has this issue affected you? What are you trying to accomplish? Providing
- context helps us come up with a solution that is most useful in the real world
--->
-
-## Environment
-<!-- Include as many relevant details about the environment you experienced the bug in -->
-* Chart.js version:
-* Browser name and version:
-* Link to your project: | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.