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 | 1fef75d990ccdb557f19d9be5e67f217d8b5c90d.json | Skip all borders if borderSkipped === true (#10530)
* Skip all borders if borderSkipped === true
This will allow you to skip all borders (not just one side) if you set borderSkipped to boolean true and so allow you to have a consistent legend marker even for bars without borders. Reason is that even if same colored borders are set there are artifacts that make the bar look bad and also even with inflateAmount the bars do look good when big but when only a few pixel in size they start to look bad too so this was the only way for me to make it work so legends are looking good and bars too.
* fix failing test, update docs and typings
* update typing comment
Co-authored-by: Istvan Petres <pijulius@users.noreply.github.com> | types/index.esm.d.ts | @@ -1984,10 +1984,10 @@ export interface BarOptions extends Omit<CommonElementOptions, 'borderWidth'> {
base: number;
/**
- * Skipped (excluded) border: 'start', 'end', 'left', 'right', 'bottom', 'top', 'middle' or false (none).
+ * Skipped (excluded) border: 'start', 'end', 'left', 'right', 'bottom', 'top', 'middle', false (none) or true (all).
* @default 'start'
*/
- borderSkipped: 'start' | 'end' | 'left' | 'right' | 'bottom' | 'top' | 'middle' | false;
+ borderSkipped: 'start' | 'end' | 'left' | 'right' | 'bottom' | 'top' | 'middle' | boolean;
/**
* Border radius | true |
Other | chartjs | Chart.js | a31e1e59d6c33883b2932b422abaabf3a2340074.json | pass boxWidth only if pointStyleWidth presents (#10524) | src/plugins/plugin.legend.js | @@ -325,7 +325,7 @@ export class Legend extends Element {
const centerY = y + halfFontSize;
// Draw pointStyle as legend symbol
- drawPointLegend(ctx, drawOptions, centerX, centerY, boxWidth);
+ drawPointLegend(ctx, drawOptions, centerX, centerY, labelOpts.pointStyleWidth && boxWidth);
} else {
// Draw box as legend symbol
// Adjust position when boxHeight < fontSize (want it centered) | false |
Other | chartjs | Chart.js | c6120f9e7143c66d5e7a1b4052ae3b0f1165d5da.json | Improve docs radial linear grid (#10518)
* make link work in github itself
* fix dead link on reload or new tab
* document the props for radial grid
* remove extra chart and space | docs/axes/radial/linear.md | @@ -18,7 +18,25 @@ Namespace: `options.scales[scaleId]`
| `pointLabels` | `object` | | Point label configuration. [more...](#point-label-options)
| `startAngle` | `number` | `0` | Starting angle of the scale. In degrees, 0 is at top.
-!!!include(axes/_common.md)!!!
+### Common options to all axes
+
+Namespace: `options.scales[scaleId]`
+
+| Name | Type | Default | Description
+| ---- | ---- | ------- | -----------
+| `type` | `string` | | Type of scale being employed. Custom scales can be created and registered with a string key. This allows changing the type of an axis for a chart.
+| `alignToPixels` | `boolean` | `false` | Align pixel values to device pixels.
+| `backgroundColor` | [`Color`](/general/colors.md) | | Background color of the scale area.
+| `display` | `boolean`\|`string` | `true` | Controls the axis global visibility (visible when `true`, hidden when `false`). When `display: 'auto'`, the axis is visible only if at least one associated dataset is visible.
+| `grid` | `object` | | Grid line configuration. [more...](#grid-line-configuration)
+| `min` | `number` | | User defined minimum number for the scale, overrides minimum value from data. [more...](/axes/index.md#axis-range-settings)
+| `max` | `number` | | User defined maximum number for the scale, overrides maximum value from data. [more...](/axes/index.md#axis-range-settings)
+| `reverse` | `boolean` | `false` | Reverse the scale.
+| `stacked` | `boolean`\|`string` | `false` | Should the data be stacked. [more...](/axes/index.md#stacking)
+| `suggestedMax` | `number` | | Adjustment used when calculating the maximum data value. [more...](/axes/index.md#axis-range-settings)
+| `suggestedMin` | `number` | | Adjustment used when calculating the minimum data value. [more...](/axes/index.md#axis-range-settings)
+| `ticks` | `object` | | Tick configuration. [more...](/axes/index.md#tick-configuration)
+| `weight` | `number` | `0` | The weight used to sort the axis. Higher weights are further away from the chart area.
## Tick Configuration
@@ -38,6 +56,21 @@ Namespace: `options.scales[scaleId].ticks`
The scriptable context is described in [Options](../../general/options.md#tick) section.
+## Grid Line Configuration
+
+Namespace: `options.scales[scaleId].grid`, it defines options for the grid lines of the axis.
+
+| Name | Type | Scriptable | Indexable | Default | Description
+| ---- | ---- | :-------------------------------: | :-----------------------------: | ------- | -----------
+| `borderDash` | `number[]` | | | `[]` | Length and spacing of dashes on grid lines. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash).
+| `borderDashOffset` | `number` | Yes | | `0.0` | Offset for line dashes. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineDashOffset).
+| `circular` | `boolean` | | | `false` | If true, gridlines are circular (on radar and polar area charts only).
+| `color` | [`Color`](../general/colors.md) | Yes | Yes | `Chart.defaults.borderColor` | The color of the grid lines. If specified as an array, the first color applies to the first grid line, the second to the second grid line, and so on.
+| `display` | `boolean` | | | `true` | If false, do not display grid lines for this axis.
+| `lineWidth` | `number` | Yes | Yes | `1` | Stroke width of grid lines.
+
+The scriptable context is described in [Options](../general/options.md#tick) section.
+
## Axis Range Settings
Given the number of axis range settings, it is important to understand how they all interact with each other. | true |
Other | chartjs | Chart.js | c6120f9e7143c66d5e7a1b4052ae3b0f1165d5da.json | Improve docs radial linear grid (#10518)
* make link work in github itself
* fix dead link on reload or new tab
* document the props for radial grid
* remove extra chart and space | docs/axes/styling.md | @@ -12,7 +12,7 @@ Namespace: `options.scales[scaleId].grid`, it defines options for the grid lines
| `borderWidth` | `number` | | | `1` | The width of the border line.
| `borderDash` | `number[]` | Yes | | `[]` | Length and spacing of dashes on grid lines. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash).
| `borderDashOffset` | `number` | Yes | | `0.0` | Offset for line dashes. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineDashOffset).
-| `circular` | `boolean` | | | `false` | If true, gridlines are circular (on radar chart only).
+| `circular` | `boolean` | | | `false` | If true, gridlines are circular (on radar and polar area charts only).
| `color` | [`Color`](../general/colors.md) | Yes | Yes | `Chart.defaults.borderColor` | The color of the grid lines. If specified as an array, the first color applies to the first grid line, the second to the second grid line, and so on.
| `display` | `boolean` | | | `true` | If false, do not display grid lines for this axis.
| `drawBorder` | `boolean` | | | `true` | If true, draw a border at the edge between the axis and the chart area. | true |
Other | chartjs | Chart.js | a4114e84d9f1f66c3e7fa76d5d1790fa64392f9a.json | parsing: support dot(s) in object keys (#10517) | docs/general/data-structures.md | @@ -85,11 +85,27 @@ options: {
}
```
+If the key contains a dot, it needs to be escaped with a double slash:
+
+```javascript
+type: 'line',
+data: {
+ datasets: [{
+ data: [{ 'data.key': 'one', 'data.value': 20 }, { 'data.key': 'two', 'data.value': 30 }]
+ }]
+},
+options: {
+ parsing: {
+ xAxisKey: 'data\\.key',
+ yAxisKey: 'data\\.value'
+ }
+}
+```
+
:::warning
When using object notation in a radar chart you still need a labels array with labels for the chart to show correctly.
:::
-
## Object
```javascript | true |
Other | chartjs | Chart.js | a4114e84d9f1f66c3e7fa76d5d1790fa64392f9a.json | parsing: support dot(s) in object keys (#10517) | src/helpers/helpers.core.js | @@ -293,25 +293,52 @@ export function _deprecated(scope, value, previous, current) {
}
}
-const emptyString = '';
-const dot = '.';
-function indexOfDotOrLength(key, start) {
- const idx = key.indexOf(dot, start);
- return idx === -1 ? key.length : idx;
-}
+// resolveObjectKey resolver cache
+const keyResolvers = {
+ // Chart.helpers.core resolveObjectKey should resolve empty key to root object
+ '': v => v,
+ // default resolvers
+ x: o => o.x,
+ y: o => o.y
+};
export function resolveObjectKey(obj, key) {
- if (key === emptyString) {
+ const resolver = keyResolvers[key] || (keyResolvers[key] = _getKeyResolver(key));
+ return resolver(obj);
+}
+
+function _getKeyResolver(key) {
+ const keys = _splitKey(key);
+ return obj => {
+ for (const k of keys) {
+ if (k === '') {
+ // For backward compatibility:
+ // Chart.helpers.core resolveObjectKey should break at empty key
+ break;
+ }
+ obj = obj && obj[k];
+ }
return obj;
+ };
+}
+
+/**
+ * @private
+ */
+export function _splitKey(key) {
+ const parts = key.split('.');
+ const keys = [];
+ let tmp = '';
+ for (const part of parts) {
+ tmp += part;
+ if (tmp.endsWith('\\')) {
+ tmp = tmp.slice(0, -1) + '.';
+ } else {
+ keys.push(tmp);
+ tmp = '';
+ }
}
- let pos = 0;
- let idx = indexOfDotOrLength(key, pos);
- while (obj && idx > pos) {
- obj = obj[key.slice(pos, idx)];
- pos = idx + 1;
- idx = indexOfDotOrLength(key, pos);
- }
- return obj;
+ return keys;
}
/** | true |
Other | chartjs | Chart.js | a4114e84d9f1f66c3e7fa76d5d1790fa64392f9a.json | parsing: support dot(s) in object keys (#10517) | test/specs/helpers.core.tests.js | @@ -456,6 +456,44 @@ describe('Chart.helpers.core', function() {
expect(() => helpers.resolveObjectKey({}, true)).toThrow();
expect(() => helpers.resolveObjectKey({}, 1)).toThrow();
});
+ it('should allow escaping dot symbol', function() {
+ expect(helpers.resolveObjectKey({'test.dot': 10}, 'test\\.dot')).toEqual(10);
+ expect(helpers.resolveObjectKey({test: {dot: 10}}, 'test\\.dot')).toEqual(undefined);
+ });
+ it('should allow nested keys with a dot', function() {
+ expect(helpers.resolveObjectKey({
+ a: {
+ 'bb.ccc': 'works',
+ bb: {
+ ccc: 'fails'
+ }
+ }
+ }, 'a.bb\\.ccc')).toEqual('works');
+ });
+
+ });
+
+ describe('_splitKey', function() {
+ it('should return array with one entry for string without a dot', function() {
+ expect(helpers._splitKey('')).toEqual(['']);
+ expect(helpers._splitKey('test')).toEqual(['test']);
+ const asciiWithoutDot = ' !"#$%&\'()*+,-/0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
+ expect(helpers._splitKey(asciiWithoutDot)).toEqual([asciiWithoutDot]);
+ });
+
+ it('should split on dot', function() {
+ expect(helpers._splitKey('test1.test2')).toEqual(['test1', 'test2']);
+ expect(helpers._splitKey('a.b.c')).toEqual(['a', 'b', 'c']);
+ expect(helpers._splitKey('a.b.')).toEqual(['a', 'b', '']);
+ expect(helpers._splitKey('a..c')).toEqual(['a', '', 'c']);
+ });
+
+ it('should preserve escaped dot', function() {
+ expect(helpers._splitKey('test1\\.test2')).toEqual(['test1.test2']);
+ expect(helpers._splitKey('a\\.b.c')).toEqual(['a.b', 'c']);
+ expect(helpers._splitKey('a.b\\.c')).toEqual(['a', 'b.c']);
+ expect(helpers._splitKey('a.\\.c')).toEqual(['a', '.c']);
+ });
});
describe('setsEqual', function() { | true |
Other | chartjs | Chart.js | de3596d4afbd3373d9fc0b6eeb7706e340ad2f1a.json | Fix dead link on reload or open in new tab (#10515)
* make link work in github itself
* fix dead link on reload or new tab | docs/axes/labelling.md | @@ -31,7 +31,7 @@ The call to the method is scoped to the scale. `this` inside the method is the s
If the callback returns `null` or `undefined` the associated grid line will be hidden.
:::tip
-The [category axis](../axes/cartesian/category), which is the default x-axis for line and bar charts, uses the `index` as internal data format. For accessing the label, use `this.getLabelForValue(value)`. [API: getLabelForValue](../api/classes/scale.html#getlabelforvalue)
+The [category axis](../axes/cartesian/category), which is the default x-axis for line and bar charts, uses the `index` as internal data format. For accessing the label, use `this.getLabelForValue(value)`. [API: getLabelForValue](../api/classes/Scale.html#getlabelforvalue)
:::
In the following example, every label of the Y-axis would be displayed with a dollar sign at the front. | false |
Other | chartjs | Chart.js | 9ba44809745a77855485dc44af6e0c9574226446.json | Resolve plugin defaults for local plugins (#10484) | src/core/core.plugins.js | @@ -118,6 +118,7 @@ export default class PluginService {
* @param {import("./core.config").default} config
*/
function allPlugins(config) {
+ const localIds = {};
const plugins = [];
const keys = Object.keys(registry.plugins.items);
for (let i = 0; i < keys.length; i++) {
@@ -130,10 +131,11 @@ function allPlugins(config) {
if (plugins.indexOf(plugin) === -1) {
plugins.push(plugin);
+ localIds[plugin.id] = true;
}
}
- return plugins;
+ return {plugins, localIds};
}
function getOpts(options, all) {
@@ -146,34 +148,36 @@ function getOpts(options, all) {
return options;
}
-function createDescriptors(chart, plugins, options, all) {
+function createDescriptors(chart, {plugins, localIds}, options, all) {
const result = [];
const context = chart.getContext();
- for (let i = 0; i < plugins.length; i++) {
- const plugin = plugins[i];
+ for (const plugin of plugins) {
const id = plugin.id;
const opts = getOpts(options[id], all);
if (opts === null) {
continue;
}
result.push({
plugin,
- options: pluginOpts(chart.config, plugin, opts, context)
+ options: pluginOpts(chart.config, {plugin, local: localIds[id]}, opts, context)
});
}
return result;
}
-/**
- * @param {import("./core.config").default} config
- * @param {*} plugin
- * @param {*} opts
- * @param {*} context
- */
-function pluginOpts(config, plugin, opts, context) {
+function pluginOpts(config, {plugin, local}, opts, context) {
const keys = config.pluginScopeKeys(plugin);
const scopes = config.getOptionScopes(opts, keys);
- return config.createResolver(scopes, context, [''], {scriptable: false, indexable: false, allKeys: true});
+ if (local && plugin.defaults) {
+ // make sure plugin defaults are in scopes for local (not registered) plugins
+ scopes.push(plugin.defaults);
+ }
+ return config.createResolver(scopes, context, [''], {
+ // These are just defaults that plugins can override
+ scriptable: false,
+ indexable: false,
+ allKeys: true
+ });
} | true |
Other | chartjs | Chart.js | 9ba44809745a77855485dc44af6e0c9574226446.json | Resolve plugin defaults for local plugins (#10484) | test/specs/core.plugin.tests.js | @@ -224,7 +224,7 @@ describe('Chart.plugins', function() {
Chart.unregister(plugins.a);
});
- it('should not called plugins when config.options.plugins.{id} is FALSE', function() {
+ it('should not call plugins when config.options.plugins.{id} is FALSE', function() {
var plugins = {
a: {id: 'a', hook: function() {}},
b: {id: 'b', hook: function() {}},
@@ -297,6 +297,29 @@ describe('Chart.plugins', function() {
Chart.unregister(plugin);
});
+ // https://github.com/chartjs/Chart.js/issues/10482
+ it('should resolve defaults for local plugins', function() {
+ var plugin = {id: 'a', hook: function() {}, defaults: {bar: 'bar'}};
+ var chart = window.acquireChart({
+ plugins: [plugin],
+ options: {
+ plugins: {
+ a: {
+ foo: 'foo'
+ }
+ }
+ },
+ });
+
+ spyOn(plugin, 'hook');
+ chart.notifyPlugins('hook');
+
+ expect(plugin.hook).toHaveBeenCalled();
+ expect(plugin.hook.calls.first().args[2]).toEqualOptions({foo: 'foo', bar: 'bar'});
+
+ Chart.unregister(plugin);
+ });
+
// https://github.com/chartjs/Chart.js/issues/5111#issuecomment-355934167
it('should update plugin options', function() {
var plugin = {id: 'a', hook: function() {}}; | true |
Other | chartjs | Chart.js | 8ccff8cad70023f7e3d3dddc25e555cf098a6712.json | draw tooltip with object borderwidth (#10489) | src/plugins/plugin.tooltip.js | @@ -1,7 +1,7 @@
import Animations from '../core/core.animations';
import Element from '../core/core.element';
import {addRoundedRectPath} from '../helpers/helpers.canvas';
-import {each, noop, isNullOrUndef, isArray, _elementsEqual} from '../helpers/helpers.core';
+import {each, noop, isNullOrUndef, isArray, _elementsEqual, isObject} from '../helpers/helpers.core';
import {toFont, toPadding, toTRBLCorners} from '../helpers/helpers.options';
import {getRtlAdapter, overrideTextDirection, restoreTextDirection} from '../helpers/helpers.rtl';
import {distanceBetweenPoints, _limitValue} from '../helpers/helpers.math';
@@ -707,7 +707,7 @@ export class Tooltip extends Element {
drawPoint(ctx, drawOptions, centerX, centerY);
} else {
// Border
- ctx.lineWidth = labelColors.borderWidth || 1; // TODO, v4 remove fallback
+ ctx.lineWidth = isObject(labelColors.borderWidth) ? Math.max(...Object.values(labelColors.borderWidth)) : (labelColors.borderWidth || 1); // TODO, v4 remove fallback
ctx.strokeStyle = labelColors.borderColor;
ctx.setLineDash(labelColors.borderDash || []);
ctx.lineDashOffset = labelColors.borderDashOffset || 0; | false |
Other | chartjs | Chart.js | eeba91e0de9e9e4df973cc51f98a5028beb04b04.json | make link work in github itself (#10497) | docs/getting-started/index.md | @@ -101,6 +101,6 @@ module.exports = {
As you can see, some of the boilerplate needed is not visible in our sample blocks, as the samples focus on the configuration options.
:::
-All our examples are [available online](/samples/).
+All our examples are [available online](../samples/).
To run the samples locally you first have to install all the necessary packages using the `npm ci` command, after this you can run `npm run docs:dev` to build the documentation. As soon as the build is done, you can go to [http://localhost:8080/samples/](http://localhost:8080/samples/) to see the samples. | false |
Other | chartjs | Chart.js | 1a1e68380f1298ccb25e6941b07e158855ac4992.json | Improve error message with id of the canvas (#10495)
* improve error message with id of the canvas
* update test | src/core/core.controller.js | @@ -111,7 +111,7 @@ class Chart {
if (existingChart) {
throw new Error(
'Canvas is already in use. Chart with ID \'' + existingChart.id + '\'' +
- ' must be destroyed before the canvas can be reused.'
+ ' must be destroyed before the canvas with ID \'' + existingChart.canvas.id + '\' can be reused.'
);
}
| true |
Other | chartjs | Chart.js | 1a1e68380f1298ccb25e6941b07e158855ac4992.json | Improve error message with id of the canvas (#10495)
* improve error message with id of the canvas
* update test | test/specs/core.controller.tests.js | @@ -32,7 +32,7 @@ describe('Chart', function() {
expect(createChart).toThrow(new Error(
'Canvas is already in use. ' +
'Chart with ID \'' + chart.id + '\'' +
- ' must be destroyed before the canvas can be reused.'
+ ' must be destroyed before the canvas with ID \'' + chart.canvas.id + '\' can be reused.'
));
chart.destroy(); | true |
Other | chartjs | Chart.js | a7fede4f465277dd0cb6ce1675153f6e4a6472e2.json | Fix jshint error | src/scales/scale.category.js | @@ -16,7 +16,7 @@ module.exports = function(Chart) {
if (this.options.ticks.min !== undefined) {
// user specified min value
- findIndex = helpers.indexOf(this.chart.data.labels, this.options.ticks.min)
+ findIndex = helpers.indexOf(this.chart.data.labels, this.options.ticks.min);
this.startIndex = findIndex !== -1 ? findIndex : this.startIndex;
}
| false |
Other | chartjs | Chart.js | 7875b0c68df08312efa76062fe5bf63dd20dc14a.json | Install latest chrome before running tests | .travis.yml | @@ -4,9 +4,13 @@ node_js:
- "4.3"
before_install:
- - "export CHROME_BIN=chromium-browser"
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
+ - "sudo apt-get update"
+ - "sudo apt-get install -y libappindicator1 fonts-liberation"
+ - "wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb"
+ - "sudo dpkg -i google-chrome*.deb"
+ - "export CHROME_BIN=/usr/bin.google-chrome"
before_script:
- npm install
@@ -19,6 +23,7 @@ script:
notifications:
slack: chartjs:pcfCZR6ugg5TEcaLtmIfQYuA
-sudo: false
+sudo: required
+
addons:
firefox: latest
\ No newline at end of file | false |
Other | chartjs | Chart.js | 5c1f242785ffe05993b8dd04de9e16a1c938894f.json | Use latest firefox version | .travis.yml | @@ -19,4 +19,6 @@ script:
notifications:
slack: chartjs:pcfCZR6ugg5TEcaLtmIfQYuA
-sudo: false
\ No newline at end of file
+sudo: false
+addons:
+ firefox: latest
\ No newline at end of file | false |
Other | chartjs | Chart.js | ef923dfe289fc41326be58f3f6e4d991c8eb741f.json | Update package + built files to 1.1.0 version | Chart.js | @@ -1,7 +1,7 @@
/*!
* Chart.js
* http://chartjs.org/
- * Version: 1.0.2
+ * Version: 1.1.0
*
* Copyright 2015 Nick Downie
* Released under the MIT license | true |
Other | chartjs | Chart.js | ef923dfe289fc41326be58f3f6e4d991c8eb741f.json | Update package + built files to 1.1.0 version | Chart.min.js | @@ -1,7 +1,7 @@
/*!
* Chart.js
* http://chartjs.org/
- * Version: 1.0.2
+ * Version: 1.1.0
*
* Copyright 2015 Nick Downie
* Released under the MIT license | true |
Other | chartjs | Chart.js | ef923dfe289fc41326be58f3f6e4d991c8eb741f.json | Update package + built files to 1.1.0 version | bower.json | @@ -16,5 +16,6 @@
"gulpfile.js",
"package.json"
],
- "dependencies": {}
+ "dependencies": {},
+ "version": "1.1.0"
} | true |
Other | chartjs | Chart.js | ef923dfe289fc41326be58f3f6e4d991c8eb741f.json | Update package + built files to 1.1.0 version | package.json | @@ -2,13 +2,13 @@
"name": "chart.js",
"homepage": "http://www.chartjs.org",
"description": "Simple HTML5 charts using the canvas element.",
- "version": "1.0.2",
+ "version": "1.1.0",
"main": "Chart.js",
"repository": {
"type": "git",
"url": "https://github.com/nnnick/Chart.js.git"
},
- "license" : "MIT",
+ "license": "MIT",
"dependences": {},
"devDependencies": {
"gulp": "3.9.x", | true |
Other | chartjs | Chart.js | 60a429f5cb2a1985ab1e43c5c3155a0bd6ebe963.json | Update doc version | docs/00-Getting-Started.md | @@ -16,7 +16,7 @@ npm install chart.js --save
bower install Chart.js --save
```
-CDN: https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.0.0-beta/Chart.js
+CDN: https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.0.0/Chart.js
###Install Chart.js
| false |
Other | chartjs | Chart.js | bf724abe8b314c45bc706617a36f40521f3c0a83.json | Fix axis IDs in documentation | docs/02-Line-Chart.md | @@ -86,8 +86,8 @@ var data = {
// The actual data
data: [65, 59, 80, 81, 56, 55, 40],
- // String - If specified, binds the dataset to a certain y-axis. If not specified, the first y-axis is used.
- yAxisID: "y-axis-1",
+ // String - If specified, binds the dataset to a certain y-axis. If not specified, the first y-axis is used. First id is y-axis-0
+ yAxisID: "y-axis-0",
},
{
label: "My Second dataset", | true |
Other | chartjs | Chart.js | bf724abe8b314c45bc706617a36f40521f3c0a83.json | Fix axis IDs in documentation | docs/03-Bar-Chart.md | @@ -50,7 +50,7 @@ var data = {
data: [65, 59, 80, 81, 56, 55, 40],
// String - If specified, binds the dataset to a certain y-axis. If not specified, the first y-axis is used.
- yAxisID: "y-axis-1",
+ yAxisID: "y-axis-0",
},
{
label: "My Second dataset", | true |
Other | chartjs | Chart.js | d7117bc79235f23832cec04568cad8a808f82737.json | Add title of license to license file. Fixes #2097 | LICENSE.md | @@ -1,3 +1,4 @@
+The MIT License (MIT)
Copyright (c) 2013-2016 Nick Downie
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | false |
Other | chartjs | Chart.js | 668b532fbee9dca9b75a5981aab949e7513a9388.json | Add angleLineInterval option to radar chart | docs/03-Radar-Chart.md | @@ -76,6 +76,9 @@ These are the customisation options specific to Radar charts. These options are
//Number - Pixel width of the angle line
angleLineWidth : 1,
+ //Number - Interval at which to draw angle lines ("every Nth point")
+ angleLineInterval: 1,
+
//String - Point label font declaration
pointLabelFontFamily : "'Arial'",
@@ -174,4 +177,4 @@ Calling `removeData()` on your Chart instance will remove the first value for al
```javascript
myRadarChart.removeData();
// Other points will now animate to their correct positions.
-```
\ No newline at end of file
+``` | true |
Other | chartjs | Chart.js | 668b532fbee9dca9b75a5981aab949e7513a9388.json | Add angleLineInterval option to radar chart | src/Chart.Core.js | @@ -2058,7 +2058,7 @@
for (var i = this.valuesCount - 1; i >= 0; i--) {
var centerOffset = null, outerPosition = null;
- if (this.angleLineWidth > 0){
+ if (this.angleLineWidth > 0 && (i % this.angleLineInterval === 0)){
centerOffset = this.calculateCenterOffset(this.max);
outerPosition = this.getPointPosition(i, centerOffset);
ctx.beginPath(); | true |
Other | chartjs | Chart.js | 668b532fbee9dca9b75a5981aab949e7513a9388.json | Add angleLineInterval option to radar chart | src/Chart.Radar.js | @@ -28,6 +28,9 @@
//Number - Pixel width of the angle line
angleLineWidth : 1,
+ //Number - Interval at which to draw angle lines ("every Nth point")
+ angleLineInterval: 1,
+
//String - Point label font declaration
pointLabelFontFamily : "'Arial'",
@@ -181,6 +184,7 @@
lineColor: this.options.scaleLineColor,
angleLineColor : this.options.angleLineColor,
angleLineWidth : (this.options.angleShowLineOut) ? this.options.angleLineWidth : 0,
+ angleLineInterval: (this.options.angleLineInterval) ? this.options.angleLineInterval : 1,
// Point labels at the edge of each line
pointLabelFontColor : this.options.pointLabelFontColor,
pointLabelFontSize : this.options.pointLabelFontSize, | true |
Other | chartjs | Chart.js | 5d2444a5ee1a4caf3d7b3721eab759763ec1cf12.json | Expose yAlign and xAlign as a tooltip option | src/core/core.tooltip.js | @@ -24,6 +24,8 @@ module.exports = function(Chart) {
footerAlign: "left",
yPadding: 6,
xPadding: 6,
+ yAlign : 'center',
+ xAlign : 'center',
caretSize: 5,
cornerRadius: 6,
multiKeyBackground: '#fff',
@@ -116,6 +118,8 @@ module.exports = function(Chart) {
footerMarginTop: options.tooltips.footerMarginTop,
// Appearance
+ yAlign : options.tooltips.yAlign,
+ xAlign : options.tooltips.xAlign,
caretSize: options.tooltips.caretSize,
cornerRadius: options.tooltips.cornerRadius,
backgroundColor: options.tooltips.backgroundColor,
@@ -333,8 +337,6 @@ module.exports = function(Chart) {
return size;
},
determineAlignment: function determineAlignment(size) {
- this._model.xAlign = this._model.yAlign = "center";
-
if (this._model.y < size.height) {
this._model.yAlign = 'top';
} else if (this._model.y > (this._chart.height - size.height)) { | false |
Other | chartjs | Chart.js | c3f765857edf974f1136e2162e00d931bc2400bc.json | Fix some time rounding problems | docs/01-Scales.md | @@ -171,8 +171,13 @@ The time scale extends the core scale class with the following tick template:
parser: false,
// string - By default, unit will automatically be detected. Override with 'week', 'month', 'year', etc. (see supported time measurements)
unit: false,
+
+ // Number - The number of steps of the above unit between ticks
+ unitStepSize: 1
+
// string - By default, no rounding is applied. To round, set to a supported time unit eg. 'week', 'month', 'year', etc.
round: false,
+
// Moment js for each of the units. Replaces `displayFormat`
// To override, use a pattern string from http://momentjs.com/docs/#/displaying/format/
displayFormats: { | true |
Other | chartjs | Chart.js | c3f765857edf974f1136e2162e00d931bc2400bc.json | Fix some time rounding problems | src/core/core.scale.js | @@ -476,10 +476,6 @@ module.exports = function(Chart) {
skipRatio = 1 + Math.floor((((longestRotatedLabel / 2) + this.options.ticks.autoSkipPadding) * this.ticks.length) / (this.width - (this.paddingLeft + this.paddingRight)));
}
- if (!useAutoskipper) {
- skipRatio = false;
- }
-
// if they defined a max number of ticks,
// increase skipRatio until that number is met
if (maxTicks && this.ticks.length > maxTicks) {
@@ -491,6 +487,10 @@ module.exports = function(Chart) {
}
}
+ if (!useAutoskipper) {
+ skipRatio = false;
+ }
+
helpers.each(this.ticks, function(label, index) {
// Blank ticks
var isLastTick = this.ticks.length === index + 1; | true |
Other | chartjs | Chart.js | c3f765857edf974f1136e2162e00d931bc2400bc.json | Fix some time rounding problems | src/scales/scale.time.js | @@ -138,22 +138,30 @@ module.exports = function(Chart) {
this.ticks = [];
this.unitScale = 1; // How much we scale the unit by, ie 2 means 2x unit per step
+ this.scaleSizeInUnits = 0; // How large the scale is in the base unit (seconds, minutes, etc)
// Set unit override if applicable
if (this.options.time.unit) {
this.tickUnit = this.options.time.unit || 'day';
this.displayFormat = this.options.time.displayFormats[this.tickUnit];
- this.tickRange = Math.ceil(this.lastTick.diff(this.firstTick, this.tickUnit, true));
+ this.scaleSizeInUnits = this.lastTick.diff(this.firstTick, this.tickUnit, true);
+ this.unitScale = helpers.getValueOrDefault(this.options.time.unitStepSize, 1);
} else {
// Determine the smallest needed unit of the time
var tickFontSize = helpers.getValueOrDefault(this.options.ticks.fontSize, Chart.defaults.global.defaultFontSize);
var innerWidth = this.isHorizontal() ? this.width - (this.paddingLeft + this.paddingRight) : this.height - (this.paddingTop + this.paddingBottom);
- var labelCapacity = innerWidth / (tickFontSize + 10);
- var buffer = this.options.time.round ? 0 : 1;
+
+ // Crude approximation of what the label length might be
+ var tempFirstLabel = this.tickFormatFunction(this.firstTick, 0, []);
+ var tickLabelWidth = tempFirstLabel.length * tickFontSize;
+ var cosRotation = Math.cos(helpers.toRadians(this.options.ticks.maxRotation));
+ var sinRotation = Math.sin(helpers.toRadians(this.options.ticks.maxRotation));
+ tickLabelWidth = (tickLabelWidth * cosRotation) + (tickFontSize * sinRotation);
+ var labelCapacity = innerWidth / (tickLabelWidth + 10);
// Start as small as possible
this.tickUnit = 'millisecond';
- this.tickRange = Math.ceil(this.lastTick.diff(this.firstTick, this.tickUnit, true) + buffer);
+ this.scaleSizeInUnits = this.lastTick.diff(this.firstTick, this.tickUnit, true);
this.displayFormat = this.options.time.displayFormats[this.tickUnit];
var unitDefinitionIndex = 0;
@@ -164,27 +172,27 @@ module.exports = function(Chart) {
// Can we scale this unit. If `false` we can scale infinitely
this.unitScale = 1;
- if (helpers.isArray(unitDefinition.steps) && Math.ceil(this.tickRange / labelCapacity) < helpers.max(unitDefinition.steps)) {
+ if (helpers.isArray(unitDefinition.steps) && Math.ceil(this.scaleSizeInUnits / labelCapacity) < helpers.max(unitDefinition.steps)) {
// Use one of the prefedined steps
for (var idx = 0; idx < unitDefinition.steps.length; ++idx) {
- if (unitDefinition.steps[idx] > Math.ceil(this.tickRange / labelCapacity)) {
- this.unitScale = unitDefinition.steps[idx];
+ if (unitDefinition.steps[idx] > Math.ceil(this.scaleSizeInUnits / labelCapacity)) {
+ this.unitScale = helpers.getValueOrDefault(this.options.time.unitStepSize, unitDefinition.steps[idx]);
break;
}
}
break;
- } else if ((unitDefinition.maxStep === false) || (Math.ceil(this.tickRange / labelCapacity) < unitDefinition.maxStep)) {
+ } else if ((unitDefinition.maxStep === false) || (Math.ceil(this.scaleSizeInUnits / labelCapacity) < unitDefinition.maxStep)) {
// We have a max step. Scale this unit
- this.unitScale = Math.ceil(this.tickRange / labelCapacity);
+ this.unitScale = helpers.getValueOrDefault(this.options.time.unitStepSize, Math.ceil(this.scaleSizeInUnits / labelCapacity));
break;
} else {
// Move to the next unit up
++unitDefinitionIndex;
unitDefinition = time.units[unitDefinitionIndex];
this.tickUnit = unitDefinition.name;
- this.tickRange = Math.ceil(this.lastTick.diff(this.firstTick, this.tickUnit) + buffer);
+ this.scaleSizeInUnits = this.lastTick.diff(this.firstTick, this.tickUnit, true);
this.displayFormat = this.options.time.displayFormats[unitDefinition.name];
}
}
@@ -222,7 +230,7 @@ module.exports = function(Chart) {
this.ticks.push(this.firstTick.clone());
// For every unit in between the first and last moment, create a moment and add it to the ticks tick
- for (var i = 1; i < this.tickRange; ++i) {
+ for (var i = 1; i < this.scaleSizeInUnits; ++i) {
var newTick = roundedStart.clone().add(i, this.tickUnit);
// Are we greater than the max time
@@ -236,12 +244,17 @@ module.exports = function(Chart) {
}
// Always show the right tick
- if (this.options.time.max) {
- this.ticks.push(this.lastTick.clone());
- } else if (this.ticks[this.ticks.length - 1].diff(this.lastTick, this.tickUnit, true) !== 0) {
- this.tickRange = Math.ceil(this.tickRange / this.unitScale) * this.unitScale;
- this.ticks.push(this.firstTick.clone().add(this.tickRange, this.tickUnit));
- this.lastTick = this.ticks[this.ticks.length - 1].clone();
+ if (this.ticks[this.ticks.length - 1].diff(this.lastTick, this.tickUnit) !== 0 || this.scaleSizeInUnits === 0) {
+ // this is a weird case. If the <max> option is the same as the end option, we can't just diff the times because the tick was created from the roundedStart
+ // but the last tick was not rounded.
+ if (this.options.time.max) {
+ this.ticks.push(this.lastTick.clone());
+ this.scaleSizeInUnits = this.lastTick.diff(this.ticks[0], this.tickUnit, true);
+ } else {
+ this.scaleSizeInUnits = Math.ceil(this.scaleSizeInUnits / this.unitScale) * this.unitScale;
+ this.ticks.push(this.firstTick.clone().add(this.scaleSizeInUnits, this.tickUnit));
+ this.lastTick = this.ticks[this.ticks.length - 1].clone();
+ }
}
},
// Get tooltip label
@@ -259,24 +272,26 @@ module.exports = function(Chart) {
return label;
},
- convertTicksToLabels: function() {
- this.ticks = this.ticks.map(function(tick, index, ticks) {
- var formattedTick = tick.format(this.displayFormat);
+ // Function to format an individual tick mark
+ tickFormatFunction: function tickFormatFunction(tick, index, ticks) {
+ var formattedTick = tick.format(this.displayFormat);
- if (this.options.ticks.userCallback) {
- return this.options.ticks.userCallback(formattedTick, index, ticks);
- } else {
- return formattedTick;
- }
- }, this);
+ if (this.options.ticks.userCallback) {
+ return this.options.ticks.userCallback(formattedTick, index, ticks);
+ } else {
+ return formattedTick;
+ }
+ },
+ convertTicksToLabels: function() {
+ this.ticks = this.ticks.map(this.tickFormatFunction, this);
},
getPixelForValue: function(value, index, datasetIndex, includeOffset) {
var labelMoment = this.getLabelMoment(datasetIndex, index);
if (labelMoment) {
var offset = labelMoment.diff(this.firstTick, this.tickUnit, true);
- var decimal = offset / this.tickRange;
+ var decimal = offset / this.scaleSizeInUnits;
if (this.isHorizontal()) {
var innerWidth = this.width - (this.paddingLeft + this.paddingRight); | true |
Other | chartjs | Chart.js | c3f765857edf974f1136e2162e00d931bc2400bc.json | Fix some time rounding problems | test/scale.time.tests.js | @@ -202,7 +202,7 @@ describe('Time scale tests', function() {
scale.update(400, 50);
// Counts down because the lines are drawn top to bottom
- expect(scale.ticks).toEqual(['Nov 20, 1981', 'Nov 20, 1981']);
+ expect(scale.ticks).toEqual(['Nov 19, 1981', 'Nov 19, 1981']);
});
it('should build ticks using the config unit', function() { | true |
Other | chartjs | Chart.js | 71ede8d52c4663520d9b8bbb43ce0852b2fe54ad.json | Docs: Apply a recommendation (fixes #3046) | docs/03-Line-Chart.md | @@ -26,7 +26,7 @@ var myLineChart = Chart.Line(ctx, {
});
```
-### Data Structure
+### Dataset Structure
The following options can be included in a line chart dataset to configure options for that specific dataset.
| true |
Other | chartjs | Chart.js | 71ede8d52c4663520d9b8bbb43ce0852b2fe54ad.json | Docs: Apply a recommendation (fixes #3046) | docs/04-Bar-Chart.md | @@ -31,7 +31,7 @@ var myBarChart = new Chart(ctx, {
});
```
-### Data Structure
+### Dataset Structure
The following options can be included in a bar chart dataset to configure options for that specific dataset.
Some properties can be specified as an array. If these are set to an array value, the first value applies to the first bar, the second value to the second bar, and so on. | true |
Other | chartjs | Chart.js | 71ede8d52c4663520d9b8bbb43ce0852b2fe54ad.json | Docs: Apply a recommendation (fixes #3046) | docs/05-Radar-Chart.md | @@ -22,7 +22,7 @@ var myRadarChart = new Chart(ctx, {
});
```
-### Data Structure
+### Dataset Structure
The following options can be included in a radar chart dataset to configure options for that specific dataset.
| true |
Other | chartjs | Chart.js | 71ede8d52c4663520d9b8bbb43ce0852b2fe54ad.json | Docs: Apply a recommendation (fixes #3046) | docs/06-Polar-Area-Chart.md | @@ -21,7 +21,7 @@ new Chart(ctx, {
});
```
-### Data Structure
+### Dataset Structure
The following options can be included in a polar area chart dataset to configure options for that specific dataset.
| true |
Other | chartjs | Chart.js | 71ede8d52c4663520d9b8bbb43ce0852b2fe54ad.json | Docs: Apply a recommendation (fixes #3046) | docs/07-Pie-Doughnut-Chart.md | @@ -40,7 +40,7 @@ var myDoughnutChart = new Chart(ctx, {
});
```
-### Data Structure
+### Dataset Structure
Property | Type | Usage
--- | --- | --- | true |
Other | chartjs | Chart.js | 71ede8d52c4663520d9b8bbb43ce0852b2fe54ad.json | Docs: Apply a recommendation (fixes #3046) | docs/08-Bubble-Chart.md | @@ -21,7 +21,7 @@ var myBubbleChart = new Chart(ctx,{
});
```
-### Data Structure
+### Dataset Structure
Property | Type | Usage
--- | --- | --- | true |
Other | chartjs | Chart.js | 08451ce95e16224e1afba6e890e33b430d662779.json | Correct duplicate error | docs/02-Scales.md | @@ -346,7 +346,7 @@ min | Number | - | User defined minimum number for the scale, overrides minimum
max | Number | - | User defined maximum number for the scale, overrides maximum value from data.
maxTicksLimit | Number | 11 | Maximum number of ticks and gridlines to show. If not defined, it will limit to 11 ticks but will show all gridlines.
showLabelBackdrop | Boolean | true | If true, draw a background behind the tick labels
-stepSize | Number | - | User defined fixed step size for the scale. If set, the scale ticks will be enumerated by multiple of stepSize, having one tick per increment. If not set, the ticks are labeled automatically using the nice numbers algorithm.
+fixedStepSize | Number | - | User defined fixed step size for the scale. If set, the scale ticks will be enumerated by multiple of stepSize, having one tick per increment. If not set, the ticks are labeled automatically using the nice numbers algorithm.
stepSize | Number | - | if defined, it can be used along with the min and the max to give a custom number of steps. See the example below.
suggestedMax | Number | - | User defined maximum number for the scale, overrides maximum value *except for if* it is lower than the maximum value.
suggestedMin | Number | - | User defined minimum number for the scale, overrides minimum value *except for if* it is higher than the minimum value. | false |
Other | chartjs | Chart.js | f46a9472b54fdafacda6f780a197b0fce5ee46d8.json | getElementAtEvent: enforce one element limit | src/core/core.controller.js | @@ -384,7 +384,7 @@ module.exports = function(Chart) {
}
});
- return elementsArray;
+ return elementsArray.slice(0, 1);
},
getElementsAtEvent: function(e) { | false |
Other | chartjs | Chart.js | 47b5ad60ae798787bad97f2d478dab396536b752.json | Fix JSHint warnings | src/elements/element.line.js | @@ -57,15 +57,16 @@ module.exports = function(Chart) {
points.push(points[0]);
}
+ var index, current, previous, currentVM;
+
// Fill Line
if (points.length && vm.fill) {
ctx.beginPath();
- for (var index = 0; index < points.length; ++index) {
- var current = points[index];
- var previous = helpers.previousItem(points, index);
-
- var currentVM = current._view;
+ for (index = 0; index < points.length; ++index) {
+ current = points[index];
+ previous = helpers.previousItem(points, index);
+ currentVM = current._view;
// First point moves to it's starting position no matter what
if (index === 0) {
@@ -97,7 +98,7 @@ module.exports = function(Chart) {
// If the first data point is NaN, then there is no real gap to skip
if (spanGaps && lastDrawnIndex !== -1) {
// We are spanning the gap, so simple draw a line to this point
- lineToPoint(previous, current)
+ lineToPoint(previous, current);
} else {
if (loop) {
ctx.lineTo(currentVM.x, currentVM.y);
@@ -142,10 +143,10 @@ module.exports = function(Chart) {
ctx.beginPath();
lastDrawnIndex = -1;
- for (var index = 0; index < points.length; ++index) {
- var current = points[index];
- var previous = helpers.previousItem(points, index);
- var currentVM = current._view;
+ for (index = 0; index < points.length; ++index) {
+ current = points[index];
+ previous = helpers.previousItem(points, index);
+ currentVM = current._view;
// First point moves to it's starting position no matter what
if (index === 0) { | false |
Other | chartjs | Chart.js | 7c66b2f28cf871e1850ea9930759acada679fec7.json | Combine performance docs (#6632) | docs/SUMMARY.md | @@ -16,6 +16,7 @@
* [Options](general/options.md)
* [Colors](general/colors.md)
* [Fonts](general/fonts.md)
+ * [Performance](general/performance.md)
* [Configuration](configuration/README.md)
* [Animations](configuration/animations.md)
* [Layout](configuration/layout.md) | true |
Other | chartjs | Chart.js | 7c66b2f28cf871e1850ea9930759acada679fec7.json | Combine performance docs (#6632) | docs/charts/line.md | @@ -216,75 +216,3 @@ var stackedLine = new Chart(ctx, {
}
});
```
-
-## High Performance Line Charts
-
-When charting a lot of data, the chart render time may start to get quite large. In that case, the following strategies can be used to improve performance.
-
-### Data Decimation
-
-Decimating your data will achieve the best results. When there is a lot of data to display on the graph, it doesn't make sense to show tens of thousands of data points on a graph that is only a few hundred pixels wide.
-
-There are many approaches to data decimation and selection of an algorithm will depend on your data and the results you want to achieve. For instance, [min/max](https://digital.ni.com/public.nsf/allkb/F694FFEEA0ACF282862576020075F784) decimation will preserve peaks in your data but could require up to 4 points for each pixel. This type of decimation would work well for a very noisy signal where you need to see data peaks.
-
-### Disable Bezier Curves
-
-If you are drawing lines on your chart, disabling bezier curves will improve render times since drawing a straight line is more performant than a bezier curve.
-
-To disable bezier curves for an entire chart:
-
-```javascript
-new Chart(ctx, {
- type: 'line',
- data: data,
- options: {
- elements: {
- line: {
- tension: 0 // disables bezier curves
- }
- }
- }
-});
-```
-
-### Disable Line Drawing
-
-If you have a lot of data points, it can be more performant to disable rendering of the line for a dataset and only draw points. Doing this means that there is less to draw on the canvas which will improve render performance.
-
-To disable lines:
-
-```javascript
-new Chart(ctx, {
- type: 'line',
- data: {
- datasets: [{
- showLine: false // disable for a single dataset
- }]
- },
- options: {
- showLines: false // disable for all datasets
- }
-});
-```
-
-### Disable Animations
-
-If your charts have long render times, it is a good idea to disable animations. Doing so will mean that the chart needs to only be rendered once during an update instead of multiple times. This will have the effect of reducing CPU usage and improving general page performance.
-
-To disable animations
-
-```javascript
-new Chart(ctx, {
- type: 'line',
- data: data,
- options: {
- animation: {
- duration: 0 // general animation time
- },
- hover: {
- animationDuration: 0 // duration of animations when hovering an item
- },
- responsiveAnimationDuration: 0 // animation duration after a resize
- }
-});
-``` | true |
Other | chartjs | Chart.js | 7c66b2f28cf871e1850ea9930759acada679fec7.json | Combine performance docs (#6632) | docs/general/performance.md | @@ -1,9 +1,84 @@
# Performance
-Chart.js charts are rendered on `canvas` elements, which makes rendering quite fast. For large datasets or performance sensitive applications, you may wish to consider the tips below:
+Chart.js charts are rendered on `canvas` elements, which makes rendering quite fast. For large datasets or performance sensitive applications, you may wish to consider the tips below.
-* Set `animation: { duration: 0 }` to disable [animations](../configuration/animations.md).
-* [Specify a rotation value](https://www.chartjs.org/docs/latest/axes/cartesian/#tick-configuration) by setting `minRotation` and `maxRotation` to the same value
-* For large datasets:
- * You may wish to sample your data before providing it to Chart.js. E.g. if you have a data point for each day, you may find it more performant to pass in a data point for each week instead
- * Set the [`ticks.sampleSize`](../axes/cartesian/README.md#tick-configuration) option in order to render axes more quickly
+## Tick Calculation
+
+### Rotation
+
+[Specify a rotation value](https://www.chartjs.org/docs/latest/axes/cartesian/#tick-configuration) by setting `minRotation` and `maxRotation` to the same value, which avoids the chart from having to automatically determine a value to use.
+
+### Sampling
+
+Set the [`ticks.sampleSize`](../axes/cartesian/README.md#tick-configuration) option. This will determine how large your labels are by looking at only a subset of them in order to render axes more quickly. This works best if there is not a large variance in the size of your labels.
+
+## Disable Animations
+
+If your charts have long render times, it is a good idea to disable animations. Doing so will mean that the chart needs to only be rendered once during an update instead of multiple times. This will have the effect of reducing CPU usage and improving general page performance.
+
+To disable animations
+
+```javascript
+new Chart(ctx, {
+ type: 'line',
+ data: data,
+ options: {
+ animation: {
+ duration: 0 // general animation time
+ },
+ hover: {
+ animationDuration: 0 // duration of animations when hovering an item
+ },
+ responsiveAnimationDuration: 0 // animation duration after a resize
+ }
+});
+```
+
+## Data Decimation
+
+Decimating your data will achieve the best results. When there is a lot of data to display on the graph, it doesn't make sense to show tens of thousands of data points on a graph that is only a few hundred pixels wide.
+
+There are many approaches to data decimation and selection of an algorithm will depend on your data and the results you want to achieve. For instance, [min/max](https://digital.ni.com/public.nsf/allkb/F694FFEEA0ACF282862576020075F784) decimation will preserve peaks in your data but could require up to 4 points for each pixel. This type of decimation would work well for a very noisy signal where you need to see data peaks.
+
+
+## Line Charts
+
+### Disable Bezier Curves
+
+If you are drawing lines on your chart, disabling bezier curves will improve render times since drawing a straight line is more performant than a bezier curve.
+
+To disable bezier curves for an entire chart:
+
+```javascript
+new Chart(ctx, {
+ type: 'line',
+ data: data,
+ options: {
+ elements: {
+ line: {
+ tension: 0 // disables bezier curves
+ }
+ }
+ }
+});
+```
+
+### Disable Line Drawing
+
+If you have a lot of data points, it can be more performant to disable rendering of the line for a dataset and only draw points. Doing this means that there is less to draw on the canvas which will improve render performance.
+
+To disable lines:
+
+```javascript
+new Chart(ctx, {
+ type: 'line',
+ data: {
+ datasets: [{
+ showLine: false // disable for a single dataset
+ }]
+ },
+ options: {
+ showLines: false // disable for all datasets
+ }
+});
+``` | true |
Other | chartjs | Chart.js | 0228776e6649c18000876e43e4d44a2317a693a5.json | Remove deprecated interaction modes (#6625)
* Remove deprecated interaction modes
* Use default modes | docs/general/interactions/modes.md | @@ -34,12 +34,6 @@ var chart = new Chart(ctx, {
});
```
-## single (deprecated)
-Finds the first item that intersects the point and returns it. Behaves like `'nearest'` mode with `intersect = true`.
-
-## label (deprecated)
-See `'index'` mode.
-
## index
Finds item at the same index. If the `intersect` setting is true, the first intersecting item is used to determine the index in the data. If `intersect` false the nearest item, in the x direction, is used to determine the index.
@@ -70,9 +64,6 @@ var chart = new Chart(ctx, {
});
```
-## x-axis (deprecated)
-Behaves like `'index'` mode with `intersect = false`.
-
## dataset
Finds items in the same dataset. If the `intersect` setting is true, the first intersecting item is used to determine the index in the data. If `intersect` false the nearest item is used to determine the index.
| true |
Other | chartjs | Chart.js | 0228776e6649c18000876e43e4d44a2317a693a5.json | Remove deprecated interaction modes (#6625)
* Remove deprecated interaction modes
* Use default modes | src/controllers/controller.bar.js | @@ -9,7 +9,7 @@ var valueOrDefault = helpers.valueOrDefault;
defaults._set('bar', {
hover: {
- mode: 'label'
+ mode: 'index'
},
scales: { | true |
Other | chartjs | Chart.js | 0228776e6649c18000876e43e4d44a2317a693a5.json | Remove deprecated interaction modes (#6625)
* Remove deprecated interaction modes
* Use default modes | src/controllers/controller.bubble.js | @@ -9,10 +9,6 @@ var valueOrDefault = helpers.valueOrDefault;
var resolve = helpers.options.resolve;
defaults._set('bubble', {
- hover: {
- mode: 'single'
- },
-
scales: {
xAxes: [{
type: 'linear', // bubble should probably use a linear scale by default | true |
Other | chartjs | Chart.js | 0228776e6649c18000876e43e4d44a2317a693a5.json | Remove deprecated interaction modes (#6625)
* Remove deprecated interaction modes
* Use default modes | src/controllers/controller.doughnut.js | @@ -18,9 +18,6 @@ defaults._set('doughnut', {
// Boolean - Whether we animate scaling the Doughnut from the centre
animateScale: false
},
- hover: {
- mode: 'single'
- },
legendCallback: function(chart) {
var list = document.createElement('ul');
var data = chart.data; | true |
Other | chartjs | Chart.js | 0228776e6649c18000876e43e4d44a2317a693a5.json | Remove deprecated interaction modes (#6625)
* Remove deprecated interaction modes
* Use default modes | src/controllers/controller.line.js | @@ -14,7 +14,7 @@ defaults._set('line', {
spanGaps: false,
hover: {
- mode: 'label'
+ mode: 'index'
},
scales: { | true |
Other | chartjs | Chart.js | 0228776e6649c18000876e43e4d44a2317a693a5.json | Remove deprecated interaction modes (#6625)
* Remove deprecated interaction modes
* Use default modes | src/controllers/controller.scatter.js | @@ -4,10 +4,6 @@ var LineController = require('./controller.line');
var defaults = require('../core/core.defaults');
defaults._set('scatter', {
- hover: {
- mode: 'single'
- },
-
scales: {
xAxes: [{
id: 'x-axis-1', // need an ID so datasets can reference the scale | true |
Other | chartjs | Chart.js | 0228776e6649c18000876e43e4d44a2317a693a5.json | Remove deprecated interaction modes (#6625)
* Remove deprecated interaction modes
* Use default modes | src/core/core.controller.js | @@ -800,15 +800,15 @@ helpers.extend(Chart.prototype, /** @lends Chart */ {
* @return An object containing the dataset index and element index of the matching element. Also contains the rectangle that was draw
*/
getElementAtEvent: function(e) {
- return Interaction.modes.single(this, e);
+ return Interaction.modes.nearest(this, e, {intersect: true});
},
getElementsAtEvent: function(e) {
- return Interaction.modes.label(this, e, {intersect: true});
+ return Interaction.modes.index(this, e, {intersect: true});
},
getElementsAtXAxis: function(e) {
- return Interaction.modes['x-axis'](this, e, {intersect: true});
+ return Interaction.modes.index(this, e, {intersect: false});
},
getElementsAtEventForMode: function(e, mode, options) { | true |
Other | chartjs | Chart.js | 0228776e6649c18000876e43e4d44a2317a693a5.json | Remove deprecated interaction modes (#6625)
* Remove deprecated interaction modes
* Use default modes | src/core/core.interaction.js | @@ -144,28 +144,6 @@ function indexMode(chart, e, options) {
module.exports = {
// Helper function for different modes
modes: {
- single: function(chart, e) {
- var position = getRelativePosition(e, chart);
- var elements = [];
-
- parseVisibleItems(chart, function(element) {
- if (element.inRange(position.x, position.y)) {
- elements.push(element);
- return elements;
- }
- });
-
- return elements.slice(0, 1);
- },
-
- /**
- * @function Chart.Interaction.modes.label
- * @deprecated since version 2.4.0
- * @todo remove at version 3
- * @private
- */
- label: indexMode,
-
/**
* Returns items at the same index. If the options.intersect parameter is true, we only return items if we intersect something
* If the options.intersect mode is false, we find the nearest item and return the items at the same index as that item
@@ -200,16 +178,6 @@ module.exports = {
return items;
},
- /**
- * @function Chart.Interaction.modes.x-axis
- * @deprecated since version 2.4.0. Use index mode and intersect == true
- * @todo remove at version 3
- * @private
- */
- 'x-axis': function(chart, e) {
- return indexMode(chart, e, {intersect: false});
- },
-
/**
* Point mode returns all elements that hit test based on the event position
* of the event | true |
Other | chartjs | Chart.js | 0228776e6649c18000876e43e4d44a2317a693a5.json | Remove deprecated interaction modes (#6625)
* Remove deprecated interaction modes
* Use default modes | test/specs/controller.line.tests.js | @@ -244,7 +244,8 @@ describe('Chart.controllers.line', function() {
legend: false,
title: false,
hover: {
- mode: 'single'
+ mode: 'nearest',
+ intersect: true
},
scales: {
xAxes: [{ | true |
Other | chartjs | Chart.js | 0228776e6649c18000876e43e4d44a2317a693a5.json | Remove deprecated interaction modes (#6625)
* Remove deprecated interaction modes
* Use default modes | test/specs/core.controller.tests.js | @@ -87,7 +87,7 @@ describe('Chart', function() {
defaults.global.responsiveAnimationDuration = 0;
defaults.global.hover.onHover = null;
defaults.line.spanGaps = false;
- defaults.line.hover.mode = 'label';
+ defaults.line.hover.mode = 'index';
});
it('should override default options', function() {
@@ -122,7 +122,7 @@ describe('Chart', function() {
defaults.global.responsiveAnimationDuration = 0;
defaults.global.hover.onHover = null;
- defaults.line.hover.mode = 'label';
+ defaults.line.hover.mode = 'index';
defaults.line.spanGaps = false;
});
| true |
Other | chartjs | Chart.js | 0228776e6649c18000876e43e4d44a2317a693a5.json | Remove deprecated interaction modes (#6625)
* Remove deprecated interaction modes
* Use default modes | test/specs/core.tooltip.tests.js | @@ -257,7 +257,8 @@ describe('Core.Tooltip', function() {
},
options: {
tooltips: {
- mode: 'single'
+ mode: 'nearest',
+ intersect: true
}
}
});
@@ -366,7 +367,7 @@ describe('Core.Tooltip', function() {
},
options: {
tooltips: {
- mode: 'label',
+ mode: 'index',
callbacks: {
beforeTitle: function() {
return 'beforeTitle';
@@ -519,7 +520,7 @@ describe('Core.Tooltip', function() {
},
options: {
tooltips: {
- mode: 'label',
+ mode: 'index',
itemSort: function(a, b) {
return a.datasetIndex > b.datasetIndex ? -1 : 1;
}
@@ -600,7 +601,7 @@ describe('Core.Tooltip', function() {
},
options: {
tooltips: {
- mode: 'label',
+ mode: 'index',
reverse: true
}
}
@@ -681,7 +682,7 @@ describe('Core.Tooltip', function() {
},
options: {
tooltips: {
- mode: 'label'
+ mode: 'index'
}
}
});
@@ -760,7 +761,7 @@ describe('Core.Tooltip', function() {
},
options: {
tooltips: {
- mode: 'label',
+ mode: 'index',
filter: function(tooltipItem, data) {
// For testing purposes remove the first dataset that has a tooltipHidden property
return !data.datasets[tooltipItem.datasetIndex].tooltipHidden;
@@ -885,7 +886,8 @@ describe('Core.Tooltip', function() {
},
options: {
tooltips: {
- mode: 'single'
+ mode: 'nearest',
+ intersect: true
}
}
});
@@ -935,7 +937,8 @@ describe('Core.Tooltip', function() {
},
options: {
tooltips: {
- mode: 'single',
+ mode: 'nearest',
+ intersect: true,
callbacks: {
title: function() {
return 'registering callback...';
@@ -1123,7 +1126,7 @@ describe('Core.Tooltip', function() {
},
options: {
tooltips: {
- mode: 'label',
+ mode: 'index',
callbacks: {
beforeTitle: function() {
return 'beforeTitle\nnewline'; | true |
Other | chartjs | Chart.js | 39d83eeae0e1713af7152aa8af40b1cfa50f800e.json | Fix scatter sample (#6627) | samples/scales/logarithmic/scatter.html | @@ -137,7 +137,7 @@
position: 'bottom',
ticks: {
userCallback: function(tick) {
- var remain = tick / (Math.pow(10, Math.floor(Chart.helpers.log10(tick))));
+ var remain = tick / (Math.pow(10, Math.floor(Chart.helpers.math.log10(tick))));
if (remain === 1 || remain === 2 || remain === 5) {
return tick.toString() + 'Hz';
} | false |
Other | chartjs | Chart.js | d932f9c56e388f100e4fbc02dd968587f5583921.json | Remove deprecated code from index.js (#6623)
Remove deprecated code from index.js | src/index.js | @@ -48,103 +48,3 @@ module.exports = Chart;
if (typeof window !== 'undefined') {
window.Chart = Chart;
}
-
-// DEPRECATIONS
-
-/**
- * Provided for backward compatibility, not available anymore
- * @namespace Chart.Chart
- * @deprecated since version 2.8.0
- * @todo remove at version 3
- * @private
- */
-Chart.Chart = Chart;
-
-/**
- * Provided for backward compatibility, not available anymore
- * @namespace Chart.Legend
- * @deprecated since version 2.1.5
- * @todo remove at version 3
- * @private
- */
-Chart.Legend = plugins.legend._element;
-
-/**
- * Provided for backward compatibility, not available anymore
- * @namespace Chart.Title
- * @deprecated since version 2.1.5
- * @todo remove at version 3
- * @private
- */
-Chart.Title = plugins.title._element;
-
-/**
- * Provided for backward compatibility, use Chart.plugins instead
- * @namespace Chart.pluginService
- * @deprecated since version 2.1.5
- * @todo remove at version 3
- * @private
- */
-Chart.pluginService = Chart.plugins;
-
-/**
- * Provided for backward compatibility, inheriting from Chart.PlugingBase has no
- * effect, instead simply create/register plugins via plain JavaScript objects.
- * @interface Chart.PluginBase
- * @deprecated since version 2.5.0
- * @todo remove at version 3
- * @private
- */
-Chart.PluginBase = Chart.Element.extend({});
-
-/**
- * Provided for backward compatibility, use Chart.helpers.canvas instead.
- * @namespace Chart.canvasHelpers
- * @deprecated since version 2.6.0
- * @todo remove at version 3
- * @private
- */
-Chart.canvasHelpers = Chart.helpers.canvas;
-
-/**
- * Provided for backward compatibility, use Chart.layouts instead.
- * @namespace Chart.layoutService
- * @deprecated since version 2.7.3
- * @todo remove at version 3
- * @private
- */
-Chart.layoutService = Chart.layouts;
-
-/**
- * Provided for backward compatibility, not available anymore.
- * @namespace Chart.LinearScaleBase
- * @deprecated since version 2.8
- * @todo remove at version 3
- * @private
- */
-Chart.LinearScaleBase = require('./scales/scale.linearbase');
-
-/**
- * Provided for backward compatibility, instead we should create a new Chart
- * by setting the type in the config (`new Chart(id, {type: '{chart-type}'}`).
- * @deprecated since version 2.8.0
- * @todo remove at version 3
- */
-Chart.helpers.each(
- [
- 'Bar',
- 'Bubble',
- 'Doughnut',
- 'Line',
- 'PolarArea',
- 'Radar',
- 'Scatter'
- ],
- function(klass) {
- Chart[klass] = function(ctx, cfg) {
- return new Chart(ctx, Chart.helpers.merge(cfg || {}, {
- type: klass.charAt(0).toLowerCase() + klass.slice(1)
- }));
- };
- }
-); | true |
Other | chartjs | Chart.js | d932f9c56e388f100e4fbc02dd968587f5583921.json | Remove deprecated code from index.js (#6623)
Remove deprecated code from index.js | test/.eslintrc.yml | @@ -1,5 +1,5 @@
parserOptions:
- ecmaVersion: 5 # don't rely on default, since its changed by env: es6
+ ecmaVersion: 6
env:
es6: true # also changes default ecmaVersion to 6 | true |
Other | chartjs | Chart.js | d932f9c56e388f100e4fbc02dd968587f5583921.json | Remove deprecated code from index.js (#6623)
Remove deprecated code from index.js | test/specs/plugin.title.tests.js | @@ -1,5 +1,7 @@
// Test the rectangle element
+var Title = Chart.plugins.getAll().find(p => p.id === 'title')._element;
+
describe('Title block tests', function() {
it('Should have the correct default config', function() {
expect(Chart.defaults.global.title).toEqual({
@@ -19,7 +21,7 @@ describe('Title block tests', function() {
var options = Chart.helpers.clone(Chart.defaults.global.title);
options.text = 'My title';
- var title = new Chart.Title({
+ var title = new Title({
chart: chart,
options: options
});
@@ -49,7 +51,7 @@ describe('Title block tests', function() {
options.text = 'My title';
options.position = 'left';
- var title = new Chart.Title({
+ var title = new Title({
chart: chart,
options: options
});
@@ -81,7 +83,7 @@ describe('Title block tests', function() {
options.display = true;
options.lineHeight = 1.5;
- var title = new Chart.Title({
+ var title = new Title({
chart: chart,
options: options
});
@@ -101,7 +103,7 @@ describe('Title block tests', function() {
var options = Chart.helpers.clone(Chart.defaults.global.title);
options.text = 'My title';
- var title = new Chart.Title({
+ var title = new Title({
chart: chart,
options: options,
ctx: context
@@ -154,7 +156,7 @@ describe('Title block tests', function() {
options.text = 'My title';
options.position = 'left';
- var title = new Chart.Title({
+ var title = new Title({
chart: chart,
options: options,
ctx: context | true |
Other | chartjs | Chart.js | 5b0a0b039ce30f40a5a4a6162667f9eaf4c62f0f.json | Time scale: return time from getValueForPixel (#6616) | src/adapters/adapter.moment.js | @@ -56,17 +56,5 @@ adapters._date.override(typeof moment === 'function' ? {
endOf: function(time, unit) {
return moment(time).endOf(unit).valueOf();
- },
-
- // DEPRECATIONS
-
- /**
- * Provided for backward compatibility with scale.getValueForPixel().
- * @deprecated since version 2.8.0
- * @todo remove at version 3
- * @private
- */
- _create: function(time) {
- return moment(time);
- },
+ }
} : {}); | true |
Other | chartjs | Chart.js | 5b0a0b039ce30f40a5a4a6162667f9eaf4c62f0f.json | Time scale: return time from getValueForPixel (#6616) | src/core/core.adapters.js | @@ -98,20 +98,7 @@ helpers.extend(DateAdapter.prototype, /** @lends DateAdapter */ {
* @param {Unit} unit - the unit as string
* @function
*/
- endOf: abstract,
-
- // DEPRECATIONS
-
- /**
- * Provided for backward compatibility for scale.getValueForPixel(),
- * this method should be overridden only by the moment adapter.
- * @deprecated since version 2.8.0
- * @todo remove at version 3
- * @private
- */
- _create: function(value) {
- return value;
- }
+ endOf: abstract
});
DateAdapter.override = function(members) { | true |
Other | chartjs | Chart.js | 5b0a0b039ce30f40a5a4a6162667f9eaf4c62f0f.json | Time scale: return time from getValueForPixel (#6616) | src/scales/scale.time.js | @@ -706,10 +706,7 @@ module.exports = Scale.extend({
var me = this;
var offsets = me._offsets;
var pos = me.getDecimalForPixel(pixel) / offsets.factor - offsets.end;
- var time = interpolate(me._table, 'pos', pos, 'time');
-
- // DEPRECATION, we should return time directly
- return me._adapter._create(time);
+ return interpolate(me._table, 'pos', pos, 'time');
},
/** | true |
Other | chartjs | Chart.js | 5b0a0b039ce30f40a5a4a6162667f9eaf4c62f0f.json | Time scale: return time from getValueForPixel (#6616) | test/specs/scale.time.tests.js | @@ -28,9 +28,9 @@ describe('Time scale tests', function() {
jasmine.addMatchers({
toBeCloseToTime: function() {
return {
- compare: function(actual, expected) {
+ compare: function(time, expected) {
var result = false;
-
+ var actual = moment(time);
var diff = actual.diff(expected.value, expected.unit, true);
result = Math.abs(diff) < (expected.threshold !== undefined ? expected.threshold : 0.01);
| true |
Other | chartjs | Chart.js | 92a4654d9b2ae91683c179cbf6186b31952cfcd1.json | Remove deprecated helpers (#6607) | src/core/core.helpers.js | @@ -148,16 +148,6 @@ module.exports = function() {
return Math.sqrt(Math.pow(pt2.x - pt1.x, 2) + Math.pow(pt2.y - pt1.y, 2));
};
- /**
- * Provided for backward compatibility, not available anymore
- * @function Chart.helpers.aliasPixel
- * @deprecated since version 2.8.0
- * @todo remove at version 3
- */
- helpers.aliasPixel = function(pixelWidth) {
- return (pixelWidth % 2 === 0) ? 0 : 0.5;
- };
-
/**
* Returns the aligned pixel value to avoid anti-aliasing blur
* @param {Chart} chart - The chart instance.
@@ -312,7 +302,7 @@ module.exports = function() {
};
// Implementation of the nice number algorithm used in determining where axis labels will go
helpers.niceNum = function(range, round) {
- var exponent = Math.floor(helpers.log10(range));
+ var exponent = Math.floor(helpers.math.log10(range));
var fraction = range / Math.pow(10, exponent);
var niceFraction;
@@ -582,21 +572,6 @@ module.exports = function() {
return longest;
};
- /**
- * @deprecated
- */
- helpers.numberOfLabelLines = function(arrayOfThings) {
- var numberOfLines = 1;
- helpers.each(arrayOfThings, function(thing) {
- if (helpers.isArray(thing)) {
- if (thing.length > numberOfLines) {
- numberOfLines = thing.length;
- }
- }
- });
- return numberOfLines;
- };
-
helpers.color = !color ?
function(value) {
console.error('Color.js not found!'); | true |
Other | chartjs | Chart.js | 92a4654d9b2ae91683c179cbf6186b31952cfcd1.json | Remove deprecated helpers (#6607) | src/core/core.ticks.js | @@ -1,6 +1,7 @@
'use strict';
var helpers = require('../helpers/index');
+var math = helpers.math;
/**
* Namespace to hold static tick generation functions
@@ -42,13 +43,13 @@ module.exports = {
}
}
- var logDelta = helpers.log10(Math.abs(delta));
+ var logDelta = math.log10(Math.abs(delta));
var tickString = '';
if (tickValue !== 0) {
var maxTick = Math.max(Math.abs(ticks[0]), Math.abs(ticks[ticks.length - 1]));
if (maxTick < 1e-4) { // all ticks are small numbers; use scientific notation
- var logTick = helpers.log10(Math.abs(tickValue));
+ var logTick = math.log10(Math.abs(tickValue));
var numExponential = Math.floor(logTick) - Math.floor(logDelta);
numExponential = Math.max(Math.min(numExponential, 20), 0);
tickString = tickValue.toExponential(numExponential);
@@ -65,7 +66,7 @@ module.exports = {
},
logarithmic: function(tickValue, index, ticks) {
- var remain = tickValue / (Math.pow(10, Math.floor(helpers.log10(tickValue))));
+ var remain = tickValue / (Math.pow(10, Math.floor(math.log10(tickValue))));
if (tickValue === 0) {
return '0'; | true |
Other | chartjs | Chart.js | 92a4654d9b2ae91683c179cbf6186b31952cfcd1.json | Remove deprecated helpers (#6607) | src/helpers/helpers.canvas.js | @@ -1,7 +1,5 @@
'use strict';
-var helpers = require('./helpers.core');
-
var PI = Math.PI;
var RAD_PER_DEG = PI / 180;
var DOUBLE_PI = PI * 2;
@@ -233,26 +231,3 @@ var exports = {
};
module.exports = exports;
-
-// DEPRECATIONS
-
-/**
- * Provided for backward compatibility, use Chart.helpers.canvas.clear instead.
- * @namespace Chart.helpers.clear
- * @deprecated since version 2.7.0
- * @todo remove at version 3
- * @private
- */
-helpers.clear = exports.clear;
-
-/**
- * Provided for backward compatibility, use Chart.helpers.canvas.roundedRect instead.
- * @namespace Chart.helpers.drawRoundedRectangle
- * @deprecated since version 2.7.0
- * @todo remove at version 3
- * @private
- */
-helpers.drawRoundedRectangle = function(ctx) {
- ctx.beginPath();
- exports.roundedRect.apply(exports, arguments);
-}; | true |
Other | chartjs | Chart.js | 92a4654d9b2ae91683c179cbf6186b31952cfcd1.json | Remove deprecated helpers (#6607) | src/helpers/helpers.core.js | @@ -317,44 +317,3 @@ var helpers = {
};
module.exports = helpers;
-
-// DEPRECATIONS
-
-/**
- * Provided for backward compatibility, use Chart.helpers.callback instead.
- * @function Chart.helpers.callCallback
- * @deprecated since version 2.6.0
- * @todo remove at version 3
- * @private
- */
-helpers.callCallback = helpers.callback;
-
-/**
- * Provided for backward compatibility, use Array.prototype.indexOf instead.
- * Array.prototype.indexOf compatibility: Chrome, Opera, Safari, FF1.5+, IE9+
- * @function Chart.helpers.indexOf
- * @deprecated since version 2.7.0
- * @todo remove at version 3
- * @private
- */
-helpers.indexOf = function(array, item, fromIndex) {
- return Array.prototype.indexOf.call(array, item, fromIndex);
-};
-
-/**
- * Provided for backward compatibility, use Chart.helpers.valueOrDefault instead.
- * @function Chart.helpers.getValueOrDefault
- * @deprecated since version 2.7.0
- * @todo remove at version 3
- * @private
- */
-helpers.getValueOrDefault = helpers.valueOrDefault;
-
-/**
- * Provided for backward compatibility, use Chart.helpers.valueAtIndexOrDefault instead.
- * @function Chart.helpers.getValueAtIndexOrDefault
- * @deprecated since version 2.7.0
- * @todo remove at version 3
- * @private
- */
-helpers.getValueAtIndexOrDefault = helpers.valueAtIndexOrDefault; | true |
Other | chartjs | Chart.js | 92a4654d9b2ae91683c179cbf6186b31952cfcd1.json | Remove deprecated helpers (#6607) | src/helpers/helpers.easing.js | @@ -1,10 +1,8 @@
'use strict';
-var helpers = require('./helpers.core');
-
/**
* Easing functions adapted from Robert Penner's easing equations.
- * @namespace Chart.helpers.easingEffects
+ * @namespace Chart.helpers.effects
* @see http://www.robertpenner.com/easing/
*/
var effects = {
@@ -237,14 +235,3 @@ var effects = {
module.exports = {
effects: effects
};
-
-// DEPRECATIONS
-
-/**
- * Provided for backward compatibility, use Chart.helpers.easing.effects instead.
- * @function Chart.helpers.easingEffects
- * @deprecated since version 2.7.0
- * @todo remove at version 3
- * @private
- */
-helpers.easingEffects = effects; | true |
Other | chartjs | Chart.js | 92a4654d9b2ae91683c179cbf6186b31952cfcd1.json | Remove deprecated helpers (#6607) | src/helpers/helpers.math.js | @@ -1,7 +1,5 @@
'use strict';
-var helpers = require('./helpers.core');
-
/**
* @alias Chart.helpers.math
* @namespace
@@ -44,14 +42,3 @@ var exports = {
};
module.exports = exports;
-
-// DEPRECATIONS
-
-/**
- * Provided for backward compatibility, use Chart.helpers.math.log10 instead.
- * @namespace Chart.helpers.log10
- * @deprecated since version 2.9.0
- * @todo remove at version 3
- * @private
- */
-helpers.log10 = exports.log10; | true |
Other | chartjs | Chart.js | 92a4654d9b2ae91683c179cbf6186b31952cfcd1.json | Remove deprecated helpers (#6607) | src/platforms/platform.dom.js | @@ -446,27 +446,3 @@ module.exports = {
removeListener(canvas, type, proxy);
}
};
-
-// DEPRECATIONS
-
-/**
- * Provided for backward compatibility, use EventTarget.addEventListener instead.
- * EventTarget.addEventListener compatibility: Chrome, Opera 7, Safari, FF1.5+, IE9+
- * @see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
- * @function Chart.helpers.addEvent
- * @deprecated since version 2.7.0
- * @todo remove at version 3
- * @private
- */
-helpers.addEvent = addListener;
-
-/**
- * Provided for backward compatibility, use EventTarget.removeEventListener instead.
- * EventTarget.removeEventListener compatibility: Chrome, Opera 7, Safari, FF1.5+, IE9+
- * @see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener
- * @function Chart.helpers.removeEvent
- * @deprecated since version 2.7.0
- * @todo remove at version 3
- * @private
- */
-helpers.removeEvent = removeListener; | true |
Other | chartjs | Chart.js | 92a4654d9b2ae91683c179cbf6186b31952cfcd1.json | Remove deprecated helpers (#6607) | test/specs/core.helpers.tests.js | @@ -378,17 +378,6 @@ describe('Core helper tests', function() {
}]);
});
- it('count look at all the labels and return maximum number of lines', function() {
- window.createMockContext();
- var arrayOfThings1 = ['Foo', 'Bar'];
- var arrayOfThings2 = [['Foo', 'Bar'], 'Foo'];
- var arrayOfThings3 = [['Foo', 'Bar', 'Boo'], ['Foo', 'Bar'], 'Foo'];
-
- expect(helpers.numberOfLabelLines(arrayOfThings1)).toEqual(1);
- expect(helpers.numberOfLabelLines(arrayOfThings2)).toEqual(2);
- expect(helpers.numberOfLabelLines(arrayOfThings3)).toEqual(3);
- });
-
it ('should get the maximum width and height for a node', function() {
// Create div with fixed size as a test bed
var div = document.createElement('div'); | true |
Other | chartjs | Chart.js | 92a4654d9b2ae91683c179cbf6186b31952cfcd1.json | Remove deprecated helpers (#6607) | test/specs/global.deprecations.tests.js | @@ -1,469 +0,0 @@
-describe('Deprecations', function() {
- describe('Version 2.9.0', function() {
- describe('Chart.Scale.mergeTicksOptions', function() {
- it('should be defined as a function', function() {
- expect(typeof Chart.Scale.prototype.mergeTicksOptions).toBe('function');
- });
- });
- });
-
- describe('Version 2.8.0', function() {
- [
- ['Bar', 'bar'],
- ['Bubble', 'bubble'],
- ['Doughnut', 'doughnut'],
- ['Line', 'line'],
- ['PolarArea', 'polarArea'],
- ['Radar', 'radar'],
- ['Scatter', 'scatter']
- ].forEach(function(descriptor) {
- var klass = descriptor[0];
- var type = descriptor[1];
-
- describe('Chart.' + klass, function() {
- it('should be defined as a function', function() {
- expect(typeof Chart[klass]).toBe('function');
- });
- it('should create a chart of type "' + type + '"', function() {
- var chart = new Chart[klass]('foo', {data: {}});
- expect(chart instanceof Chart.Controller).toBeTruthy();
- expect(chart.config.type).toBe(type);
- });
- });
- });
-
- describe('Chart.Chart', function() {
- it('should be defined as an alias to Chart', function() {
- expect(Chart.Chart).toBe(Chart);
- });
- });
-
- describe('Chart.helpers.aliasPixel', function() {
- it('should be defined as a function', function() {
- expect(typeof Chart.helpers.aliasPixel).toBe('function');
- });
- });
-
- describe('Chart.LinearScaleBase', function() {
- it('should be defined and inherit from Chart.Scale', function() {
- expect(typeof Chart.LinearScaleBase).toBe('function');
- expect(Chart.LinearScaleBase.prototype instanceof Chart.Scale).toBeTruthy();
- });
- });
-
- describe('Chart.types', function() {
- it('should be defined as an empty object', function() {
- expect(Chart.types).toEqual({});
- });
- });
-
- describe('Chart.helpers.configMerge', function() {
- it('should be defined as a function', function() {
- expect(typeof Chart.helpers.configMerge).toBe('function');
- });
- });
-
- describe('Chart.helpers.scaleMerge', function() {
- it('should be defined as a function', function() {
- expect(typeof Chart.helpers.scaleMerge).toBe('function');
- });
- });
- });
-
- describe('Version 2.7.3', function() {
- describe('Chart.layoutService', function() {
- it('should be defined and an alias of Chart.layouts', function() {
- expect(Chart.layoutService).toBeDefined();
- expect(Chart.layoutService).toBe(Chart.layouts);
- });
- });
- });
-
- describe('Version 2.7.0', function() {
- describe('Chart.Controller.update(duration, lazy)', function() {
- it('should add an animation with the provided options', function() {
- var chart = acquireChart({
- type: 'doughnut',
- options: {
- animation: {
- easing: 'linear',
- duration: 500
- }
- }
- });
-
- spyOn(Chart.animationService, 'addAnimation');
-
- chart.update(800, false);
-
- expect(Chart.animationService.addAnimation).toHaveBeenCalledWith(
- chart,
- jasmine.objectContaining({easing: 'linear'}),
- 800,
- false
- );
- });
- });
-
- describe('Chart.Controller.render(duration, lazy)', function() {
- it('should add an animation with the provided options', function() {
- var chart = acquireChart({
- type: 'doughnut',
- options: {
- animation: {
- easing: 'linear',
- duration: 500
- }
- }
- });
-
- spyOn(Chart.animationService, 'addAnimation');
-
- chart.render(800, true);
-
- expect(Chart.animationService.addAnimation).toHaveBeenCalledWith(
- chart,
- jasmine.objectContaining({easing: 'linear'}),
- 800,
- true
- );
- });
- });
-
- describe('Chart.helpers.indexOf', function() {
- it('should be defined and a function', function() {
- expect(typeof Chart.helpers.indexOf).toBe('function');
- });
- it('should returns the correct index', function() {
- expect(Chart.helpers.indexOf([1, 2, 42], 42)).toBe(2);
- expect(Chart.helpers.indexOf([1, 2, 42], 3)).toBe(-1);
- expect(Chart.helpers.indexOf([1, 42, 2, 42], 42, 2)).toBe(3);
- expect(Chart.helpers.indexOf([1, 42, 2, 42], 3, 2)).toBe(-1);
- });
- });
-
- describe('Chart.helpers.clear', function() {
- it('should be defined and an alias of Chart.helpers.canvas.clear', function() {
- expect(Chart.helpers.clear).toBeDefined();
- expect(Chart.helpers.clear).toBe(Chart.helpers.canvas.clear);
- });
- });
-
- describe('Chart.helpers.getValueOrDefault', function() {
- it('should be defined and an alias of Chart.helpers.valueOrDefault', function() {
- expect(Chart.helpers.getValueOrDefault).toBeDefined();
- expect(Chart.helpers.getValueOrDefault).toBe(Chart.helpers.valueOrDefault);
- });
- });
-
- describe('Chart.helpers.getValueAtIndexOrDefault', function() {
- it('should be defined and an alias of Chart.helpers.valueAtIndexOrDefault', function() {
- expect(Chart.helpers.getValueAtIndexOrDefault).toBeDefined();
- expect(Chart.helpers.getValueAtIndexOrDefault).toBe(Chart.helpers.valueAtIndexOrDefault);
- });
- });
-
- describe('Chart.helpers.easingEffects', function() {
- it('should be defined and an alias of Chart.helpers.easing.effects', function() {
- expect(Chart.helpers.easingEffects).toBeDefined();
- expect(Chart.helpers.easingEffects).toBe(Chart.helpers.easing.effects);
- });
- });
-
- describe('Chart.helpers.drawRoundedRectangle', function() {
- it('should be defined and a function', function() {
- expect(typeof Chart.helpers.drawRoundedRectangle).toBe('function');
- });
- it('should call Chart.helpers.canvas.roundedRect', function() {
- var ctx = window.createMockContext();
- spyOn(Chart.helpers.canvas, 'roundedRect');
-
- Chart.helpers.drawRoundedRectangle(ctx, 10, 20, 30, 40, 5);
-
- var calls = ctx.getCalls();
- expect(calls[0]).toEqual({name: 'beginPath', args: []});
- expect(Chart.helpers.canvas.roundedRect).toHaveBeenCalledWith(ctx, 10, 20, 30, 40, 5);
- });
- });
-
- describe('Chart.helpers.addEvent', function() {
- it('should be defined and a function', function() {
- expect(typeof Chart.helpers.addEvent).toBe('function');
- });
- it('should correctly add event listener', function() {
- var listener = jasmine.createSpy('spy');
- Chart.helpers.addEvent(window, 'test', listener);
- window.dispatchEvent(new Event('test'));
- expect(listener).toHaveBeenCalled();
- });
- });
-
- describe('Chart.helpers.removeEvent', function() {
- it('should be defined and a function', function() {
- expect(typeof Chart.helpers.removeEvent).toBe('function');
- });
- it('should correctly remove event listener', function() {
- var listener = jasmine.createSpy('spy');
- Chart.helpers.addEvent(window, 'test', listener);
- Chart.helpers.removeEvent(window, 'test', listener);
- window.dispatchEvent(new Event('test'));
- expect(listener).not.toHaveBeenCalled();
- });
- });
- });
-
- describe('Version 2.6.0', function() {
- // https://github.com/chartjs/Chart.js/issues/2481
- describe('Chart.Controller', function() {
- it('should be defined and an alias of Chart', function() {
- expect(Chart.Controller).toBeDefined();
- expect(Chart.Controller).toBe(Chart);
- });
- it('should be prototype of chart instances', function() {
- var chart = acquireChart({});
- expect(chart.constructor).toBe(Chart.Controller);
- expect(chart instanceof Chart.Controller).toBeTruthy();
- expect(Chart.Controller.prototype.isPrototypeOf(chart)).toBeTruthy();
- });
- });
-
- describe('chart.chart', function() {
- it('should be defined and an alias of chart', function() {
- var chart = acquireChart({});
- var proxy = chart.chart;
- expect(proxy).toBeDefined();
- expect(proxy).toBe(chart);
- });
- it('should defined previously existing properties', function() {
- var chart = acquireChart({}, {
- canvas: {
- style: 'width: 140px; height: 320px'
- }
- });
-
- var proxy = chart.chart;
- expect(proxy.config instanceof Object).toBeTruthy();
- expect(proxy.controller instanceof Chart.Controller).toBeTruthy();
- expect(proxy.canvas instanceof HTMLCanvasElement).toBeTruthy();
- expect(proxy.ctx instanceof CanvasRenderingContext2D).toBeTruthy();
- expect(proxy.currentDevicePixelRatio).toBe(window.devicePixelRatio || 1);
- expect(proxy.aspectRatio).toBe(140 / 320);
- expect(proxy.height).toBe(320);
- expect(proxy.width).toBe(140);
- });
- });
-
- describe('Chart.Animation.animationObject', function() {
- it('should be defined and an alias of Chart.Animation', function(done) {
- var animation = null;
-
- acquireChart({
- options: {
- animation: {
- duration: 50,
- onComplete: function(arg) {
- animation = arg;
- }
- }
- }
- });
-
- setTimeout(function() {
- expect(animation).not.toBeNull();
- expect(animation.animationObject).toBeDefined();
- expect(animation.animationObject).toBe(animation);
- done();
- }, 200);
- });
- });
-
- describe('Chart.Animation.chartInstance', function() {
- it('should be defined and an alias of Chart.Animation.chart', function(done) {
- var animation = null;
- var chart = acquireChart({
- options: {
- animation: {
- duration: 50,
- onComplete: function(arg) {
- animation = arg;
- }
- }
- }
- });
-
- setTimeout(function() {
- expect(animation).not.toBeNull();
- expect(animation.chartInstance).toBeDefined();
- expect(animation.chartInstance).toBe(chart);
- done();
- }, 200);
- });
- });
-
- describe('Chart.elements.Line: fill option', function() {
- it('should decode "zero", "top" and "bottom" as "origin", "start" and "end"', function() {
- var chart = window.acquireChart({
- type: 'line',
- data: {
- datasets: [
- {fill: 'zero'},
- {fill: 'bottom'},
- {fill: 'top'},
- ]
- }
- });
-
- ['origin', 'start', 'end'].forEach(function(expected, index) {
- var meta = chart.getDatasetMeta(index);
- expect(meta.$filler).toBeDefined();
- expect(meta.$filler.fill).toBe(expected);
- });
- });
- });
-
- describe('Chart.helpers.callCallback', function() {
- it('should be defined and an alias of Chart.helpers.callback', function() {
- expect(Chart.helpers.callCallback).toBeDefined();
- expect(Chart.helpers.callCallback).toBe(Chart.helpers.callback);
- });
- });
-
- describe('Time Axis: unitStepSize option', function() {
- it('should use the stepSize property', function() {
- var chart = window.acquireChart({
- type: 'line',
- data: {
- labels: ['2015-01-01T20:00:00', '2015-01-01T21:00:00'],
- },
- options: {
- scales: {
- xAxes: [{
- id: 'time',
- type: 'time',
- bounds: 'ticks',
- time: {
- unit: 'hour',
- unitStepSize: 2
- }
- }]
- }
- }
- });
-
- var ticks = chart.scales.time.getTicks().map(function(tick) {
- return tick.label;
- });
-
- expect(ticks).toEqual(['8PM', '10PM']);
- });
- });
- });
-
- describe('Version 2.5.0', function() {
- describe('Chart.PluginBase', function() {
- it('should exist and extendable', function() {
- expect(Chart.PluginBase).toBeDefined();
- expect(Chart.PluginBase.extend).toBeDefined();
- });
- });
-
- describe('IPlugin.afterScaleUpdate', function() {
- it('should be called after the chart as been layed out', function() {
- var sequence = [];
- var plugin = {};
- var hooks = [
- 'beforeLayout',
- 'afterScaleUpdate',
- 'afterLayout'
- ];
-
- var override = Chart.layouts.update;
- Chart.layouts.update = function() {
- sequence.push('layoutUpdate');
- override.apply(this, arguments);
- };
-
- hooks.forEach(function(name) {
- plugin[name] = function() {
- sequence.push(name);
- };
- });
-
- window.acquireChart({plugins: [plugin]});
- expect(sequence).toEqual([].concat(
- 'beforeLayout',
- 'layoutUpdate',
- 'afterScaleUpdate',
- 'afterLayout'
- ));
- });
- });
- });
-
- describe('Version 2.4.0', function() {
- describe('x-axis mode', function() {
- it ('behaves like index mode with intersect: false', function() {
- var data = {
- datasets: [{
- label: 'Dataset 1',
- data: [10, 20, 30],
- pointHoverBorderColor: 'rgb(255, 0, 0)',
- pointHoverBackgroundColor: 'rgb(0, 255, 0)'
- }, {
- label: 'Dataset 2',
- data: [40, 40, 40],
- pointHoverBorderColor: 'rgb(0, 0, 255)',
- pointHoverBackgroundColor: 'rgb(0, 255, 255)'
- }],
- labels: ['Point 1', 'Point 2', 'Point 3']
- };
-
- var chart = window.acquireChart({
- type: 'line',
- data: data
- });
- var meta0 = chart.getDatasetMeta(0);
- var meta1 = chart.getDatasetMeta(1);
-
- var evt = {
- type: 'click',
- chart: chart,
- native: true, // needed otherwise things its a DOM event
- x: 0,
- y: 0
- };
-
- var elements = Chart.Interaction.modes['x-axis'](chart, evt);
- expect(elements).toEqual([meta0.data[0], meta1.data[0]]);
- });
- });
- });
-
- describe('Version 2.1.5', function() {
- // https://github.com/chartjs/Chart.js/pull/2752
- describe('Chart.pluginService', function() {
- it('should be defined and an alias of Chart.plugins', function() {
- expect(Chart.pluginService).toBeDefined();
- expect(Chart.pluginService).toBe(Chart.plugins);
- });
- });
-
- describe('Chart.Legend', function() {
- it('should be defined and an instance of Chart.Element', function() {
- var legend = new Chart.Legend({});
- expect(Chart.Legend).toBeDefined();
- expect(legend).not.toBe(undefined);
- expect(legend instanceof Chart.Element).toBeTruthy();
- });
- });
-
- describe('Chart.Title', function() {
- it('should be defined and an instance of Chart.Element', function() {
- var title = new Chart.Title({});
- expect(Chart.Title).toBeDefined();
- expect(title).not.toBe(undefined);
- expect(title instanceof Chart.Element).toBeTruthy();
- });
- });
- });
-}); | true |
Other | chartjs | Chart.js | 0da237a31575093c1b5c964574a45ab8e6a1f88b.json | Remove undocumented "custom" feature (#6605)
Remove undocumented "custom" feature | src/controllers/controller.bar.js | @@ -179,7 +179,7 @@ module.exports = DatasetController.extend({
var me = this;
var meta = me.getMeta();
var dataset = me.getDataset();
- var options = me._resolveDataElementOptions(rectangle, index);
+ var options = me._resolveDataElementOptions(index);
rectangle._xScale = me.getScaleForId(meta.xAxisID);
rectangle._yScale = me.getScaleForId(meta.yAxisID); | true |
Other | chartjs | Chart.js | 0da237a31575093c1b5c964574a45ab8e6a1f88b.json | Remove undocumented "custom" feature (#6605)
Remove undocumented "custom" feature | src/controllers/controller.bubble.js | @@ -83,10 +83,9 @@ module.exports = DatasetController.extend({
updateElement: function(point, index, reset) {
var me = this;
var meta = me.getMeta();
- var custom = point.custom || {};
var xScale = me.getScaleForId(meta.xAxisID);
var yScale = me.getScaleForId(meta.yAxisID);
- var options = me._resolveDataElementOptions(point, index);
+ var options = me._resolveDataElementOptions(index);
var data = me.getDataset().data[index];
var dsIndex = me.index;
@@ -106,7 +105,7 @@ module.exports = DatasetController.extend({
pointStyle: options.pointStyle,
rotation: options.rotation,
radius: reset ? 0 : options.radius,
- skip: custom.skip || isNaN(x) || isNaN(y),
+ skip: isNaN(x) || isNaN(y),
x: x,
y: y,
};
@@ -138,11 +137,10 @@ module.exports = DatasetController.extend({
/**
* @private
*/
- _resolveDataElementOptions: function(point, index) {
+ _resolveDataElementOptions: function(index) {
var me = this;
var chart = me.chart;
var dataset = me.getDataset();
- var custom = point.custom || {};
var data = dataset.data[index] || {};
var values = DatasetController.prototype._resolveDataElementOptions.apply(me, arguments);
@@ -161,7 +159,6 @@ module.exports = DatasetController.extend({
// Custom radius resolution
values.radius = resolve([
- custom.radius,
data.r,
me._config.radius,
chart.options.elements.point.radius | true |
Other | chartjs | Chart.js | 0da237a31575093c1b5c964574a45ab8e6a1f88b.json | Remove undocumented "custom" feature (#6605)
Remove undocumented "custom" feature | src/controllers/controller.doughnut.js | @@ -190,7 +190,7 @@ module.exports = DatasetController.extend({
}
for (i = 0, ilen = arcs.length; i < ilen; ++i) {
- arcs[i]._options = me._resolveDataElementOptions(arcs[i], i);
+ arcs[i]._options = me._resolveDataElementOptions(i);
}
chart.borderWidth = me.getMaxBorderWidth();
@@ -323,7 +323,7 @@ module.exports = DatasetController.extend({
arc = arcs[i];
if (controller) {
controller._configure();
- options = controller._resolveDataElementOptions(arc, i);
+ options = controller._resolveDataElementOptions(i);
} else {
options = arc._options;
} | true |
Other | chartjs | Chart.js | 0da237a31575093c1b5c964574a45ab8e6a1f88b.json | Remove undocumented "custom" feature (#6605)
Remove undocumented "custom" feature | src/controllers/controller.line.js | @@ -93,7 +93,7 @@ module.exports = DatasetController.extend({
// Data
line._children = points;
// Model
- line._model = me._resolveDatasetElementOptions(line);
+ line._model = me._resolveDatasetElementOptions();
line.pivot();
}
@@ -116,7 +116,6 @@ module.exports = DatasetController.extend({
updateElement: function(point, index, reset) {
var me = this;
var meta = me.getMeta();
- var custom = point.custom || {};
var dataset = me.getDataset();
var datasetIndex = me.index;
var value = dataset.data[index];
@@ -125,7 +124,7 @@ module.exports = DatasetController.extend({
var lineModel = meta.dataset._model;
var x, y;
- var options = me._resolveDataElementOptions(point, index);
+ var options = me._resolveDataElementOptions(index);
x = xScale.getPixelForValue(typeof value === 'object' ? value : NaN, index, datasetIndex);
y = reset ? yScale.getBasePixel() : me.calculatePointY(value, index, datasetIndex);
@@ -141,15 +140,15 @@ module.exports = DatasetController.extend({
point._model = {
x: x,
y: y,
- skip: custom.skip || isNaN(x) || isNaN(y),
+ skip: isNaN(x) || isNaN(y),
// Appearance
radius: options.radius,
pointStyle: options.pointStyle,
rotation: options.rotation,
backgroundColor: options.backgroundColor,
borderColor: options.borderColor,
borderWidth: options.borderWidth,
- tension: valueOrDefault(custom.tension, lineModel ? lineModel.tension : 0),
+ tension: lineModel ? lineModel.tension : 0,
steppedLine: lineModel ? lineModel.steppedLine : false,
// Tooltip
hitRadius: options.hitRadius
@@ -159,10 +158,9 @@ module.exports = DatasetController.extend({
/**
* @private
*/
- _resolveDatasetElementOptions: function(element) {
+ _resolveDatasetElementOptions: function() {
var me = this;
var config = me._config;
- var custom = element.custom || {};
var options = me.chart.options;
var lineOptions = options.elements.line;
var values = DatasetController.prototype._resolveDatasetElementOptions.apply(me, arguments);
@@ -172,7 +170,7 @@ module.exports = DatasetController.extend({
// This option gives lines the ability to span gaps
values.spanGaps = valueOrDefault(config.spanGaps, options.spanGaps);
values.tension = valueOrDefault(config.lineTension, lineOptions.tension);
- values.steppedLine = resolve([custom.steppedLine, config.steppedLine, lineOptions.stepped]);
+ values.steppedLine = resolve([config.steppedLine, lineOptions.stepped]);
return values;
}, | true |
Other | chartjs | Chart.js | 0da237a31575093c1b5c964574a45ab8e6a1f88b.json | Remove undocumented "custom" feature (#6605)
Remove undocumented "custom" feature | src/controllers/controller.polarArea.js | @@ -159,7 +159,7 @@ module.exports = DatasetController.extend({
}
for (i = 0, ilen = arcs.length; i < ilen; ++i) {
- arcs[i]._options = me._resolveDataElementOptions(arcs[i], i);
+ arcs[i]._options = me._resolveDataElementOptions(i);
me.updateElement(arcs[i], i, reset);
}
}, | true |
Other | chartjs | Chart.js | 0da237a31575093c1b5c964574a45ab8e6a1f88b.json | Remove undocumented "custom" feature (#6605)
Remove undocumented "custom" feature | src/controllers/controller.radar.js | @@ -92,7 +92,7 @@ module.exports = DatasetController.extend({
line._children = points;
line._loop = true;
// Model
- line._model = me._resolveDatasetElementOptions(line);
+ line._model = me._resolveDatasetElementOptions();
line.pivot();
@@ -112,11 +112,10 @@ module.exports = DatasetController.extend({
updateElement: function(point, index, reset) {
var me = this;
- var custom = point.custom || {};
var dataset = me.getDataset();
var scale = me.chart.scale;
var pointPosition = scale.getPointPositionForValue(index, dataset.data[index]);
- var options = me._resolveDataElementOptions(point, index);
+ var options = me._resolveDataElementOptions(index);
var lineModel = me.getMeta().dataset._model;
var x = reset ? scale.xCenter : pointPosition.x;
var y = reset ? scale.yCenter : pointPosition.y;
@@ -131,15 +130,15 @@ module.exports = DatasetController.extend({
point._model = {
x: x, // value not used in dataset scale, but we want a consistent API between scales
y: y,
- skip: custom.skip || isNaN(x) || isNaN(y),
+ skip: isNaN(x) || isNaN(y),
// Appearance
radius: options.radius,
pointStyle: options.pointStyle,
rotation: options.rotation,
backgroundColor: options.backgroundColor,
borderColor: options.borderColor,
borderWidth: options.borderWidth,
- tension: valueOrDefault(custom.tension, lineModel ? lineModel.tension : 0),
+ tension: lineModel ? lineModel.tension : 0,
// Tooltip
hitRadius: options.hitRadius | true |
Other | chartjs | Chart.js | 0da237a31575093c1b5c964574a45ab8e6a1f88b.json | Remove undocumented "custom" feature (#6605)
Remove undocumented "custom" feature | src/core/core.datasetController.js | @@ -340,10 +340,10 @@ helpers.extend(DatasetController.prototype, {
me._configure();
if (dataset && index === undefined) {
- style = me._resolveDatasetElementOptions(dataset || {});
+ style = me._resolveDatasetElementOptions();
} else {
index = index || 0;
- style = me._resolveDataElementOptions(meta.data[index] || {}, index);
+ style = me._resolveDataElementOptions(index);
}
if (style.fill === false || style.fill === null) {
@@ -356,11 +356,10 @@ helpers.extend(DatasetController.prototype, {
/**
* @private
*/
- _resolveDatasetElementOptions: function(element, hover) {
+ _resolveDatasetElementOptions: function(hover) {
var me = this;
var chart = me.chart;
var datasetOpts = me._config;
- var custom = element.custom || {};
var options = chart.options.elements[me.datasetElementType.prototype._type] || {};
var elementOptions = me._datasetElementOptions;
var values = {};
@@ -378,7 +377,6 @@ helpers.extend(DatasetController.prototype, {
key = elementOptions[i];
readKey = hover ? 'hover' + key.charAt(0).toUpperCase() + key.slice(1) : key;
values[key] = resolve([
- custom[readKey],
datasetOpts[readKey],
options[readKey]
], context);
@@ -390,11 +388,10 @@ helpers.extend(DatasetController.prototype, {
/**
* @private
*/
- _resolveDataElementOptions: function(element, index) {
+ _resolveDataElementOptions: function(index) {
var me = this;
- var custom = element && element.custom;
var cached = me._cachedDataOpts;
- if (cached && !custom) {
+ if (cached) {
return cached;
}
var chart = me.chart;
@@ -412,17 +409,14 @@ helpers.extend(DatasetController.prototype, {
};
// `resolve` sets cacheable to `false` if any option is indexed or scripted
- var info = {cacheable: !custom};
+ var info = {cacheable: true};
var keys, i, ilen, key;
- custom = custom || {};
-
if (helpers.isArray(elementOptions)) {
for (i = 0, ilen = elementOptions.length; i < ilen; ++i) {
key = elementOptions[i];
values[key] = resolve([
- custom[key],
datasetOpts[key],
options[key]
], context, index, info);
@@ -432,7 +426,6 @@ helpers.extend(DatasetController.prototype, {
for (i = 0, ilen = keys.length; i < ilen; ++i) {
key = keys[i];
values[key] = resolve([
- custom[key],
datasetOpts[elementOptions[key]],
datasetOpts[key],
options[key]
@@ -455,7 +448,6 @@ helpers.extend(DatasetController.prototype, {
setHoverStyle: function(element) {
var dataset = this.chart.data.datasets[element._datasetIndex];
var index = element._index;
- var custom = element.custom || {};
var model = element._model;
var getHoverColor = helpers.getHoverColor;
@@ -465,9 +457,9 @@ helpers.extend(DatasetController.prototype, {
borderWidth: model.borderWidth
};
- model.backgroundColor = resolve([custom.hoverBackgroundColor, dataset.hoverBackgroundColor, getHoverColor(model.backgroundColor)], undefined, index);
- model.borderColor = resolve([custom.hoverBorderColor, dataset.hoverBorderColor, getHoverColor(model.borderColor)], undefined, index);
- model.borderWidth = resolve([custom.hoverBorderWidth, dataset.hoverBorderWidth, model.borderWidth], undefined, index);
+ model.backgroundColor = resolve([dataset.hoverBackgroundColor, getHoverColor(model.backgroundColor)], undefined, index);
+ model.borderColor = resolve([dataset.hoverBorderColor, getHoverColor(model.borderColor)], undefined, index);
+ model.borderWidth = resolve([dataset.hoverBorderWidth, model.borderWidth], undefined, index);
},
/**
@@ -494,7 +486,7 @@ helpers.extend(DatasetController.prototype, {
}
model = element._model;
- hoverOptions = this._resolveDatasetElementOptions(element, true);
+ hoverOptions = this._resolveDatasetElementOptions(true);
keys = Object.keys(hoverOptions);
for (i = 0, ilen = keys.length; i < ilen; ++i) { | true |
Other | chartjs | Chart.js | 0da237a31575093c1b5c964574a45ab8e6a1f88b.json | Remove undocumented "custom" feature (#6605)
Remove undocumented "custom" feature | test/specs/controller.bar.tests.js | @@ -1407,18 +1407,6 @@ 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);
-
- // Should allow a custom style
- bar.custom = {
- hoverBackgroundColor: 'rgb(255, 0, 0)',
- hoverBorderColor: 'rgb(0, 255, 0)',
- hoverBorderWidth: 1.5
- };
-
- meta.controller.setHoverStyle(bar);
- expect(bar._model.backgroundColor).toBe('rgb(255, 0, 0)');
- expect(bar._model.borderColor).toBe('rgb(0, 255, 0)');
- expect(bar._model.borderWidth).toBe(1.5);
});
it('should remove a hover style from a bar', function() {
@@ -1483,26 +1471,6 @@ 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);
-
- // Should allow a custom style
- bar.custom = {
- backgroundColor: 'rgb(255, 0, 0)',
- borderColor: 'rgb(0, 255, 0)',
- borderWidth: 1.5
- };
-
- chart.update();
- expect(bar._model.backgroundColor).toBe('rgb(255, 0, 0)');
- expect(bar._model.borderColor).toBe('rgb(0, 255, 0)');
- expect(bar._model.borderWidth).toBe(1.5);
- meta.controller.setHoverStyle(bar);
- expect(bar._model.backgroundColor).toBe(helpers.getHoverColor('rgb(255, 0, 0)'));
- expect(bar._model.borderColor).toBe(helpers.getHoverColor('rgb(0, 255, 0)'));
- expect(bar._model.borderWidth).toBe(1.5);
- meta.controller.removeHoverStyle(bar);
- expect(bar._model.backgroundColor).toBe('rgb(255, 0, 0)');
- expect(bar._model.borderColor).toBe('rgb(0, 255, 0)');
- expect(bar._model.borderWidth).toBe(1.5);
});
describe('Bar width', function() { | true |
Other | chartjs | Chart.js | 0da237a31575093c1b5c964574a45ab8e6a1f88b.json | Remove undocumented "custom" feature (#6605)
Remove undocumented "custom" feature | test/specs/controller.bubble.tests.js | @@ -180,27 +180,6 @@ describe('Chart.controllers.bubble', function() {
skip: false
}));
}
-
- // point styles
- meta.data[0].custom = {
- radius: 2.2,
- backgroundColor: 'rgb(0, 1, 3)',
- borderColor: 'rgb(4, 6, 8)',
- borderWidth: 0.787,
- tension: 0.15,
- hitRadius: 5,
- skip: true
- };
-
- chart.update();
-
- expect(meta.data[0]._model).toEqual(jasmine.objectContaining({
- backgroundColor: 'rgb(0, 1, 3)',
- borderColor: 'rgb(4, 6, 8)',
- borderWidth: 0.787,
- hitRadius: 5,
- skip: true
- }));
});
it('should handle number of data point changes in update', function() {
@@ -389,31 +368,5 @@ describe('Chart.controllers.bubble', function() {
expect(point._model.borderWidth).toBe(2);
expect(point._model.radius).toBe(20);
});
-
- it ('should handle hover styles defined via element custom', function() {
- var chart = this.chart;
- var point = chart.getDatasetMeta(0).data[0];
-
- point.custom = {
- hoverBackgroundColor: 'rgb(200, 100, 150)',
- hoverBorderColor: 'rgb(150, 50, 100)',
- hoverBorderWidth: 8.4,
- hoverRadius: 4.2
- };
-
- chart.update();
-
- jasmine.triggerMouseEvent(chart, 'mousemove', point);
- expect(point._model.backgroundColor).toBe('rgb(200, 100, 150)');
- expect(point._model.borderColor).toBe('rgb(150, 50, 100)');
- expect(point._model.borderWidth).toBe(8.4);
- expect(point._model.radius).toBe(20 + 4.2);
-
- jasmine.triggerMouseEvent(chart, 'mouseout', point);
- expect(point._model.backgroundColor).toBe('rgb(100, 150, 200)');
- expect(point._model.borderColor).toBe('rgb(50, 100, 150)');
- expect(point._model.borderWidth).toBe(2);
- expect(point._model.radius).toBe(20);
- });
});
}); | true |
Other | chartjs | Chart.js | 0da237a31575093c1b5c964574a45ab8e6a1f88b.json | Remove undocumented "custom" feature (#6605)
Remove undocumented "custom" feature | test/specs/controller.doughnut.tests.js | @@ -408,28 +408,5 @@ describe('Chart.controllers.doughnut', function() {
expect(arc._model.borderColor).toBe('rgb(50, 100, 150)');
expect(arc._model.borderWidth).toBe(2);
});
-
- it ('should handle hover styles defined via element custom', function() {
- var chart = this.chart;
- var arc = chart.getDatasetMeta(0).data[0];
-
- arc.custom = {
- hoverBackgroundColor: 'rgb(200, 100, 150)',
- hoverBorderColor: 'rgb(150, 50, 100)',
- hoverBorderWidth: 8.4,
- };
-
- chart.update();
-
- jasmine.triggerMouseEvent(chart, 'mousemove', arc);
- expect(arc._model.backgroundColor).toBe('rgb(200, 100, 150)');
- expect(arc._model.borderColor).toBe('rgb(150, 50, 100)');
- expect(arc._model.borderWidth).toBe(8.4);
-
- jasmine.triggerMouseEvent(chart, 'mouseout', arc);
- expect(arc._model.backgroundColor).toBe('rgb(100, 150, 200)');
- expect(arc._model.borderColor).toBe('rgb(50, 100, 150)');
- expect(arc._model.borderWidth).toBe(2);
- });
});
}); | true |
Other | chartjs | Chart.js | 0da237a31575093c1b5c964574a45ab8e6a1f88b.json | Remove undocumented "custom" feature (#6605)
Remove undocumented "custom" feature | test/specs/controller.line.tests.js | @@ -870,32 +870,6 @@ describe('Chart.controllers.line', function() {
expect(point._model.radius).toBe(3);
});
- it ('should handle hover styles defined via element custom', function() {
- var chart = this.chart;
- var point = chart.getDatasetMeta(0).data[0];
-
- point.custom = {
- hoverBackgroundColor: 'rgb(200, 100, 150)',
- hoverBorderColor: 'rgb(150, 50, 100)',
- hoverBorderWidth: 8.4,
- hoverRadius: 4.2
- };
-
- chart.update();
-
- jasmine.triggerMouseEvent(chart, 'mousemove', point);
- expect(point._model.backgroundColor).toBe('rgb(200, 100, 150)');
- expect(point._model.borderColor).toBe('rgb(150, 50, 100)');
- expect(point._model.borderWidth).toBe(8.4);
- expect(point._model.radius).toBe(4.2);
-
- jasmine.triggerMouseEvent(chart, 'mouseout', point);
- expect(point._model.backgroundColor).toBe('rgb(100, 150, 200)');
- expect(point._model.borderColor).toBe('rgb(50, 100, 150)');
- expect(point._model.borderWidth).toBe(2);
- expect(point._model.radius).toBe(3);
- });
-
it ('should handle dataset hover styles defined via dataset properties', function() {
var chart = this.chart;
var point = chart.getDatasetMeta(0).data[0]; | true |
Other | chartjs | Chart.js | 0da237a31575093c1b5c964574a45ab8e6a1f88b.json | Remove undocumented "custom" feature (#6605)
Remove undocumented "custom" feature | test/specs/controller.polarArea.tests.js | @@ -135,27 +135,12 @@ describe('Chart.controllers.polarArea', function() {
expect(meta.data[i]._model.borderWidth).toBe(1.123);
}
- // arc styles
- meta.data[0].custom = {
- backgroundColor: 'rgb(0, 1, 3)',
- borderColor: 'rgb(4, 6, 8)',
- borderWidth: 0.787
- };
-
chart.update();
expect(meta.data[0]._model.x).toBeCloseToPixel(256);
expect(meta.data[0]._model.y).toBeCloseToPixel(259);
expect(meta.data[0]._model.innerRadius).toBeCloseToPixel(0);
expect(meta.data[0]._model.outerRadius).toBeCloseToPixel(177);
- expect(meta.data[0]._model).toEqual(jasmine.objectContaining({
- startAngle: -0.5 * Math.PI,
- endAngle: 0,
- backgroundColor: 'rgb(0, 1, 3)',
- borderWidth: 0.787,
- borderColor: 'rgb(4, 6, 8)',
- label: 'label1'
- }));
});
it('should update elements with start angle from options', function() {
@@ -337,28 +322,5 @@ describe('Chart.controllers.polarArea', function() {
expect(arc._model.borderColor).toBe('rgb(50, 100, 150)');
expect(arc._model.borderWidth).toBe(2);
});
-
- it ('should handle hover styles defined via element custom', function() {
- var chart = this.chart;
- var arc = chart.getDatasetMeta(0).data[0];
-
- arc.custom = {
- hoverBackgroundColor: 'rgb(200, 100, 150)',
- hoverBorderColor: 'rgb(150, 50, 100)',
- hoverBorderWidth: 8.4,
- };
-
- chart.update();
-
- jasmine.triggerMouseEvent(chart, 'mousemove', arc);
- expect(arc._model.backgroundColor).toBe('rgb(200, 100, 150)');
- expect(arc._model.borderColor).toBe('rgb(150, 50, 100)');
- expect(arc._model.borderWidth).toBe(8.4);
-
- jasmine.triggerMouseEvent(chart, 'mouseout', arc);
- expect(arc._model.backgroundColor).toBe('rgb(100, 150, 200)');
- expect(arc._model.borderColor).toBe('rgb(50, 100, 150)');
- expect(arc._model.borderWidth).toBe(2);
- });
});
}); | true |
Other | chartjs | Chart.js | 0da237a31575093c1b5c964574a45ab8e6a1f88b.json | Remove undocumented "custom" feature (#6605)
Remove undocumented "custom" feature | test/specs/controller.radar.tests.js | @@ -231,59 +231,6 @@ describe('Chart.controllers.radar', function() {
tension: 0,
}));
});
-
-
- // Use custom styles for lines & first point
- meta.dataset.custom = {
- backgroundColor: 'rgb(55, 55, 54)',
- borderColor: 'rgb(8, 7, 6)',
- borderWidth: 0.3,
- borderCapStyle: 'square',
- borderDash: [4, 3],
- borderDashOffset: 4.4,
- borderJoinStyle: 'round',
- fill: true,
- };
-
- // point styles
- meta.data[0].custom = {
- radius: 2.2,
- backgroundColor: 'rgb(0, 1, 3)',
- borderColor: 'rgb(4, 6, 8)',
- borderWidth: 0.787,
- tension: 0.15,
- skip: true,
- hitRadius: 5,
- };
-
- meta.controller._update();
-
- expect(meta.dataset._model).toEqual(jasmine.objectContaining({
- backgroundColor: 'rgb(55, 55, 54)',
- borderCapStyle: 'square',
- borderColor: 'rgb(8, 7, 6)',
- borderDash: [4, 3],
- borderDashOffset: 4.4,
- borderJoinStyle: 'round',
- borderWidth: 0.3,
- fill: true,
- }));
-
- expect(meta.data[0]._model.x).toBeCloseToPixel(256);
- expect(meta.data[0]._model.y).toBeCloseToPixel(120);
- expect(meta.data[0]._model.controlPointPreviousX).toBeCloseToPixel(241);
- expect(meta.data[0]._model.controlPointPreviousY).toBeCloseToPixel(120);
- expect(meta.data[0]._model.controlPointNextX).toBeCloseToPixel(281);
- expect(meta.data[0]._model.controlPointNextY).toBeCloseToPixel(120);
- expect(meta.data[0]._model).toEqual(jasmine.objectContaining({
- radius: 2.2,
- backgroundColor: 'rgb(0, 1, 3)',
- borderColor: 'rgb(4, 6, 8)',
- borderWidth: 0.787,
- tension: 0.15,
- skip: true,
- hitRadius: 5,
- }));
});
describe('Interactions', function() {
@@ -377,32 +324,6 @@ describe('Chart.controllers.radar', function() {
expect(point._model.borderWidth).toBe(2);
expect(point._model.radius).toBe(3);
});
-
- it ('should handle hover styles defined via element custom', function() {
- var chart = this.chart;
- var point = chart.getDatasetMeta(0).data[0];
-
- point.custom = {
- hoverBackgroundColor: 'rgb(200, 100, 150)',
- hoverBorderColor: 'rgb(150, 50, 100)',
- hoverBorderWidth: 8.4,
- hoverRadius: 4.2
- };
-
- chart.update();
-
- jasmine.triggerMouseEvent(chart, 'mousemove', point);
- expect(point._model.backgroundColor).toBe('rgb(200, 100, 150)');
- expect(point._model.borderColor).toBe('rgb(150, 50, 100)');
- expect(point._model.borderWidth).toBe(8.4);
- expect(point._model.radius).toBe(4.2);
-
- jasmine.triggerMouseEvent(chart, 'mouseout', point);
- expect(point._model.backgroundColor).toBe('rgb(100, 150, 200)');
- expect(point._model.borderColor).toBe('rgb(50, 100, 150)');
- expect(point._model.borderWidth).toBe(2);
- expect(point._model.radius).toBe(3);
- });
});
it('should allow pointBorderWidth to be set to 0', function() { | true |
Other | chartjs | Chart.js | db4a0d45699dedff00c875087d9d07135a7d2e80.json | Limit onClick to chartArea (#6227)
* Limit onClick to chartArea
* Utilize helpers.canvas._isPointInArea | src/core/core.controller.js | @@ -1080,7 +1080,7 @@ helpers.extend(Chart.prototype, /** @lends Chart */ {
helpers.callback(options.onHover || options.hover.onHover, [e.native, me.active], me);
if (e.type === 'mouseup' || e.type === 'click') {
- if (options.onClick) {
+ if (options.onClick && helpers.canvas._isPointInArea(e, me.chartArea)) {
// Use e.native here for backwards compatibility
options.onClick.call(me, e.native, me.active);
} | false |
Other | chartjs | Chart.js | ae80936f0357eac8d8d100fac1dc5af7851443bd.json | Add link to performance documentation (#6613) | docs/general/README.md | @@ -8,3 +8,4 @@ These sections describe general configuration options that can apply elsewhere i
* [Options](./options.md) scriptable and indexable options syntax.
* [Colors](./colors.md) defines acceptable color values.
* [Font](./fonts.md) defines various font options.
+* [Performance](./performance.md) gives tips for performance-sensitive applications. | false |
Other | chartjs | Chart.js | 21da5be3c63e69a4edfc364d040e270471d8234d.json | Fix horizontalBar deprecation warnings (#6603)
Fix horizontalBar deprecation warnings | src/controllers/controller.horizontalBar.js | @@ -18,8 +18,6 @@ defaults._set('horizontalBar', {
yAxes: [{
type: 'category',
position: 'left',
- categoryPercentage: 0.8,
- barPercentage: 0.9,
offset: true,
gridLines: {
offsetGridLines: true
@@ -39,6 +37,15 @@ defaults._set('horizontalBar', {
}
});
+defaults._set('global', {
+ datasets: {
+ horizontalBar: {
+ categoryPercentage: 0.8,
+ barPercentage: 0.9
+ }
+ }
+});
+
module.exports = BarController.extend({
/**
* @private
@@ -54,4 +61,3 @@ module.exports = BarController.extend({
return this.getMeta().yAxisID;
}
});
- | true |
Other | chartjs | Chart.js | 21da5be3c63e69a4edfc364d040e270471d8234d.json | Fix horizontalBar deprecation warnings (#6603)
Fix horizontalBar deprecation warnings | test/specs/controller.bar.tests.js | @@ -1593,8 +1593,9 @@ describe('Chart.controllers.bar', function() {
var meta = chart.getDatasetMeta(0);
var yScale = chart.scales[meta.yAxisID];
- var categoryPercentage = yScale.options.categoryPercentage;
- var barPercentage = yScale.options.barPercentage;
+ var config = meta.controller._config;
+ var categoryPercentage = config.categoryPercentage;
+ var barPercentage = config.barPercentage;
var stacked = yScale.options.stacked;
var totalBarHeight = 0; | true |
Other | chartjs | Chart.js | 4d7fefcdb6bd48a078af6378fba33dbcb63cf747.json | Remove a couple calls to helpers.each (#6594) | src/core/core.controller.js | @@ -417,32 +417,35 @@ helpers.extend(Chart.prototype, /** @lends Chart */ {
buildOrUpdateControllers: function() {
var me = this;
var newControllers = [];
+ var datasets = me.data.datasets;
+ var i, ilen;
- helpers.each(me.data.datasets, function(dataset, datasetIndex) {
- var meta = me.getDatasetMeta(datasetIndex);
+ for (i = 0, ilen = datasets.length; i < ilen; i++) {
+ var dataset = datasets[i];
+ var meta = me.getDatasetMeta(i);
var type = dataset.type || me.config.type;
if (meta.type && meta.type !== type) {
- me.destroyDatasetMeta(datasetIndex);
- meta = me.getDatasetMeta(datasetIndex);
+ me.destroyDatasetMeta(i);
+ meta = me.getDatasetMeta(i);
}
meta.type = type;
meta.order = dataset.order || 0;
- meta.index = datasetIndex;
+ meta.index = i;
if (meta.controller) {
- meta.controller.updateIndex(datasetIndex);
+ meta.controller.updateIndex(i);
meta.controller.linkScales();
} else {
var ControllerClass = controllers[meta.type];
if (ControllerClass === undefined) {
throw new Error('"' + meta.type + '" is not a chart type.');
}
- meta.controller = new ControllerClass(me, datasetIndex);
+ meta.controller = new ControllerClass(me, i);
newControllers.push(meta.controller);
}
- }, me);
+ }
return newControllers;
},
@@ -468,6 +471,7 @@ helpers.extend(Chart.prototype, /** @lends Chart */ {
update: function(config) {
var me = this;
+ var i, ilen;
if (!config || typeof config !== 'object') {
// backwards compatibility
@@ -494,9 +498,9 @@ helpers.extend(Chart.prototype, /** @lends Chart */ {
var newControllers = me.buildOrUpdateControllers();
// Make sure all dataset controllers have correct meta data counts
- helpers.each(me.data.datasets, function(dataset, datasetIndex) {
- me.getDatasetMeta(datasetIndex).controller.buildOrUpdateElements();
- }, me);
+ for (i = 0, ilen = me.data.datasets.length; i < ilen; i++) {
+ me.getDatasetMeta(i).controller.buildOrUpdateElements();
+ }
me.updateLayout();
| false |
Other | chartjs | Chart.js | f606c23f2fbea2612208ffb49511b66e37ce4335.json | Fix unit determination when autoSkip is enabled (#6583) | src/scales/scale.time.js | @@ -257,7 +257,7 @@ function determineUnitForAutoTicks(minUnit, min, max, capacity) {
for (i = UNITS.indexOf(minUnit); i < ilen - 1; ++i) {
interval = INTERVALS[UNITS[i]];
- factor = interval.steps ? interval.steps / 2 : MAX_INTEGER;
+ factor = interval.steps ? interval.steps : MAX_INTEGER;
if (interval.common && Math.ceil((max - min) / (factor * interval.size)) <= capacity) {
return UNITS[i];
@@ -270,12 +270,12 @@ function determineUnitForAutoTicks(minUnit, min, max, capacity) {
/**
* Figures out what unit to format a set of ticks with
*/
-function determineUnitForFormatting(scale, ticks, minUnit, min, max) {
+function determineUnitForFormatting(scale, numTicks, minUnit, min, max) {
var i, unit;
for (i = UNITS.length - 1; i >= UNITS.indexOf(minUnit); i--) {
unit = UNITS[i];
- if (INTERVALS[unit].common && scale._adapter.diff(max, min, unit) >= ticks.length - 1) {
+ if (INTERVALS[unit].common && scale._adapter.diff(max, min, unit) >= numTicks - 1) {
return unit;
}
}
@@ -562,11 +562,12 @@ module.exports = Scale.extend({
var min = me.min;
var max = me.max;
var options = me.options;
+ var tickOpts = options.ticks;
var timeOpts = options.time;
var timestamps = me._timestamps;
var ticks = [];
var capacity = me.getLabelCapacity(min);
- var source = options.ticks.source;
+ var source = tickOpts.source;
var distribution = options.distribution;
var i, ilen, timestamp;
@@ -599,13 +600,17 @@ module.exports = Scale.extend({
me.max = max;
// PRIVATE
- me._unit = timeOpts.unit || determineUnitForFormatting(me, ticks, timeOpts.minUnit, me.min, me.max);
- me._majorUnit = !options.ticks.major.enabled || me._unit === 'year' ? undefined
+ // determineUnitForFormatting relies on the number of ticks so we don't use it when
+ // autoSkip is enabled because we don't yet know what the final number of ticks will be
+ me._unit = timeOpts.unit || (tickOpts.autoSkip
+ ? determineUnitForAutoTicks(timeOpts.minUnit, me.min, me.max, capacity)
+ : determineUnitForFormatting(me, ticks.length, timeOpts.minUnit, me.min, me.max));
+ me._majorUnit = !tickOpts.major.enabled || me._unit === 'year' ? undefined
: determineMajorUnit(me._unit);
me._table = buildLookupTable(me._timestamps.data, min, max, distribution);
me._offsets = computeOffsets(me._table, ticks, min, max, options);
- if (options.ticks.reverse) {
+ if (tickOpts.reverse) {
ticks.reverse();
}
| true |
Other | chartjs | Chart.js | f606c23f2fbea2612208ffb49511b66e37ce4335.json | Fix unit determination when autoSkip is enabled (#6583) | test/specs/scale.time.tests.js | @@ -128,7 +128,7 @@ describe('Time scale tests', function() {
var ticks = getTicksLabels(scale);
// `bounds === 'data'`: first and last ticks removed since outside the data range
- expect(ticks).toEqual(['Jan 2', 'Jan 3', 'Jan 4', 'Jan 5', 'Jan 6', 'Jan 7', 'Jan 8', 'Jan 9', 'Jan 10']);
+ expect(ticks.length).toEqual(217);
});
it('should accept labels as date objects', function() {
@@ -139,7 +139,7 @@ describe('Time scale tests', function() {
var ticks = getTicksLabels(scale);
// `bounds === 'data'`: first and last ticks removed since outside the data range
- expect(ticks).toEqual(['Jan 2', 'Jan 3', 'Jan 4', 'Jan 5', 'Jan 6', 'Jan 7', 'Jan 8', 'Jan 9', 'Jan 10']);
+ expect(ticks.length).toEqual(217);
});
it('should accept data as xy points', function() {
@@ -187,7 +187,7 @@ describe('Time scale tests', function() {
var ticks = getTicksLabels(xScale);
// `bounds === 'data'`: first and last ticks removed since outside the data range
- expect(ticks).toEqual(['Jan 2', 'Jan 3', 'Jan 4', 'Jan 5', 'Jan 6', 'Jan 7', 'Jan 8', 'Jan 9', 'Jan 10']);
+ expect(ticks.length).toEqual(217);
});
it('should accept data as ty points', function() {
@@ -235,7 +235,7 @@ describe('Time scale tests', function() {
var ticks = getTicksLabels(tScale);
// `bounds === 'data'`: first and last ticks removed since outside the data range
- expect(ticks).toEqual(['Jan 2', 'Jan 3', 'Jan 4', 'Jan 5', 'Jan 6', 'Jan 7', 'Jan 8', 'Jan 9', 'Jan 10']);
+ expect(ticks.length).toEqual(217);
});
});
| true |
Other | chartjs | Chart.js | 6c9f202c6835d60fbaa220cbfab99b9946aae999.json | Fix autoskip for first segment of chart (#6584)
* Fix autoskip for first segment of chart
* Fix issue identified during review | src/core/core.scale.js | @@ -305,6 +305,12 @@ function skip(ticks, spacing, majorStart, majorEnd) {
}
next = start;
+
+ while (next < 0) {
+ count++;
+ next = Math.round(start + count * spacing);
+ }
+
for (i = Math.max(start, 0); i < end; i++) {
tick = ticks[i];
if (i === next) { | false |
Other | chartjs | Chart.js | d3860137fe236b9c8d92ef7be7147ac976b9c545.json | Fix logarighmic test to use correct scale (#6580) | test/specs/scale.logarithmic.tests.js | @@ -749,7 +749,7 @@ describe('Logarithmic Scale tests', function() {
}
});
- expect(chart.scales.yScale1.getLabelForIndex(0, 2)).toBe(150);
+ expect(chart.scales.yScale0.getLabelForIndex(0, 2)).toBe(150);
});
describe('when', function() { | false |
Other | chartjs | Chart.js | fc76610b121d71fc5b903631d21edd04b886e3e0.json | Add ticks.sampleSize option (#6508) | docs/axes/cartesian/README.md | @@ -28,6 +28,7 @@ The following options are common to all cartesian axes but do not apply to other
| ---- | ---- | ------- | -----------
| `min` | `number` | | User defined minimum value for the scale, overrides minimum value from data.
| `max` | `number` | | User defined maximum value for the scale, overrides maximum value from data.
+| `sampleSize` | `number` | `ticks.length` | The number of ticks to examine when deciding how many labels will fit. Setting a smaller value will be faster, but may be less accurate when there is large variability in label length.
| `autoSkip` | `boolean` | `true` | If true, automatically calculates how many labels can be shown and hides labels accordingly. Labels will be rotated up to `maxRotation` before skipping any. Turn `autoSkip` off to show all labels no matter what.
| `autoSkipPadding` | `number` | `0` | Padding between the ticks on the horizontal axis when `autoSkip` is enabled.
| `labelOffset` | `number` | `0` | Distance in pixels to offset the label from the centre point of the tick (in the x direction for the x axis, and the y direction for the y axis). *Note: this can cause labels at the edges to be cropped by the edge of the canvas* | true |
Other | chartjs | Chart.js | fc76610b121d71fc5b903631d21edd04b886e3e0.json | Add ticks.sampleSize option (#6508) | docs/general/performance.md | @@ -0,0 +1,8 @@
+# Performance
+
+Chart.js charts are rendered on `canvas` elements, which makes rendering quite fast. For large datasets or performance sensitive applications, you may wish to consider the tips below:
+
+* Set `animation: { duration: 0 }` to disable [animations](../configuration/animations.md).
+* For large datasets:
+ * You may wish to sample your data before providing it to Chart.js. E.g. if you have a data point for each day, you may find it more performant to pass in a data point for each week instead
+ * Set the [`ticks.sampleSize`](../axes/cartesian/README.md#tick-configuration) option in order to render axes more quickly | true |
Other | chartjs | Chart.js | fc76610b121d71fc5b903631d21edd04b886e3e0.json | Add ticks.sampleSize option (#6508) | src/core/core.scale.js | @@ -67,6 +67,19 @@ defaults._set('scale', {
}
});
+/** Returns a new array containing numItems from arr */
+function sample(arr, numItems) {
+ var result = [];
+ var increment = arr.length / numItems;
+ var i = 0;
+ var len = arr.length;
+
+ for (; i < len; i += increment) {
+ result.push(arr[Math.floor(i)]);
+ }
+ return result;
+}
+
function getPixelForGridLine(scale, index, offsetGridLines) {
var length = scale.getTicks().length;
var validIndex = Math.min(index, length - 1);
@@ -266,7 +279,8 @@ var Scale = Element.extend({
update: function(maxWidth, maxHeight, margins) {
var me = this;
var tickOpts = me.options.ticks;
- var i, ilen, labels, label, ticks, tick;
+ var sampleSize = tickOpts.sampleSize;
+ var i, ilen, labels, ticks;
// Update Lifecycle - Probably don't want to ever extend or overwrite this function ;)
me.beforeUpdate();
@@ -281,6 +295,8 @@ var Scale = Element.extend({
bottom: 0
}, margins);
+ me._ticks = null;
+ me.ticks = null;
me._labelSizes = null;
me._maxLabelLines = 0;
me.longestLabelWidth = 0;
@@ -314,35 +330,23 @@ var Scale = Element.extend({
// Allow modification of ticks in callback.
ticks = me.afterBuildTicks(ticks) || ticks;
- me.beforeTickToLabelConversion();
-
- // New implementations should return the formatted tick labels but for BACKWARD
- // COMPAT, we still support no return (`this.ticks` internally changed by calling
- // this method and supposed to contain only string values).
- labels = me.convertTicksToLabels(ticks) || me.ticks;
-
- me.afterTickToLabelConversion();
-
- me.ticks = labels; // BACKWARD COMPATIBILITY
-
- // IMPORTANT: below this point, we consider that `this.ticks` will NEVER change!
-
- // BACKWARD COMPAT: synchronize `_ticks` with labels (so potentially `this.ticks`)
- for (i = 0, ilen = labels.length; i < ilen; ++i) {
- label = labels[i];
- tick = ticks[i];
- if (!tick) {
- ticks.push(tick = {
- label: label,
+ // Ensure ticks contains ticks in new tick format
+ if ((!ticks || !ticks.length) && me.ticks) {
+ ticks = [];
+ for (i = 0, ilen = me.ticks.length; i < ilen; ++i) {
+ ticks.push({
+ value: me.ticks[i],
major: false
});
- } else {
- tick.label = label;
}
}
me._ticks = ticks;
+ // Compute tick rotation and fit using a sampled subset of labels
+ // We generally don't need to compute the size of every single label for determining scale size
+ labels = me._convertTicksToLabels(sampleSize ? sample(ticks, sampleSize) : ticks);
+
// _configure is called twice, once here, once from core.controller.updateLayout.
// Here we haven't been positioned yet, but dimensions are correct.
// Variables set in _configure are needed for calculateTickRotation, and
@@ -353,19 +357,28 @@ var Scale = Element.extend({
me.beforeCalculateTickRotation();
me.calculateTickRotation();
me.afterCalculateTickRotation();
- // Fit
+
me.beforeFit();
me.fit();
me.afterFit();
+
// Auto-skip
- me._ticksToDraw = tickOpts.display && tickOpts.autoSkip ? me._autoSkip(me._ticks) : me._ticks;
+ me._ticksToDraw = tickOpts.display && tickOpts.autoSkip ? me._autoSkip(ticks) : ticks;
+
+ if (sampleSize) {
+ // Generate labels using all non-skipped ticks
+ labels = me._convertTicksToLabels(me._ticksToDraw);
+ }
+
+ me.ticks = labels; // BACKWARD COMPATIBILITY
+
+ // IMPORTANT: after this point, we consider that `this.ticks` will NEVER change!
me.afterUpdate();
// 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;
-
},
/**
@@ -673,6 +686,31 @@ var Scale = Element.extend({
return rawValue;
},
+ _convertTicksToLabels: function(ticks) {
+ var me = this;
+ var labels, i, ilen;
+
+ me.ticks = ticks.map(function(tick) {
+ return tick.value;
+ });
+
+ me.beforeTickToLabelConversion();
+
+ // New implementations should return the formatted tick labels but for BACKWARD
+ // COMPAT, we still support no return (`this.ticks` internally changed by calling
+ // this method and supposed to contain only string values).
+ labels = me.convertTicksToLabels(ticks) || me.ticks;
+
+ me.afterTickToLabelConversion();
+
+ // BACKWARD COMPAT: synchronize `_ticks` with labels (so potentially `this.ticks`)
+ for (i = 0, ilen = ticks.length; i < ilen; ++i) {
+ ticks[i].label = labels[i];
+ }
+
+ return labels;
+ },
+
/**
* @private
*/
@@ -835,11 +873,12 @@ var Scale = Element.extend({
for (i = 0; i < tickCount; i++) {
tick = ticks[i];
- if (skipRatio > 1 && i % skipRatio > 0) {
- // leave tick in place but make sure it's not displayed (#4635)
+ if (skipRatio <= 1 || i % skipRatio === 0) {
+ tick._index = i;
+ result.push(tick);
+ } else {
delete tick.label;
}
- result.push(tick);
}
return result;
},
@@ -966,7 +1005,7 @@ var Scale = Element.extend({
borderDashOffset = gridLines.borderDashOffset || 0.0;
}
- lineValue = getPixelForGridLine(me, i, offsetGridLines);
+ lineValue = getPixelForGridLine(me, tick._index || i, offsetGridLines);
// Skip if the pixel is out of the range
if (lineValue === undefined) {
@@ -1044,7 +1083,7 @@ var Scale = Element.extend({
continue;
}
- pixel = me.getPixelForTick(i) + optionTicks.labelOffset;
+ pixel = me.getPixelForTick(tick._index || i) + optionTicks.labelOffset;
font = tick.major ? fonts.major : fonts.minor;
lineHeight = font.lineHeight;
lineCount = isArray(label) ? label.length : 1; | true |
Other | chartjs | Chart.js | e9f341889fe2e4a43c9ef66b379ec88cf2241415.json | Add link to linear radial axis for radar chart doc (#6554) | docs/charts/radar.md | @@ -152,12 +152,18 @@ The radar chart defines the following configuration options. These options are m
## Scale Options
The radar chart supports only a single scale. The options for this scale are defined in the `scale` property.
+The options for this scale are defined in the `scale` property, which can be referenced from the [Linear Radial Axis page](../axes/radial/linear).
```javascript
options = {
scale: {
- // Hides the scale
- display: false
+ angleLines: {
+ display: false
+ },
+ ticks: {
+ suggestedMin: 50,
+ suggestedMax: 100
+ }
}
};
``` | false |
Other | chartjs | Chart.js | ce8ee02ccd992c062cfa734df713730c077cdb2e.json | Reduce indentation by reversing if check (#6497) | src/plugins/plugin.legend.js | @@ -250,80 +250,82 @@ var Legend = Element.extend({
}
// Increase sizes here
- if (display) {
- ctx.font = labelFont.string;
+ if (!display) {
+ me.width = minSize.width = me.height = minSize.height = 0;
+ return;
+ }
+ ctx.font = labelFont.string;
- if (isHorizontal) {
- // Labels
-
- // Width of each line of legend boxes. Labels wrap onto multiple lines when there are too many to fit on one
- var lineWidths = me.lineWidths = [0];
- var totalHeight = 0;
-
- ctx.textAlign = 'left';
- ctx.textBaseline = 'middle';
-
- helpers.each(me.legendItems, function(legendItem, i) {
- var boxWidth = getBoxWidth(labelOpts, fontSize);
- var width = boxWidth + (fontSize / 2) + ctx.measureText(legendItem.text).width;
-
- if (i === 0 || lineWidths[lineWidths.length - 1] + width + 2 * labelOpts.padding > minSize.width) {
- totalHeight += fontSize + labelOpts.padding;
- lineWidths[lineWidths.length - (i > 0 ? 0 : 1)] = 0;
- }
-
- // Store the hitbox width and height here. Final position will be updated in `draw`
- hitboxes[i] = {
- left: 0,
- top: 0,
- width: width,
- height: fontSize
- };
+ if (isHorizontal) {
+ // Labels
- lineWidths[lineWidths.length - 1] += width + labelOpts.padding;
- });
+ // Width of each line of legend boxes. Labels wrap onto multiple lines when there are too many to fit on one
+ var lineWidths = me.lineWidths = [0];
+ var totalHeight = 0;
- minSize.height += totalHeight;
+ ctx.textAlign = 'left';
+ ctx.textBaseline = 'middle';
- } else {
- var vPadding = labelOpts.padding;
- var columnWidths = me.columnWidths = [];
- var columnHeights = me.columnHeights = [];
- var totalWidth = labelOpts.padding;
- var currentColWidth = 0;
- var currentColHeight = 0;
-
- helpers.each(me.legendItems, function(legendItem, i) {
- var boxWidth = getBoxWidth(labelOpts, fontSize);
- var itemWidth = boxWidth + (fontSize / 2) + ctx.measureText(legendItem.text).width;
-
- // If too tall, go to new column
- if (i > 0 && currentColHeight + fontSize + 2 * vPadding > minSize.height) {
- totalWidth += currentColWidth + labelOpts.padding;
- columnWidths.push(currentColWidth); // previous column width
- columnHeights.push(currentColHeight);
- currentColWidth = 0;
- currentColHeight = 0;
- }
-
- // Get max width
- currentColWidth = Math.max(currentColWidth, itemWidth);
- currentColHeight += fontSize + vPadding;
-
- // Store the hitbox width and height here. Final position will be updated in `draw`
- hitboxes[i] = {
- left: 0,
- top: 0,
- width: itemWidth,
- height: fontSize
- };
- });
+ helpers.each(me.legendItems, function(legendItem, i) {
+ var boxWidth = getBoxWidth(labelOpts, fontSize);
+ var width = boxWidth + (fontSize / 2) + ctx.measureText(legendItem.text).width;
- totalWidth += currentColWidth;
- columnWidths.push(currentColWidth);
- columnHeights.push(currentColHeight);
- minSize.width += totalWidth;
- }
+ if (i === 0 || lineWidths[lineWidths.length - 1] + width + 2 * labelOpts.padding > minSize.width) {
+ totalHeight += fontSize + labelOpts.padding;
+ lineWidths[lineWidths.length - (i > 0 ? 0 : 1)] = 0;
+ }
+
+ // Store the hitbox width and height here. Final position will be updated in `draw`
+ hitboxes[i] = {
+ left: 0,
+ top: 0,
+ width: width,
+ height: fontSize
+ };
+
+ lineWidths[lineWidths.length - 1] += width + labelOpts.padding;
+ });
+
+ minSize.height += totalHeight;
+
+ } else {
+ var vPadding = labelOpts.padding;
+ var columnWidths = me.columnWidths = [];
+ var columnHeights = me.columnHeights = [];
+ var totalWidth = labelOpts.padding;
+ var currentColWidth = 0;
+ var currentColHeight = 0;
+
+ helpers.each(me.legendItems, function(legendItem, i) {
+ var boxWidth = getBoxWidth(labelOpts, fontSize);
+ var itemWidth = boxWidth + (fontSize / 2) + ctx.measureText(legendItem.text).width;
+
+ // If too tall, go to new column
+ if (i > 0 && currentColHeight + fontSize + 2 * vPadding > minSize.height) {
+ totalWidth += currentColWidth + labelOpts.padding;
+ columnWidths.push(currentColWidth); // previous column width
+ columnHeights.push(currentColHeight);
+ currentColWidth = 0;
+ currentColHeight = 0;
+ }
+
+ // Get max width
+ currentColWidth = Math.max(currentColWidth, itemWidth);
+ currentColHeight += fontSize + vPadding;
+
+ // Store the hitbox width and height here. Final position will be updated in `draw`
+ hitboxes[i] = {
+ left: 0,
+ top: 0,
+ width: itemWidth,
+ height: fontSize
+ };
+ });
+
+ totalWidth += currentColWidth;
+ columnWidths.push(currentColWidth);
+ columnHeights.push(currentColHeight);
+ minSize.width += totalWidth;
}
me.width = minSize.width;
@@ -349,146 +351,148 @@ var Legend = Element.extend({
var legendWidth = me.width;
var lineWidths = me.lineWidths;
- if (opts.display) {
- var ctx = me.ctx;
- var fontColor = valueOrDefault(labelOpts.fontColor, globalDefaults.defaultFontColor);
- var labelFont = helpers.options._parseFont(labelOpts);
- var fontSize = labelFont.size;
- var cursor;
+ if (!opts.display) {
+ return;
+ }
- // Canvas setup
- ctx.textAlign = 'left';
- ctx.textBaseline = 'middle';
- ctx.lineWidth = 0.5;
- ctx.strokeStyle = fontColor; // for strikethrough effect
- ctx.fillStyle = fontColor; // render in correct colour
- ctx.font = labelFont.string;
-
- var boxWidth = getBoxWidth(labelOpts, fontSize);
- var hitboxes = me.legendHitBoxes;
-
- // current position
- var drawLegendBox = function(x, y, legendItem) {
- if (isNaN(boxWidth) || boxWidth <= 0) {
- return;
- }
+ var ctx = me.ctx;
+ var fontColor = valueOrDefault(labelOpts.fontColor, globalDefaults.defaultFontColor);
+ var labelFont = helpers.options._parseFont(labelOpts);
+ var fontSize = labelFont.size;
+ var cursor;
+
+ // Canvas setup
+ ctx.textAlign = 'left';
+ ctx.textBaseline = 'middle';
+ ctx.lineWidth = 0.5;
+ ctx.strokeStyle = fontColor; // for strikethrough effect
+ ctx.fillStyle = fontColor; // render in correct colour
+ ctx.font = labelFont.string;
+
+ var boxWidth = getBoxWidth(labelOpts, fontSize);
+ var hitboxes = me.legendHitBoxes;
+
+ // current position
+ var drawLegendBox = function(x, y, legendItem) {
+ if (isNaN(boxWidth) || boxWidth <= 0) {
+ return;
+ }
- // Set the ctx for the box
- ctx.save();
+ // Set the ctx for the box
+ ctx.save();
- var lineWidth = valueOrDefault(legendItem.lineWidth, lineDefault.borderWidth);
- ctx.fillStyle = valueOrDefault(legendItem.fillStyle, defaultColor);
- ctx.lineCap = valueOrDefault(legendItem.lineCap, lineDefault.borderCapStyle);
- ctx.lineDashOffset = valueOrDefault(legendItem.lineDashOffset, lineDefault.borderDashOffset);
- ctx.lineJoin = valueOrDefault(legendItem.lineJoin, lineDefault.borderJoinStyle);
- ctx.lineWidth = lineWidth;
- ctx.strokeStyle = valueOrDefault(legendItem.strokeStyle, defaultColor);
+ var lineWidth = valueOrDefault(legendItem.lineWidth, lineDefault.borderWidth);
+ ctx.fillStyle = valueOrDefault(legendItem.fillStyle, defaultColor);
+ ctx.lineCap = valueOrDefault(legendItem.lineCap, lineDefault.borderCapStyle);
+ ctx.lineDashOffset = valueOrDefault(legendItem.lineDashOffset, lineDefault.borderDashOffset);
+ ctx.lineJoin = valueOrDefault(legendItem.lineJoin, lineDefault.borderJoinStyle);
+ ctx.lineWidth = lineWidth;
+ ctx.strokeStyle = valueOrDefault(legendItem.strokeStyle, defaultColor);
- if (ctx.setLineDash) {
- // IE 9 and 10 do not support line dash
- ctx.setLineDash(valueOrDefault(legendItem.lineDash, lineDefault.borderDash));
- }
+ if (ctx.setLineDash) {
+ // IE 9 and 10 do not support line dash
+ ctx.setLineDash(valueOrDefault(legendItem.lineDash, lineDefault.borderDash));
+ }
+
+ if (labelOpts && labelOpts.usePointStyle) {
+ // Recalculate x and y for drawPoint() because its expecting
+ // x and y to be center of figure (instead of top left)
+ var radius = boxWidth * Math.SQRT2 / 2;
+ var centerX = x + boxWidth / 2;
+ var centerY = y + fontSize / 2;
- if (labelOpts && labelOpts.usePointStyle) {
- // Recalculate x and y for drawPoint() because its expecting
- // x and y to be center of figure (instead of top left)
- var radius = boxWidth * Math.SQRT2 / 2;
- var centerX = x + boxWidth / 2;
- var centerY = y + fontSize / 2;
-
- // Draw pointStyle as legend symbol
- helpers.canvas.drawPoint(ctx, legendItem.pointStyle, radius, centerX, centerY, legendItem.rotation);
- } else {
- // Draw box as legend symbol
- ctx.fillRect(x, y, boxWidth, fontSize);
- if (lineWidth !== 0) {
- ctx.strokeRect(x, y, boxWidth, fontSize);
- }
+ // Draw pointStyle as legend symbol
+ helpers.canvas.drawPoint(ctx, legendItem.pointStyle, radius, centerX, centerY, legendItem.rotation);
+ } else {
+ // Draw box as legend symbol
+ ctx.fillRect(x, y, boxWidth, fontSize);
+ if (lineWidth !== 0) {
+ ctx.strokeRect(x, y, boxWidth, fontSize);
}
+ }
- ctx.restore();
+ ctx.restore();
+ };
+ var fillText = function(x, y, legendItem, textWidth) {
+ var halfFontSize = fontSize / 2;
+ var xLeft = boxWidth + halfFontSize + x;
+ var yMiddle = y + halfFontSize;
+
+ ctx.fillText(legendItem.text, xLeft, yMiddle);
+
+ if (legendItem.hidden) {
+ // Strikethrough the text if hidden
+ ctx.beginPath();
+ ctx.lineWidth = 2;
+ ctx.moveTo(xLeft, yMiddle);
+ ctx.lineTo(xLeft + textWidth, yMiddle);
+ ctx.stroke();
+ }
+ };
+
+ var alignmentOffset = function(dimension, blockSize) {
+ switch (opts.align) {
+ case 'start':
+ return labelOpts.padding;
+ case 'end':
+ return dimension - blockSize;
+ default: // center
+ return (dimension - blockSize + labelOpts.padding) / 2;
+ }
+ };
+
+ // Horizontal
+ var isHorizontal = me.isHorizontal();
+ if (isHorizontal) {
+ cursor = {
+ x: me.left + alignmentOffset(legendWidth, lineWidths[0]),
+ y: me.top + labelOpts.padding,
+ line: 0
};
- var fillText = function(x, y, legendItem, textWidth) {
- var halfFontSize = fontSize / 2;
- var xLeft = boxWidth + halfFontSize + x;
- var yMiddle = y + halfFontSize;
-
- ctx.fillText(legendItem.text, xLeft, yMiddle);
-
- if (legendItem.hidden) {
- // Strikethrough the text if hidden
- ctx.beginPath();
- ctx.lineWidth = 2;
- ctx.moveTo(xLeft, yMiddle);
- ctx.lineTo(xLeft + textWidth, yMiddle);
- ctx.stroke();
- }
+ } else {
+ cursor = {
+ x: me.left + labelOpts.padding,
+ y: me.top + alignmentOffset(legendHeight, columnHeights[0]),
+ line: 0
};
+ }
- var alignmentOffset = function(dimension, blockSize) {
- switch (opts.align) {
- case 'start':
- return labelOpts.padding;
- case 'end':
- return dimension - blockSize;
- default: // center
- return (dimension - blockSize + labelOpts.padding) / 2;
- }
- };
+ var itemHeight = fontSize + labelOpts.padding;
+ helpers.each(me.legendItems, function(legendItem, i) {
+ var textWidth = ctx.measureText(legendItem.text).width;
+ var width = boxWidth + (fontSize / 2) + textWidth;
+ var x = cursor.x;
+ var y = cursor.y;
- // Horizontal
- var isHorizontal = me.isHorizontal();
+ // Use (me.left + me.minSize.width) and (me.top + me.minSize.height)
+ // instead of me.right and me.bottom because me.width and me.height
+ // may have been changed since me.minSize was calculated
if (isHorizontal) {
- cursor = {
- x: me.left + alignmentOffset(legendWidth, lineWidths[0]),
- y: me.top + labelOpts.padding,
- line: 0
- };
- } else {
- cursor = {
- x: me.left + labelOpts.padding,
- y: me.top + alignmentOffset(legendHeight, columnHeights[0]),
- line: 0
- };
- }
-
- var itemHeight = fontSize + labelOpts.padding;
- helpers.each(me.legendItems, function(legendItem, i) {
- var textWidth = ctx.measureText(legendItem.text).width;
- var width = boxWidth + (fontSize / 2) + textWidth;
- var x = cursor.x;
- var y = cursor.y;
-
- // Use (me.left + me.minSize.width) and (me.top + me.minSize.height)
- // instead of me.right and me.bottom because me.width and me.height
- // may have been changed since me.minSize was calculated
- if (isHorizontal) {
- if (i > 0 && x + width + labelOpts.padding > me.left + me.minSize.width) {
- y = cursor.y += itemHeight;
- cursor.line++;
- x = cursor.x = me.left + alignmentOffset(legendWidth, lineWidths[cursor.line]);
- }
- } else if (i > 0 && y + itemHeight > me.top + me.minSize.height) {
- x = cursor.x = x + me.columnWidths[cursor.line] + labelOpts.padding;
+ if (i > 0 && x + width + labelOpts.padding > me.left + me.minSize.width) {
+ y = cursor.y += itemHeight;
cursor.line++;
- y = cursor.y = me.top + alignmentOffset(legendHeight, columnHeights[cursor.line]);
+ x = cursor.x = me.left + alignmentOffset(legendWidth, lineWidths[cursor.line]);
}
+ } else if (i > 0 && y + itemHeight > me.top + me.minSize.height) {
+ x = cursor.x = x + me.columnWidths[cursor.line] + labelOpts.padding;
+ cursor.line++;
+ y = cursor.y = me.top + alignmentOffset(legendHeight, columnHeights[cursor.line]);
+ }
- drawLegendBox(x, y, legendItem);
+ drawLegendBox(x, y, legendItem);
- hitboxes[i].left = x;
- hitboxes[i].top = y;
+ hitboxes[i].left = x;
+ hitboxes[i].top = y;
- // Fill the actual label
- fillText(x, y, legendItem, textWidth);
+ // Fill the actual label
+ fillText(x, y, legendItem, textWidth);
- if (isHorizontal) {
- cursor.x += width + labelOpts.padding;
- } else {
- cursor.y += itemHeight;
- }
- });
- }
+ if (isHorizontal) {
+ cursor.x += width + labelOpts.padding;
+ } else {
+ cursor.y += itemHeight;
+ }
+ });
},
/** | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.