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
4b4b4b79e1e24d2f8e253abbe365a34021a29b79.json
Convert all scales to use ES6 classes
src/scales/scale.linearbase.js
@@ -1,9 +1,9 @@ 'use strict'; -var helpers = require('../helpers/index'); -var Scale = require('../core/core.scale'); +const helpers = require('../helpers/index'); +const Scale = require('../core/core.scale'); -var isNullOrUndef = helpers.isNullOrUndef; +const isNullOrUndef = helpers.isNullOrUndef; /** * Generate a set of linear ticks @@ -83,8 +83,8 @@ function generateTicks(generationOptions, dataRange) { return ticks; } -module.exports = Scale.extend({ - _parse: function(raw, index) { // eslint-disable-line no-unused-vars +class LinearScaleBase extends Scale { + _parse(raw, index) { // eslint-disable-line no-unused-vars if (helpers.isNullOrUndef(raw)) { return NaN; } @@ -93,9 +93,9 @@ module.exports = Scale.extend({ } return +raw; - }, + } - handleTickRangeOptions: function() { + handleTickRangeOptions() { var me = this; var opts = me.options; @@ -159,9 +159,9 @@ module.exports = Scale.extend({ me.min--; } } - }, + } - getTickLimit: function() { + getTickLimit() { var me = this; var tickOpts = me.options.ticks; var stepSize = tickOpts.stepSize; @@ -180,17 +180,17 @@ module.exports = Scale.extend({ } return maxTicks; - }, + } - _computeTickLimit: function() { + _computeTickLimit() { return Number.POSITIVE_INFINITY; - }, + } - _handleDirectionalChanges: function(ticks) { + _handleDirectionalChanges(ticks) { return ticks; - }, + } - buildTicks: function() { + buildTicks() { var me = this; var opts = me.options; var tickOpts = opts.ticks; @@ -228,15 +228,15 @@ module.exports = Scale.extend({ } return ticks; - }, + } - generateTickLabels: function(ticks) { + generateTickLabels(ticks) { var me = this; me._tickValues = ticks.map(t => t.value); Scale.prototype.generateTickLabels.call(me, ticks); - }, + } - _configure: function() { + _configure() { var me = this; var ticks = me.getTicks(); var start = me.min; @@ -254,4 +254,6 @@ module.exports = Scale.extend({ me._endValue = end; me._valueRange = end - start; } -}); +} + +module.exports = LinearScaleBase;
true
Other
chartjs
Chart.js
4b4b4b79e1e24d2f8e253abbe365a34021a29b79.json
Convert all scales to use ES6 classes
src/scales/scale.logarithmic.js
@@ -1,13 +1,13 @@ 'use strict'; -var defaults = require('../core/core.defaults'); -var helpers = require('../helpers/index'); -var Scale = require('../core/core.scale'); -var LinearScaleBase = require('./scale.linearbase'); -var Ticks = require('../core/core.ticks'); +const defaults = require('../core/core.defaults'); +const helpers = require('../helpers/index'); +const Scale = require('../core/core.scale'); +const LinearScaleBase = require('./scale.linearbase'); +const Ticks = require('../core/core.ticks'); -var valueOrDefault = helpers.valueOrDefault; -var log10 = helpers.math.log10; +const valueOrDefault = helpers.valueOrDefault; +const log10 = helpers.math.log10; /** * Generate a set of logarithmic ticks @@ -55,7 +55,7 @@ function generateTicks(generationOptions, dataRange) { return ticks; } -var defaultConfig = { +const defaultConfig = { position: 'left', // label settings @@ -64,13 +64,13 @@ var defaultConfig = { } }; -module.exports = Scale.extend({ - _parse: function(raw, index) { // eslint-disable-line no-unused-vars +class LogarithmicScale extends Scale { + _parse(raw, index) { // eslint-disable-line no-unused-vars const value = LinearScaleBase.prototype._parse.apply(this, arguments); return helpers.isFinite(value) && value >= 0 ? value : undefined; - }, + } - determineDataLimits: function() { + determineDataLimits() { var me = this; var minmax = me._getMinMax(true); var min = minmax.min; @@ -82,9 +82,9 @@ module.exports = Scale.extend({ me.minNotZero = helpers.isFinite(minPositive) ? minPositive : null; me.handleTickRangeOptions(); - }, + } - handleTickRangeOptions: function() { + handleTickRangeOptions() { var me = this; var DEFAULT_MIN = 1; var DEFAULT_MAX = 10; @@ -119,9 +119,9 @@ module.exports = Scale.extend({ } me.min = min; me.max = max; - }, + } - buildTicks: function() { + buildTicks() { var me = this; var opts = me.options; var reverse = !me.isHorizontal(); @@ -148,36 +148,36 @@ module.exports = Scale.extend({ ticks.reverse(); } return ticks; - }, + } - generateTickLabels: function(ticks) { + generateTickLabels(ticks) { this._tickValues = ticks.map(t => t.value); return Scale.prototype.generateTickLabels.call(this, ticks); - }, + } - getPixelForTick: function(index) { + getPixelForTick(index) { var ticks = this._tickValues; if (index < 0 || index > ticks.length - 1) { return null; } return this.getPixelForValue(ticks[index]); - }, + } /** * Returns the value of the first tick. * @param {number} value - The minimum not zero value. * @return {number} The first tick value. * @private */ - _getFirstTickValue: function(value) { + _getFirstTickValue(value) { var exp = Math.floor(log10(value)); var significand = Math.floor(value / Math.pow(10, exp)); return significand * Math.pow(10, exp); - }, + } - _configure: function() { + _configure() { var me = this; var start = me.min; var offset = 0; @@ -192,26 +192,27 @@ module.exports = Scale.extend({ me._startValue = log10(start); me._valueOffset = offset; me._valueRange = (log10(me.max) - log10(start)) / (1 - offset); - }, + } - getPixelForValue: function(value) { + getPixelForValue(value) { var me = this; var decimal = 0; if (value > me.min && value > 0) { decimal = (log10(value) - me._startValue) / me._valueRange + me._valueOffset; } return me.getPixelForDecimal(decimal); - }, + } - getValueForPixel: function(pixel) { + getValueForPixel(pixel) { var me = this; var decimal = me.getDecimalForPixel(pixel); return decimal === 0 && me.min === 0 ? 0 : Math.pow(10, me._startValue + (decimal - me._valueOffset) * me._valueRange); } -}); +} +module.exports = LogarithmicScale; // INTERNAL: static default options, registered in src/index.js module.exports._defaults = defaultConfig;
true
Other
chartjs
Chart.js
4b4b4b79e1e24d2f8e253abbe365a34021a29b79.json
Convert all scales to use ES6 classes
src/scales/scale.radialLinear.js
@@ -1,15 +1,15 @@ 'use strict'; -var defaults = require('../core/core.defaults'); -var helpers = require('../helpers/index'); -var LinearScaleBase = require('./scale.linearbase'); -var Ticks = require('../core/core.ticks'); +const defaults = require('../core/core.defaults'); +const helpers = require('../helpers/index'); +const LinearScaleBase = require('./scale.linearbase'); +const Ticks = require('../core/core.ticks'); -var valueOrDefault = helpers.valueOrDefault; -var valueAtIndexOrDefault = helpers.valueAtIndexOrDefault; -var resolve = helpers.options.resolve; +const valueOrDefault = helpers.valueOrDefault; +const valueAtIndexOrDefault = helpers.valueAtIndexOrDefault; +const resolve = helpers.options.resolve; -var defaultConfig = { +const defaultConfig = { display: true, // Boolean - Whether to animate scaling the chart from the centre @@ -290,8 +290,8 @@ function numberOrZero(param) { return helpers.isNumber(param) ? param : 0; } -module.exports = LinearScaleBase.extend({ - setDimensions: function() { +class RadialLinearScale extends LinearScaleBase { + setDimensions() { var me = this; // Set the unconstrained dimension before label rotation @@ -301,9 +301,9 @@ module.exports = LinearScaleBase.extend({ me.xCenter = Math.floor(me.width / 2); me.yCenter = Math.floor((me.height - me.paddingTop) / 2); me.drawingArea = Math.min(me.height - me.paddingTop, me.width) / 2; - }, + } - determineDataLimits: function() { + determineDataLimits() { var me = this; var minmax = me._getMinMax(false); var min = minmax.min; @@ -314,14 +314,14 @@ module.exports = LinearScaleBase.extend({ // Common base implementation to handle min, max, beginAtZero me.handleTickRangeOptions(); - }, + } // Returns the maximum number of ticks based on the scale dimension - _computeTickLimit: function() { + _computeTickLimit() { return Math.ceil(this.drawingArea / getTickBackdropHeight(this.options)); - }, + } - generateTickLabels: function(ticks) { + generateTickLabels(ticks) { var me = this; LinearScaleBase.prototype.generateTickLabels.call(me, ticks); @@ -331,9 +331,9 @@ module.exports = LinearScaleBase.extend({ var label = helpers.callback(me.options.pointLabels.callback, arguments, me); return label || label === 0 ? label : ''; }); - }, + } - fit: function() { + fit() { var me = this; var opts = me.options; @@ -342,13 +342,13 @@ module.exports = LinearScaleBase.extend({ } else { me.setCenterPoint(0, 0, 0, 0); } - }, + } /** * Set radius reductions and determine new radius and center point * @private */ - setReductions: function(largestPossibleRadius, furthestLimits, furthestAngles) { + setReductions(largestPossibleRadius, furthestLimits, furthestAngles) { var me = this; var radiusReductionLeft = furthestLimits.l / Math.sin(furthestAngles.l); var radiusReductionRight = Math.max(furthestLimits.r - me.width, 0) / Math.sin(furthestAngles.r); @@ -364,9 +364,9 @@ module.exports = LinearScaleBase.extend({ Math.floor(largestPossibleRadius - (radiusReductionLeft + radiusReductionRight) / 2), Math.floor(largestPossibleRadius - (radiusReductionTop + radiusReductionBottom) / 2)); me.setCenterPoint(radiusReductionLeft, radiusReductionRight, radiusReductionTop, radiusReductionBottom); - }, + } - setCenterPoint: function(leftMovement, rightMovement, topMovement, bottomMovement) { + setCenterPoint(leftMovement, rightMovement, topMovement, bottomMovement) { var me = this; var maxRight = me.width - rightMovement - me.drawingArea; var maxLeft = leftMovement + me.drawingArea; @@ -375,9 +375,9 @@ module.exports = LinearScaleBase.extend({ me.xCenter = Math.floor(((maxLeft + maxRight) / 2) + me.left); me.yCenter = Math.floor(((maxTop + maxBottom) / 2) + me.top + me.paddingTop); - }, + } - getIndexAngle: function(index) { + getIndexAngle(index) { var chart = this.chart; var angleMultiplier = 360 / chart.data.labels.length; var options = chart.options || {}; @@ -387,9 +387,9 @@ module.exports = LinearScaleBase.extend({ var angle = (index * angleMultiplier + startAngle) % 360; return (angle < 0 ? angle + 360 : angle) * Math.PI * 2 / 360; - }, + } - getDistanceFromCenterForValue: function(value) { + getDistanceFromCenterForValue(value) { var me = this; if (helpers.isNullOrUndef(value)) { @@ -402,22 +402,22 @@ module.exports = LinearScaleBase.extend({ return (me.max - value) * scalingFactor; } return (value - me.min) * scalingFactor; - }, + } - getPointPosition: function(index, distanceFromCenter) { + getPointPosition(index, distanceFromCenter) { var me = this; var thisAngle = me.getIndexAngle(index) - (Math.PI / 2); return { x: Math.cos(thisAngle) * distanceFromCenter + me.xCenter, y: Math.sin(thisAngle) * distanceFromCenter + me.yCenter }; - }, + } - getPointPositionForValue: function(index, value) { + getPointPositionForValue(index, value) { return this.getPointPosition(index, this.getDistanceFromCenterForValue(value)); - }, + } - getBasePosition: function(index) { + getBasePosition(index) { var me = this; var min = me.min; var max = me.max; @@ -427,12 +427,12 @@ module.exports = LinearScaleBase.extend({ min < 0 && max < 0 ? max : min > 0 && max > 0 ? min : 0); - }, + } /** * @private */ - _drawGrid: function() { + _drawGrid() { var me = this; var ctx = me.ctx; var opts = me.options; @@ -475,12 +475,12 @@ module.exports = LinearScaleBase.extend({ ctx.restore(); } - }, + } /** * @private */ - _drawLabels: function() { + _drawLabels() { var me = this; var ctx = me.ctx; var opts = me.options; @@ -526,13 +526,14 @@ module.exports = LinearScaleBase.extend({ }); ctx.restore(); - }, + } /** * @private */ - _drawTitle: helpers.noop -}); + _drawTitle() {} +} +module.exports = RadialLinearScale; // INTERNAL: static default options, registered in src/index.js module.exports._defaults = defaultConfig;
true
Other
chartjs
Chart.js
4b4b4b79e1e24d2f8e253abbe365a34021a29b79.json
Convert all scales to use ES6 classes
src/scales/scale.time.js
@@ -1,17 +1,17 @@ 'use strict'; -var adapters = require('../core/core.adapters'); -var defaults = require('../core/core.defaults'); -var helpers = require('../helpers/index'); -var Scale = require('../core/core.scale'); +const adapters = require('../core/core.adapters'); +const defaults = require('../core/core.defaults'); +const helpers = require('../helpers/index'); +const Scale = require('../core/core.scale'); -var resolve = helpers.options.resolve; -var valueOrDefault = helpers.valueOrDefault; +const resolve = helpers.options.resolve; +const valueOrDefault = helpers.valueOrDefault; // Integer constants are from the ES6 spec. -var MAX_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991; +const MAX_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991; -var INTERVALS = { +const INTERVALS = { millisecond: { common: true, size: 1, @@ -58,7 +58,7 @@ var INTERVALS = { } }; -var UNITS = Object.keys(INTERVALS); +const UNITS = Object.keys(INTERVALS); function sorter(a, b) { return a - b; @@ -477,7 +477,7 @@ function filterBetween(timestamps, min, max) { : timestamps; } -var defaultConfig = { +const defaultConfig = { position: 'bottom', /** @@ -526,29 +526,31 @@ var defaultConfig = { } }; -module.exports = Scale.extend({ - _parse: function(raw, index) { // eslint-disable-line no-unused-vars +class TimeScale extends Scale { + _parse(raw, index) { // eslint-disable-line no-unused-vars if (raw === undefined) { return NaN; } return parse(this, raw); - }, + } - _parseObject: function(obj, axis, index) { + _parseObject(obj, axis, index) { if (obj && obj.t) { return this._parse(obj.t, index); } if (obj[axis] !== undefined) { return this._parse(obj[axis], index); } return null; - }, + } - _invalidateCaches: function() { + _invalidateCaches() { this._cache = {}; - }, + } + + constructor(props) { + super(props); - initialize: function() { var me = this; var options = me.options; var time = options.time || (options.time = {}); @@ -563,11 +565,9 @@ module.exports = Scale.extend({ // missing formats on update helpers.mergeIf(time.displayFormats, adapter.formats()); + } - Scale.prototype.initialize.call(me); - }, - - determineDataLimits: function() { + determineDataLimits() { var me = this; var options = me.options; var adapter = me._adapter; @@ -601,9 +601,9 @@ module.exports = Scale.extend({ // Make sure that max is strictly higher than min (required by the lookup table) me.min = Math.min(min, max); me.max = Math.max(min + 1, max); - }, + } - buildTicks: function() { + buildTicks() { var me = this; var options = me.options; var timeOpts = options.time; @@ -640,9 +640,9 @@ module.exports = Scale.extend({ } return ticksFromTimestamps(me, ticks, me._majorUnit); - }, + } - getLabelForValue: function(value) { + getLabelForValue(value) { var me = this; var adapter = me._adapter; var timeOpts = me.options.time; @@ -651,13 +651,13 @@ module.exports = Scale.extend({ return adapter.format(value, timeOpts.tooltipFormat); } return adapter.format(value, timeOpts.displayFormats.datetime); - }, + } /** * Function to format an individual tick mark * @private */ - _tickFormatFunction: function(time, index, ticks, format) { + _tickFormatFunction(time, index, ticks, format) { var me = this; var adapter = me._adapter; var options = me.options; @@ -676,28 +676,28 @@ module.exports = Scale.extend({ ]); return formatter ? formatter(label, index, ticks) : label; - }, + } - generateTickLabels: function(ticks) { + generateTickLabels(ticks) { var i, ilen, tick; for (i = 0, ilen = ticks.length; i < ilen; ++i) { tick = ticks[i]; tick.label = this._tickFormatFunction(tick.value, i, ticks); } - }, + } /** * @private */ - _getPixelForOffset: function(time) { + _getPixelForOffset(time) { var me = this; var offsets = me._offsets; var pos = interpolate(me._table, 'time', time, 'pos'); return me.getPixelForDecimal((offsets.start + pos) * offsets.factor); - }, + } - getPixelForValue: function(value) { + getPixelForValue(value) { var me = this; if (typeof value !== 'number') { @@ -707,26 +707,26 @@ module.exports = Scale.extend({ if (value !== null) { return me._getPixelForOffset(value); } - }, + } - getPixelForTick: function(index) { + getPixelForTick(index) { var ticks = this.getTicks(); return index >= 0 && index < ticks.length ? this._getPixelForOffset(ticks[index].value) : null; - }, + } - getValueForPixel: function(pixel) { + getValueForPixel(pixel) { var me = this; var offsets = me._offsets; var pos = me.getDecimalForPixel(pixel) / offsets.factor - offsets.end; return interpolate(me._table, 'pos', pos, 'time'); - }, + } /** * @private */ - _getLabelSize: function(label) { + _getLabelSize(label) { var me = this; var ticksOpts = me.options.ticks; var tickLabelWidth = me.ctx.measureText(label).width; @@ -739,12 +739,12 @@ module.exports = Scale.extend({ w: (tickLabelWidth * cosRotation) + (tickFontSize * sinRotation), h: (tickLabelWidth * sinRotation) + (tickFontSize * cosRotation) }; - }, + } /** * @private */ - _getLabelCapacity: function(exampleTime) { + _getLabelCapacity(exampleTime) { var me = this; var timeOpts = me.options.time; var displayFormats = timeOpts.displayFormats; @@ -761,7 +761,8 @@ module.exports = Scale.extend({ return capacity > 0 ? capacity : 1; } -}); +} +module.exports = TimeScale; // INTERNAL: static default options, registered in src/index.js module.exports._defaults = defaultConfig;
true
Other
chartjs
Chart.js
8f0de52c4e446b33c4dbcf0e738f67eabdd43f6d.json
Remove moment from dependencies (#6745) * Remove moment from dependencies * Remove version number in docs
docs/axes/cartesian/time.md
@@ -4,7 +4,7 @@ The time scale is used to display times and dates. When building its ticks, it w ## Date Adapters -The time scale requires both a date library and corresponding adapter to be present. By default, Chart.js includes an adapter for Moment.js. You may wish to [exclude moment](../../getting-started/integration.md) and choose from [other available adapters](https://github.com/chartjs/awesome#adapters) instead. +The time scale requires both a date library and corresponding adapter to be present. By default, Chart.js includes an adapter for Moment.js. You may wish to choose from [other available adapters](https://github.com/chartjs/awesome#adapters) instead. ## Data Sets
true
Other
chartjs
Chart.js
8f0de52c4e446b33c4dbcf0e738f67eabdd43f6d.json
Remove moment from dependencies (#6745) * Remove moment from dependencies * Remove version number in docs
docs/getting-started/integration.md
@@ -25,26 +25,6 @@ import Chart from 'chart.js'; var myChart = new Chart(ctx, {...}); ``` -**Note:** Moment.js is installed along Chart.js as dependency. If you don't want to use Moment.js (either because you use a different date adapter or simply because don't need time functionalities), you will have to configure your bundler to exclude this dependency (e.g. using [`externals` for Webpack](https://webpack.js.org/configuration/externals/) or [`external` for Rollup](https://rollupjs.org/guide/en#peer-dependencies)). - -```javascript -// Webpack -{ - externals: { - moment: 'moment' - } -} -``` - -```javascript -// Rollup -{ - external: { - ['moment'] - } -} -``` - ## Require JS **Important:** RequireJS [can **not** load CommonJS module as is](https://requirejs.org/docs/commonjs.html#intro), so be sure to require one of the UMD builds instead (i.e. `dist/Chart.js`, `dist/Chart.min.js`, etc.). @@ -55,7 +35,7 @@ require(['path/to/chartjs/dist/Chart.min.js'], function(Chart){ }); ``` -**Note:** starting v2.8, Moment.js is an optional dependency for `Chart.js` and `Chart.min.js`. In order to use the time scale with Moment.js, you need to make sure Moment.js is fully loaded **before** requiring Chart.js. You can either use a shim: +**Note:** in order to use the time scale, you need to make sure [one of the available date adapters](https://github.com/chartjs/awesome#adapters) and corresponding date library are fully loaded **before** requiring Chart.js. The date adapter for Moment.js is included with Chart.js, but you still need to include Moment.js itself if this is the date adapter you choose to use. You can either use a shim: ```javascript require.config({
true
Other
chartjs
Chart.js
8f0de52c4e446b33c4dbcf0e738f67eabdd43f6d.json
Remove moment from dependencies (#6745) * Remove moment from dependencies * Remove version number in docs
docs/getting-started/v3-migration.md
@@ -2,11 +2,12 @@ Chart.js 3.0 introduces a number of breaking changes. Chart.js 2.0 was released in April 2016. In the years since then, as Chart.js has grown in popularity and feature set, we've learned some lessons about how to better create a charting library. In order to improve performance, offer new features, and improve maintainability it was necessary to break backwards compatibility, but we aimed to do so only when necessary. -## Setup +## End user migration -Chart.js is no longer providing the `Chart.bundle.js` and `Chart.bundle.min.js`. Please see the [installation](installation.md) and [integration](integration.md) docs for details on the recommended way to setup Chart.js if you were using these builds. +### Setup and installation -## End user migration +* Chart.js is no longer providing the `Chart.bundle.js` and `Chart.bundle.min.js`. Please see the [installation](installation.md) and [integration](integration.md) docs for details on the recommended way to setup Chart.js if you were using these builds. +* `moment` is no longer specified as an npm dependency. If you are using the time scale, you must include one of [the available adapters](https://github.com/chartjs/awesome#adapters) and corresponding date library. If you are using a date library other than moment, you no longer need to exclude moment from your build. ### Ticks
true
Other
chartjs
Chart.js
8f0de52c4e446b33c4dbcf0e738f67eabdd43f6d.json
Remove moment from dependencies (#6745) * Remove moment from dependencies * Remove version number in docs
package-lock.json
@@ -6843,7 +6843,8 @@ "moment": { "version": "2.24.0", "resolved": "https://registry.npmjs.org/moment/-/moment-2.24.0.tgz", - "integrity": "sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg==" + "integrity": "sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg==", + "dev": true }, "ms": { "version": "2.1.2",
true
Other
chartjs
Chart.js
8f0de52c4e446b33c4dbcf0e738f67eabdd43f6d.json
Remove moment from dependencies (#6745) * Remove moment from dependencies * Remove version number in docs
package.json
@@ -61,6 +61,7 @@ "karma-rollup-preprocessor": "^7.0.0", "karma-safari-private-launcher": "^1.0.0", "merge-stream": "^1.0.1", + "moment": "^2.10.2", "pixelmatch": "^5.0.0", "rollup": "^1.0.0", "rollup-plugin-babel": "^4.3.3", @@ -71,7 +72,6 @@ "yargs": "^14.0.0" }, "dependencies": { - "chartjs-color": "^2.1.0", - "moment": "^2.10.2" + "chartjs-color": "^2.1.0" } }
true
Other
chartjs
Chart.js
fef2a13ef6f89e09d78b77930faa9d1208b978d2.json
Update time combo sample (#6736)
samples/scales/time/combo.html
@@ -27,68 +27,45 @@ <button id="addData">Add Data</button> <button id="removeData">Remove Data</button> <script> - var timeFormat = 'MM/DD/YYYY HH:mm'; + function newDate(days) { + return moment().startOf('day').add(days, 'd').valueOf(); + } - function newDateString(days) { - return moment().add(days, 'd').format(timeFormat); + var labels = []; + var data1 = []; + var data2 = []; + var data3 = []; + for (var i = 0; i < 7; i++) { + labels.push(newDate(i)); + data1.push(randomScalingFactor()); + data2.push(randomScalingFactor()); + data3.push(randomScalingFactor()); } var color = Chart.helpers.color; var config = { type: 'bar', data: { - labels: [ - newDateString(0), - newDateString(1), - newDateString(2), - newDateString(3), - newDateString(4), - newDateString(5), - newDateString(6) - ], + labels: labels, datasets: [{ type: 'bar', label: 'Dataset 1', backgroundColor: color(window.chartColors.red).alpha(0.5).rgbString(), borderColor: window.chartColors.red, - data: [ - randomScalingFactor(), - randomScalingFactor(), - randomScalingFactor(), - randomScalingFactor(), - randomScalingFactor(), - randomScalingFactor(), - randomScalingFactor() - ], + data: data1, }, { type: 'bar', label: 'Dataset 2', backgroundColor: color(window.chartColors.blue).alpha(0.5).rgbString(), borderColor: window.chartColors.blue, - data: [ - randomScalingFactor(), - randomScalingFactor(), - randomScalingFactor(), - randomScalingFactor(), - randomScalingFactor(), - randomScalingFactor(), - randomScalingFactor() - ], + data: data2, }, { type: 'line', label: 'Dataset 3', backgroundColor: color(window.chartColors.green).alpha(0.5).rgbString(), borderColor: window.chartColors.green, fill: false, - data: [ - randomScalingFactor(), - randomScalingFactor(), - randomScalingFactor(), - randomScalingFactor(), - randomScalingFactor(), - randomScalingFactor(), - randomScalingFactor() - ], + data: data3, }] }, options: { @@ -99,9 +76,9 @@ xAxes: [{ type: 'time', display: true, + offset: true, time: { - format: timeFormat, - // round: 'day' + unit: 'day' } }], }, @@ -145,7 +122,7 @@ document.getElementById('addData').addEventListener('click', function() { if (config.data.datasets.length > 0) { - config.data.labels.push(newDateString(config.data.labels.length)); + config.data.labels.push(newDate(config.data.labels.length)); for (var index = 0; index < config.data.datasets.length; ++index) { config.data.datasets[index].data.push(randomScalingFactor());
false
Other
chartjs
Chart.js
91466ae358b9adec11e26e5d5e5149a73f1fcb44.json
Remove remaingin zeroLine* references (#6728)
samples/charts/scatter/multi-axis.html
@@ -97,9 +97,6 @@ scales: { xAxes: [{ position: 'bottom', - gridLines: { - zeroLineColor: 'rgba(0,0,0,1)' - } }], yAxes: [{ type: 'linear', // only linear but allow scale type registration. This allows extensions to exist solely for log scale for instance
true
Other
chartjs
Chart.js
91466ae358b9adec11e26e5d5e5149a73f1fcb44.json
Remove remaingin zeroLine* references (#6728)
test/fixtures/core.scale/tick-drawing.json
@@ -46,8 +46,7 @@ "gridLines":{ "drawOnChartArea": false, "drawBorder": false, - "color": "rgba(0, 0, 0, 1)", - "zeroLineColor": "rgba(0, 0, 0, 1)" + "color": "rgba(0, 0, 0, 1)" } }, { "type": "linear", @@ -61,8 +60,7 @@ "gridLines":{ "drawOnChartArea": false, "drawBorder": false, - "color": "rgba(0, 0, 0, 1)", - "zeroLineColor": "rgba(0, 0, 0, 1)" + "color": "rgba(0, 0, 0, 1)" } }] }
true
Other
chartjs
Chart.js
a3392e0e59ae77a9c081b4c14de2c95a35422e18.json
Remove index and datasetIndex from Element (#6688) Remove `index` and `datasetIndex` properties from elements.
docs/getting-started/v3-migration.md
@@ -106,3 +106,17 @@ Chart.js is no longer providing the `Chart.bundle.js` and `Chart.bundle.min.js`. ##### Time Scale * `getValueForPixel` now returns milliseconds since the epoch + +#### Controllers + +##### Core Controller + +* The first parameter to `updateHoverStyle` is now an array of objects containing the `element`, `datasetIndex`, and `index` + +##### Dataset Controllers + +* `setHoverStyle` now additionally takes the `datasetIndex` and `index` + +#### Interactions + +* Interaction mode methods now return an array of objects containing the `element`, `datasetIndex`, and `index`
true
Other
chartjs
Chart.js
a3392e0e59ae77a9c081b4c14de2c95a35422e18.json
Remove index and datasetIndex from Element (#6688) Remove `index` and `datasetIndex` properties from elements.
src/controllers/controller.bar.js
@@ -240,8 +240,6 @@ module.exports = DatasetController.extend({ var me = this; var options = me._resolveDataElementOptions(index); - rectangle._datasetIndex = me.index; - rectangle._index = index; rectangle._model = { backgroundColor: options.backgroundColor, borderColor: options.borderColor,
true
Other
chartjs
Chart.js
a3392e0e59ae77a9c081b4c14de2c95a35422e18.json
Remove index and datasetIndex from Element (#6688) Remove `index` and `datasetIndex` properties from elements.
src/controllers/controller.bubble.js
@@ -107,8 +107,6 @@ module.exports = DatasetController.extend({ var y = reset ? yScale.getBasePixel() : yScale.getPixelForValue(parsed[yScale.id]); point._options = options; - point._datasetIndex = me.index; - point._index = index; point._model = { backgroundColor: options.backgroundColor, borderColor: options.borderColor,
true
Other
chartjs
Chart.js
a3392e0e59ae77a9c081b4c14de2c95a35422e18.json
Remove index and datasetIndex from Element (#6688) Remove `index` and `datasetIndex` properties from elements.
src/controllers/controller.doughnut.js
@@ -238,10 +238,6 @@ module.exports = DatasetController.extend({ var options = arc._options || {}; helpers.extend(arc, { - // Utility - _datasetIndex: me.index, - _index: index, - // Desired view properties _model: { backgroundColor: options.backgroundColor,
true
Other
chartjs
Chart.js
a3392e0e59ae77a9c081b4c14de2c95a35422e18.json
Remove index and datasetIndex from Element (#6688) Remove `index` and `datasetIndex` properties from elements.
src/controllers/controller.line.js
@@ -82,8 +82,6 @@ module.exports = DatasetController.extend({ // Update Line if (showLine) { - // Utility - line._datasetIndex = me.index; // Data line._children = points; // Model @@ -110,7 +108,6 @@ module.exports = DatasetController.extend({ updateElement: function(point, index, reset) { var me = this; var meta = me.getMeta(); - var datasetIndex = me.index; var xScale = me._xScale; var yScale = me._yScale; var lineModel = meta.dataset._model; @@ -122,8 +119,6 @@ module.exports = DatasetController.extend({ // Utility point._options = options; - point._datasetIndex = datasetIndex; - point._index = index; // Desired view properties point._model = {
true
Other
chartjs
Chart.js
a3392e0e59ae77a9c081b4c14de2c95a35422e18.json
Remove index and datasetIndex from Element (#6688) Remove `index` and `datasetIndex` properties from elements.
src/controllers/controller.polarArea.js
@@ -201,10 +201,6 @@ module.exports = DatasetController.extend({ var options = arc._options || {}; helpers.extend(arc, { - // Utility - _datasetIndex: me.index, - _index: index, - // Desired view properties _model: { backgroundColor: options.backgroundColor,
true
Other
chartjs
Chart.js
a3392e0e59ae77a9c081b4c14de2c95a35422e18.json
Remove index and datasetIndex from Element (#6688) Remove `index` and `datasetIndex` properties from elements.
src/controllers/controller.radar.js
@@ -83,8 +83,6 @@ module.exports = DatasetController.extend({ config.lineTension = config.tension; } - // Utility - line._datasetIndex = me.index; // Data line._children = points; line._loop = true; @@ -119,8 +117,6 @@ module.exports = DatasetController.extend({ // Utility point._options = options; - point._datasetIndex = me.index; - point._index = index; // Desired view properties point._model = {
true
Other
chartjs
Chart.js
a3392e0e59ae77a9c081b4c14de2c95a35422e18.json
Remove index and datasetIndex from Element (#6688) Remove `index` and `datasetIndex` properties from elements.
src/core/core.controller.js
@@ -980,19 +980,24 @@ helpers.extend(Chart.prototype, /** @lends Chart */ { }); }, - updateHoverStyle: function(elements, mode, enabled) { + updateHoverStyle: function(items, mode, enabled) { var prefix = enabled ? 'set' : 'remove'; - var element, i, ilen; + var meta, item, i, ilen; - for (i = 0, ilen = elements.length; i < ilen; ++i) { - element = elements[i]; - if (element) { - this.getDatasetMeta(element._datasetIndex).controller[prefix + 'HoverStyle'](element); + if (mode === 'dataset') { + meta = this.getDatasetMeta(items[0].datasetIndex); + meta.controller['_' + prefix + 'DatasetHoverStyle'](); + for (i = 0, ilen = meta.data.length; i < ilen; ++i) { + meta.controller[prefix + 'HoverStyle'](meta.data[i], items[0].datasetIndex, i); } + return; } - if (mode === 'dataset') { - this.getDatasetMeta(elements[0]._datasetIndex).controller['_' + prefix + 'DatasetHoverStyle'](); + for (i = 0, ilen = items.length; i < ilen; ++i) { + item = items[i]; + if (item) { + this.getDatasetMeta(item.datasetIndex).controller[prefix + 'HoverStyle'](item.element, item.datasetIndex, item.index); + } } }, @@ -1100,7 +1105,7 @@ helpers.extend(Chart.prototype, /** @lends Chart */ { } me._updateHoverStyles(); - changed = !helpers.arrayEquals(me.active, me.lastActive); + changed = !helpers._elementsEqual(me.active, me.lastActive); // Remember Last Actives me.lastActive = me.active;
true
Other
chartjs
Chart.js
a3392e0e59ae77a9c081b4c14de2c95a35422e18.json
Remove index and datasetIndex from Element (#6688) Remove `index` and `datasetIndex` properties from elements.
src/core/core.datasetController.js
@@ -793,9 +793,8 @@ helpers.extend(DatasetController.prototype, { delete element.$previousStyle; }, - setHoverStyle: function(element) { - var dataset = this.chart.data.datasets[element._datasetIndex]; - var index = element._index; + setHoverStyle: function(element, datasetIndex, index) { + var dataset = this.chart.data.datasets[datasetIndex]; var model = element._model; var getHoverColor = helpers.getHoverColor;
true
Other
chartjs
Chart.js
a3392e0e59ae77a9c081b4c14de2c95a35422e18.json
Remove index and datasetIndex from Element (#6688) Remove `index` and `datasetIndex` properties from elements.
src/core/core.element.js
@@ -56,12 +56,13 @@ class Element { constructor(configuration) { helpers.extend(this, configuration); + + // this.hidden = false; we assume Element has an attribute called hidden, but do not initialize to save memory + this.initialize.apply(this, arguments); } - initialize() { - this.hidden = false; - } + initialize() {} pivot(animationsDisabled) { var me = this;
true
Other
chartjs
Chart.js
a3392e0e59ae77a9c081b4c14de2c95a35422e18.json
Remove index and datasetIndex from Element (#6688) Remove `index` and `datasetIndex` properties from elements.
src/core/core.interaction.js
@@ -33,7 +33,7 @@ function parseVisibleItems(chart, handler) { for (j = 0, jlen = metadata.length; j < jlen; ++j) { element = metadata[j]; if (!element._view.skip) { - handler(element); + handler(element, i, j); } } } @@ -48,9 +48,9 @@ function parseVisibleItems(chart, handler) { function getIntersectItems(chart, position) { var elements = []; - parseVisibleItems(chart, function(element) { + parseVisibleItems(chart, function(element, datasetIndex, index) { if (element.inRange(position.x, position.y)) { - elements.push(element); + elements.push({element, datasetIndex, index}); } }); @@ -69,19 +69,19 @@ function getNearestItems(chart, position, intersect, distanceMetric) { var minDistance = Number.POSITIVE_INFINITY; var nearestItems = []; - parseVisibleItems(chart, function(element) { + parseVisibleItems(chart, function(element, datasetIndex, index) { if (intersect && !element.inRange(position.x, position.y)) { return; } var center = element.getCenterPoint(); var distance = distanceMetric(position, center); if (distance < minDistance) { - nearestItems = [element]; + nearestItems = [{element, datasetIndex, index}]; minDistance = distance; } else if (distance === minDistance) { // Can have multiple items at the same distance in which case we sort by size - nearestItems.push(element); + nearestItems.push({element, datasetIndex, index}); } }); @@ -117,11 +117,12 @@ function indexMode(chart, e, options) { } chart._getSortedVisibleDatasetMetas().forEach(function(meta) { - var element = meta.data[items[0]._index]; + var index = items[0].index; + var element = meta.data[index]; // don't count items that are skipped (null data) if (element && !element._view.skip) { - elements.push(element); + elements.push({element, datasetIndex: meta.index, index}); } }); @@ -152,7 +153,7 @@ module.exports = { * @param {Chart} chart - the chart we are returning items from * @param {Event} e - the event we are find things at * @param {IInteractionOptions} options - options to use during interaction - * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned + * @return {Object[]} Array of elements that are under the point. If none are found, an empty array is returned */ index: indexMode, @@ -163,7 +164,7 @@ module.exports = { * @param {Chart} chart - the chart we are returning items from * @param {Event} e - the event we are find things at * @param {IInteractionOptions} options - options to use during interaction - * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned + * @return {Object[]} Array of elements that are under the point. If none are found, an empty array is returned */ dataset: function(chart, e, options) { var position = getRelativePosition(e, chart); @@ -172,7 +173,7 @@ module.exports = { var items = options.intersect ? getIntersectItems(chart, position) : getNearestItems(chart, position, false, distanceMetric); if (items.length > 0) { - items = chart.getDatasetMeta(items[0]._datasetIndex).data; + items = [{datasetIndex: items[0].datasetIndex}]; // when mode: 'dataset' we only need to return datasetIndex } return items; @@ -184,7 +185,7 @@ module.exports = { * @function Chart.Interaction.modes.intersect * @param {Chart} chart - the chart we are returning items from * @param {Event} e - the event we are find things at - * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned + * @return {Object[]} Array of elements that are under the point. If none are found, an empty array is returned */ point: function(chart, e) { var position = getRelativePosition(e, chart); @@ -197,7 +198,7 @@ module.exports = { * @param {Chart} chart - the chart we are returning items from * @param {Event} e - the event we are find things at * @param {IInteractionOptions} options - options to use - * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned + * @return {Object[]} Array of elements that are under the point. If none are found, an empty array is returned */ nearest: function(chart, e, options) { var position = getRelativePosition(e, chart); @@ -212,16 +213,16 @@ module.exports = { * @param {Chart} chart - the chart we are returning items from * @param {Event} e - the event we are find things at * @param {IInteractionOptions} options - options to use - * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned + * @return {Object[]} Array of elements that are under the point. If none are found, an empty array is returned */ x: function(chart, e, options) { var position = getRelativePosition(e, chart); var items = []; var intersectsItem = false; - parseVisibleItems(chart, function(element) { + parseVisibleItems(chart, function(element, datasetIndex, index) { if (element.inXRange(position.x)) { - items.push(element); + items.push({element, datasetIndex, index}); } if (element.inRange(position.x, position.y)) { @@ -243,16 +244,16 @@ module.exports = { * @param {Chart} chart - the chart we are returning items from * @param {Event} e - the event we are find things at * @param {IInteractionOptions} options - options to use - * @return {Chart.Element[]} Array of elements that are under the point. If none are found, an empty array is returned + * @return {Object[]} Array of elements that are under the point. If none are found, an empty array is returned */ y: function(chart, e, options) { var position = getRelativePosition(e, chart); var items = []; var intersectsItem = false; - parseVisibleItems(chart, function(element) { + parseVisibleItems(chart, function(element, datasetIndex, index) { if (element.inYRange(position.y)) { - items.push(element); + items.push({element, datasetIndex, index}); } if (element.inRange(position.x, position.y)) {
true
Other
chartjs
Chart.js
a3392e0e59ae77a9c081b4c14de2c95a35422e18.json
Remove index and datasetIndex from Element (#6688) Remove `index` and `datasetIndex` properties from elements.
src/core/core.tooltip.js
@@ -117,7 +117,7 @@ var positioners = { var count = 0; for (i = 0, len = elements.length; i < len; ++i) { - var el = elements[i]; + var el = elements[i].element; if (el && el.hasValue()) { var pos = el.tooltipPosition(); x += pos.x; @@ -146,7 +146,7 @@ var positioners = { var i, len, nearestElement; for (i = 0, len = elements.length; i < len; ++i) { - var el = elements[i]; + var el = elements[i].element; if (el && el.hasValue()) { var center = el.getCenterPoint(); var d = helpers.distanceBetweenPoints(eventPosition, center); @@ -201,16 +201,15 @@ function splitNewlines(str) { /** * Private helper to create a tooltip item model - * @param element - the chart element (point, arc, bar) to create the tooltip item for + * @param item - the chart element (point, arc, bar) to create the tooltip item for * @return new tooltip item */ -function createTooltipItem(chart, element) { - var datasetIndex = element._datasetIndex; - var index = element._index; - var controller = chart.getDatasetMeta(datasetIndex).controller; - var indexScale = controller._getIndexScale(); - var valueScale = controller._getValueScale(); - var parsed = controller._getParsed(index); +function createTooltipItem(chart, item) { + const {datasetIndex, element, index} = item; + const controller = chart.getDatasetMeta(datasetIndex).controller; + const indexScale = controller._getIndexScale(); + const valueScale = controller._getValueScale(); + const parsed = controller._getParsed(index); return { label: indexScale ? '' + indexScale.getLabelForValue(parsed[indexScale.id]) : '', @@ -1016,7 +1015,7 @@ class Tooltip extends Element { } // Remember Last Actives - changed = !helpers.arrayEquals(me._active, me._lastActive); + changed = !helpers._elementsEqual(me._active, me._lastActive); // Only handle target event on tooltip change if (changed) {
true
Other
chartjs
Chart.js
a3392e0e59ae77a9c081b4c14de2c95a35422e18.json
Remove index and datasetIndex from Element (#6688) Remove `index` and `datasetIndex` properties from elements.
src/helpers/helpers.core.js
@@ -164,6 +164,31 @@ var helpers = { return true; }, + /** + * Returns true if the `a0` and `a1` arrays have the same content, else returns false. + * @param {Array} a0 - The array to compare + * @param {Array} a1 - The array to compare + * @returns {boolean} + */ + _elementsEqual: function(a0, a1) { + let i, ilen, v0, v1; + + if (!a0 || !a1 || a0.length !== a1.length) { + return false; + } + + for (i = 0, ilen = a0.length; i < ilen; ++i) { + v0 = a0[i]; + v1 = a1[i]; + + if (v0.datasetIndex !== v1.datasetIndex || v0.index !== v1.index) { + return false; + } + } + + return true; + }, + /** * Returns a deep copy of `source` without keeping references on objects and arrays. * @param {*} source - The value to clone.
true
Other
chartjs
Chart.js
a3392e0e59ae77a9c081b4c14de2c95a35422e18.json
Remove index and datasetIndex from Element (#6688) Remove `index` and `datasetIndex` properties from elements.
test/specs/controller.bar.tests.js
@@ -1379,7 +1379,7 @@ describe('Chart.controllers.bar', function() { var meta = chart.getDatasetMeta(1); var bar = meta.data[0]; - meta.controller.setHoverStyle(bar); + meta.controller.setHoverStyle(bar, 1, 0); expect(bar._model.backgroundColor).toBe('rgb(230, 0, 0)'); expect(bar._model.borderColor).toBe('rgb(0, 0, 230)'); expect(bar._model.borderWidth).toBe(2); @@ -1389,7 +1389,7 @@ describe('Chart.controllers.bar', function() { chart.data.datasets[1].hoverBorderColor = 'rgb(0, 0, 0)'; chart.data.datasets[1].hoverBorderWidth = 5; - meta.controller.setHoverStyle(bar); + meta.controller.setHoverStyle(bar, 1, 0); expect(bar._model.backgroundColor).toBe('rgb(128, 128, 128)'); expect(bar._model.borderColor).toBe('rgb(0, 0, 0)'); expect(bar._model.borderWidth).toBe(5); @@ -1399,7 +1399,7 @@ describe('Chart.controllers.bar', function() { chart.data.datasets[1].hoverBorderColor = ['rgb(9, 9, 9)', 'rgb(0, 0, 0)']; chart.data.datasets[1].hoverBorderWidth = [2.5, 5]; - meta.controller.setHoverStyle(bar); + meta.controller.setHoverStyle(bar, 1, 0); expect(bar._model.backgroundColor).toBe('rgb(255, 255, 255)'); expect(bar._model.borderColor).toBe('rgb(9, 9, 9)'); expect(bar._model.borderWidth).toBe(2.5); @@ -1441,7 +1441,7 @@ describe('Chart.controllers.bar', function() { expect(bar._model.backgroundColor).toBe('rgb(128, 128, 128)'); expect(bar._model.borderColor).toBe('rgb(15, 15, 15)'); expect(bar._model.borderWidth).toBe(3.14); - meta.controller.setHoverStyle(bar); + meta.controller.setHoverStyle(bar, 1, 0); expect(bar._model.backgroundColor).toBe(helpers.getHoverColor('rgb(128, 128, 128)')); expect(bar._model.borderColor).toBe(helpers.getHoverColor('rgb(15, 15, 15)')); expect(bar._model.borderWidth).toBe(3.14); @@ -1459,7 +1459,7 @@ describe('Chart.controllers.bar', function() { expect(bar._model.backgroundColor).toBe('rgb(255, 255, 255)'); expect(bar._model.borderColor).toBe('rgb(9, 9, 9)'); expect(bar._model.borderWidth).toBe(2.5); - meta.controller.setHoverStyle(bar); + meta.controller.setHoverStyle(bar, 1, 0); expect(bar._model.backgroundColor).toBe(helpers.getHoverColor('rgb(255, 255, 255)')); expect(bar._model.borderColor).toBe(helpers.getHoverColor('rgb(9, 9, 9)')); expect(bar._model.borderWidth).toBe(2.5);
true
Other
chartjs
Chart.js
a3392e0e59ae77a9c081b4c14de2c95a35422e18.json
Remove index and datasetIndex from Element (#6688) Remove `index` and `datasetIndex` properties from elements.
test/specs/core.controller.tests.js
@@ -1168,13 +1168,13 @@ describe('Chart', function() { // Check and see if tooltip was displayed var tooltip = chart.tooltip; - expect(chart.lastActive).toEqual([point]); - expect(tooltip._lastActive).toEqual([point]); + expect(chart.lastActive[0].element).toEqual(point); + expect(tooltip._lastActive[0].element).toEqual(point); // Update and confirm tooltip is updated chart.update(); - expect(chart.lastActive).toEqual([point]); - expect(tooltip._lastActive).toEqual([point]); + expect(chart.lastActive[0].element).toEqual(point); + expect(tooltip._lastActive[0].element).toEqual(point); }); it ('should update the metadata', function() {
true
Other
chartjs
Chart.js
a3392e0e59ae77a9c081b4c14de2c95a35422e18.json
Remove index and datasetIndex from Element (#6688) Remove `index` and `datasetIndex` properties from elements.
test/specs/core.interaction.tests.js
@@ -37,7 +37,7 @@ describe('Core.Interaction', function() { y: point._model.y, }; - var elements = Chart.Interaction.modes.point(chart, evt); + var elements = Chart.Interaction.modes.point(chart, evt).map(item => item.element); expect(elements).toEqual([point, meta1.data[1]]); }); @@ -51,7 +51,7 @@ describe('Core.Interaction', function() { y: 0 }; - var elements = Chart.Interaction.modes.point(chart, evt); + var elements = Chart.Interaction.modes.point(chart, evt).map(item => item.element); expect(elements).toEqual([]); }); }); @@ -92,7 +92,7 @@ describe('Core.Interaction', function() { y: point._model.y, }; - var elements = Chart.Interaction.modes.index(chart, evt, {intersect: true}); + var elements = Chart.Interaction.modes.index(chart, evt, {intersect: true}).map(item => item.element); expect(elements).toEqual([point, meta1.data[1]]); }); @@ -106,7 +106,7 @@ describe('Core.Interaction', function() { y: 0, }; - var elements = Chart.Interaction.modes.index(chart, evt, {intersect: true}); + var elements = Chart.Interaction.modes.index(chart, evt, {intersect: true}).map(item => item.element); expect(elements).toEqual([]); }); }); @@ -147,7 +147,7 @@ describe('Core.Interaction', function() { y: 0 }; - var elements = Chart.Interaction.modes.index(chart, evt, {intersect: false}); + var elements = Chart.Interaction.modes.index(chart, evt, {intersect: false}).map(item => item.element); expect(elements).toEqual([meta0.data[0], meta1.data[0]]); }); @@ -169,7 +169,7 @@ describe('Core.Interaction', function() { y: center.y + 30, }; - var elements = Chart.Interaction.modes.index(chart, evt, {axis: 'y', intersect: false}); + var elements = Chart.Interaction.modes.index(chart, evt, {axis: 'y', intersect: false}).map(item => item.element); expect(elements).toEqual([meta0.data[0], meta1.data[0]]); }); @@ -186,7 +186,7 @@ describe('Core.Interaction', function() { y: 0 }; - var elements = Chart.Interaction.modes.index(chart, evt, {axis: 'xy', intersect: false}); + var elements = Chart.Interaction.modes.index(chart, evt, {axis: 'xy', intersect: false}).map(item => item.element); expect(elements).toEqual([meta0.data[0], meta1.data[0]]); }); }); @@ -228,7 +228,7 @@ describe('Core.Interaction', function() { }; var elements = Chart.Interaction.modes.dataset(chart, evt, {intersect: true}); - expect(elements).toEqual(meta.data); + expect(elements).toEqual([{datasetIndex: 0}]); }); it ('should return an empty array if nothing found', function() { @@ -284,9 +284,7 @@ describe('Core.Interaction', function() { }; var elements = Chart.Interaction.modes.dataset(chart, evt, {axis: 'x', intersect: false}); - - var meta = chart.getDatasetMeta(0); - expect(elements).toEqual(meta.data); + expect(elements).toEqual([{datasetIndex: 0}]); }); it ('axis: y gets correct items', function() { @@ -300,9 +298,7 @@ describe('Core.Interaction', function() { }; var elements = Chart.Interaction.modes.dataset(chart, evt, {axis: 'y', intersect: false}); - - var meta = chart.getDatasetMeta(1); - expect(elements).toEqual(meta.data); + expect(elements).toEqual([{datasetIndex: 1}]); }); it ('axis: xy gets correct items', function() { @@ -316,9 +312,7 @@ describe('Core.Interaction', function() { }; var elements = Chart.Interaction.modes.dataset(chart, evt, {intersect: false}); - - var meta = chart.getDatasetMeta(1); - expect(elements).toEqual(meta.data); + expect(elements).toEqual([{datasetIndex: 1}]); }); }); }); @@ -359,7 +353,7 @@ describe('Core.Interaction', function() { }; // Nearest to 0,0 (top left) will be first point of dataset 2 - var elements = Chart.Interaction.modes.nearest(chart, evt, {intersect: false}); + var elements = Chart.Interaction.modes.nearest(chart, evt, {intersect: false}).map(item => item.element); var meta = chart.getDatasetMeta(1); expect(elements).toEqual([meta.data[0]]); }); @@ -384,7 +378,7 @@ describe('Core.Interaction', function() { }; // Both points are nearest - var elements = Chart.Interaction.modes.nearest(chart, evt, {intersect: false}); + var elements = Chart.Interaction.modes.nearest(chart, evt, {intersect: false}).map(item => item.element); expect(elements).toEqual([meta0.data[1], meta1.data[1]]); }); }); @@ -410,7 +404,7 @@ describe('Core.Interaction', function() { }; // Middle point from both series are nearest - var elements = Chart.Interaction.modes.nearest(chart, evt, {axis: 'x', intersect: false}); + var elements = Chart.Interaction.modes.nearest(chart, evt, {axis: 'x', intersect: false}).map(item => item.element); expect(elements).toEqual([meta0.data[1], meta1.data[1]]); }); @@ -434,7 +428,7 @@ describe('Core.Interaction', function() { }; // Should return all (4) points from 'Point 1' and 'Point 2' - var elements = Chart.Interaction.modes.nearest(chart, evt, {axis: 'x', intersect: false}); + var elements = Chart.Interaction.modes.nearest(chart, evt, {axis: 'x', intersect: false}).map(item => item.element); expect(elements).toEqual([meta0.data[0], meta0.data[1], meta1.data[0], meta1.data[1]]); }); }); @@ -459,7 +453,7 @@ describe('Core.Interaction', function() { }; // Middle point from both series are nearest - var elements = Chart.Interaction.modes.nearest(chart, evt, {axis: 'y', intersect: false}); + var elements = Chart.Interaction.modes.nearest(chart, evt, {axis: 'y', intersect: false}).map(item => item.element); expect(elements).toEqual([meta0.data[2]]); }); @@ -483,7 +477,7 @@ describe('Core.Interaction', function() { }; // Should return points with value 40 - var elements = Chart.Interaction.modes.nearest(chart, evt, {axis: 'y', intersect: false}); + var elements = Chart.Interaction.modes.nearest(chart, evt, {axis: 'y', intersect: false}).map(item => item.element); expect(elements).toEqual([meta0.data[1], meta1.data[0], meta1.data[1], meta1.data[2]]); }); }); @@ -525,7 +519,7 @@ describe('Core.Interaction', function() { }; // Nothing intersects so find nothing - var elements = Chart.Interaction.modes.nearest(chart, evt, {intersect: true}); + var elements = Chart.Interaction.modes.nearest(chart, evt, {intersect: true}).map(item => item.element); expect(elements).toEqual([]); evt = { @@ -535,7 +529,7 @@ describe('Core.Interaction', function() { x: point._view.x, y: point._view.y }; - elements = Chart.Interaction.modes.nearest(chart, evt, {intersect: true}); + elements = Chart.Interaction.modes.nearest(chart, evt, {intersect: true}).map(item => item.element); expect(elements).toEqual([point]); }); @@ -565,7 +559,7 @@ describe('Core.Interaction', function() { y: pt.y }; - var elements = Chart.Interaction.modes.nearest(chart, evt, {intersect: true}); + var elements = Chart.Interaction.modes.nearest(chart, evt, {intersect: true}).map(item => item.element); expect(elements).toEqual([meta0.data[1]]); }); @@ -595,7 +589,7 @@ describe('Core.Interaction', function() { y: pt.y }; - var elements = Chart.Interaction.modes.nearest(chart, evt, {intersect: true}); + var elements = Chart.Interaction.modes.nearest(chart, evt, {intersect: true}).map(item => item.element); expect(elements).toEqual([meta0.data[1], meta1.data[1]]); }); }); @@ -644,7 +638,7 @@ describe('Core.Interaction', function() { y: 0 }; - var elements = Chart.Interaction.modes.x(chart, evt, {intersect: false}); + var elements = Chart.Interaction.modes.x(chart, evt, {intersect: false}).map(item => item.element); expect(elements).toEqual([meta0.data[1], meta1.data[1]]); evt = { @@ -655,7 +649,7 @@ describe('Core.Interaction', function() { y: 0 }; - elements = Chart.Interaction.modes.x(chart, evt, {intersect: false}); + elements = Chart.Interaction.modes.x(chart, evt, {intersect: false}).map(item => item.element); expect(elements).toEqual([]); }); @@ -678,7 +672,7 @@ describe('Core.Interaction', function() { y: 0 }; - var elements = Chart.Interaction.modes.x(chart, evt, {intersect: true}); + var elements = Chart.Interaction.modes.x(chart, evt, {intersect: true}).map(item => item.element); expect(elements).toEqual([]); // we don't intersect anything evt = { @@ -689,7 +683,7 @@ describe('Core.Interaction', function() { y: pt.y }; - elements = Chart.Interaction.modes.x(chart, evt, {intersect: true}); + elements = Chart.Interaction.modes.x(chart, evt, {intersect: true}).map(item => item.element); expect(elements).toEqual([meta0.data[1], meta1.data[1]]); }); }); @@ -736,7 +730,7 @@ describe('Core.Interaction', function() { y: pt.y, }; - var elements = Chart.Interaction.modes.y(chart, evt, {intersect: false}); + var elements = Chart.Interaction.modes.y(chart, evt, {intersect: false}).map(item => item.element); expect(elements).toEqual([meta0.data[1], meta1.data[0], meta1.data[1], meta1.data[2]]); evt = { @@ -747,7 +741,7 @@ describe('Core.Interaction', function() { y: pt.y + 20, // out of range }; - elements = Chart.Interaction.modes.y(chart, evt, {intersect: false}); + elements = Chart.Interaction.modes.y(chart, evt, {intersect: false}).map(item => item.element); expect(elements).toEqual([]); }); @@ -770,7 +764,7 @@ describe('Core.Interaction', function() { y: pt.y }; - var elements = Chart.Interaction.modes.y(chart, evt, {intersect: true}); + var elements = Chart.Interaction.modes.y(chart, evt, {intersect: true}).map(item => item.element); expect(elements).toEqual([]); // we don't intersect anything evt = { @@ -781,7 +775,7 @@ describe('Core.Interaction', function() { y: pt.y, }; - elements = Chart.Interaction.modes.y(chart, evt, {intersect: true}); + elements = Chart.Interaction.modes.y(chart, evt, {intersect: true}).map(item => item.element); expect(elements).toEqual([meta0.data[1], meta1.data[0], meta1.data[1], meta1.data[2]]); }); });
true
Other
chartjs
Chart.js
a3392e0e59ae77a9c081b4c14de2c95a35422e18.json
Remove index and datasetIndex from Element (#6688) Remove `index` and `datasetIndex` properties from elements.
test/specs/global.defaults.tests.js
@@ -18,7 +18,7 @@ describe('Default Configs', function() { }); // fake out the tooltip hover and force the tooltip to update - chart.tooltip._active = [chart.getDatasetMeta(0).data[0]]; + chart.tooltip._active = [{element: chart.getDatasetMeta(0).data[0], datasetIndex: 0, index: 0}]; chart.tooltip.update(); // Title is always blank @@ -46,7 +46,7 @@ describe('Default Configs', function() { }); // fake out the tooltip hover and force the tooltip to update - chart.tooltip._active = [chart.getDatasetMeta(0).data[1]]; + chart.tooltip._active = [{element: chart.getDatasetMeta(0).data[1], datasetIndex: 0, index: 1}]; chart.tooltip.update(); // Title is always blank @@ -72,7 +72,7 @@ describe('Default Configs', function() { }); // fake out the tooltip hover and force the tooltip to update - chart.tooltip._active = [chart.getDatasetMeta(0).data[1]]; + chart.tooltip._active = [{element: chart.getDatasetMeta(0).data[1], datasetIndex: 0, index: 1}]; chart.tooltip.update(); // Title is always blank @@ -125,14 +125,14 @@ describe('Default Configs', function() { var expected = [{ text: 'label1', fillStyle: 'red', - hidden: false, + hidden: undefined, index: 0, strokeStyle: '#000', lineWidth: 2 }, { text: 'label2', fillStyle: 'green', - hidden: false, + hidden: undefined, index: 1, strokeStyle: '#000', lineWidth: 2 @@ -192,7 +192,7 @@ describe('Default Configs', function() { }); // fake out the tooltip hover and force the tooltip to update - chart.tooltip._active = [chart.getDatasetMeta(0).data[1]]; + chart.tooltip._active = [{element: chart.getDatasetMeta(0).data[1], datasetIndex: 0, index: 1}]; chart.tooltip.update(); // Title is always blank @@ -241,14 +241,14 @@ describe('Default Configs', function() { var expected = [{ text: 'label1', fillStyle: 'red', - hidden: false, + hidden: undefined, index: 0, strokeStyle: '#000', lineWidth: 2 }, { text: 'label2', fillStyle: 'green', - hidden: false, + hidden: undefined, index: 1, strokeStyle: '#000', lineWidth: 2
true
Other
chartjs
Chart.js
a3392e0e59ae77a9c081b4c14de2c95a35422e18.json
Remove index and datasetIndex from Element (#6688) Remove `index` and `datasetIndex` properties from elements.
test/specs/helpers.core.tests.js
@@ -264,6 +264,18 @@ describe('Chart.helpers.core', function() { }); }); + describe('_elementsEqual', function() { + it('should return true if arrays are the same', function() { + expect(helpers._elementsEqual( + [{datasetIndex: 0, index: 1}, {datasetIndex: 0, index: 2}], + [{datasetIndex: 0, index: 1}, {datasetIndex: 0, index: 2}])).toBeTruthy(); + }); + it('should return false if arrays are not the same', function() { + expect(helpers._elementsEqual([], [{datasetIndex: 0, index: 1}])).toBeFalsy(); + expect(helpers._elementsEqual([{datasetIndex: 0, index: 2}], [{datasetIndex: 0, index: 1}])).toBeFalsy(); + }); + }); + describe('clone', function() { it('should clone primitive values', function() { expect(helpers.clone()).toBe(undefined);
true
Other
chartjs
Chart.js
46aff21a3d5b8391c1f0204b6fe2a33c20de8cd0.json
Fix undefined variable (#6699)
src/core/core.scale.js
@@ -400,7 +400,7 @@ class Scale extends Element { */ _getLabels() { var data = this.chart.data; - return this.options.labels || (this.isHorizontal() ? data.xLabels : data.yLabels) || data.labels; + return this.options.labels || (this.isHorizontal() ? data.xLabels : data.yLabels) || data.labels || []; } // These methods are ordered by lifecyle. Utilities then follow.
false
Other
chartjs
Chart.js
fcf76c5edd244a8a0a35b862cbe0db472a2caa46.json
Fix sample paths and include all options (#6712)
samples/scales/axes-labels.html
@@ -3,8 +3,8 @@ <head> <title>Line Chart</title> - <script src="../../../dist/Chart.min.js"></script> - <script src="../../utils.js"></script> + <script src="../../dist/Chart.min.js"></script> + <script src="../utils.js"></script> <style> canvas{ -moz-user-select: none; @@ -80,14 +80,26 @@ display: true, scaleLabel: { display: true, - labelString: 'Month' + labelString: 'Month', + lineHeight: 1.2, + fontColor: '#911', + fontFamily: 'Comic Sans MS', + fontSize: 20, + fontStyle: 'bold', + padding: {top: 20, left: 0, right: 0, bottom: 0} } }], yAxes: [{ display: true, scaleLabel: { display: true, - labelString: 'Value' + labelString: 'Value', + lineHeight: 1.2, + fontColor: '#191', + fontFamily: 'Times', + fontSize: 20, + fontStyle: 'normal', + padding: {top: 30, left: 0, right: 0, bottom: 0} } }] }
false
Other
chartjs
Chart.js
4a8a7ee8247c7c69e7e5f0a9388cdeb07e4fc197.json
Use ES6 classes for elements (#6702) * Use ES6 classes for elements * Add additional elements
src/core/core.animation.js
@@ -1,16 +1,24 @@ 'use strict'; -var Element = require('./core.element'); +const Element = require('./core.element'); +const helpers = require('../helpers/index'); -var exports = Element.extend({ - chart: null, // the animation associated chart instance - currentStep: 0, // the current animation step - numSteps: 60, // default number of steps - easing: '', // the easing to use for this animation - render: null, // render function used by the animation service +class Animation extends Element { - onAnimationProgress: null, // user specified callback to fire on each step of the animation - onAnimationComplete: null, // user specified callback to fire when the animation finishes -}); + constructor(props) { + super({ + chart: null, // the animation associated chart instance + currentStep: 0, // the current animation step + numSteps: 60, // default number of steps + easing: '', // the easing to use for this animation + render: null, // render function used by the animation service -module.exports = exports; + onAnimationProgress: null, // user specified callback to fire on each step of the animation + onAnimationComplete: null, // user specified callback to fire when the animation finishes + }); + helpers.extend(this, props); + } + +} + +module.exports = Animation;
true
Other
chartjs
Chart.js
4a8a7ee8247c7c69e7e5f0a9388cdeb07e4fc197.json
Use ES6 classes for elements (#6702) * Use ES6 classes for elements * Add additional elements
src/core/core.element.js
@@ -1,7 +1,7 @@ 'use strict'; -var color = require('chartjs-color'); -var helpers = require('../helpers/index'); +const color = require('chartjs-color'); +const helpers = require('../helpers/index'); function interpolate(start, view, model, ease) { var keys = Object.keys(model); @@ -52,28 +52,27 @@ function interpolate(start, view, model, ease) { } } -var Element = function(configuration) { - helpers.extend(this, configuration); - this.initialize.apply(this, arguments); -}; +class Element { -helpers.extend(Element.prototype, { - _type: undefined, + constructor(configuration) { + helpers.extend(this, configuration); + this.initialize.apply(this, arguments); + } - initialize: function() { + initialize() { this.hidden = false; - }, + } - pivot: function() { + pivot() { var me = this; if (!me._view) { me._view = helpers.extend({}, me._model); } me._start = {}; return me; - }, + } - transition: function(ease) { + transition(ease) { var me = this; var model = me._model; var start = me._start; @@ -99,19 +98,19 @@ helpers.extend(Element.prototype, { interpolate(start, view, model, ease); return me; - }, + } - tooltipPosition: function() { + tooltipPosition() { return { x: this._model.x, y: this._model.y }; - }, + } - hasValue: function() { + hasValue() { return helpers.isNumber(this._model.x) && helpers.isNumber(this._model.y); } -}); +} Element.extend = helpers.inherits;
true
Other
chartjs
Chart.js
4a8a7ee8247c7c69e7e5f0a9388cdeb07e4fc197.json
Use ES6 classes for elements (#6702) * Use ES6 classes for elements * Add additional elements
src/core/core.scale.js
@@ -1,14 +1,14 @@ 'use strict'; -var defaults = require('./core.defaults'); -var Element = require('./core.element'); -var helpers = require('../helpers/index'); -var Ticks = require('./core.ticks'); +const defaults = require('./core.defaults'); +const Element = require('./core.element'); +const helpers = require('../helpers/index'); +const Ticks = require('./core.ticks'); -var isArray = helpers.isArray; -var isNullOrUndef = helpers.isNullOrUndef; -var valueOrDefault = helpers.valueOrDefault; -var valueAtIndexOrDefault = helpers.valueAtIndexOrDefault; +const isArray = helpers.isArray; +const isNullOrUndef = helpers.isNullOrUndef; +const valueOrDefault = helpers.valueOrDefault; +const valueAtIndexOrDefault = helpers.valueAtIndexOrDefault; defaults._set('scale', { display: true, @@ -319,17 +319,18 @@ function skip(ticks, spacing, majorStart, majorEnd) { } } -var Scale = Element.extend({ +class Scale extends Element { + /** * Parse a supported input value to internal representation. * @param {*} raw * @param {number} index * @private * @since 3.0 */ - _parse: function(raw, index) { // eslint-disable-line no-unused-vars + _parse(raw, index) { // eslint-disable-line no-unused-vars return raw; - }, + } /** * Parse an object for axis to internal representation. @@ -339,14 +340,14 @@ var Scale = Element.extend({ * @private * @since 3.0 */ - _parseObject: function(obj, axis, index) { + _parseObject(obj, axis, index) { if (obj[axis] !== undefined) { return this._parse(obj[axis], index); } return null; - }, + } - _getMinMax: function(canStack) { + _getMinMax(canStack) { var me = this; var metas = me._getMatchingVisibleMetas(); var min = Number.POSITIVE_INFINITY; @@ -366,49 +367,49 @@ var Scale = Element.extend({ max: max, minPositive: minPositive }; - }, + } - _invalidateCaches: helpers.noop, + _invalidateCaches() {} /** * Get the padding needed for the scale * @method getPadding * @private * @returns {Padding} the necessary padding */ - getPadding: function() { + getPadding() { var me = this; return { left: me.paddingLeft || 0, top: me.paddingTop || 0, right: me.paddingRight || 0, bottom: me.paddingBottom || 0 }; - }, + } /** * Returns the scale tick objects ({label, major}) * @since 2.7 */ - getTicks: function() { + getTicks() { return this.ticks; - }, + } /** * @private */ - _getLabels: function() { + _getLabels() { var data = this.chart.data; return this.options.labels || (this.isHorizontal() ? data.xLabels : data.yLabels) || data.labels; - }, + } // These methods are ordered by lifecyle. Utilities then follow. // Any function defined here is inherited by all scale types. // Any function can be extended by the scale type - beforeUpdate: function() { + beforeUpdate() { helpers.callback(this.options.beforeUpdate, [this]); - }, + } /** * @param {number} maxWidth - the max width in pixels @@ -418,7 +419,7 @@ var Scale = Element.extend({ * - padding - space that's required to show the labels at the edges of the scale * - thickness of scales or legends in another orientation */ - update: function(maxWidth, maxHeight, margins) { + update(maxWidth, maxHeight, margins) { var me = this; var tickOpts = me.options.ticks; var sampleSize = tickOpts.sampleSize; @@ -497,12 +498,12 @@ var Scale = Element.extend({ // TODO(v3): remove minSize as a public property and return value from all layout boxes. It is unused // make maxWidth and maxHeight private return me.minSize; - }, + } /** * @private */ - _configure: function() { + _configure() { var me = this; var reversePixels = me.options.ticks.reverse; var startPixel, endPixel; @@ -520,18 +521,18 @@ var Scale = Element.extend({ me._endPixel = endPixel; me._reversePixels = reversePixels; me._length = endPixel - startPixel; - }, + } - afterUpdate: function() { + afterUpdate() { helpers.callback(this.options.afterUpdate, [this]); - }, + } // - beforeSetDimensions: function() { + beforeSetDimensions() { helpers.callback(this.options.beforeSetDimensions, [this]); - }, - setDimensions: function() { + } + setDimensions() { var me = this; // Set the unconstrained dimension before label rotation if (me.isHorizontal()) { @@ -552,54 +553,54 @@ var Scale = Element.extend({ me.paddingTop = 0; me.paddingRight = 0; me.paddingBottom = 0; - }, - afterSetDimensions: function() { + } + afterSetDimensions() { helpers.callback(this.options.afterSetDimensions, [this]); - }, + } // Data limits - beforeDataLimits: function() { + beforeDataLimits() { helpers.callback(this.options.beforeDataLimits, [this]); - }, - determineDataLimits: helpers.noop, - afterDataLimits: function() { + } + determineDataLimits() {} + afterDataLimits() { helpers.callback(this.options.afterDataLimits, [this]); - }, + } // - beforeBuildTicks: function() { + beforeBuildTicks() { helpers.callback(this.options.beforeBuildTicks, [this]); - }, - buildTicks: helpers.noop, - afterBuildTicks: function() { + } + buildTicks() {} + afterBuildTicks() { helpers.callback(this.options.afterBuildTicks, [this]); - }, + } - beforeTickToLabelConversion: function() { + beforeTickToLabelConversion() { helpers.callback(this.options.beforeTickToLabelConversion, [this]); - }, + } /** * Convert ticks to label strings */ - generateTickLabels: function(ticks) { + generateTickLabels(ticks) { var me = this; var tickOpts = me.options.ticks; var i, ilen, tick; for (i = 0, ilen = ticks.length; i < ilen; i++) { tick = ticks[i]; tick.label = helpers.callback(tickOpts.callback, [tick.value, i, ticks], me); } - }, - afterTickToLabelConversion: function() { + } + afterTickToLabelConversion() { helpers.callback(this.options.afterTickToLabelConversion, [this]); - }, + } // - beforeCalculateTickRotation: function() { + beforeCalculateTickRotation() { helpers.callback(this.options.beforeCalculateTickRotation, [this]); - }, - calculateTickRotation: function() { + } + calculateTickRotation() { var me = this; var options = me.options; var tickOpts = options.ticks; @@ -637,17 +638,17 @@ var Scale = Element.extend({ } me.labelRotation = labelRotation; - }, - afterCalculateTickRotation: function() { + } + afterCalculateTickRotation() { helpers.callback(this.options.afterCalculateTickRotation, [this]); - }, + } // - beforeFit: function() { + beforeFit() { helpers.callback(this.options.beforeFit, [this]); - }, - fit: function() { + } + fit() { var me = this; // Reset var minSize = me.minSize = { @@ -748,49 +749,49 @@ var Scale = Element.extend({ me.width = minSize.width; me.height = me._length = chart.height - me.margins.top - me.margins.bottom; } - }, + } /** * Handle margins and padding interactions * @private */ - handleMargins: function() { + handleMargins() { var me = this; if (me.margins) { me.margins.left = Math.max(me.paddingLeft, me.margins.left); me.margins.top = Math.max(me.paddingTop, me.margins.top); me.margins.right = Math.max(me.paddingRight, me.margins.right); me.margins.bottom = Math.max(me.paddingBottom, me.margins.bottom); } - }, + } - afterFit: function() { + afterFit() { helpers.callback(this.options.afterFit, [this]); - }, + } // Shared Methods - isHorizontal: function() { + isHorizontal() { var pos = this.options.position; return pos === 'top' || pos === 'bottom'; - }, - isFullWidth: function() { + } + isFullWidth() { return this.options.fullWidth; - }, + } - _convertTicksToLabels: function(ticks) { + _convertTicksToLabels(ticks) { var me = this; me.beforeTickToLabelConversion(); me.generateTickLabels(ticks); me.afterTickToLabelConversion(); - }, + } /** * @private */ - _getLabelSizes: function() { + _getLabelSizes() { var me = this; var labelSizes = me._labelSizes; @@ -800,15 +801,15 @@ var Scale = Element.extend({ } return labelSizes; - }, + } /** * Used to get the label to display in the tooltip for the given value * @param value */ - getLabelForValue: function(value) { + getLabelForValue(value) { return value; - }, + } /** * Returns the location of the given data point. Value can either be an index or a numerical value @@ -817,20 +818,20 @@ var Scale = Element.extend({ * @param index * @param datasetIndex */ - getPixelForValue: helpers.noop, + getPixelForValue() {} /** * Used to get the data value from a given pixel. This is the inverse of getPixelForValue * The coordinate (0, 0) is at the upper-left corner of the canvas * @param pixel */ - getValueForPixel: helpers.noop, + getValueForPixel() {} /** * Returns the location of the tick at the given index * The coordinate (0, 0) is at the upper-left corner of the canvas */ - getPixelForTick: function(index) { + getPixelForTick(index) { var me = this; var offset = me.options.offset; var numTicks = me.ticks.length; @@ -839,36 +840,36 @@ var Scale = Element.extend({ return index < 0 || index > numTicks - 1 ? null : me.getPixelForDecimal(index * tickWidth + (offset ? tickWidth / 2 : 0)); - }, + } /** * Utility for getting the pixel location of a percentage of scale * The coordinate (0, 0) is at the upper-left corner of the canvas */ - getPixelForDecimal: function(decimal) { + getPixelForDecimal(decimal) { var me = this; if (me._reversePixels) { decimal = 1 - decimal; } return me._startPixel + decimal * me._length; - }, + } - getDecimalForPixel: function(pixel) { + getDecimalForPixel(pixel) { var decimal = (pixel - this._startPixel) / this._length; return this._reversePixels ? 1 - decimal : decimal; - }, + } /** * Returns the pixel for the minimum chart value * The coordinate (0, 0) is at the upper-left corner of the canvas */ - getBasePixel: function() { + getBasePixel() { return this.getPixelForValue(this.getBaseValue()); - }, + } - getBaseValue: function() { + getBaseValue() { var me = this; var min = me.min; var max = me.max; @@ -877,13 +878,13 @@ var Scale = Element.extend({ min < 0 && max < 0 ? max : min > 0 && max > 0 ? min : 0; - }, + } /** * Returns a subset of ticks to be plotted to avoid overlapping labels. * @private */ - _autoSkip: function(ticks) { + _autoSkip(ticks) { var me = this; var tickOpts = me.options.ticks; var axisLength = me._length; @@ -913,12 +914,12 @@ var Scale = Element.extend({ } skip(ticks, spacing); return nonSkipped(ticks); - }, + } /** * @private */ - _tickSize: function() { + _tickSize() { var me = this; var optionTicks = me.options.ticks; @@ -936,25 +937,25 @@ var Scale = Element.extend({ return me.isHorizontal() ? h * cos > w * sin ? w / cos : h / sin : h * sin < w * cos ? h / cos : w / sin; - }, + } /** * @private */ - _isVisible: function() { + _isVisible() { var display = this.options.display; if (display !== 'auto') { return !!display; } return this._getMatchingVisibleMetas().length > 0; - }, + } /** * @private */ - _computeGridLineItems: function(chartArea) { + _computeGridLineItems(chartArea) { var me = this; var chart = me.chart; var options = me.options; @@ -1045,12 +1046,12 @@ var Scale = Element.extend({ items.borderValue = borderValue; return items; - }, + } /** * @private */ - _computeLabelItems: function() { + _computeLabelItems() { var me = this; var options = me.options; var optionTicks = options.ticks; @@ -1110,12 +1111,12 @@ var Scale = Element.extend({ } return items; - }, + } /** * @private */ - _drawGrid: function(chartArea) { + _drawGrid(chartArea) { var me = this; var gridLines = me.options.gridLines; @@ -1185,12 +1186,12 @@ var Scale = Element.extend({ ctx.lineTo(x2, y2); ctx.stroke(); } - }, + } /** * @private */ - _drawLabels: function() { + _drawLabels() { var me = this; var optionTicks = me.options.ticks; @@ -1228,12 +1229,12 @@ var Scale = Element.extend({ } ctx.restore(); } - }, + } /** * @private */ - _drawTitle: function() { + _drawTitle() { var me = this; var ctx = me.ctx; var options = me.options; @@ -1300,9 +1301,9 @@ var Scale = Element.extend({ ctx.font = scaleLabelFont.string; ctx.fillText(scaleLabel.labelString, 0, 0); ctx.restore(); - }, + } - draw: function(chartArea) { + draw(chartArea) { var me = this; if (!me._isVisible()) { @@ -1312,12 +1313,12 @@ var Scale = Element.extend({ me._drawGrid(chartArea); me._drawTitle(); me._drawLabels(); - }, + } /** * @private */ - _layers: function() { + _layers() { var me = this; var opts = me.options; var tz = opts.ticks && opts.ticks.z || 0; @@ -1345,21 +1346,21 @@ var Scale = Element.extend({ me._drawLabels.apply(me, arguments); } }]; - }, + } /** * @private */ - _getAxisID: function() { + _getAxisID() { return this.isHorizontal() ? 'xAxisID' : 'yAxisID'; - }, + } /** * Returns visible dataset metas that are attached to this scale * @param {string} [type] - if specified, also filter by dataset type * @private */ - _getMatchingVisibleMetas: function(type) { + _getMatchingVisibleMetas(type) { var me = this; var metas = me.chart._getSortedVisibleDatasetMetas(); var axisID = me._getAxisID(); @@ -1374,7 +1375,7 @@ var Scale = Element.extend({ } return result; } -}); +} Scale.prototype._draw = Scale.prototype.draw;
true
Other
chartjs
Chart.js
4a8a7ee8247c7c69e7e5f0a9388cdeb07e4fc197.json
Use ES6 classes for elements (#6702) * Use ES6 classes for elements * Add additional elements
src/core/core.tooltip.js
@@ -1,11 +1,11 @@ 'use strict'; -var defaults = require('./core.defaults'); -var Element = require('./core.element'); -var helpers = require('../helpers/index'); +const defaults = require('./core.defaults'); +const Element = require('./core.element'); +const helpers = require('../helpers/index'); -var valueOrDefault = helpers.valueOrDefault; -var getRtlHelper = helpers.rtl.getRtlAdapter; +const valueOrDefault = helpers.valueOrDefault; +const getRtlHelper = helpers.rtl.getRtlAdapter; defaults._set('global', { tooltips: { @@ -488,15 +488,15 @@ function getBeforeAfterBodyLines(callback) { return pushOrConcat([], splitNewlines(callback)); } -var exports = Element.extend({ - initialize: function() { +class Tooltip extends Element { + initialize() { var me = this; me._model = getBaseModel(me._options); me._view = {}; me._lastActive = []; - }, + } - transition: function(easingValue) { + transition(easingValue) { var me = this; var options = me._options; @@ -509,11 +509,11 @@ var exports = Element.extend({ } Element.prototype.transition.call(me, easingValue); - }, + } // Get the title // Args are: (tooltipItem, data) - getTitle: function() { + getTitle() { var me = this; var opts = me._options; var callbacks = opts.callbacks; @@ -528,15 +528,15 @@ var exports = Element.extend({ lines = pushOrConcat(lines, splitNewlines(afterTitle)); return lines; - }, + } // Args are: (tooltipItem, data) - getBeforeBody: function() { + getBeforeBody() { return getBeforeAfterBodyLines(this._options.callbacks.beforeBody.apply(this, arguments)); - }, + } // Args are: (tooltipItem, data) - getBody: function(tooltipItems, data) { + getBody(tooltipItems, data) { var me = this; var callbacks = me._options.callbacks; var bodyItems = []; @@ -555,16 +555,16 @@ var exports = Element.extend({ }); return bodyItems; - }, + } // Args are: (tooltipItem, data) - getAfterBody: function() { + getAfterBody() { return getBeforeAfterBodyLines(this._options.callbacks.afterBody.apply(this, arguments)); - }, + } // Get the footer and beforeFooter and afterFooter lines // Args are: (tooltipItem, data) - getFooter: function() { + getFooter() { var me = this; var callbacks = me._options.callbacks; @@ -578,9 +578,9 @@ var exports = Element.extend({ lines = pushOrConcat(lines, splitNewlines(afterFooter)); return lines; - }, + } - update: function(changed) { + update(changed) { var me = this; var opts = me._options; @@ -690,18 +690,19 @@ var exports = Element.extend({ } return me; - }, + } - drawCaret: function(tooltipPoint, size) { + drawCaret(tooltipPoint, size) { var ctx = this._chart.ctx; var vm = this._view; var caretPosition = this.getCaretPosition(tooltipPoint, size, vm); ctx.lineTo(caretPosition.x1, caretPosition.y1); ctx.lineTo(caretPosition.x2, caretPosition.y2); ctx.lineTo(caretPosition.x3, caretPosition.y3); - }, - getCaretPosition: function(tooltipPoint, size, vm) { + } + + getCaretPosition(tooltipPoint, size, vm) { var x1, x2, x3, y1, y2, y3; var caretSize = vm.caretSize; var cornerRadius = vm.cornerRadius; @@ -759,9 +760,9 @@ var exports = Element.extend({ } } return {x1: x1, x2: x2, x3: x3, y1: y1, y2: y2, y3: y3}; - }, + } - drawTitle: function(pt, vm, ctx) { + drawTitle(pt, vm, ctx) { var title = vm.title; var length = title.length; var titleFontSize, titleSpacing, i; @@ -789,9 +790,9 @@ var exports = Element.extend({ } } } - }, + } - drawBody: function(pt, vm, ctx) { + drawBody(pt, vm, ctx) { var bodyFontSize = vm.bodyFontSize; var bodySpacing = vm.bodySpacing; var bodyAlign = vm._bodyAlign; @@ -866,9 +867,9 @@ var exports = Element.extend({ // After body lines helpers.each(vm.afterBody, fillLineOfText); pt.y -= bodySpacing; // Remove last body spacing - }, + } - drawFooter: function(pt, vm, ctx) { + drawFooter(pt, vm, ctx) { var footer = vm.footer; var length = footer.length; var footerFontSize, i; @@ -892,9 +893,9 @@ var exports = Element.extend({ pt.y += footerFontSize + vm.footerSpacing; } } - }, + } - drawBackground: function(pt, vm, ctx, tooltipSize) { + drawBackground(pt, vm, ctx, tooltipSize) { ctx.fillStyle = vm.backgroundColor; ctx.strokeStyle = vm.borderColor; ctx.lineWidth = vm.borderWidth; @@ -935,9 +936,9 @@ var exports = Element.extend({ if (vm.borderWidth > 0) { ctx.stroke(); } - }, + } - draw: function() { + draw() { var ctx = this._chart.ctx; var vm = this._view; @@ -985,15 +986,15 @@ var exports = Element.extend({ ctx.restore(); } - }, + } /** * Handle an event * @private * @param {IEvent} event - The event to handle * @returns {boolean} true if the tooltip changed */ - handleEvent: function(e) { + handleEvent(e) { var me = this; var options = me._options; var changed = false; @@ -1034,11 +1035,11 @@ var exports = Element.extend({ return changed; } -}); +} /** * @namespace Chart.Tooltip.positioners */ -exports.positioners = positioners; +Tooltip.positioners = positioners; -module.exports = exports; +module.exports = Tooltip;
true
Other
chartjs
Chart.js
4a8a7ee8247c7c69e7e5f0a9388cdeb07e4fc197.json
Use ES6 classes for elements (#6702) * Use ES6 classes for elements * Add additional elements
src/elements/element.arc.js
@@ -1,9 +1,9 @@ 'use strict'; -var defaults = require('../core/core.defaults'); -var Element = require('../core/core.element'); -var helpers = require('../helpers/index'); -var TAU = Math.PI * 2; +const defaults = require('../core/core.defaults'); +const Element = require('../core/core.element'); +const helpers = require('../helpers/index'); +const TAU = Math.PI * 2; defaults._set('global', { elements: { @@ -91,10 +91,13 @@ function drawBorder(ctx, vm, arc) { ctx.stroke(); } -module.exports = Element.extend({ - _type: 'arc', +class Arc extends Element { - inRange: function(chartX, chartY) { + constructor(props) { + super(props); + } + + inRange(chartX, chartY) { var vm = this._view; if (vm) { @@ -122,19 +125,19 @@ module.exports = Element.extend({ return (betweenAngles && withinRadius); } return false; - }, + } - getCenterPoint: function() { + getCenterPoint() { var vm = this._view; var halfAngle = (vm.startAngle + vm.endAngle) / 2; var halfRadius = (vm.innerRadius + vm.outerRadius) / 2; return { x: vm.x + Math.cos(halfAngle) * halfRadius, y: vm.y + Math.sin(halfAngle) * halfRadius }; - }, + } - tooltipPosition: function() { + tooltipPosition() { var vm = this._view; var centreAngle = vm.startAngle + ((vm.endAngle - vm.startAngle) / 2); var rangeFromCentre = (vm.outerRadius - vm.innerRadius) / 2 + vm.innerRadius; @@ -143,9 +146,9 @@ module.exports = Element.extend({ x: vm.x + (Math.cos(centreAngle) * rangeFromCentre), y: vm.y + (Math.sin(centreAngle) * rangeFromCentre) }; - }, + } - draw: function() { + draw() { var ctx = this._ctx; var vm = this._view; var pixelMargin = (vm.borderAlign === 'inner') ? 0.33 : 0; @@ -190,4 +193,8 @@ module.exports = Element.extend({ ctx.restore(); } -}); +} + +Arc.prototype._type = 'arc'; + +module.exports = Arc;
true
Other
chartjs
Chart.js
4a8a7ee8247c7c69e7e5f0a9388cdeb07e4fc197.json
Use ES6 classes for elements (#6702) * Use ES6 classes for elements * Add additional elements
src/elements/element.line.js
@@ -1,12 +1,12 @@ 'use strict'; -var defaults = require('../core/core.defaults'); -var Element = require('../core/core.element'); -var helpers = require('../helpers/index'); +const defaults = require('../core/core.defaults'); +const Element = require('../core/core.element'); +const helpers = require('../helpers/index'); -var valueOrDefault = helpers.valueOrDefault; +const valueOrDefault = helpers.valueOrDefault; -var defaultColor = defaults.global.defaultColor; +const defaultColor = defaults.global.defaultColor; defaults._set('global', { elements: { @@ -25,10 +25,13 @@ defaults._set('global', { } }); -module.exports = Element.extend({ - _type: 'line', +class Line extends Element { - draw: function() { + constructor(props) { + super(props); + } + + draw() { var me = this; var vm = me._view; var ctx = me._ctx; @@ -108,4 +111,8 @@ module.exports = Element.extend({ ctx.stroke(); ctx.restore(); } -}); +} + +Line.prototype._type = 'line'; + +module.exports = Line;
true
Other
chartjs
Chart.js
4a8a7ee8247c7c69e7e5f0a9388cdeb07e4fc197.json
Use ES6 classes for elements (#6702) * Use ES6 classes for elements * Add additional elements
src/elements/element.point.js
@@ -1,12 +1,12 @@ 'use strict'; -var defaults = require('../core/core.defaults'); -var Element = require('../core/core.element'); -var helpers = require('../helpers/index'); +const defaults = require('../core/core.defaults'); +const Element = require('../core/core.element'); +const helpers = require('../helpers/index'); -var valueOrDefault = helpers.valueOrDefault; +const valueOrDefault = helpers.valueOrDefault; -var defaultColor = defaults.global.defaultColor; +const defaultColor = defaults.global.defaultColor; defaults._set('global', { elements: { @@ -24,45 +24,45 @@ defaults._set('global', { } }); -function xRange(mouseX) { - var vm = this._view; - return vm ? (Math.abs(mouseX - vm.x) < vm.radius + vm.hitRadius) : false; -} - -function yRange(mouseY) { - var vm = this._view; - return vm ? (Math.abs(mouseY - vm.y) < vm.radius + vm.hitRadius) : false; -} +class Point extends Element { -module.exports = Element.extend({ - _type: 'point', + constructor(props) { + super(props); + } - inRange: function(mouseX, mouseY) { + inRange(mouseX, mouseY) { var vm = this._view; return vm ? ((Math.pow(mouseX - vm.x, 2) + Math.pow(mouseY - vm.y, 2)) < Math.pow(vm.hitRadius + vm.radius, 2)) : false; - }, + } + + inXRange(mouseX) { + var vm = this._view; + return vm ? (Math.abs(mouseX - vm.x) < vm.radius + vm.hitRadius) : false; + } - inXRange: xRange, - inYRange: yRange, + inYRange(mouseY) { + var vm = this._view; + return vm ? (Math.abs(mouseY - vm.y) < vm.radius + vm.hitRadius) : false; + } - getCenterPoint: function() { + getCenterPoint() { var vm = this._view; return { x: vm.x, y: vm.y }; - }, + } - tooltipPosition: function() { + tooltipPosition() { var vm = this._view; return { x: vm.x, y: vm.y, padding: vm.radius + vm.borderWidth }; - }, + } - draw: function(chartArea) { + draw(chartArea) { var vm = this._view; var ctx = this._ctx; var pointStyle = vm.pointStyle; @@ -85,4 +85,8 @@ module.exports = Element.extend({ helpers.canvas.drawPoint(ctx, pointStyle, radius, x, y, rotation); } } -}); +} + +Point.prototype._type = 'point'; + +module.exports = Point;
true
Other
chartjs
Chart.js
4a8a7ee8247c7c69e7e5f0a9388cdeb07e4fc197.json
Use ES6 classes for elements (#6702) * Use ES6 classes for elements * Add additional elements
src/elements/element.rectangle.js
@@ -1,10 +1,10 @@ 'use strict'; -var defaults = require('../core/core.defaults'); -var Element = require('../core/core.element'); -var helpers = require('../helpers/index'); +const defaults = require('../core/core.defaults'); +const Element = require('../core/core.element'); +const helpers = require('../helpers/index'); -var defaultColor = defaults.global.defaultColor; +const defaultColor = defaults.global.defaultColor; defaults._set('global', { elements: { @@ -130,10 +130,13 @@ function inRange(vm, x, y) { && (skipY || y >= bounds.top && y <= bounds.bottom); } -module.exports = Element.extend({ - _type: 'rectangle', +class Rectangle extends Element { - draw: function() { + constructor(props) { + super(props); + } + + draw() { var ctx = this._ctx; var vm = this._view; var rects = boundingRects(vm); @@ -155,21 +158,21 @@ module.exports = Element.extend({ ctx.rect(inner.x, inner.y, inner.w, inner.h); ctx.fill('evenodd'); ctx.restore(); - }, + } - inRange: function(mouseX, mouseY) { + inRange(mouseX, mouseY) { return inRange(this._view, mouseX, mouseY); - }, + } - inXRange: function(mouseX) { + inXRange(mouseX) { return inRange(this._view, mouseX, null); - }, + } - inYRange: function(mouseY) { + inYRange(mouseY) { return inRange(this._view, null, mouseY); - }, + } - getCenterPoint: function() { + getCenterPoint() { var vm = this._view; var x, y; if (isVertical(vm)) { @@ -181,13 +184,17 @@ module.exports = Element.extend({ } return {x: x, y: y}; - }, + } - tooltipPosition: function() { + tooltipPosition() { var vm = this._view; return { x: vm.x, y: vm.y }; } -}); +} + +Rectangle.prototype._type = 'rectangle'; + +module.exports = Rectangle;
true
Other
chartjs
Chart.js
4a8a7ee8247c7c69e7e5f0a9388cdeb07e4fc197.json
Use ES6 classes for elements (#6702) * Use ES6 classes for elements * Add additional elements
src/plugins/plugin.legend.js
@@ -1,13 +1,12 @@ 'use strict'; -var defaults = require('../core/core.defaults'); -var Element = require('../core/core.element'); -var helpers = require('../helpers/index'); -var layouts = require('../core/core.layouts'); +const defaults = require('../core/core.defaults'); +const Element = require('../core/core.element'); +const helpers = require('../helpers/index'); +const layouts = require('../core/core.layouts'); -var getRtlHelper = helpers.rtl.getRtlAdapter; -var noop = helpers.noop; -var valueOrDefault = helpers.valueOrDefault; +const getRtlHelper = helpers.rtl.getRtlAdapter; +const valueOrDefault = helpers.valueOrDefault; defaults._set('global', { legend: { @@ -112,9 +111,9 @@ function getBoxWidth(labelOpts, fontSize) { /** * IMPORTANT: this class is exposed publicly as Chart.Legend, backward compatibility required! */ -var Legend = Element.extend({ +class Legend extends Element { - initialize: function(config) { + initialize(config) { var me = this; helpers.extend(me, config); @@ -128,14 +127,15 @@ var Legend = Element.extend({ // Are we in doughnut mode which has a different data type me.doughnutMode = false; - }, + } // These methods are ordered by lifecycle. Utilities then follow. // Any function defined here is inherited by all legend types. // Any function can be extended by the legend type - beforeUpdate: noop, - update: function(maxWidth, maxHeight, margins) { + beforeUpdate() {} + + update(maxWidth, maxHeight, margins) { var me = this; // Update Lifecycle - Probably don't want to ever extend or overwrite this function ;) @@ -163,13 +163,15 @@ var Legend = Element.extend({ me.afterUpdate(); return me.minSize; - }, - afterUpdate: noop, + } + + afterUpdate() {} // - beforeSetDimensions: noop, - setDimensions: function() { + beforeSetDimensions() {} + + setDimensions() { var me = this; // Set the unconstrained dimension before label rotation if (me.isHorizontal()) { @@ -196,13 +198,15 @@ var Legend = Element.extend({ width: 0, height: 0 }; - }, - afterSetDimensions: noop, + } + + afterSetDimensions() {} // - beforeBuildLabels: noop, - buildLabels: function() { + beforeBuildLabels() {} + + buildLabels() { var me = this; var labelOpts = me.options.labels || {}; var legendItems = helpers.callback(labelOpts.generateLabels, [me.chart], me) || []; @@ -218,13 +222,15 @@ var Legend = Element.extend({ } me.legendItems = legendItems; - }, - afterBuildLabels: noop, + } + + afterBuildLabels() {} // - beforeFit: noop, - fit: function() { + beforeFit() {} + + fit() { var me = this; var opts = me.options; var labelOpts = opts.labels; @@ -330,16 +336,17 @@ var Legend = Element.extend({ me.width = minSize.width; me.height = minSize.height; - }, - afterFit: noop, + } + + afterFit() {} // Shared Methods - isHorizontal: function() { + isHorizontal() { return this.options.position === 'top' || this.options.position === 'bottom'; - }, + } // Actually draw the legend on the canvas - draw: function() { + draw() { var me = this; var opts = me.options; var labelOpts = opts.labels; @@ -503,12 +510,12 @@ var Legend = Element.extend({ }); helpers.rtl.restoreTextDirection(me.ctx, opts.textDirection); - }, + } /** * @private */ - _getLegendItemAt: function(x, y) { + _getLegendItemAt(x, y) { var me = this; var i, hitBox, lh; @@ -526,14 +533,14 @@ var Legend = Element.extend({ } return null; - }, + } /** * Handle an event * @private * @param {IEvent} event - The event to handle */ - handleEvent: function(e) { + handleEvent(e) { var me = this; var opts = me.options; var type = e.type === 'mouseup' ? 'click' : e.type; @@ -573,7 +580,7 @@ var Legend = Element.extend({ } } } -}); +} function createNewLegendAndAttach(chart, legendOpts) { var legend = new Legend({
true
Other
chartjs
Chart.js
4a8a7ee8247c7c69e7e5f0a9388cdeb07e4fc197.json
Use ES6 classes for elements (#6702) * Use ES6 classes for elements * Add additional elements
src/plugins/plugin.title.js
@@ -1,11 +1,9 @@ 'use strict'; -var defaults = require('../core/core.defaults'); -var Element = require('../core/core.element'); -var helpers = require('../helpers/index'); -var layouts = require('../core/core.layouts'); - -var noop = helpers.noop; +const defaults = require('../core/core.defaults'); +const Element = require('../core/core.element'); +const helpers = require('../helpers/index'); +const layouts = require('../core/core.layouts'); defaults._set('global', { title: { @@ -22,19 +20,19 @@ defaults._set('global', { /** * IMPORTANT: this class is exposed publicly as Chart.Legend, backward compatibility required! */ -var Title = Element.extend({ - initialize: function(config) { +class Title extends Element { + initialize(config) { var me = this; helpers.extend(me, config); // Contains hit boxes for each dataset (in dataset order) me.legendHitBoxes = []; - }, + } // These methods are ordered by lifecycle. Utilities then follow. - beforeUpdate: noop, - update: function(maxWidth, maxHeight, margins) { + beforeUpdate() {} + update(maxWidth, maxHeight, margins) { var me = this; // Update Lifecycle - Probably don't want to ever extend or overwrite this function ;) @@ -63,13 +61,13 @@ var Title = Element.extend({ return me.minSize; - }, - afterUpdate: noop, + } + afterUpdate() {} // - beforeSetDimensions: noop, - setDimensions: function() { + beforeSetDimensions() {} + setDimensions() { var me = this; // Set the unconstrained dimension before label rotation if (me.isHorizontal()) { @@ -96,19 +94,19 @@ var Title = Element.extend({ width: 0, height: 0 }; - }, - afterSetDimensions: noop, + } + afterSetDimensions() {} // - beforeBuildLabels: noop, - buildLabels: noop, - afterBuildLabels: noop, + beforeBuildLabels() {} + buildLabels() {} + afterBuildLabels() {} // - beforeFit: noop, - fit: function() { + beforeFit() {} + fit() { var me = this; var opts = me.options; var minSize = me.minSize = {}; @@ -125,17 +123,17 @@ var Title = Element.extend({ me.width = minSize.width = isHorizontal ? me.maxWidth : textSize; me.height = minSize.height = isHorizontal ? textSize : me.maxHeight; - }, - afterFit: noop, + } + afterFit() {} // Shared Methods - isHorizontal: function() { + isHorizontal() { var pos = this.options.position; return pos === 'top' || pos === 'bottom'; - }, + } // Actually draw the title block on the canvas - draw: function() { + draw() { var me = this; var ctx = me.ctx; var opts = me.options; @@ -188,7 +186,7 @@ var Title = Element.extend({ ctx.restore(); } -}); +} function createNewTitleBlockAndAttach(chart, titleOpts) { var title = new Title({
true
Other
chartjs
Chart.js
94afa634507036d8cd6b34d2c96eb225177b197e.json
Remove zeroLineIndex functionality (#6697) * Remove zeroLineIndex functionality * Remove docs * Code review updates
docs/axes/styling.md
@@ -18,10 +18,6 @@ The grid line configuration is nested under the scale configuration in the `grid | `drawOnChartArea` | `boolean` | `true` | If true, draw lines on the chart area inside the axis lines. This is useful when there are multiple axes and you need to control which grid lines are drawn. | `drawTicks` | `boolean` | `true` | If true, draw lines beside the ticks in the axis area beside the chart. | `tickMarkLength` | `number` | `10` | Length in pixels that the grid lines will draw into the axis area. -| `zeroLineWidth` | `number` | `1` | Stroke width of the grid line for the first index (index 0). -| `zeroLineColor` | `Color` | `'rgba(0, 0, 0, 0.25)'` | Stroke color of the grid line for the first index (index 0). -| `zeroLineBorderDash` | `number[]` | `[]` | Length and spacing of dashes of the grid line for the first index (index 0). See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash). -| `zeroLineBorderDashOffset` | `number` | `0.0` | Offset for line dashes of the grid line for the first index (index 0). See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineDashOffset). | `offsetGridLines` | `boolean` | `false` | If true, grid lines will be shifted to be between labels. This is set to `true` for a bar chart by default. | `z` | `number` | `0` | z-index of gridline layer. Values &lt;= 0 are drawn under datasets, &gt; 0 on top.
true
Other
chartjs
Chart.js
94afa634507036d8cd6b34d2c96eb225177b197e.json
Remove zeroLineIndex functionality (#6697) * Remove zeroLineIndex functionality * Remove docs * Code review updates
docs/getting-started/v3-migration.md
@@ -26,6 +26,7 @@ Chart.js is no longer providing the `Chart.bundle.js` and `Chart.bundle.min.js`. ### Customizability * `custom` attribute of elements was removed. Please use scriptable options +* The `zeroLine*` options of axes were removed. ### Options
true
Other
chartjs
Chart.js
94afa634507036d8cd6b34d2c96eb225177b197e.json
Remove zeroLineIndex functionality (#6697) * Remove zeroLineIndex functionality * Remove docs * Code review updates
src/core/core.scale.js
@@ -24,10 +24,6 @@ defaults._set('scale', { drawOnChartArea: true, drawTicks: true, tickMarkLength: 10, - zeroLineWidth: 1, - zeroLineColor: 'rgba(0,0,0,0.25)', - zeroLineBorderDash: [], - zeroLineBorderDashOffset: 0.0, offsetGridLines: false, borderDash: [], borderDashOffset: 0.0 @@ -324,9 +320,6 @@ function skip(ticks, spacing, majorStart, majorEnd) { } var Scale = Element.extend({ - - zeroLineIndex: 0, - /** * Parse a supported input value to internal representation. * @param {*} raw @@ -981,7 +974,7 @@ var Scale = Element.extend({ return alignPixel(chart, pixel, axisWidth); }; var borderValue, i, tick, lineValue, alignedLineValue; - var tx1, ty1, tx2, ty2, x1, y1, x2, y2, lineWidth, lineColor, borderDash, borderDashOffset; + var tx1, ty1, tx2, ty2, x1, y1, x2, y2; if (position === 'top') { borderValue = alignBorderValue(me.bottom); @@ -1012,18 +1005,10 @@ var Scale = Element.extend({ for (i = 0; i < ticksLength; ++i) { tick = ticks[i] || {}; - if (i === me.zeroLineIndex && options.offset === offsetGridLines) { - // Draw the first index specially - lineWidth = gridLines.zeroLineWidth; - lineColor = gridLines.zeroLineColor; - borderDash = gridLines.zeroLineBorderDash || []; - borderDashOffset = gridLines.zeroLineBorderDashOffset || 0.0; - } else { - lineWidth = valueAtIndexOrDefault(gridLines.lineWidth, i, 1); - lineColor = valueAtIndexOrDefault(gridLines.color, i, 'rgba(0,0,0,0.1)'); - borderDash = gridLines.borderDash || []; - borderDashOffset = gridLines.borderDashOffset || 0.0; - } + const lineWidth = valueAtIndexOrDefault(gridLines.lineWidth, i, 1); + const lineColor = valueAtIndexOrDefault(gridLines.color, i, 'rgba(0,0,0,0.1)'); + const borderDash = gridLines.borderDash || []; + const borderDashOffset = gridLines.borderDashOffset || 0.0; lineValue = getPixelForGridLine(me, tick._index || i, offsetGridLines);
true
Other
chartjs
Chart.js
94afa634507036d8cd6b34d2c96eb225177b197e.json
Remove zeroLineIndex functionality (#6697) * Remove zeroLineIndex functionality * Remove docs * Code review updates
src/scales/scale.linearbase.js
@@ -234,8 +234,6 @@ module.exports = Scale.extend({ generateTickLabels: function(ticks) { var me = this; me._tickValues = ticks.map(t => t.value); - me.zeroLineIndex = me._tickValues.indexOf(0); - Scale.prototype.generateTickLabels.call(me, ticks); },
true
Other
chartjs
Chart.js
94afa634507036d8cd6b34d2c96eb225177b197e.json
Remove zeroLineIndex functionality (#6697) * Remove zeroLineIndex functionality * Remove docs * Code review updates
test/fixtures/core.scale/tick-drawing.json
@@ -19,8 +19,7 @@ "gridLines":{ "drawOnChartArea": false, "drawBorder": false, - "color": "rgba(0, 0, 0, 1)", - "zeroLineColor": "rgba(0, 0, 0, 1)" + "color": "rgba(0, 0, 0, 1)" } }, { "type": "category", @@ -32,8 +31,7 @@ "gridLines":{ "drawOnChartArea": false, "drawBorder": false, - "color": "rgba(0, 0, 0, 1)", - "zeroLineColor": "rgba(0, 0, 0, 1)" + "color": "rgba(0, 0, 0, 1)" } }], "yAxes": [{
true
Other
chartjs
Chart.js
94afa634507036d8cd6b34d2c96eb225177b197e.json
Remove zeroLineIndex functionality (#6697) * Remove zeroLineIndex functionality * Remove docs * Code review updates
test/specs/scale.category.tests.js
@@ -29,10 +29,6 @@ describe('Category scale tests', function() { lineWidth: 1, offsetGridLines: false, display: true, - zeroLineColor: 'rgba(0,0,0,0.25)', - zeroLineWidth: 1, - zeroLineBorderDash: [], - zeroLineBorderDashOffset: 0.0, borderDash: [], borderDashOffset: 0.0 },
true
Other
chartjs
Chart.js
94afa634507036d8cd6b34d2c96eb225177b197e.json
Remove zeroLineIndex functionality (#6697) * Remove zeroLineIndex functionality * Remove docs * Code review updates
test/specs/scale.linear.tests.js
@@ -23,10 +23,6 @@ describe('Linear Scale', function() { lineWidth: 1, offsetGridLines: false, display: true, - zeroLineColor: 'rgba(0,0,0,0.25)', - zeroLineWidth: 1, - zeroLineBorderDash: [], - zeroLineBorderDashOffset: 0.0, borderDash: [], borderDashOffset: 0.0 },
true
Other
chartjs
Chart.js
94afa634507036d8cd6b34d2c96eb225177b197e.json
Remove zeroLineIndex functionality (#6697) * Remove zeroLineIndex functionality * Remove docs * Code review updates
test/specs/scale.logarithmic.tests.js
@@ -22,10 +22,6 @@ describe('Logarithmic Scale tests', function() { lineWidth: 1, offsetGridLines: false, display: true, - zeroLineColor: 'rgba(0,0,0,0.25)', - zeroLineWidth: 1, - zeroLineBorderDash: [], - zeroLineBorderDashOffset: 0.0, borderDash: [], borderDashOffset: 0.0 },
true
Other
chartjs
Chart.js
94afa634507036d8cd6b34d2c96eb225177b197e.json
Remove zeroLineIndex functionality (#6697) * Remove zeroLineIndex functionality * Remove docs * Code review updates
test/specs/scale.radialLinear.tests.js
@@ -34,10 +34,6 @@ describe('Test the radial linear scale', function() { lineWidth: 1, offsetGridLines: false, display: true, - zeroLineColor: 'rgba(0,0,0,0.25)', - zeroLineWidth: 1, - zeroLineBorderDash: [], - zeroLineBorderDashOffset: 0.0, borderDash: [], borderDashOffset: 0.0 },
true
Other
chartjs
Chart.js
94afa634507036d8cd6b34d2c96eb225177b197e.json
Remove zeroLineIndex functionality (#6697) * Remove zeroLineIndex functionality * Remove docs * Code review updates
test/specs/scale.time.tests.js
@@ -69,10 +69,6 @@ describe('Time scale tests', function() { lineWidth: 1, offsetGridLines: false, display: true, - zeroLineColor: 'rgba(0,0,0,0.25)', - zeroLineWidth: 1, - zeroLineBorderDash: [], - zeroLineBorderDashOffset: 0.0, borderDash: [], borderDashOffset: 0.0 },
true
Other
chartjs
Chart.js
aff7d411404fe3499b9cd11333fb45d5922cdf91.json
Add cross-platform CI (#6670) * Linux and Windows CI with GitHub Actions * Add karma-edge-launcher * Add edge configuration to karma.conf.js * Support --browsers on the command line for karma tests * Add macOS CI builds * Add karma-safari-private-launcher * Document browser specification for tests
.github/workflows/ci.yml
@@ -0,0 +1,49 @@ +name: CI + +on: [push] + +jobs: + build: + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + fail-fast: false + + steps: + - uses: actions/checkout@v1 + - name: Use Node.js + uses: actions/setup-node@v1 + - name: Setup xvfb + run: | + Xvfb :99 -screen 0 1024x768x24 & + echo "::set-env name=DISPLAY:::99.0" + if: runner.os == 'Linux' + - name: Install gulp + run: npm install --global gulp + if: runner.os == 'macOS' + - name: Install chrome + run: | + brew update + brew cask install google-chrome + if: runner.os == 'macOS' + - name: Select browsers + run: | + if [ "${{ runner.os }}" == "macOS" ]; then + echo "::set-env name=BROWSERS::--browsers chrome" + fi + shell: bash + - name: Build and Test + run: | + npm install + gulp build + gulp test --coverage ${BROWSERS} + - name: Package + run: | + gulp docs + gulp package + gulp bower + - name: Publish Test Results + run: cat ./coverage/lcov.info | ./node_modules/.bin/coveralls + continue-on-error: true
true
Other
chartjs
Chart.js
aff7d411404fe3499b9cd11333fb45d5922cdf91.json
Add cross-platform CI (#6670) * Linux and Windows CI with GitHub Actions * Add karma-edge-launcher * Add edge configuration to karma.conf.js * Support --browsers on the command line for karma tests * Add macOS CI builds * Add karma-safari-private-launcher * Document browser specification for tests
docs/developers/contributing.md
@@ -36,6 +36,7 @@ The following commands are now available from the repository root: > gulp unittest --coverage // run tests and generate coverage reports in ./coverage > gulp lint // perform code linting (ESLint) > gulp test // perform code linting and run unit tests +> gulp test --browsers ... // test with specified browsers (comma-separated) > gulp docs // build the documentation in ./dist/docs > gulp docs --watch // starts the gitbook live reloaded server ```
true
Other
chartjs
Chart.js
aff7d411404fe3499b9cd11333fb45d5922cdf91.json
Add cross-platform CI (#6670) * Linux and Windows CI with GitHub Actions * Add karma-edge-launcher * Add edge configuration to karma.conf.js * Support --browsers on the command line for karma tests * Add macOS CI builds * Add karma-safari-private-launcher * Document browser specification for tests
gulpfile.js
@@ -145,6 +145,7 @@ function unittestTask(done) { args: { coverage: !!argv.coverage, inputs: (argv.inputs || 'test/specs/**/*.js').split(';'), + browsers: (argv.browsers || 'chrome,firefox').split(','), watch: argv.watch } },
true
Other
chartjs
Chart.js
aff7d411404fe3499b9cd11333fb45d5922cdf91.json
Add cross-platform CI (#6670) * Linux and Windows CI with GitHub Actions * Add karma-edge-launcher * Add edge configuration to karma.conf.js * Support --browsers on the command line for karma tests * Add macOS CI builds * Add karma-safari-private-launcher * Document browser specification for tests
karma.conf.js
@@ -22,7 +22,7 @@ module.exports = function(karma) { karma.set({ frameworks: ['jasmine'], reporters: ['progress', 'kjhtml'], - browsers: ['chrome', 'firefox'], + browsers: args.browsers, logLevel: karma.LOG_WARN, // Explicitly disable hardware acceleration to make image @@ -40,6 +40,12 @@ module.exports = function(karma) { prefs: { 'layers.acceleration.disabled': true } + }, + safari: { + base: 'SafariPrivate' + }, + edge: { + base: 'Edge' } },
true
Other
chartjs
Chart.js
aff7d411404fe3499b9cd11333fb45d5922cdf91.json
Add cross-platform CI (#6670) * Linux and Windows CI with GitHub Actions * Add karma-edge-launcher * Add edge configuration to karma.conf.js * Support --browsers on the command line for karma tests * Add macOS CI builds * Add karma-safari-private-launcher * Document browser specification for tests
package-lock.json
@@ -938,6 +938,12 @@ "buffer-equal": "^1.0.0" } }, + "applescript": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/applescript/-/applescript-1.0.0.tgz", + "integrity": "sha1-u4evVoytA0pOSMS9r2Bno6JwExc=", + "dev": true + }, "archy": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/archy/-/archy-1.0.0.tgz", @@ -2969,6 +2975,12 @@ "safer-buffer": "^2.1.0" } }, + "edge-launcher": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/edge-launcher/-/edge-launcher-1.2.2.tgz", + "integrity": "sha1-60Cq+9Bnpup27/+rBke81VCbN7I=", + "dev": true + }, "editions": { "version": "1.3.4", "resolved": "https://registry.npmjs.org/editions/-/editions-1.3.4.tgz", @@ -6057,6 +6069,15 @@ "source-map": "^0.5.1" } }, + "karma-edge-launcher": { + "version": "0.4.2", + "resolved": "https://registry.npmjs.org/karma-edge-launcher/-/karma-edge-launcher-0.4.2.tgz", + "integrity": "sha512-YAJZb1fmRcxNhMIWYsjLuxwODBjh2cSHgTW/jkVmdpGguJjLbs9ZgIK/tEJsMQcBLUkO+yO4LBbqYxqgGW2HIw==", + "dev": true, + "requires": { + "edge-launcher": "1.2.2" + } + }, "karma-firefox-launcher": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/karma-firefox-launcher/-/karma-firefox-launcher-1.2.0.tgz", @@ -6189,6 +6210,15 @@ } } }, + "karma-safari-private-launcher": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/karma-safari-private-launcher/-/karma-safari-private-launcher-1.0.0.tgz", + "integrity": "sha1-d/zpBIgrNBvRNBWv01KcuSJkC0M=", + "dev": true, + "requires": { + "applescript": "^1.0.0" + } + }, "kind-of": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz",
true
Other
chartjs
Chart.js
aff7d411404fe3499b9cd11333fb45d5922cdf91.json
Add cross-platform CI (#6670) * Linux and Windows CI with GitHub Actions * Add karma-edge-launcher * Add edge configuration to karma.conf.js * Support --browsers on the command line for karma tests * Add macOS CI builds * Add karma-safari-private-launcher * Document browser specification for tests
package.json
@@ -53,10 +53,12 @@ "karma": "^4.0.0", "karma-chrome-launcher": "^3.0.0", "karma-coverage": "^2.0.0", + "karma-edge-launcher": "^0.4.2", "karma-firefox-launcher": "^1.0.1", "karma-jasmine": "^2.0.1", "karma-jasmine-html-reporter": "^1.4.0", "karma-rollup-preprocessor": "^7.0.0", + "karma-safari-private-launcher": "^1.0.0", "merge-stream": "^1.0.1", "pixelmatch": "^5.0.0", "rollup": "^1.0.0",
true
Other
chartjs
Chart.js
b90552b9ca851bf8567acca5176597e6f316a68f.json
Remove check that is always true (#6701)
src/core/core.scale.js
@@ -1012,11 +1012,6 @@ var Scale = Element.extend({ for (i = 0; i < ticksLength; ++i) { tick = ticks[i] || {}; - // autoskipper skipped this tick (#4635) - if (isNullOrUndef(tick.label) && i < ticks.length) { - continue; - } - if (i === me.zeroLineIndex && options.offset === offsetGridLines) { // Draw the first index specially lineWidth = gridLines.zeroLineWidth; @@ -1103,11 +1098,6 @@ var Scale = Element.extend({ tick = ticks[i]; label = tick.label; - // autoskipper skipped this tick (#4635) - if (isNullOrUndef(label)) { - continue; - } - pixel = me.getPixelForTick(tick._index || i) + optionTicks.labelOffset; font = tick.major ? fonts.major : fonts.minor; lineHeight = font.lineHeight;
false
Other
chartjs
Chart.js
e42413f3e81703aae14272198a5b4ec54136bc15.json
Remove unused model properties (#6691) * Remove unused model properties * Add to migration guide
docs/getting-started/v3-migration.md
@@ -66,6 +66,11 @@ Chart.js is no longer providing the `Chart.bundle.js` and `Chart.bundle.min.js`. * Made `scale.handleDirectionalChanges` private * Made `scale.tickValues` private +#### Removal of private APIs + +* `_model.datasetLabel` +* `_model.label` + ### Renamed * `helpers.clear` was renamed to `helpers.canvas.clear`
true
Other
chartjs
Chart.js
e42413f3e81703aae14272198a5b4ec54136bc15.json
Remove unused model properties (#6691) * Remove unused model properties * Add to migration guide
src/controllers/controller.bar.js
@@ -238,7 +238,6 @@ module.exports = DatasetController.extend({ updateElement: function(rectangle, index, reset) { var me = this; - var dataset = me.getDataset(); var options = me._resolveDataElementOptions(index); rectangle._datasetIndex = me.index; @@ -247,9 +246,7 @@ module.exports = DatasetController.extend({ backgroundColor: options.backgroundColor, borderColor: options.borderColor, borderSkipped: options.borderSkipped, - borderWidth: options.borderWidth, - datasetLabel: dataset.label, - label: me.chart.data.labels[index] + borderWidth: options.borderWidth }; // all borders are drawn for floating bar
true
Other
chartjs
Chart.js
e42413f3e81703aae14272198a5b4ec54136bc15.json
Remove unused model properties (#6691) * Remove unused model properties * Add to migration guide
src/controllers/controller.doughnut.js
@@ -232,7 +232,6 @@ module.exports = DatasetController.extend({ var centerY = (chartArea.top + chartArea.bottom) / 2; var startAngle = opts.rotation; // non reset case handled later var endAngle = opts.rotation; // non reset case handled later - var dataset = me.getDataset(); var circumference = reset && animationOpts.animateRotate ? 0 : arc.hidden ? 0 : me.calculateCircumference(arc._val * opts.circumference / DOUBLE_PI); var innerRadius = reset && animationOpts.animateScale ? 0 : me.innerRadius; var outerRadius = reset && animationOpts.animateScale ? 0 : me.outerRadius; @@ -255,8 +254,7 @@ module.exports = DatasetController.extend({ endAngle: endAngle, circumference: circumference, outerRadius: outerRadius, - innerRadius: innerRadius, - label: helpers.valueAtIndexOrDefault(dataset.label, index, chart.data.labels[index]) + innerRadius: innerRadius } });
true
Other
chartjs
Chart.js
e42413f3e81703aae14272198a5b4ec54136bc15.json
Remove unused model properties (#6691) * Remove unused model properties * Add to migration guide
src/controllers/controller.polarArea.js
@@ -187,7 +187,6 @@ module.exports = DatasetController.extend({ var opts = chart.options; var animationOpts = opts.animation; var scale = chart.scale; - var labels = chart.data.labels; var centerX = scale.xCenter; var centerY = scale.yCenter; @@ -217,8 +216,7 @@ module.exports = DatasetController.extend({ innerRadius: 0, outerRadius: reset ? resetRadius : distance, startAngle: reset && animationOpts.animateRotate ? datasetStartAngle : startAngle, - endAngle: reset && animationOpts.animateRotate ? datasetStartAngle : endAngle, - label: helpers.valueAtIndexOrDefault(labels, index, labels[index]) + endAngle: reset && animationOpts.animateRotate ? datasetStartAngle : endAngle } });
true
Other
chartjs
Chart.js
e42413f3e81703aae14272198a5b4ec54136bc15.json
Remove unused model properties (#6691) * Remove unused model properties * Add to migration guide
test/specs/controller.bar.tests.js
@@ -746,8 +746,6 @@ describe('Chart.controllers.bar', function() { expect(meta.data[i]._model.base).toBeCloseToPixel(1024); expect(meta.data[i]._model.width).toBeCloseToPixel(46); expect(meta.data[i]._model).toEqual(jasmine.objectContaining({ - datasetLabel: chart.data.datasets[1].label, - label: chart.data.labels[i], backgroundColor: 'red', borderSkipped: 'top', borderColor: 'blue',
true
Other
chartjs
Chart.js
e42413f3e81703aae14272198a5b4ec54136bc15.json
Remove unused model properties (#6691) * Remove unused model properties * Add to migration guide
test/specs/controller.doughnut.tests.js
@@ -114,7 +114,6 @@ describe('Chart.controllers.doughnut', function() { expect(meta.data[i]._model).toEqual(jasmine.objectContaining({ startAngle: Math.PI * -0.5, endAngle: Math.PI * -0.5, - label: chart.data.labels[i], backgroundColor: 'rgb(255, 0, 0)', borderColor: 'rgb(0, 0, 255)', borderWidth: 2 @@ -137,7 +136,6 @@ describe('Chart.controllers.doughnut', function() { expect(meta.data[i]._model.startAngle).toBeCloseTo(expected.s, 8); expect(meta.data[i]._model.endAngle).toBeCloseTo(expected.e, 8); expect(meta.data[i]._model).toEqual(jasmine.objectContaining({ - label: chart.data.labels[i], backgroundColor: 'rgb(255, 0, 0)', borderColor: 'rgb(0, 0, 255)', borderWidth: 2
true
Other
chartjs
Chart.js
e42413f3e81703aae14272198a5b4ec54136bc15.json
Remove unused model properties (#6691) * Remove unused model properties * Add to migration guide
test/specs/controller.polarArea.tests.js
@@ -117,8 +117,7 @@ describe('Chart.controllers.polarArea', function() { expect(meta.data[i]._model).toEqual(jasmine.objectContaining({ backgroundColor: 'rgb(255, 0, 0)', borderColor: 'rgb(0, 255, 0)', - borderWidth: 1.2, - label: chart.data.labels[i] + borderWidth: 1.2 })); }); @@ -186,8 +185,7 @@ describe('Chart.controllers.polarArea', function() { expect(meta.data[i]._model).toEqual(jasmine.objectContaining({ backgroundColor: 'rgb(255, 0, 0)', borderColor: 'rgb(0, 255, 0)', - borderWidth: 1.2, - label: chart.data.labels[i] + borderWidth: 1.2 })); }); });
true
Other
chartjs
Chart.js
7a2160461df1541993f1ba2936d87d5292dd14be.json
Remove unused Element methods (#6694)
docs/getting-started/v3-migration.md
@@ -53,13 +53,16 @@ Chart.js is no longer providing the `Chart.bundle.js` and `Chart.bundle.min.js`. * `helpers.numberOfLabelLines` * `helpers.removeEvent` * `helpers.scaleMerge` -* `scale.getRightValue` -* `scale.mergeTicksOptions` -* `scale.ticksAsNumbers` +* `Scale.getRightValue` +* `Scale.mergeTicksOptions` +* `Scale.ticksAsNumbers` * `Chart.Controller` * `Chart.chart.chart` * `Chart.types` * `Line.calculatePointY` +* `Element.getArea` +* `Element.height` +* `Element.inLabelRange` * Made `scale.handleDirectionalChanges` private * Made `scale.tickValues` private
true
Other
chartjs
Chart.js
7a2160461df1541993f1ba2936d87d5292dd14be.json
Remove unused Element methods (#6694)
src/elements/element.arc.js
@@ -94,15 +94,6 @@ function drawBorder(ctx, vm, arc) { module.exports = Element.extend({ _type: 'arc', - inLabelRange: function(mouseX) { - var vm = this._view; - - if (vm) { - return (Math.pow(mouseX - vm.x, 2) < Math.pow(vm.radius + vm.hoverRadius, 2)); - } - return false; - }, - inRange: function(chartX, chartY) { var vm = this._view; @@ -143,11 +134,6 @@ module.exports = Element.extend({ }; }, - getArea: function() { - var vm = this._view; - return Math.PI * ((vm.endAngle - vm.startAngle) / (2 * Math.PI)) * (Math.pow(vm.outerRadius, 2) - Math.pow(vm.innerRadius, 2)); - }, - tooltipPosition: function() { var vm = this._view; var centreAngle = vm.startAngle + ((vm.endAngle - vm.startAngle) / 2);
true
Other
chartjs
Chart.js
7a2160461df1541993f1ba2936d87d5292dd14be.json
Remove unused Element methods (#6694)
src/elements/element.point.js
@@ -42,7 +42,6 @@ module.exports = Element.extend({ return vm ? ((Math.pow(mouseX - vm.x, 2) + Math.pow(mouseY - vm.y, 2)) < Math.pow(vm.hitRadius + vm.radius, 2)) : false; }, - inLabelRange: xRange, inXRange: xRange, inYRange: yRange, @@ -54,10 +53,6 @@ module.exports = Element.extend({ }; }, - getArea: function() { - return Math.PI * Math.pow(this._view.radius, 2); - }, - tooltipPosition: function() { var vm = this._view; return {
true
Other
chartjs
Chart.js
7a2160461df1541993f1ba2936d87d5292dd14be.json
Remove unused Element methods (#6694)
src/elements/element.rectangle.js
@@ -157,22 +157,10 @@ module.exports = Element.extend({ ctx.restore(); }, - height: function() { - var vm = this._view; - return vm.base - vm.y; - }, - inRange: function(mouseX, mouseY) { return inRange(this._view, mouseX, mouseY); }, - inLabelRange: function(mouseX, mouseY) { - var vm = this._view; - return isVertical(vm) - ? inRange(vm, mouseX, null) - : inRange(vm, null, mouseY); - }, - inXRange: function(mouseX) { return inRange(this._view, mouseX, null); }, @@ -195,14 +183,6 @@ module.exports = Element.extend({ return {x: x, y: y}; }, - getArea: function() { - var vm = this._view; - - return isVertical(vm) - ? vm.width * Math.abs(vm.y - vm.base) - : vm.height * Math.abs(vm.x - vm.base); - }, - tooltipPosition: function() { var vm = this._view; return {
true
Other
chartjs
Chart.js
7a2160461df1541993f1ba2936d87d5292dd14be.json
Remove unused Element methods (#6694)
test/specs/element.arc.tests.js
@@ -18,10 +18,6 @@ describe('Arc element tests', function() { _index: 1 }); - // Make sure we can run these before the view is added - expect(arc.inRange(2, 2)).toBe(false); - expect(arc.inLabelRange(2)).toBe(false); - // Mock out the view as if the controller put it there arc._view = { startAngle: 0, @@ -60,25 +56,6 @@ describe('Arc element tests', function() { expect(pos.y).toBeCloseTo(0.5); }); - it ('should get the area', function() { - var arc = new Chart.elements.Arc({ - _datasetIndex: 2, - _index: 1 - }); - - // Mock out the view as if the controller put it there - arc._view = { - startAngle: 0, - endAngle: Math.PI / 2, - x: 0, - y: 0, - innerRadius: 0, - outerRadius: Math.sqrt(2), - }; - - expect(arc.getArea()).toBeCloseTo(0.5 * Math.PI, 6); - }); - it ('should get the center', function() { var arc = new Chart.elements.Arc({ _datasetIndex: 2,
true
Other
chartjs
Chart.js
7a2160461df1541993f1ba2936d87d5292dd14be.json
Remove unused Element methods (#6694)
test/specs/element.point.tests.js
@@ -20,7 +20,6 @@ describe('Chart.elements.Point', function() { // Safely handles if these are called before the viewmodel is instantiated expect(point.inRange(5)).toBe(false); - expect(point.inLabelRange(5)).toBe(false); // Attach a view object as if we were the controller point._view = { @@ -34,13 +33,6 @@ describe('Chart.elements.Point', function() { expect(point.inRange(10, 10)).toBe(false); expect(point.inRange(10, 5)).toBe(false); expect(point.inRange(5, 5)).toBe(false); - - expect(point.inLabelRange(5)).toBe(false); - expect(point.inLabelRange(7)).toBe(true); - expect(point.inLabelRange(10)).toBe(true); - expect(point.inLabelRange(12)).toBe(true); - expect(point.inLabelRange(15)).toBe(false); - expect(point.inLabelRange(20)).toBe(false); }); it ('should get the correct tooltip position', function() { @@ -64,20 +56,6 @@ describe('Chart.elements.Point', function() { }); }); - it('should get the correct area', function() { - var point = new Chart.elements.Point({ - _datasetIndex: 2, - _index: 1 - }); - - // Attach a view object as if we were the controller - point._view = { - radius: 2, - }; - - expect(point.getArea()).toEqual(Math.PI * 4); - }); - it('should get the correct center point', function() { var point = new Chart.elements.Point({ _datasetIndex: 2,
true
Other
chartjs
Chart.js
7a2160461df1541993f1ba2936d87d5292dd14be.json
Remove unused Element methods (#6694)
test/specs/element.rectangle.tests.js
@@ -20,7 +20,6 @@ describe('Rectangle element tests', function() { // Safely handles if these are called before the viewmodel is instantiated expect(rectangle.inRange(5)).toBe(false); - expect(rectangle.inLabelRange(5)).toBe(false); // Attach a view object as if we were the controller rectangle._view = { @@ -35,13 +34,6 @@ describe('Rectangle element tests', function() { expect(rectangle.inRange(10, 16)).toBe(false); expect(rectangle.inRange(5, 5)).toBe(false); - expect(rectangle.inLabelRange(5)).toBe(false); - expect(rectangle.inLabelRange(7)).toBe(false); - expect(rectangle.inLabelRange(10)).toBe(true); - expect(rectangle.inLabelRange(12)).toBe(true); - expect(rectangle.inLabelRange(15)).toBe(false); - expect(rectangle.inLabelRange(20)).toBe(false); - // Test when the y is below the base (negative bar) var negativeRectangle = new Chart.elements.Rectangle({ _datasetIndex: 2, @@ -61,38 +53,6 @@ describe('Rectangle element tests', function() { expect(negativeRectangle.inRange(10, -5)).toBe(true); }); - it('should get the correct height', function() { - var rectangle = new Chart.elements.Rectangle({ - _datasetIndex: 2, - _index: 1 - }); - - // Attach a view object as if we were the controller - rectangle._view = { - base: 0, - width: 4, - x: 10, - y: 15 - }; - - expect(rectangle.height()).toBe(-15); - - // Test when the y is below the base (negative bar) - var negativeRectangle = new Chart.elements.Rectangle({ - _datasetIndex: 2, - _index: 1 - }); - - // Attach a view object as if we were the controller - negativeRectangle._view = { - base: -10, - width: 4, - x: 10, - y: -15 - }; - expect(negativeRectangle.height()).toBe(5); - }); - it('should get the correct tooltip position', function() { var rectangle = new Chart.elements.Rectangle({ _datasetIndex: 2, @@ -132,40 +92,6 @@ describe('Rectangle element tests', function() { }); }); - it('should get the correct vertical area', function() { - var rectangle = new Chart.elements.Rectangle({ - _datasetIndex: 2, - _index: 1 - }); - - // Attach a view object as if we were the controller - rectangle._view = { - base: 0, - width: 4, - x: 10, - y: 15 - }; - - expect(rectangle.getArea()).toEqual(60); - }); - - it('should get the correct horizontal area', function() { - var rectangle = new Chart.elements.Rectangle({ - _datasetIndex: 2, - _index: 1 - }); - - // Attach a view object as if we were the controller - rectangle._view = { - base: 0, - height: 4, - x: 10, - y: 15 - }; - - expect(rectangle.getArea()).toEqual(40); - }); - it('should get the center', function() { var rectangle = new Chart.elements.Rectangle({ _datasetIndex: 2,
true
Other
chartjs
Chart.js
f0fb2c65b1ba9b0dbc60acac611daec3ee54b320.json
Remove tension option backwards compatibility (#6692)
docs/getting-started/v3-migration.md
@@ -29,6 +29,7 @@ Chart.js is no longer providing the `Chart.bundle.js` and `Chart.bundle.min.js`. ### Options +* The dataset option `tension` was renamed to `lineTension` * `scales.[x/y]Axes.barPercentage` was moved to dataset option `barPercentage` * `scales.[x/y]Axes.barThickness` was moved to dataset option `barThickness` * `scales.[x/y]Axes.categoryPercentage` was moved to dataset option `categoryPercentage`
true
Other
chartjs
Chart.js
f0fb2c65b1ba9b0dbc60acac611daec3ee54b320.json
Remove tension option backwards compatibility (#6692)
src/controllers/controller.line.js
@@ -82,11 +82,6 @@ module.exports = DatasetController.extend({ // Update Line if (showLine) { - // Compatibility: If the properties are defined with only the old name, use those values - if (config.tension !== undefined && config.lineTension === undefined) { - config.lineTension = config.tension; - } - // Utility line._datasetIndex = me.index; // Data
true
Other
chartjs
Chart.js
83d447f317cebeb8c2445abfc8b5e17e0187e698.json
Fix doughnut sample (#6690)
src/core/core.controller.js
@@ -449,7 +449,7 @@ helpers.extend(Chart.prototype, /** @lends Chart */ { }, /** - * Resets the chart back to it's state before the initial animation + * Resets the chart back to its state before the initial animation */ reset: function() { this.resetElements(); @@ -460,6 +460,8 @@ helpers.extend(Chart.prototype, /** @lends Chart */ { var me = this; var i, ilen; + config = config || {}; + updateConfig(me); // plugins options references might have change, let's invalidate the cache
false
Other
chartjs
Chart.js
dd8d267956686cd2237134157e2e1b7bb8b2c244.json
Remove bundled builds (#6680)
docs/developers/README.md
@@ -13,8 +13,8 @@ Latest documentation and samples, including unreleased features, are available a Latest builds are available for testing at: + - https://www.chartjs.org/dist/master/Chart.js - https://www.chartjs.org/dist/master/Chart.min.js - - https://www.chartjs.org/dist/master/Chart.bundle.min.js > Note: Development builds are currently only available via HTTP, so in order to include them in [JSFiddle](https://jsfiddle.net) or [CodePen](https://codepen.io), you need to access these tools via HTTP as well.
true
Other
chartjs
Chart.js
dd8d267956686cd2237134157e2e1b7bb8b2c244.json
Remove bundled builds (#6680)
docs/getting-started/installation.md
@@ -38,21 +38,3 @@ https://www.jsdelivr.com/package/npm/chart.js?path=dist You can download the latest version of [Chart.js on GitHub](https://github.com/chartjs/Chart.js/releases/latest). If you download or clone the repository, you must [build](../developers/contributing.md#building-and-testing) Chart.js to generate the dist files. Chart.js no longer comes with prebuilt release versions, so an alternative option to downloading the repo is **strongly** advised. - -## Selecting the Correct Build - -Chart.js provides two different builds for you to choose: **Stand-Alone Build**, **Bundled Build**. - -### Stand-Alone Build -Files: -* `dist/Chart.js` -* `dist/Chart.min.js` - -The stand-alone build includes Chart.js as well as the color parsing library. If this version is used, you are required to include [Moment.js](https://momentjs.com/) before Chart.js for the functionality of the time axis. - -### Bundled Build -Files: -* `dist/Chart.bundle.js` -* `dist/Chart.bundle.min.js` - -The bundled build includes Moment.js in a single file. You should use this version if you require time axes and want to include a single file. You should not use this build if your application already included Moment.js. Otherwise, Moment.js will be included twice which results in increasing page load time and possible version compatibility issues. The Moment.js version in the bundled build is private to Chart.js so if you want to use Moment.js yourself, it's better to use Chart.js (non bundled) and import Moment.js manually.
true
Other
chartjs
Chart.js
dd8d267956686cd2237134157e2e1b7bb8b2c244.json
Remove bundled builds (#6680)
docs/getting-started/v3-migration.md
@@ -2,7 +2,11 @@ Chart.js 3.0 introduces a number of breaking changes. Chart.js 2.0 was released in April 2016. In the years since then, as Chart.js has grown in popularity and feature set, we've learned some lessons about how to better create a charting library. In order to improve performance, offer new features, and improve maintainability it was necessary to break backwards compatibility, but we aimed to do so only when necessary. -## Eng user migration +## Setup + +Chart.js is no longer providing the `Chart.bundle.js` and `Chart.bundle.min.js`. Please see the [installation](installation.md) and [integration](integration.md) docs for details on the recommended way to setup Chart.js if you were using these builds. + +## End user migration ### Ticks
true
Other
chartjs
Chart.js
dd8d267956686cd2237134157e2e1b7bb8b2c244.json
Remove bundled builds (#6680)
rollup.config.js
@@ -17,7 +17,7 @@ const banner = `/*! */`; module.exports = [ - // ES6 builds (excluding moment) + // ES6 builds // dist/Chart.esm.min.js // dist/Chart.esm.js { @@ -77,7 +77,7 @@ module.exports = [ 'moment' ] }, - // UMD builds (excluding moment) + // UMD builds // dist/Chart.min.js // dist/Chart.js { @@ -142,96 +142,5 @@ module.exports = [ external: [ 'moment' ] - }, - - // ES6 builds (including moment) - // dist/Chart.bundle.esm.min.js - // dist/Chart.bundle.esm.js - { - input: input, - plugins: [ - resolve(), - commonjs(), - babel({ - exclude: 'node_modules/**' - }), - stylesheet() - ], - output: { - name: 'Chart', - file: 'dist/Chart.bundle.esm.js', - banner: banner, - format: 'esm', - indent: false - } - }, - { - input: input, - plugins: [ - resolve(), - commonjs(), - babel({ - exclude: 'node_modules/**' - }), - stylesheet({ - minify: true - }), - terser({ - output: { - preamble: banner - } - }) - ], - output: { - name: 'Chart', - file: 'dist/Chart.bundle.esm.min.js', - format: 'esm', - indent: false - } - }, - // UMD builds (including moment) - // dist/Chart.bundle.min.js - // dist/Chart.bundle.js - { - input: input, - plugins: [ - resolve(), - commonjs(), - babel({ - exclude: 'node_modules/**' - }), - stylesheet() - ], - output: { - name: 'Chart', - file: 'dist/Chart.bundle.js', - banner: banner, - format: 'umd', - indent: false - } - }, - { - input: input, - plugins: [ - resolve(), - commonjs(), - babel({ - exclude: 'node_modules/**' - }), - stylesheet({ - minify: true - }), - terser({ - output: { - preamble: banner - } - }) - ], - output: { - name: 'Chart', - file: 'dist/Chart.bundle.min.js', - format: 'umd', - indent: false - } } ];
true
Other
chartjs
Chart.js
80587bb68dd7a1b5d6bea2f70b0362378bf27a62.json
Remove unused parameters (#6674)
src/core/core.controller.js
@@ -622,11 +622,10 @@ helpers.extend(Chart.prototype, /** @lends Chart */ { easing: config.easing || animationOptions.easing, render: function(chart, animationObject) { - var easingFunction = helpers.easing.effects[animationObject.easing]; - var currentStep = animationObject.currentStep; - var stepDecimal = currentStep / animationObject.numSteps; + const easingFunction = helpers.easing.effects[animationObject.easing]; + const stepDecimal = animationObject.currentStep / animationObject.numSteps; - chart.draw(easingFunction(stepDecimal), stepDecimal, currentStep); + chart.draw(easingFunction(stepDecimal)); }, onAnimationProgress: animationOptions.onProgress,
false
Other
chartjs
Chart.js
6942e9058c06494105b42f4efd18f80b2ab64ac1.json
Hide correct dataset from legend (#6667)
src/plugins/plugin.legend.js
@@ -53,13 +53,13 @@ defaults._set('global', { var options = chart.options.legend || {}; var usePointStyle = options.labels && options.labels.usePointStyle; - return chart._getSortedDatasetMetas().map(function(meta, i) { + return chart._getSortedDatasetMetas().map(function(meta) { var style = meta.controller.getStyle(usePointStyle ? 0 : undefined); return { text: datasets[meta.index].label, fillStyle: style.backgroundColor, - hidden: !chart.isDatasetVisible(i), + hidden: !chart.isDatasetVisible(meta.index), lineCap: style.borderCapStyle, lineDash: style.borderDash, lineDashOffset: style.borderDashOffset, @@ -70,7 +70,7 @@ defaults._set('global', { rotation: style.rotation, // Below is extra data used for toggling the datasets - datasetIndex: i + datasetIndex: meta.index }; }, this); }
false
Other
chartjs
Chart.js
0a873c0786934964c32b15e90fcb7cdc05a727e2.json
Fix polar area sample (#6665)
samples/charts/polar-area.html
@@ -29,8 +29,8 @@ var chartColors = window.chartColors; var color = Chart.helpers.color; var config = { + type: 'polarArea', data: { - type: 'polarArea', datasets: [{ data: [ randomScalingFactor(),
false
Other
chartjs
Chart.js
5452502b8ced16384d80d3ca70434d10717eb7cd.json
Add pointStyleWidth option for legend (#10412) * add pointStyleWidth for legend * add drawPointLegend to keep drawPoint signature
docs/configuration/legend.md
@@ -65,7 +65,8 @@ Namespace: `options.plugins.legend.labels` | `sort` | `function` | `null` | Sorts legend items. Type is : `sort(a: LegendItem, b: LegendItem, data: ChartData): number;`. Receives 3 parameters, two [Legend Items](#legend-item-interface) and the chart data. The return value of the function is a number that indicates the order of the two legend item parameters. The ordering matches the [return value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#description) of `Array.prototype.sort()` | [`pointStyle`](elements.md#point-styles) | [`pointStyle`](elements.md#types) | `'circle'` | If specified, this style of point is used for the legend. Only used if `usePointStyle` is true. | `textAlign` | `string` | `'center'` | Horizontal alignment of the label text. Options are: `'left'`, `'right'` or `'center'`. -| `usePointStyle` | `boolean` | `false` | Label style will match corresponding point style (size is based on the minimum value between boxWidth and font.size). +| `usePointStyle` | `boolean` | `false` | Label style will match corresponding point style (size is based on pointStyleWidth or the minimum value between boxWidth and font.size). +| `pointStyleWidth` | `number` | `null` | If `usePointStyle` is true, the width of the point style used for the legend (only for `circle`, `rect` and `line` point stlye). ## Legend Title Configuration
true
Other
chartjs
Chart.js
5452502b8ced16384d80d3ca70434d10717eb7cd.json
Add pointStyleWidth option for legend (#10412) * add pointStyleWidth for legend * add drawPointLegend to keep drawPoint signature
src/helpers/helpers.canvas.js
@@ -127,7 +127,11 @@ export function clearCanvas(canvas, ctx) { } export function drawPoint(ctx, options, x, y) { - let type, xOffset, yOffset, size, cornerRadius; + drawPointLegend(ctx, options, x, y, null); +} + +export function drawPointLegend(ctx, options, x, y, w) { + let type, xOffset, yOffset, size, cornerRadius, width; const style = options.pointStyle; const rotation = options.rotation; const radius = options.radius; @@ -154,7 +158,11 @@ export function drawPoint(ctx, options, x, y) { switch (style) { // Default includes circle default: - ctx.arc(x, y, radius, 0, TAU); + if (w) { + ctx.ellipse(x, y, w / 2, radius, 0, 0, TAU); + } else { + ctx.arc(x, y, radius, 0, TAU); + } ctx.closePath(); break; case 'triangle': @@ -186,7 +194,8 @@ export function drawPoint(ctx, options, x, y) { case 'rect': if (!rotation) { size = Math.SQRT1_2 * radius; - ctx.rect(x - size, y - size, 2 * size, 2 * size); + width = w ? w / 2 : size; + ctx.rect(x - width, y - size, 2 * width, 2 * size); break; } rad += QUARTER_PI; @@ -227,7 +236,7 @@ export function drawPoint(ctx, options, x, y) { ctx.lineTo(x - yOffset, y + xOffset); break; case 'line': - xOffset = Math.cos(rad) * radius; + xOffset = w ? w / 2 : Math.cos(rad) * radius; yOffset = Math.sin(rad) * radius; ctx.moveTo(x - xOffset, y - yOffset); ctx.lineTo(x + xOffset, y + yOffset);
true
Other
chartjs
Chart.js
5452502b8ced16384d80d3ca70434d10717eb7cd.json
Add pointStyleWidth option for legend (#10412) * add pointStyleWidth for legend * add drawPointLegend to keep drawPoint signature
src/plugins/plugin.legend.js
@@ -1,7 +1,7 @@ import defaults from '../core/core.defaults'; import Element from '../core/core.element'; import layouts from '../core/core.layouts'; -import {addRoundedRectPath, drawPoint, renderText} from '../helpers/helpers.canvas'; +import {addRoundedRectPath, drawPointLegend, renderText} from '../helpers/helpers.canvas'; import { callback as call, valueOrDefault, toFont, toPadding, getRtlAdapter, overrideTextDirection, restoreTextDirection, @@ -18,7 +18,7 @@ const getBoxSize = (labelOpts, fontSize) => { if (labelOpts.usePointStyle) { boxHeight = Math.min(boxHeight, fontSize); - boxWidth = Math.min(boxWidth, fontSize); + boxWidth = labelOpts.pointStyleWidth || Math.min(boxWidth, fontSize); } return { @@ -316,7 +316,7 @@ export class Legend extends Element { // Recalculate x and y for drawPoint() because its expecting // x and y to be center of figure (instead of top left) const drawOptions = { - radius: boxWidth * Math.SQRT2 / 2, + radius: boxHeight * Math.SQRT2 / 2, pointStyle: legendItem.pointStyle, rotation: legendItem.rotation, borderWidth: lineWidth @@ -325,7 +325,7 @@ export class Legend extends Element { const centerY = y + halfFontSize; // Draw pointStyle as legend symbol - drawPoint(ctx, drawOptions, centerX, centerY); + drawPointLegend(ctx, drawOptions, centerX, centerY, boxWidth); } else { // Draw box as legend symbol // Adjust position when boxHeight < fontSize (want it centered)
true
Other
chartjs
Chart.js
5452502b8ced16384d80d3ca70434d10717eb7cd.json
Add pointStyleWidth option for legend (#10412) * add pointStyleWidth for legend * add drawPointLegend to keep drawPoint signature
types/helpers/helpers.canvas.d.ts
@@ -18,6 +18,8 @@ export interface DrawPointOptions { export function drawPoint(ctx: CanvasRenderingContext2D, options: DrawPointOptions, x: number, y: number): void; +export function drawPointLegend(ctx: CanvasRenderingContext2D, options: DrawPointOptions, x: number, y: number, w: number): void; + /** * Converts the given font object into a CSS font string. * @param font a font object
true
Other
chartjs
Chart.js
e3b2b5279081b9040fdc493030e2c70ca8f71cc7.json
Fix crash with skipNull and uneven datasets (#10454)
src/controllers/controller.bar.js
@@ -390,41 +390,36 @@ export default class BarController extends DatasetController { * @private */ _getStacks(last, dataIndex) { - const meta = this._cachedMeta; - const iScale = meta.iScale; - const metasets = iScale.getMatchingVisibleMetas(this._type); + const {iScale} = this._cachedMeta; + const metasets = iScale.getMatchingVisibleMetas(this._type) + .filter(meta => meta.controller.options.grouped); const stacked = iScale.options.stacked; - const ilen = metasets.length; const stacks = []; - let i, item; - for (i = 0; i < ilen; ++i) { - item = metasets[i]; + const skipNull = (meta) => { + const parsed = meta.controller.getParsed(dataIndex); + const val = parsed && parsed[meta.vScale.axis]; - if (!item.controller.options.grouped) { - continue; + if (isNullOrUndef(val) || isNaN(val)) { + return true; } + }; - if (typeof dataIndex !== 'undefined') { - const val = item.controller.getParsed(dataIndex)[ - item.controller._cachedMeta.vScale.axis - ]; - - if (isNullOrUndef(val) || isNaN(val)) { - continue; - } + for (const meta of metasets) { + if (dataIndex !== undefined && skipNull(meta)) { + continue; } // stacked | meta.stack // | found | not found | undefined // false | x | x | x // true | | x | // undefined | | x | x - if (stacked === false || stacks.indexOf(item.stack) === -1 || - (stacked === undefined && item.stack === undefined)) { - stacks.push(item.stack); + if (stacked === false || stacks.indexOf(meta.stack) === -1 || + (stacked === undefined && meta.stack === undefined)) { + stacks.push(meta.stack); } - if (item.index === last) { + if (meta.index === last) { break; } }
true
Other
chartjs
Chart.js
e3b2b5279081b9040fdc493030e2c70ca8f71cc7.json
Fix crash with skipNull and uneven datasets (#10454)
test/specs/controller.bar.tests.js
@@ -1655,4 +1655,24 @@ describe('Chart.controllers.bar', function() { expect(ctx.getCalls().filter(x => x.name === 'clip').length).toEqual(0); }); }); + + it('should not crash with skipNull and uneven datasets', function() { + function unevenChart() { + window.acquireChart({ + type: 'bar', + data: { + labels: [1, 2], + datasets: [ + {data: [1, 2]}, + {data: [1, 2, 3]}, + ] + }, + options: { + skipNull: true, + } + }); + } + + expect(unevenChart).not.toThrow(); + }); });
true
Other
chartjs
Chart.js
58e736a0b98e021e5ac1d340aa52d63eb3606573.json
Update aspectRatio documentation (#10456)
docs/configuration/responsive.md
@@ -18,7 +18,7 @@ Namespace: `options` | ---- | ---- | ------- | ----------- | `responsive` | `boolean` | `true` | Resizes the chart canvas when its container does ([important note...](#important-note)). | `maintainAspectRatio` | `boolean` | `true` | Maintain the original canvas aspect ratio `(width / height)` when resizing. -| `aspectRatio` | `number` | `2` | Canvas aspect ratio (i.e. `width / height`, a value of 1 representing a square canvas). Note that this option is ignored if the height is explicitly defined either as attribute or via the style. +| `aspectRatio` | `number` | `1`\|`2` | Canvas aspect ratio (i.e. `width / height`, a value of 1 representing a square canvas). Note that this option is ignored if the height is explicitly defined either as attribute or via the style. The default value varies by chart type; Radial charts (doughnut, pie, polarArea, radar) default to `1` and others default to `2`. | `onResize` | `function` | `null` | Called when a resize occurs. Gets passed two arguments: the chart instance and the new size. | `resizeDelay` | `number` | `0` | Delay the resize update by the given amount of milliseconds. This can ease the resize process by debouncing the update of the elements.
false
Other
chartjs
Chart.js
0312697f38f88b3930f83e56d5850c4b4ff288c4.json
Add index to legendItem interface (#10436) * Add index to legendItem interface for doughnut, pie and polarArea charts. Make datasetIndex optional since the before named charts dont include it. * Remove test to check if datasetIndex has been set in generateLabels function for legend
types/index.esm.d.ts
@@ -2165,7 +2165,12 @@ export interface LegendItem { /** * Index of the associated dataset */ - datasetIndex: number; + datasetIndex?: number; + + /** + * Index the associated label in the labels array + */ + index?: number /** * Fill style of the legend box
true
Other
chartjs
Chart.js
0312697f38f88b3930f83e56d5850c4b4ff288c4.json
Add index to legendItem interface (#10436) * Add index to legendItem interface for doughnut, pie and polarArea charts. Make datasetIndex optional since the before named charts dont include it. * Remove test to check if datasetIndex has been set in generateLabels function for legend
types/tests/plugins/defaults.ts
@@ -9,10 +9,3 @@ defaults.plugins.legend.labels.generateLabels = function(chart) { text: 'test' }]; }; - -// @ts-expect-error Type '{ text: string; }[]' is not assignable to type 'LegendItem[]'. -defaults.plugins.legend.labels.generateLabels = function(chart) { - return [{ - text: 'test' - }]; -};
true
Other
chartjs
Chart.js
ebcaff15c2bd8aa74b1d8c1d082aee783f700f1b.json
Add option to include invisible points (#10362) * Add option to include invisible points * Minor fixes * Add doc for newly added option * Fix typo * Add test for newly added option * Improve description of the new option * Update docs/configuration/interactions.md Co-authored-by: Jacco van den Berg <39033624+LeeLenaleee@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Jacco van den Berg <39033624+LeeLenaleee@users.noreply.github.com> Co-authored-by: Yiwen Wang 🌊 <yiwwan@microsoft.com> Co-authored-by: Jacco van den Berg <39033624+LeeLenaleee@users.noreply.github.com>
docs/configuration/interactions.md
@@ -7,6 +7,7 @@ Namespace: `options.interaction`, the global interaction configuration is at `Ch | `mode` | `string` | `'nearest'` | Sets which elements appear in the interaction. See [Interaction Modes](#modes) for details. | `intersect` | `boolean` | `true` | if true, the interaction mode only applies when the mouse position intersects an item on the chart. | `axis` | `string` | `'x'` | Can be set to `'x'`, `'y'`, `'xy'` or `'r'` to define which directions are used in calculating distances. Defaults to `'x'` for `'index'` mode and `'xy'` in `dataset` and `'nearest'` modes. +| `includeInvisible` | `boolean` | `true` | if true, the invisible points that are outside of the chart area will also be included when evaluating interactions. By default, these options apply to both the hover and tooltip interactions. The same options can be set in the `options.hover` namespace, in which case they will only affect the hover interaction. Similarly, the options can be set in the `options.plugins.tooltip` namespace to independently configure the tooltip interactions.
true
Other
chartjs
Chart.js
ebcaff15c2bd8aa74b1d8c1d082aee783f700f1b.json
Add option to include invisible points (#10362) * Add option to include invisible points * Minor fixes * Add doc for newly added option * Fix typo * Add test for newly added option * Improve description of the new option * Update docs/configuration/interactions.md Co-authored-by: Jacco van den Berg <39033624+LeeLenaleee@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Jacco van den Berg <39033624+LeeLenaleee@users.noreply.github.com> Co-authored-by: Yiwen Wang 🌊 <yiwwan@microsoft.com> Co-authored-by: Jacco van den Berg <39033624+LeeLenaleee@users.noreply.github.com>
src/core/core.defaults.js
@@ -62,7 +62,8 @@ export class Defaults { this.indexAxis = 'x'; this.interaction = { mode: 'nearest', - intersect: true + intersect: true, + includeInvisible: false }; this.maintainAspectRatio = true; this.onHover = null;
true
Other
chartjs
Chart.js
ebcaff15c2bd8aa74b1d8c1d082aee783f700f1b.json
Add option to include invisible points (#10362) * Add option to include invisible points * Minor fixes * Add doc for newly added option * Fix typo * Add test for newly added option * Improve description of the new option * Update docs/configuration/interactions.md Co-authored-by: Jacco van den Berg <39033624+LeeLenaleee@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Jacco van den Berg <39033624+LeeLenaleee@users.noreply.github.com> Co-authored-by: Yiwen Wang 🌊 <yiwwan@microsoft.com> Co-authored-by: Jacco van den Berg <39033624+LeeLenaleee@users.noreply.github.com>
src/core/core.interaction.js
@@ -6,7 +6,7 @@ import {_isPointInArea} from '../helpers'; /** * @typedef { import("./core.controller").default } Chart * @typedef { import("../../types/index.esm").ChartEvent } ChartEvent - * @typedef {{axis?: string, intersect?: boolean}} InteractionOptions + * @typedef {{axis?: string, intersect?: boolean, includeInvisible?: boolean}} InteractionOptions * @typedef {{datasetIndex: number, index: number, element: import("./core.element").default}} InteractionItem * @typedef { import("../../types/index.esm").Point } Point */ @@ -88,17 +88,18 @@ function getDistanceMetricForAxis(axis) { * @param {Point} position - the point to be nearest to, in relative coordinates * @param {string} axis - the axis mode. x|y|xy|r * @param {boolean} [useFinalPosition] - use the element's animation target instead of current position + * @param {boolean} [includeInvisible] - include invisible points that are outside of the chart area * @return {InteractionItem[]} the nearest items */ -function getIntersectItems(chart, position, axis, useFinalPosition) { +function getIntersectItems(chart, position, axis, useFinalPosition, includeInvisible) { const items = []; - if (!chart.isPointInArea(position)) { + if (!includeInvisible && !chart.isPointInArea(position)) { return items; } const evaluationFunc = function(element, datasetIndex, index) { - if (!_isPointInArea(element, chart.chartArea, 0)) { + if (!includeInvisible && !_isPointInArea(element, chart.chartArea, 0)) { return; } if (element.inRange(position.x, position.y, useFinalPosition)) { @@ -141,9 +142,10 @@ function getNearestRadialItems(chart, position, axis, useFinalPosition) { * @param {string} axis - the axes along which to measure distance * @param {boolean} [intersect] - if true, only consider items that intersect the position * @param {boolean} [useFinalPosition] - use the element's animation target instead of current position + * @param {boolean} [includeInvisible] - include invisible points that are outside of the chart area * @return {InteractionItem[]} the nearest items */ -function getNearestCartesianItems(chart, position, axis, intersect, useFinalPosition) { +function getNearestCartesianItems(chart, position, axis, intersect, useFinalPosition, includeInvisible) { let items = []; const distanceMetric = getDistanceMetricForAxis(axis); let minDistance = Number.POSITIVE_INFINITY; @@ -155,7 +157,7 @@ function getNearestCartesianItems(chart, position, axis, intersect, useFinalPosi } const center = element.getCenterPoint(useFinalPosition); - const pointInArea = chart.isPointInArea(center); + const pointInArea = !!includeInvisible || chart.isPointInArea(center); if (!pointInArea && !inRange) { return; } @@ -181,16 +183,17 @@ function getNearestCartesianItems(chart, position, axis, intersect, useFinalPosi * @param {string} axis - the axes along which to measure distance * @param {boolean} [intersect] - if true, only consider items that intersect the position * @param {boolean} [useFinalPosition] - use the element's animation target instead of current position + * @param {boolean} [includeInvisible] - include invisible points that are outside of the chart area * @return {InteractionItem[]} the nearest items */ -function getNearestItems(chart, position, axis, intersect, useFinalPosition) { - if (!chart.isPointInArea(position)) { +function getNearestItems(chart, position, axis, intersect, useFinalPosition, includeInvisible) { + if (!includeInvisible && !chart.isPointInArea(position)) { return []; } return axis === 'r' && !intersect ? getNearestRadialItems(chart, position, axis, useFinalPosition) - : getNearestCartesianItems(chart, position, axis, intersect, useFinalPosition); + : getNearestCartesianItems(chart, position, axis, intersect, useFinalPosition, includeInvisible); } /** @@ -247,9 +250,10 @@ export default { const position = getRelativePosition(e, chart); // Default axis for index mode is 'x' to match old behaviour const axis = options.axis || 'x'; + const includeInvisible = options.includeInvisible || false; const items = options.intersect - ? getIntersectItems(chart, position, axis, useFinalPosition) - : getNearestItems(chart, position, axis, false, useFinalPosition); + ? getIntersectItems(chart, position, axis, useFinalPosition, includeInvisible) + : getNearestItems(chart, position, axis, false, useFinalPosition, includeInvisible); const elements = []; if (!items.length) { @@ -282,9 +286,10 @@ export default { dataset(chart, e, options, useFinalPosition) { const position = getRelativePosition(e, chart); const axis = options.axis || 'xy'; + const includeInvisible = options.includeInvisible || false; let items = options.intersect - ? getIntersectItems(chart, position, axis, useFinalPosition) : - getNearestItems(chart, position, axis, false, useFinalPosition); + ? getIntersectItems(chart, position, axis, useFinalPosition, includeInvisible) : + getNearestItems(chart, position, axis, false, useFinalPosition, includeInvisible); if (items.length > 0) { const datasetIndex = items[0].datasetIndex; @@ -311,7 +316,8 @@ export default { point(chart, e, options, useFinalPosition) { const position = getRelativePosition(e, chart); const axis = options.axis || 'xy'; - return getIntersectItems(chart, position, axis, useFinalPosition); + const includeInvisible = options.includeInvisible || false; + return getIntersectItems(chart, position, axis, useFinalPosition, includeInvisible); }, /** @@ -326,7 +332,8 @@ export default { nearest(chart, e, options, useFinalPosition) { const position = getRelativePosition(e, chart); const axis = options.axis || 'xy'; - return getNearestItems(chart, position, axis, options.intersect, useFinalPosition); + const includeInvisible = options.includeInvisible || false; + return getNearestItems(chart, position, axis, options.intersect, useFinalPosition, includeInvisible); }, /**
true
Other
chartjs
Chart.js
ebcaff15c2bd8aa74b1d8c1d082aee783f700f1b.json
Add option to include invisible points (#10362) * Add option to include invisible points * Minor fixes * Add doc for newly added option * Fix typo * Add test for newly added option * Improve description of the new option * Update docs/configuration/interactions.md Co-authored-by: Jacco van den Berg <39033624+LeeLenaleee@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Jacco van den Berg <39033624+LeeLenaleee@users.noreply.github.com> Co-authored-by: Yiwen Wang 🌊 <yiwwan@microsoft.com> Co-authored-by: Jacco van den Berg <39033624+LeeLenaleee@users.noreply.github.com>
src/platform/platform.dom.js
@@ -211,7 +211,7 @@ function createResizeObserver(chart, type, listener) { const width = entry.contentRect.width; const height = entry.contentRect.height; // When its container's display is set to 'none' the callback will be called with a - // size of (0, 0), which will cause the chart to lost its original height, so skip + // size of (0, 0), which will cause the chart to lose its original height, so skip // resizing in such case. if (width === 0 && height === 0) { return;
true
Other
chartjs
Chart.js
ebcaff15c2bd8aa74b1d8c1d082aee783f700f1b.json
Add option to include invisible points (#10362) * Add option to include invisible points * Minor fixes * Add doc for newly added option * Fix typo * Add test for newly added option * Improve description of the new option * Update docs/configuration/interactions.md Co-authored-by: Jacco van den Berg <39033624+LeeLenaleee@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Jacco van den Berg <39033624+LeeLenaleee@users.noreply.github.com> Co-authored-by: Yiwen Wang 🌊 <yiwwan@microsoft.com> Co-authored-by: Jacco van den Berg <39033624+LeeLenaleee@users.noreply.github.com>
test/specs/core.interaction.tests.js
@@ -870,5 +870,46 @@ describe('Core.Interaction', function() { const elements = Chart.Interaction.modes.point(chart, evt, {intersect: true}).map(item => item.element); expect(elements).not.toContain(firstElement); }); + + it ('out-of-range datapoints are shown in tooltip if included', function() { + let data = []; + for (let i = 0; i < 1000; i++) { + data.push({x: i, y: i}); + } + + const chart = window.acquireChart({ + type: 'scatter', + data: { + datasets: [{data}] + }, + options: { + scales: { + x: { + min: 2 + } + } + } + }); + + const meta0 = chart.getDatasetMeta(0); + const firstElement = meta0.data[0]; + + const evt = { + type: 'click', + chart: chart, + native: true, // needed otherwise it thinks its a DOM event + x: firstElement.x, + y: firstElement.y + }; + + const elements = Chart.Interaction.modes.point( + chart, + evt, + { + intersect: true, + includeInvisible: true + }).map(item => item.element); + expect(elements).toContain(firstElement); + }); }); });
true
Other
chartjs
Chart.js
ebcaff15c2bd8aa74b1d8c1d082aee783f700f1b.json
Add option to include invisible points (#10362) * Add option to include invisible points * Minor fixes * Add doc for newly added option * Fix typo * Add test for newly added option * Improve description of the new option * Update docs/configuration/interactions.md Co-authored-by: Jacco van den Berg <39033624+LeeLenaleee@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Jacco van den Berg <39033624+LeeLenaleee@users.noreply.github.com> Co-authored-by: Yiwen Wang 🌊 <yiwwan@microsoft.com> Co-authored-by: Jacco van den Berg <39033624+LeeLenaleee@users.noreply.github.com>
types/index.esm.d.ts
@@ -701,6 +701,7 @@ export const defaults: Defaults; export interface InteractionOptions { axis?: string; intersect?: boolean; + includeInvisible?: boolean; } export interface InteractionItem { @@ -1434,6 +1435,12 @@ export interface CoreInteractionOptions { * Defines which directions are used in calculating distances. Defaults to 'x' for 'index' mode and 'xy' in dataset and 'nearest' modes. */ axis: InteractionAxis; + + /** + * if true, the invisible points that are outside of the chart area will also be included when evaluating interactions. + * @default false + */ + includeInvisible: boolean; } export interface CoreChartOptions<TType extends ChartType> extends ParsingOptions, AnimationOptions<TType> {
true
Other
chartjs
Chart.js
4183b7f04a8f5b1e8336aaa8b93f260ffd66a042.json
Add links to docs in all the samples (#10308)
docs/samples/advanced/data-decimation.md
@@ -111,3 +111,8 @@ module.exports = { config: config, }; ``` +## Docs +* [Data Decimation](../../configuration/decimation.html) +* [Line](../../charts/line.html) +* [Time Scale](../../axes/cartesian/time.html) +
true
Other
chartjs
Chart.js
4183b7f04a8f5b1e8336aaa8b93f260ffd66a042.json
Add links to docs in all the samples (#10308)
docs/samples/advanced/derived-axis-type.md
@@ -48,3 +48,8 @@ module.exports = { ## Log2 axis implementation <<< @/docs/scripts/log2.js + +## Docs +* [Data structures (`labels`)](../../general/data-structures.html) +* [Line](../../charts/line.html) +* [New Axes](../../developers/axes.html)
true