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 | 4c763bff44345ff5bbf2acc97cbce8918fa5b055.json | Enforce spaces around infix/unary words operators (#4547)
Enable ESLint `space-infix-ops` and `space-unary-ops` (for words only) rules. Also added `samples` to the linting task to match Code Climate expectations.
http://eslint.org/docs/rules/space-infix-ops
http://eslint.org/docs/rules/space-unary-ops | src/scales/scale.radialLinear.js | @@ -222,7 +222,7 @@ module.exports = function(Chart) {
for (var i = 0; i < text.length; ++i) {
ctx.fillText(text[i], position.x, y);
- y+= spacing;
+ y += spacing;
}
} else {
ctx.fillText(text, position.x, position.y); | true |
Other | chartjs | Chart.js | 4c763bff44345ff5bbf2acc97cbce8918fa5b055.json | Enforce spaces around infix/unary words operators (#4547)
Enable ESLint `space-infix-ops` and `space-unary-ops` (for words only) rules. Also added `samples` to the linting task to match Code Climate expectations.
http://eslint.org/docs/rules/space-infix-ops
http://eslint.org/docs/rules/space-unary-ops | src/scales/scale.time.js | @@ -2,7 +2,7 @@
'use strict';
var moment = require('moment');
-moment = typeof(moment) === 'function' ? moment : window.moment;
+moment = typeof moment === 'function' ? moment : window.moment;
var defaults = require('../core/core.defaults');
var helpers = require('../helpers/index');
@@ -45,7 +45,7 @@ function buildLookupTable(timestamps, min, max, linear) {
items.push(max);
}
- for (i = 0, ilen = items.length; i<ilen; ++i) {
+ for (i = 0, ilen = items.length; i < ilen; ++i) {
next = items[i + 1];
prev = items[i - 1];
curr = items[i];
@@ -331,8 +331,8 @@ module.exports = function(Chart) {
var majorFormat = me.majorDisplayFormat;
var majorTime = tick.clone().startOf(me.majorUnit).valueOf();
var major = majorUnit && majorFormat && time === majorTime;
- var formattedTick = tick.format(major? majorFormat : me.displayFormat);
- var tickOpts = major? options.ticks.major : options.ticks.minor;
+ var formattedTick = tick.format(major ? majorFormat : me.displayFormat);
+ var tickOpts = major ? options.ticks.major : options.ticks.minor;
var formatter = helpers.valueOrDefault(tickOpts.callback, tickOpts.userCallback);
if (formatter) { | true |
Other | chartjs | Chart.js | 4c763bff44345ff5bbf2acc97cbce8918fa5b055.json | Enforce spaces around infix/unary words operators (#4547)
Enable ESLint `space-infix-ops` and `space-unary-ops` (for words only) rules. Also added `samples` to the linting task to match Code Climate expectations.
http://eslint.org/docs/rules/space-infix-ops
http://eslint.org/docs/rules/space-unary-ops | test/jasmine.matchers.js | @@ -33,7 +33,7 @@ function buildPixelMatchPreview(actual, expected, diff, threshold, tolerance, co
'diff: ' + count + 'px ' +
'(' + toPercent(ratio) + '%)<br/>' +
'thr: ' + toPercent(threshold) + '%, ' +
- 'tol: '+ toPercent(tolerance) + '%'
+ 'tol: ' + toPercent(tolerance) + '%'
}
].forEach(function(values) {
var item = document.createElement('div');
@@ -104,7 +104,7 @@ function toBeValidChart() {
}
return {
- message: message? message : 'Expected ' + actual + ' to be valid chart',
+ message: message ? message : 'Expected ' + actual + ' to be valid chart',
pass: !message
};
}
@@ -149,7 +149,7 @@ function toBeChartOfSize() {
}
return {
- message: message? message : 'Expected ' + actual + ' to be a chart of size ' + expected,
+ message: message ? message : 'Expected ' + actual + ' to be a chart of size ' + expected,
pass: !message
};
}
@@ -161,8 +161,8 @@ function toEqualImageData() {
compare: function(actual, expected, opts) {
var message = null;
var debug = opts.debug || false;
- var tolerance = opts.tolerance === undefined? 0.001 : opts.tolerance;
- var threshold = opts.threshold === undefined? 0.1 : opts.threshold;
+ var tolerance = opts.tolerance === undefined ? 0.001 : opts.tolerance;
+ var threshold = opts.threshold === undefined ? 0.1 : opts.threshold;
var ctx, idata, ddata, w, h, count, ratio;
if (actual instanceof Chart) { | true |
Other | chartjs | Chart.js | 4c763bff44345ff5bbf2acc97cbce8918fa5b055.json | Enforce spaces around infix/unary words operators (#4547)
Enable ESLint `space-infix-ops` and `space-unary-ops` (for words only) rules. Also added `samples` to the linting task to match Code Climate expectations.
http://eslint.org/docs/rules/space-infix-ops
http://eslint.org/docs/rules/space-unary-ops | test/jasmine.utils.js | @@ -68,8 +68,8 @@ function acquireChart(config, options) {
// by default, remove chart animation and auto resize
config.options = config.options || {};
- config.options.animation = config.options.animation === undefined? false : config.options.animation;
- config.options.responsive = config.options.responsive === undefined? false : config.options.responsive;
+ config.options.animation = config.options.animation === undefined ? false : config.options.animation;
+ config.options.responsive = config.options.responsive === undefined ? false : config.options.responsive;
config.options.defaultFontFamily = config.options.defaultFontFamily || 'Arial';
wrapper.appendChild(canvas); | true |
Other | chartjs | Chart.js | 4c763bff44345ff5bbf2acc97cbce8918fa5b055.json | Enforce spaces around infix/unary words operators (#4547)
Enable ESLint `space-infix-ops` and `space-unary-ops` (for words only) rules. Also added `samples` to the linting task to match Code Climate expectations.
http://eslint.org/docs/rules/space-infix-ops
http://eslint.org/docs/rules/space-unary-ops | test/specs/controller.bubble.tests.js | @@ -162,7 +162,7 @@ describe('Bubble controller tests', function() {
chart.update();
- for (var i=0; i<4; ++i) {
+ for (var i = 0; i < 4; ++i) {
expect(meta.data[i]._model).toEqual(jasmine.objectContaining({
backgroundColor: 'rgb(98, 98, 98)',
borderColor: 'rgb(8, 8, 8)', | true |
Other | chartjs | Chart.js | 4c763bff44345ff5bbf2acc97cbce8918fa5b055.json | Enforce spaces around infix/unary words operators (#4547)
Enable ESLint `space-infix-ops` and `space-unary-ops` (for words only) rules. Also added `samples` to the linting task to match Code Climate expectations.
http://eslint.org/docs/rules/space-infix-ops
http://eslint.org/docs/rules/space-unary-ops | test/specs/core.controller.tests.js | @@ -10,7 +10,7 @@ describe('Chart', function() {
setTimeout(callback, 50);
};
- Chart.helpers.addEvent(content, state !== 'complete'? 'load' : 'resize', handler);
+ Chart.helpers.addEvent(content, state !== 'complete' ? 'load' : 'resize', handler);
}
// https://github.com/chartjs/Chart.js/issues/2481 | true |
Other | chartjs | Chart.js | 4c763bff44345ff5bbf2acc97cbce8918fa5b055.json | Enforce spaces around infix/unary words operators (#4547)
Enable ESLint `space-infix-ops` and `space-unary-ops` (for words only) rules. Also added `samples` to the linting task to match Code Climate expectations.
http://eslint.org/docs/rules/space-infix-ops
http://eslint.org/docs/rules/space-unary-ops | test/specs/global.deprecations.tests.js | @@ -104,7 +104,7 @@ describe('Deprecations', function() {
var calls = ctx.getCalls();
expect(calls[0]).toEqual({name: 'beginPath', args: []});
- expect(calls[calls.length-1]).toEqual({name: 'closePath', args: []});
+ expect(calls[calls.length - 1]).toEqual({name: 'closePath', args: []});
expect(Chart.helpers.canvas.roundedRect).toHaveBeenCalledWith(ctx, 10, 20, 30, 40, 5);
});
});
@@ -172,7 +172,7 @@ describe('Deprecations', function() {
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.aspectRatio).toBe(140 / 320);
expect(proxy.height).toBe(320);
expect(proxy.width).toBe(140);
}); | true |
Other | chartjs | Chart.js | 4c763bff44345ff5bbf2acc97cbce8918fa5b055.json | Enforce spaces around infix/unary words operators (#4547)
Enable ESLint `space-infix-ops` and `space-unary-ops` (for words only) rules. Also added `samples` to the linting task to match Code Climate expectations.
http://eslint.org/docs/rules/space-infix-ops
http://eslint.org/docs/rules/space-unary-ops | test/specs/helpers.core.tests.js | @@ -150,7 +150,7 @@ describe('Chart.helpers.core', function() {
it('should return the value returned by fn', function() {
expect(helpers.callback(helpers.noop, [41])).toBe(undefined);
expect(helpers.callback(function(i) {
- return i+1;
+ return i + 1;
}, [41])).toBe(42);
});
}); | true |
Other | chartjs | Chart.js | 4c763bff44345ff5bbf2acc97cbce8918fa5b055.json | Enforce spaces around infix/unary words operators (#4547)
Enable ESLint `space-infix-ops` and `space-unary-ops` (for words only) rules. Also added `samples` to the linting task to match Code Climate expectations.
http://eslint.org/docs/rules/space-infix-ops
http://eslint.org/docs/rules/space-unary-ops | test/specs/helpers.easing.tests.js | @@ -45,8 +45,8 @@ describe('Chart.helpers.easing', function() {
var values = [];
var i;
- for (i=0; i<=count; ++i) {
- values.push(Math.round(accuracy * fn(i/count)) / accuracy);
+ for (i = 0; i <= count; ++i) {
+ values.push(Math.round(accuracy * fn(i / count)) / accuracy);
}
return values; | true |
Other | chartjs | Chart.js | 4c763bff44345ff5bbf2acc97cbce8918fa5b055.json | Enforce spaces around infix/unary words operators (#4547)
Enable ESLint `space-infix-ops` and `space-unary-ops` (for words only) rules. Also added `samples` to the linting task to match Code Climate expectations.
http://eslint.org/docs/rules/space-infix-ops
http://eslint.org/docs/rules/space-unary-ops | test/specs/platform.dom.tests.js | @@ -10,7 +10,7 @@ describe('Platform.dom', function() {
setTimeout(callback, 50);
};
- Chart.helpers.addEvent(content, state !== 'complete'? 'load' : 'resize', handler);
+ Chart.helpers.addEvent(content, state !== 'complete' ? 'load' : 'resize', handler);
}
describe('context acquisition', function() { | true |
Other | chartjs | Chart.js | f6b6956a3aeb341fb3987a8ddb6c76fb9a37999c.json | Fix ESLint errors (#4485) | src/chart.js | @@ -53,9 +53,9 @@ require('./charts/Chart.Scatter')(Chart);
var plugins = [];
plugins.push(
- require('./plugins/plugin.filler')(Chart),
- require('./plugins/plugin.legend')(Chart),
- require('./plugins/plugin.title')(Chart)
+ require('./plugins/plugin.filler')(Chart),
+ require('./plugins/plugin.legend')(Chart),
+ require('./plugins/plugin.title')(Chart)
);
Chart.plugins.register(plugins); | true |
Other | chartjs | Chart.js | f6b6956a3aeb341fb3987a8ddb6c76fb9a37999c.json | Fix ESLint errors (#4485) | src/controllers/controller.doughnut.js | @@ -168,7 +168,7 @@ module.exports = function(Chart) {
var endAngle = startAngle + circumference;
var start = {x: Math.cos(startAngle), y: Math.sin(startAngle)};
var end = {x: Math.cos(endAngle), y: Math.sin(endAngle)};
- var contains0 = (startAngle <= 0 && 0 <= endAngle) || (startAngle <= Math.PI * 2.0 && Math.PI * 2.0 <= endAngle);
+ var contains0 = (startAngle <= 0 && endAngle >= 0) || (startAngle <= Math.PI * 2.0 && Math.PI * 2.0 <= endAngle);
var contains90 = (startAngle <= Math.PI * 0.5 && Math.PI * 0.5 <= endAngle) || (startAngle <= Math.PI * 2.5 && Math.PI * 2.5 <= endAngle);
var contains180 = (startAngle <= -Math.PI && -Math.PI <= endAngle) || (startAngle <= Math.PI && Math.PI <= endAngle);
var contains270 = (startAngle <= -Math.PI * 0.5 && -Math.PI * 0.5 <= endAngle) || (startAngle <= Math.PI * 1.5 && Math.PI * 1.5 <= endAngle); | true |
Other | chartjs | Chart.js | f6b6956a3aeb341fb3987a8ddb6c76fb9a37999c.json | Fix ESLint errors (#4485) | src/core/core.controller.js | @@ -95,7 +95,7 @@ module.exports = function(Chart) {
* @private
*/
me.chart = me;
- me.controller = me; // chart.chart.controller #inception
+ me.controller = me; // chart.chart.controller #inception
// Add the chart instance to the global namespace
Chart.instances[me.id] = me;
@@ -172,7 +172,7 @@ module.exports = function(Chart) {
// the canvas render width and height will be casted to integers so make sure that
// the canvas display style uses the same integer values to avoid blurring effect.
- // Set to 0 instead of canvas.size because the size defaults to 300x150 if the element is collased
+ // Set to 0 instead of canvas.size because the size defaults to 300x150 if the element is collased
var newWidth = Math.max(0, Math.floor(helpers.getMaximumWidth(canvas)));
var newHeight = Math.max(0, Math.floor(aspectRatio ? newWidth / aspectRatio : helpers.getMaximumHeight(canvas)));
@@ -709,7 +709,7 @@ module.exports = function(Chart) {
var me = this;
me.tooltip = new Chart.Tooltip({
_chart: me,
- _chartInstance: me, // deprecated, backward compatibility
+ _chartInstance: me, // deprecated, backward compatibility
_data: me.data,
_options: me.options.tooltips
}, me); | true |
Other | chartjs | Chart.js | f6b6956a3aeb341fb3987a8ddb6c76fb9a37999c.json | Fix ESLint errors (#4485) | src/core/core.scale.js | @@ -509,9 +509,9 @@ module.exports = function(Chart) {
var min = me.min;
var max = me.max;
- return me.beginAtZero ? 0:
- min < 0 && max < 0? max :
- min > 0 && max > 0? min :
+ return me.beginAtZero ? 0 :
+ min < 0 && max < 0 ? max :
+ min > 0 && max > 0 ? min :
0;
},
| true |
Other | chartjs | Chart.js | f6b6956a3aeb341fb3987a8ddb6c76fb9a37999c.json | Fix ESLint errors (#4485) | src/scales/scale.logarithmic.js | @@ -235,7 +235,7 @@ module.exports = function(Chart) {
if (me.isHorizontal()) {
innerDimension = me.width;
value = me.start * Math.pow(10, (pixel - me.left) * range / innerDimension);
- } else { // todo: if start === 0
+ } else { // todo: if start === 0
innerDimension = me.height;
value = Math.pow(10, (me.bottom - pixel) * range / innerDimension) / me.start;
} | true |
Other | chartjs | Chart.js | f6b6956a3aeb341fb3987a8ddb6c76fb9a37999c.json | Fix ESLint errors (#4485) | src/scales/scale.radialLinear.js | @@ -460,9 +460,9 @@ module.exports = function(Chart) {
var max = me.max;
return me.getPointPositionForValue(0,
- me.beginAtZero? 0:
- min < 0 && max < 0? max :
- min > 0 && max > 0? min :
+ me.beginAtZero ? 0 :
+ min < 0 && max < 0 ? max :
+ min > 0 && max > 0 ? min :
0);
},
| true |
Other | chartjs | Chart.js | f6b6956a3aeb341fb3987a8ddb6c76fb9a37999c.json | Fix ESLint errors (#4485) | test/jasmine.utils.js | @@ -98,7 +98,7 @@ function injectCSS(css) {
var head = document.getElementsByTagName('head')[0];
var style = document.createElement('style');
style.setAttribute('type', 'text/css');
- if (style.styleSheet) { // IE
+ if (style.styleSheet) { // IE
style.styleSheet.cssText = css;
} else {
style.appendChild(document.createTextNode(css)); | true |
Other | chartjs | Chart.js | f6b6956a3aeb341fb3987a8ddb6c76fb9a37999c.json | Fix ESLint errors (#4485) | test/specs/controller.polarArea.tests.js | @@ -5,8 +5,8 @@ describe('Polar area controller tests', function() {
type: 'polarArea',
data: {
datasets: [
- {data: []},
- {data: []}
+ {data: []},
+ {data: []}
],
labels: []
} | true |
Other | chartjs | Chart.js | f6b6956a3aeb341fb3987a8ddb6c76fb9a37999c.json | Fix ESLint errors (#4485) | test/specs/scale.category.tests.js | @@ -42,7 +42,7 @@ describe('Category scale tests', function() {
padding: 0,
reverse: false,
display: true,
- callback: defaultConfig.ticks.callback, // make this nicer, then check explicitly below
+ callback: defaultConfig.ticks.callback, // make this nicer, then check explicitly below
autoSkip: true,
autoSkipPadding: 0,
labelOffset: 0, | true |
Other | chartjs | Chart.js | f6b6956a3aeb341fb3987a8ddb6c76fb9a37999c.json | Fix ESLint errors (#4485) | test/specs/scale.logarithmic.tests.js | @@ -718,20 +718,20 @@ describe('Logarithmic Scale tests', function() {
});
var xScale = chart.scales.xScale;
- expect(xScale.getPixelForValue(80, 0, 0)).toBeCloseToPixel(495); // right - paddingRight
+ expect(xScale.getPixelForValue(80, 0, 0)).toBeCloseToPixel(495); // right - paddingRight
expect(xScale.getPixelForValue(1, 0, 0)).toBeCloseToPixel(37); // left + paddingLeft
- expect(xScale.getPixelForValue(10, 0, 0)).toBeCloseToPixel(278); // halfway
+ expect(xScale.getPixelForValue(10, 0, 0)).toBeCloseToPixel(278); // halfway
expect(xScale.getPixelForValue(0, 0, 0)).toBeCloseToPixel(37); // 0 is invalid, put it on the left.
expect(xScale.getValueForPixel(495)).toBeCloseToPixel(80);
expect(xScale.getValueForPixel(48)).toBeCloseTo(1, 1e-4);
expect(xScale.getValueForPixel(278)).toBeCloseTo(10, 1e-4);
var yScale = chart.scales.yScale;
- expect(yScale.getPixelForValue(80, 0, 0)).toBeCloseToPixel(32); // top + paddingTop
+ expect(yScale.getPixelForValue(80, 0, 0)).toBeCloseToPixel(32); // top + paddingTop
expect(yScale.getPixelForValue(1, 0, 0)).toBeCloseToPixel(484); // bottom - paddingBottom
- expect(yScale.getPixelForValue(10, 0, 0)).toBeCloseToPixel(246); // halfway
- expect(yScale.getPixelForValue(0, 0, 0)).toBeCloseToPixel(484); // 0 is invalid. force it on bottom
+ expect(yScale.getPixelForValue(10, 0, 0)).toBeCloseToPixel(246); // halfway
+ expect(yScale.getPixelForValue(0, 0, 0)).toBeCloseToPixel(484); // 0 is invalid. force it on bottom
expect(yScale.getValueForPixel(32)).toBeCloseTo(80, 1e-4);
expect(yScale.getValueForPixel(484)).toBeCloseTo(1, 1e-4);
@@ -762,20 +762,20 @@ describe('Logarithmic Scale tests', function() {
});
var yScale = chart.scales.yScale;
- expect(yScale.getPixelForValue(70, 0, 0)).toBeCloseToPixel(32); // top + paddingTop
- expect(yScale.getPixelForValue(0, 0, 0)).toBeCloseToPixel(484); // bottom - paddingBottom
- expect(yScale.getPixelForValue(0.063, 0, 0)).toBeCloseToPixel(475); // minNotZero 2% from range
+ expect(yScale.getPixelForValue(70, 0, 0)).toBeCloseToPixel(32); // top + paddingTop
+ expect(yScale.getPixelForValue(0, 0, 0)).toBeCloseToPixel(484); // bottom - paddingBottom
+ expect(yScale.getPixelForValue(0.063, 0, 0)).toBeCloseToPixel(475); // minNotZero 2% from range
expect(yScale.getPixelForValue(0.5, 0, 0)).toBeCloseToPixel(344);
expect(yScale.getPixelForValue(4, 0, 0)).toBeCloseToPixel(213);
expect(yScale.getPixelForValue(10, 0, 0)).toBeCloseToPixel(155);
expect(yScale.getPixelForValue(63, 0, 0)).toBeCloseToPixel(38.5);
- chart.options.scales.yAxes[0].ticks.reverse = true; // Reverse mode
+ chart.options.scales.yAxes[0].ticks.reverse = true; // Reverse mode
chart.update();
- expect(yScale.getPixelForValue(70, 0, 0)).toBeCloseToPixel(484); // bottom - paddingBottom
- expect(yScale.getPixelForValue(0, 0, 0)).toBeCloseToPixel(32); // top + paddingTop
- expect(yScale.getPixelForValue(0.063, 0, 0)).toBeCloseToPixel(41); // minNotZero 2% from range
+ expect(yScale.getPixelForValue(70, 0, 0)).toBeCloseToPixel(484); // bottom - paddingBottom
+ expect(yScale.getPixelForValue(0, 0, 0)).toBeCloseToPixel(32); // top + paddingTop
+ expect(yScale.getPixelForValue(0.063, 0, 0)).toBeCloseToPixel(41); // minNotZero 2% from range
expect(yScale.getPixelForValue(0.5, 0, 0)).toBeCloseToPixel(172);
expect(yScale.getPixelForValue(4, 0, 0)).toBeCloseToPixel(303);
expect(yScale.getPixelForValue(10, 0, 0)).toBeCloseToPixel(361); | true |
Other | chartjs | Chart.js | 090196c07c601cdaf5a91ff0ba731cc46945c101.json | Add support for line height CSS values (#4531)
The title plugin and scale title now accept lineHeight specified using unitless value (1.4), length ('1.4em' or '12px'), percentage ('200%') or keyword ('normal' === 1.2). The line height parsing has been refactored under the 'Chart.helpers.options' namespace. Also fix incorrect text positioning in the title plugin.
https://developer.mozilla.org/en-US/docs/Web/CSS/line-height | docs/axes/labelling.md | @@ -10,7 +10,7 @@ The scale label configuration is nested under the scale configuration in the `sc
| -----| ---- | --------| -----------
| `display` | `Boolean` | `false` | If true, display the axis title.
| `labelString` | `String` | `''` | The text for the title. (i.e. "# of People" or "Response Choices").
-| `lineHeight` | `Number` | `` | Height of an individual line of text. If not defined, the font size is used.
+| `lineHeight` | `Number|String` | `1.2` | Height of an individual line of text (see [MDN](https://developer.mozilla.org/en-US/docs/Web/CSS/line-height))
| `fontColor` | Color | `'#666'` | Font color for scale title.
| `fontFamily` | `String` | `"'Helvetica Neue', 'Helvetica', 'Arial', sans-serif"` | Font family for the scale title, follows CSS font-family options.
| `fontSize` | `Number` | `12` | Font size for scale title. | true |
Other | chartjs | Chart.js | 090196c07c601cdaf5a91ff0ba731cc46945c101.json | Add support for line height CSS values (#4531)
The title plugin and scale title now accept lineHeight specified using unitless value (1.4), length ('1.4em' or '12px'), percentage ('200%') or keyword ('normal' === 1.2). The line height parsing has been refactored under the 'Chart.helpers.options' namespace. Also fix incorrect text positioning in the title plugin.
https://developer.mozilla.org/en-US/docs/Web/CSS/line-height | docs/configuration/title.md | @@ -14,7 +14,7 @@ The title configuration is passed into the `options.title` namespace. The global
| `fontColor` | Color | `'#666'` | Font color
| `fontStyle` | `String` | `'bold'` | Font style
| `padding` | `Number` | `10` | Number of pixels to add above and below the title text.
-| `lineHeight` | `Number` | `undefined` | Height of line of text. If not specified, the `fontSize` is used.
+| `lineHeight` | `Number|String` | `1.2` | Height of an individual line of text (see [MDN](https://developer.mozilla.org/en-US/docs/Web/CSS/line-height))
| `text` | `String/String[]` | `''` | Title text to display. If specified as an array, text is rendered on multiple lines.
### Position | true |
Other | chartjs | Chart.js | 090196c07c601cdaf5a91ff0ba731cc46945c101.json | Add support for line height CSS values (#4531)
The title plugin and scale title now accept lineHeight specified using unitless value (1.4), length ('1.4em' or '12px'), percentage ('200%') or keyword ('normal' === 1.2). The line height parsing has been refactored under the 'Chart.helpers.options' namespace. Also fix incorrect text positioning in the title plugin.
https://developer.mozilla.org/en-US/docs/Web/CSS/line-height | src/core/core.scale.js | @@ -28,11 +28,13 @@ defaults._set('scale', {
// scale label
scaleLabel: {
+ // display property
+ display: false,
+
// actual label
labelString: '',
- // display property
- display: false,
+ lineHeight: 1.2
},
// label settings
@@ -77,6 +79,12 @@ module.exports = function(Chart) {
};
}
+ function parseLineHeight(options) {
+ return helpers.options.toLineHeight(
+ helpers.valueOrDefault(options.lineHeight, 1.2),
+ helpers.valueOrDefault(options.fontSize, defaults.global.defaultFontSize));
+ }
+
Chart.Scale = Chart.Element.extend({
/**
* Get the padding needed for the scale
@@ -310,8 +318,8 @@ module.exports = function(Chart) {
var isHorizontal = me.isHorizontal();
var tickFont = parseFontOptions(tickOpts);
- var scaleLabelLineHeight = helpers.valueOrDefault(scaleLabelOpts.lineHeight, parseFontOptions(scaleLabelOpts).size * 1.5);
var tickMarkLength = opts.gridLines.tickMarkLength;
+ var scaleLabelLineHeight = parseLineHeight(scaleLabelOpts);
// Width
if (isHorizontal) {
@@ -738,7 +746,7 @@ module.exports = function(Chart) {
var scaleLabelX;
var scaleLabelY;
var rotation = 0;
- var halfLineHeight = helpers.valueOrDefault(scaleLabel.lineHeight, scaleLabelFont.size) / 2;
+ var halfLineHeight = parseLineHeight(scaleLabel) / 2;
if (isHorizontal) {
scaleLabelX = me.left + ((me.right - me.left) / 2); // midpoint of the width | true |
Other | chartjs | Chart.js | 090196c07c601cdaf5a91ff0ba731cc46945c101.json | Add support for line height CSS values (#4531)
The title plugin and scale title now accept lineHeight specified using unitless value (1.4), length ('1.4em' or '12px'), percentage ('200%') or keyword ('normal' === 1.2). The line height parsing has been refactored under the 'Chart.helpers.options' namespace. Also fix incorrect text positioning in the title plugin.
https://developer.mozilla.org/en-US/docs/Web/CSS/line-height | src/helpers/helpers.options.js | @@ -0,0 +1,35 @@
+'use strict';
+
+/**
+ * @namespace Chart.helpers.options
+ */
+module.exports = {
+ /**
+ * Converts the given line height `value` in pixels for a specific font `size`.
+ * @param {Number|String} value - The lineHeight to parse (eg. 1.6, '14px', '75%', '1.6em').
+ * @param {Number} size - The font size (in pixels) used to resolve relative `value`.
+ * @returns {Number} The effective line height in pixels (size * 1.2 if value is invalid).
+ * @see https://developer.mozilla.org/en-US/docs/Web/CSS/line-height
+ * @since 2.7.0
+ */
+ toLineHeight: function(value, size) {
+ var matches = (''+value).match(/^(normal|(\d+(?:\.\d+)?)(px|em|%)?)$/);
+ if (!matches || matches[1] === 'normal') {
+ return size * 1.2;
+ }
+
+ value = parseFloat(matches[2]);
+
+ switch (matches[3]) {
+ case 'px':
+ return value;
+ case '%':
+ value /= 100;
+ break;
+ default:
+ break;
+ }
+
+ return size * value;
+ }
+}; | true |
Other | chartjs | Chart.js | 090196c07c601cdaf5a91ff0ba731cc46945c101.json | Add support for line height CSS values (#4531)
The title plugin and scale title now accept lineHeight specified using unitless value (1.4), length ('1.4em' or '12px'), percentage ('200%') or keyword ('normal' === 1.2). The line height parsing has been refactored under the 'Chart.helpers.options' namespace. Also fix incorrect text positioning in the title plugin.
https://developer.mozilla.org/en-US/docs/Web/CSS/line-height | src/helpers/index.js | @@ -3,4 +3,5 @@
module.exports = require('./helpers.core');
module.exports.easing = require('./helpers.easing');
module.exports.canvas = require('./helpers.canvas');
+module.exports.options = require('./helpers.options');
module.exports.time = require('./helpers.time'); | true |
Other | chartjs | Chart.js | 090196c07c601cdaf5a91ff0ba731cc46945c101.json | Add support for line height CSS values (#4531)
The title plugin and scale title now accept lineHeight specified using unitless value (1.4), length ('1.4em' or '12px'), percentage ('200%') or keyword ('normal' === 1.2). The line height parsing has been refactored under the 'Chart.helpers.options' namespace. Also fix incorrect text positioning in the title plugin.
https://developer.mozilla.org/en-US/docs/Web/CSS/line-height | src/plugins/plugin.title.js | @@ -8,6 +8,7 @@ defaults._set('global', {
display: false,
fontStyle: 'bold',
fullWidth: true,
+ lineHeight: 1.2,
padding: 10,
position: 'top',
text: '',
@@ -114,7 +115,7 @@ module.exports = function(Chart) {
fontSize = valueOrDefault(opts.fontSize, defaults.global.defaultFontSize),
minSize = me.minSize,
lineCount = helpers.isArray(opts.text) ? opts.text.length : 1,
- lineHeight = valueOrDefault(opts.lineHeight, fontSize),
+ lineHeight = helpers.options.toLineHeight(opts.lineHeight, fontSize),
textSize = display ? (lineCount * lineHeight) + (opts.padding * 2) : 0;
if (me.isHorizontal()) {
@@ -150,7 +151,8 @@ module.exports = function(Chart) {
fontStyle = valueOrDefault(opts.fontStyle, globalDefaults.defaultFontStyle),
fontFamily = valueOrDefault(opts.fontFamily, globalDefaults.defaultFontFamily),
titleFont = helpers.fontString(fontSize, fontStyle, fontFamily),
- lineHeight = valueOrDefault(opts.lineHeight, fontSize),
+ lineHeight = helpers.options.toLineHeight(opts.lineHeight, fontSize),
+ offset = lineHeight/2 + opts.padding,
rotation = 0,
titleX,
titleY,
@@ -166,10 +168,10 @@ module.exports = function(Chart) {
// Horizontal
if (me.isHorizontal()) {
titleX = left + ((right - left) / 2); // midpoint of the width
- titleY = top + ((bottom - top) / 2); // midpoint of the height
+ titleY = top + offset;
maxWidth = right - left;
} else {
- titleX = opts.position === 'left' ? left + (fontSize / 2) : right - (fontSize / 2);
+ titleX = opts.position === 'left' ? left + offset : right - offset;
titleY = top + ((bottom - top) / 2);
maxWidth = bottom - top;
rotation = Math.PI * (opts.position === 'left' ? -0.5 : 0.5); | true |
Other | chartjs | Chart.js | 090196c07c601cdaf5a91ff0ba731cc46945c101.json | Add support for line height CSS values (#4531)
The title plugin and scale title now accept lineHeight specified using unitless value (1.4), length ('1.4em' or '12px'), percentage ('200%') or keyword ('normal' === 1.2). The line height parsing has been refactored under the 'Chart.helpers.options' namespace. Also fix incorrect text positioning in the title plugin.
https://developer.mozilla.org/en-US/docs/Web/CSS/line-height | test/specs/core.helpers.tests.js | @@ -128,8 +128,9 @@ describe('Core helper tests', function() {
},
position: 'right',
scaleLabel: {
- labelString: '',
display: false,
+ labelString: '',
+ lineHeight: 1.2
},
ticks: {
beginAtZero: false,
@@ -168,8 +169,9 @@ describe('Core helper tests', function() {
},
position: 'left',
scaleLabel: {
- labelString: '',
display: false,
+ labelString: '',
+ lineHeight: 1.2
},
ticks: {
beginAtZero: false, | true |
Other | chartjs | Chart.js | 090196c07c601cdaf5a91ff0ba731cc46945c101.json | Add support for line height CSS values (#4531)
The title plugin and scale title now accept lineHeight specified using unitless value (1.4), length ('1.4em' or '12px'), percentage ('200%') or keyword ('normal' === 1.2). The line height parsing has been refactored under the 'Chart.helpers.options' namespace. Also fix incorrect text positioning in the title plugin.
https://developer.mozilla.org/en-US/docs/Web/CSS/line-height | test/specs/helpers.options.tests.js | @@ -0,0 +1,27 @@
+'use strict';
+
+describe('Chart.helpers.options', function() {
+ var options = Chart.helpers.options;
+
+ describe('toLineHeight', function() {
+ it ('should support keyword values', function() {
+ expect(options.toLineHeight('normal', 16)).toBe(16 * 1.2);
+ });
+ it ('should support unitless values', function() {
+ expect(options.toLineHeight(1.4, 16)).toBe(16 * 1.4);
+ expect(options.toLineHeight('1.4', 16)).toBe(16 * 1.4);
+ });
+ it ('should support length values', function() {
+ expect(options.toLineHeight('42px', 16)).toBe(42);
+ expect(options.toLineHeight('1.4em', 16)).toBe(16 * 1.4);
+ });
+ it ('should support percentage values', function() {
+ expect(options.toLineHeight('140%', 16)).toBe(16 * 1.4);
+ });
+ it ('should fallback to default (1.2) for invalid values', function() {
+ expect(options.toLineHeight(null, 16)).toBe(16 * 1.2);
+ expect(options.toLineHeight(undefined, 16)).toBe(16 * 1.2);
+ expect(options.toLineHeight('foobar', 16)).toBe(16 * 1.2);
+ });
+ });
+}); | true |
Other | chartjs | Chart.js | 090196c07c601cdaf5a91ff0ba731cc46945c101.json | Add support for line height CSS values (#4531)
The title plugin and scale title now accept lineHeight specified using unitless value (1.4), length ('1.4em' or '12px'), percentage ('200%') or keyword ('normal' === 1.2). The line height parsing has been refactored under the 'Chart.helpers.options' namespace. Also fix incorrect text positioning in the title plugin.
https://developer.mozilla.org/en-US/docs/Web/CSS/line-height | test/specs/plugin.title.tests.js | @@ -13,6 +13,7 @@ describe('Title block tests', function() {
fullWidth: true,
weight: 2000,
fontStyle: 'bold',
+ lineHeight: 1.2,
padding: 10,
text: ''
});
@@ -43,7 +44,7 @@ describe('Title block tests', function() {
expect(minSize).toEqual({
width: 400,
- height: 32
+ height: 34.4
});
});
@@ -72,7 +73,7 @@ describe('Title block tests', function() {
minSize = title.update(200, 400);
expect(minSize).toEqual({
- width: 32,
+ width: 34.4,
height: 400
});
});
@@ -84,7 +85,7 @@ describe('Title block tests', function() {
options.text = ['line1', 'line2'];
options.position = 'left';
options.display = true;
- options.lineHeight = 15;
+ options.lineHeight = 1.5;
var title = new Chart.Title({
chart: chart,
@@ -94,7 +95,7 @@ describe('Title block tests', function() {
var minSize = title.update(200, 400);
expect(minSize).toEqual({
- width: 50,
+ width: 56,
height: 400
});
});
@@ -135,7 +136,7 @@ describe('Title block tests', function() {
args: []
}, {
name: 'translate',
- args: [300, 66]
+ args: [300, 67.2]
}, {
name: 'rotate',
args: [0]
@@ -185,7 +186,7 @@ describe('Title block tests', function() {
args: []
}, {
name: 'translate',
- args: [106, 250]
+ args: [117.2, 250]
}, {
name: 'rotate',
args: [-0.5 * Math.PI]
@@ -218,7 +219,7 @@ describe('Title block tests', function() {
args: []
}, {
name: 'translate',
- args: [126, 250]
+ args: [117.2, 250]
}, {
name: 'rotate',
args: [0.5 * Math.PI] | true |
Other | chartjs | Chart.js | 090196c07c601cdaf5a91ff0ba731cc46945c101.json | Add support for line height CSS values (#4531)
The title plugin and scale title now accept lineHeight specified using unitless value (1.4), length ('1.4em' or '12px'), percentage ('200%') or keyword ('normal' === 1.2). The line height parsing has been refactored under the 'Chart.helpers.options' namespace. Also fix incorrect text positioning in the title plugin.
https://developer.mozilla.org/en-US/docs/Web/CSS/line-height | test/specs/scale.category.tests.js | @@ -30,8 +30,9 @@ describe('Category scale tests', function() {
},
position: 'bottom',
scaleLabel: {
+ display: false,
labelString: '',
- display: false
+ lineHeight: 1.2
},
ticks: {
beginAtZero: false, | true |
Other | chartjs | Chart.js | 090196c07c601cdaf5a91ff0ba731cc46945c101.json | Add support for line height CSS values (#4531)
The title plugin and scale title now accept lineHeight specified using unitless value (1.4), length ('1.4em' or '12px'), percentage ('200%') or keyword ('normal' === 1.2). The line height parsing has been refactored under the 'Chart.helpers.options' namespace. Also fix incorrect text positioning in the title plugin.
https://developer.mozilla.org/en-US/docs/Web/CSS/line-height | test/specs/scale.linear.tests.js | @@ -28,8 +28,9 @@ describe('Linear Scale', function() {
},
position: 'left',
scaleLabel: {
- labelString: '',
display: false,
+ labelString: '',
+ lineHeight: 1.2
},
ticks: {
beginAtZero: false,
@@ -772,15 +773,15 @@ describe('Linear Scale', function() {
expect(xScale.paddingBottom).toBeCloseToPixel(0);
expect(xScale.paddingLeft).toBeCloseToPixel(0);
expect(xScale.paddingRight).toBeCloseToPixel(0);
- expect(xScale.width).toBeCloseToPixel(450);
- expect(xScale.height).toBeCloseToPixel(46);
+ expect(xScale.width).toBeCloseToPixel(454);
+ expect(xScale.height).toBeCloseToPixel(42);
expect(yScale.paddingTop).toBeCloseToPixel(0);
expect(yScale.paddingBottom).toBeCloseToPixel(0);
expect(yScale.paddingLeft).toBeCloseToPixel(0);
expect(yScale.paddingRight).toBeCloseToPixel(0);
- expect(yScale.width).toBeCloseToPixel(48);
- expect(yScale.height).toBeCloseToPixel(434);
+ expect(yScale.width).toBeCloseToPixel(44);
+ expect(yScale.height).toBeCloseToPixel(438);
});
it('should fit correctly when display is turned off', function() {
@@ -820,7 +821,8 @@ describe('Linear Scale', function() {
drawBorder: false
},
scaleLabel: {
- display: false
+ display: false,
+ lineHeight: 1.2
},
ticks: {
display: false, | true |
Other | chartjs | Chart.js | 090196c07c601cdaf5a91ff0ba731cc46945c101.json | Add support for line height CSS values (#4531)
The title plugin and scale title now accept lineHeight specified using unitless value (1.4), length ('1.4em' or '12px'), percentage ('200%') or keyword ('normal' === 1.2). The line height parsing has been refactored under the 'Chart.helpers.options' namespace. Also fix incorrect text positioning in the title plugin.
https://developer.mozilla.org/en-US/docs/Web/CSS/line-height | test/specs/scale.logarithmic.tests.js | @@ -27,8 +27,9 @@ describe('Logarithmic Scale tests', function() {
},
position: 'left',
scaleLabel: {
- labelString: '',
display: false,
+ labelString: '',
+ lineHeight: 1.2
},
ticks: {
beginAtZero: false, | true |
Other | chartjs | Chart.js | 090196c07c601cdaf5a91ff0ba731cc46945c101.json | Add support for line height CSS values (#4531)
The title plugin and scale title now accept lineHeight specified using unitless value (1.4), length ('1.4em' or '12px'), percentage ('200%') or keyword ('normal' === 1.2). The line height parsing has been refactored under the 'Chart.helpers.options' namespace. Also fix incorrect text positioning in the title plugin.
https://developer.mozilla.org/en-US/docs/Web/CSS/line-height | test/specs/scale.radialLinear.tests.js | @@ -40,8 +40,9 @@ describe('Test the radial linear scale', function() {
},
position: 'chartArea',
scaleLabel: {
- labelString: '',
display: false,
+ labelString: '',
+ lineHeight: 1.2
},
ticks: {
backdropColor: 'rgba(255,255,255,0.75)', | true |
Other | chartjs | Chart.js | 090196c07c601cdaf5a91ff0ba731cc46945c101.json | Add support for line height CSS values (#4531)
The title plugin and scale title now accept lineHeight specified using unitless value (1.4), length ('1.4em' or '12px'), percentage ('200%') or keyword ('normal' === 1.2). The line height parsing has been refactored under the 'Chart.helpers.options' namespace. Also fix incorrect text positioning in the title plugin.
https://developer.mozilla.org/en-US/docs/Web/CSS/line-height | test/specs/scale.time.tests.js | @@ -81,8 +81,9 @@ describe('Time scale tests', function() {
},
position: 'bottom',
scaleLabel: {
+ display: false,
labelString: '',
- display: false
+ lineHeight: 1.2
},
ticks: {
beginAtZero: false, | true |
Other | chartjs | Chart.js | a0fc1c9019503e873405fe7f8e81b1e1092feb79.json | Add link to Java integration (#4527) | docs/notes/extensions.md | @@ -45,3 +45,6 @@ In addition, many plugins can be found on the [npm registry](https://www.npmjs.c
### Vue.js
- <a href="https://github.com/apertureless/vue-chartjs/" target="_blank">vue-chartjs</a>
+
+### Java
+ - <a href="https://github.com/mdewilde/chart/" target="_blank">Chart.java</a> | false |
Other | chartjs | Chart.js | f16d8a32e2641bae8483a5194b7ddb1ec56ab5fa.json | Fix links in documentations (#4477)
* Fix relative links in documentation of configurations
* Fix relative link of 'Time Units'
* Fix relative links for chart types documentations
* Fix the release version link in developers/plugins | docs/axes/cartesian/time.md | @@ -13,9 +13,9 @@ The following options are provided by the time scale. They are all located in th
| `max` | [Time](#date-formats) | | If defined, this will override the data maximum
| `min` | [Time](#date-formats) | | If defined, this will override the data minimum
| `parser` | `String` or `Function` | | Custom parser for dates. [more...](#parser)
-| `round` | `String` | `false` | If defined, dates will be rounded to the start of this unit. See [Time Units](#scales-time-units) below for the allowed units.
+| `round` | `String` | `false` | If defined, dates will be rounded to the start of this unit. See [Time Units](#time-units) below for the allowed units.
| `tooltipFormat` | `String` | | The moment js format string to use for the tooltip.
-| `unit` | `String` | `false` | If defined, will force the unit to be a certain type. See [Time Units](#scales-time-units) section below for details.
+| `unit` | `String` | `false` | If defined, will force the unit to be a certain type. See [Time Units](#time-units) section below for details.
| `stepSize` | `Number` | `1` | The number of units between grid lines.
| `minUnit` | `String` | `'millisecond'` | The minimum display format to be used for a time unit.
| true |
Other | chartjs | Chart.js | f16d8a32e2641bae8483a5194b7ddb1ec56ab5fa.json | Fix links in documentations (#4477)
* Fix relative links in documentation of configurations
* Fix relative link of 'Time Units'
* Fix relative links for chart types documentations
* Fix the release version link in developers/plugins | docs/charts/bar.md | @@ -73,7 +73,7 @@ Some properties can be specified as an array. If these are set to an array value
| `backgroundColor` | `Color/Color[]` | The fill color of the bar. See [Colors](../general/colors.md#colors)
| `borderColor` | `Color/Color[]` | The color of the bar border. See [Colors](../general/colors.md#colors)
| `borderWidth` | `Number/Number[]` | The stroke width of the bar in pixels.
-| `borderSkipped` | `String` | Which edge to skip drawing the border for. [more...](#borderSkipped)
+| `borderSkipped` | `String` | Which edge to skip drawing the border for. [more...](#borderskipped)
| `hoverBackgroundColor` | `Color/Color[]` | The fill colour of the bars when hovered.
| `hoverBorderColor` | `Color/Color[]` | The stroke colour of the bars when hovered.
| `hoverBorderWidth` | `Number/Number[]` | The stroke width of the bars when hovered.
@@ -93,11 +93,11 @@ The bar chart defines the following configuration options. These options are mer
| Name | Type | Default | Description
| ---- | ---- | ------- | -----------
-| `barPercentage` | `Number` | `0.9` | Percent (0-1) of the available width each bar should be within the category percentage. 1.0 will take the whole category width and put the bars right next to each other. [more...](#bar-chart-barpercentage-vs-categorypercentage)
-| `categoryPercentage` | `Number` | `0.8` | Percent (0-1) of the available width (the space between the gridlines for small datasets) for each data-point to use for the bars. [more...](#bar-chart-barpercentage-vs-categorypercentage)
+| `barPercentage` | `Number` | `0.9` | Percent (0-1) of the available width each bar should be within the category percentage. 1.0 will take the whole category width and put the bars right next to each other. [more...](#barpercentage-vs-categorypercentage)
+| `categoryPercentage` | `Number` | `0.8` | Percent (0-1) of the available width (the space between the gridlines for small datasets) for each data-point to use for the bars. [more...](#barpercentage-vs-categorypercentage)
| `barThickness` | `Number` | | Manually set width of each bar in pixels. If not set, the bars are sized automatically using `barPercentage` and `categoryPercentage`;
| `maxBarThickness` | `Number` | | Set this to ensure that the automatically sized bars are not sized thicker than this. Only works if barThickness is not set (automatic sizing is enabled).
-| `gridLines.offsetGridLines` | `Boolean` | `true` | If true, the bars for a particular data point fall between the grid lines. If false, the grid line will go right down the middle of the bars. [more...](#offsetGridLines)
+| `gridLines.offsetGridLines` | `Boolean` | `true` | If true, the bars for a particular data point fall between the grid lines. If false, the grid line will go right down the middle of the bars. [more...](#offsetgridlines)
### offsetGridLines
If true, the bars for a particular data point fall between the grid lines. If false, the grid line will go right down the middle of the bars. It is unlikely that this will ever need to be changed in practice. It exists more as a way to reuse the axis code by configuring the existing axis slightly differently.
@@ -235,6 +235,6 @@ var myBarChart = new Chart(ctx, {
```
## Config Options
-The configuration options for the horizontal bar chart are the same as for the [bar chart](../bar/config-options.md#config-options). However, any options specified on the x axis in a bar chart, are applied to the y axis in a horizontal bar chart.
+The configuration options for the horizontal bar chart are the same as for the [bar chart](#configuration-options). However, any options specified on the x axis in a bar chart, are applied to the y axis in a horizontal bar chart.
-The default horizontal bar configuration is specified in `Chart.defaults.horizontalBar`.
\ No newline at end of file
+The default horizontal bar configuration is specified in `Chart.defaults.horizontalBar`. | true |
Other | chartjs | Chart.js | f16d8a32e2641bae8483a5194b7ddb1ec56ab5fa.json | Fix links in documentations (#4477)
* Fix relative links in documentation of configurations
* Fix relative link of 'Time Units'
* Fix relative links for chart types documentations
* Fix the release version link in developers/plugins | docs/charts/bubble.md | @@ -53,7 +53,7 @@ All properties, except `label` can be specified as an array. If these are set to
## Config Options
-The bubble chart has no unique configuration options. To configure options common to all of the bubbles, the [point element options](../configuration/elements/point.md#point-configuration) are used.
+The bubble chart has no unique configuration options. To configure options common to all of the bubbles, the [point element options](../configuration/elements.md#point-configuration) are used.
## Default Options
@@ -78,4 +78,4 @@ Data for the bubble chart is passed in the form of an object. The object must im
// Radius of bubble. This is not scaled.
r: <Number>
}
-```
\ No newline at end of file
+``` | true |
Other | chartjs | Chart.js | f16d8a32e2641bae8483a5194b7ddb1ec56ab5fa.json | Fix links in documentations (#4477)
* Fix relative links in documentation of configurations
* Fix relative link of 'Time Units'
* Fix relative links for chart types documentations
* Fix the release version link in developers/plugins | docs/charts/line.md | @@ -55,14 +55,14 @@ All point* properties can be specified as an array. If these are set to an array
| `borderDashOffset` | `Number` | Offset for line dashes. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineDashOffset)
| `borderCapStyle` | `String` | Cap style of the line. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineCap)
| `borderJoinStyle` | `String` | Line joint style. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineJoin)
-| `cubicInterpolationMode` | `String` | Algorithm used to interpolate a smooth curve from the discrete data points. [more...](#cubicInterpolationMode)
+| `cubicInterpolationMode` | `String` | Algorithm used to interpolate a smooth curve from the discrete data points. [more...](#cubicinterpolationmode)
| `fill` | `Boolean/String` | How to fill the area under the line. See [area charts](area.md)
| `lineTension` | `Number` | Bezier curve tension of the line. Set to 0 to draw straightlines. This option is ignored if monotone cubic interpolation is used.
| `pointBackgroundColor` | `Color/Color[]` | The fill color for points.
| `pointBorderColor` | `Color/Color[]` | The border color for points.
| `pointBorderWidth` | `Number/Number[]` | The width of the point border in pixels.
| `pointRadius` | `Number/Number[]` | The radius of the point shape. If set to 0, the point is not rendered.
-| `pointStyle` | `String/String[]/Image/Image[]` | Style of the point. [more...](#pointStyle)
+| `pointStyle` | `String/String[]/Image/Image[]` | Style of the point. [more...](#pointstyle)
| `pointHitRadius` | `Number/Number[]` | The pixel size of the non-displayed point that reacts to mouse events.
| `pointHoverBackgroundColor` | `Color/Color[]` | Point background color when hovered.
| `pointHoverBorderColor` | `Color/Color[]` | Point border color when hovered. | true |
Other | chartjs | Chart.js | f16d8a32e2641bae8483a5194b7ddb1ec56ab5fa.json | Fix links in documentations (#4477)
* Fix relative links in documentation of configurations
* Fix relative link of 'Time Units'
* Fix relative links for chart types documentations
* Fix the release version link in developers/plugins | docs/charts/polar.md | @@ -56,7 +56,7 @@ The following options can be included in a polar area chart dataset to configure
## Config Options
-These are the customisation options specific to Polar Area charts. These options are merged with the [global chart configuration options](#global-chart-configuration), and form the options of the chart.
+These are the customisation options specific to Polar Area charts. These options are merged with the [global chart default options](#default-options), and form the options of the chart.
| Name | Type | Default | Description
| ---- | ---- | ------- | -----------
@@ -92,4 +92,4 @@ data = {
'Blue'
]
};
-```
\ No newline at end of file
+``` | true |
Other | chartjs | Chart.js | f16d8a32e2641bae8483a5194b7ddb1ec56ab5fa.json | Fix links in documentations (#4477)
* Fix relative links in documentation of configurations
* Fix relative link of 'Time Units'
* Fix relative links for chart types documentations
* Fix the release version link in developers/plugins | docs/charts/radar.md | @@ -82,7 +82,7 @@ All point* properties can be specified as an array. If these are set to an array
| `pointBorderColor` | `Color/Color[]` | The border color for points.
| `pointBorderWidth` | `Number/Number[]` | The width of the point border in pixels.
| `pointRadius` | `Number/Number[]` | The radius of the point shape. If set to 0, the point is not rendered.
-| `pointStyle` | `String/String[]/Image/Image[]` | Style of the point. [more...](#pointStyle)
+| `pointStyle` | `String/String[]/Image/Image[]` | Style of the point. [more...](#pointstyle)
| `pointHitRadius` | `Number/Number[]` | The pixel size of the non-displayed point that reacts to mouse events.
| `pointHoverBackgroundColor` | `Color/Color[]` | Point background color when hovered.
| `pointHoverBorderColor` | `Color/Color[]` | Point border color when hovered. | true |
Other | chartjs | Chart.js | f16d8a32e2641bae8483a5194b7ddb1ec56ab5fa.json | Fix links in documentations (#4477)
* Fix relative links in documentation of configurations
* Fix relative link of 'Time Units'
* Fix relative links for chart types documentations
* Fix the release version link in developers/plugins | docs/configuration/legend.md | @@ -34,8 +34,8 @@ The legend label configuration is nested below the legend configuration using th
| `fontColor` | Color | `'#666'` | Color of text
| `fontFamily` | `String` | `"'Helvetica Neue', 'Helvetica', 'Arial', sans-serif"` | Font family of legend text.
| `padding` | `Number` | `10` | Padding between rows of colored boxes.
-| `generateLabels` | `Function` | | Generates legend items for each thing in the legend. Default implementation returns the text + styling for the color box. See [Legend Item](#chart-configuration-legend-item-interface) for details.
-| `filter` | `Function` | `null` | Filters legend items out of the legend. Receives 2 parameters, a [Legend Item](#chart-configuration-legend-item-interface) and the chart data.
+| `generateLabels` | `Function` | | Generates legend items for each thing in the legend. Default implementation returns the text + styling for the color box. See [Legend Item](#legend-item-interface) for details.
+| `filter` | `Function` | `null` | Filters legend items out of the legend. Receives 2 parameters, a [Legend Item](#legend-item-interface) and the chart data.
| `usePointStyle` | `Boolean` | `false` | Label style will match corresponding point style (size is based on fontSize, boxWidth is not used in this case).
## Legend Item Interface
@@ -163,4 +163,4 @@ var chart = new Chart(ctx, {
}
}
});
-```
\ No newline at end of file
+``` | true |
Other | chartjs | Chart.js | f16d8a32e2641bae8483a5194b7ddb1ec56ab5fa.json | Fix links in documentations (#4477)
* Fix relative links in documentation of configurations
* Fix relative link of 'Time Units'
* Fix relative links for chart types documentations
* Fix the release version link in developers/plugins | docs/configuration/tooltip.md | @@ -7,7 +7,7 @@ The tooltip configuration is passed into the `options.tooltips` namespace. The g
| Name | Type | Default | Description
| -----| ---- | --------| -----------
| `enabled` | `Boolean` | `true` | Are tooltips enabled
-| `custom` | `Function` | `null` | See [custom tooltip](#custom-tooltips) section.
+| `custom` | `Function` | `null` | See [custom tooltip](#external-custom-tooltips) section.
| `mode` | `String` | `'nearest'` | Sets which elements appear in the tooltip. [more...](../general/interactions/modes.md#interaction-modes).
| `intersect` | `Boolean` | `true` | if true, the tooltip mode applies only when the mouse position intersects with an element. If false, the mode will be applied at all times.
| `position` | `String` | `'average'` | The mode for positioning the tooltip. [more...](#position-modes)
@@ -53,17 +53,17 @@ New modes can be defined by adding functions to the Chart.Tooltip.positioners ma
### Sort Callback
-Allows sorting of [tooltip items](#chart-configuration-tooltip-item-interface). Must implement at minimum a function that can be passed to [Array.prototype.sort](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort). This function can also accept a third parameter that is the data object passed to the chart.
+Allows sorting of [tooltip items](#tooltip-item-interface). Must implement at minimum a function that can be passed to [Array.prototype.sort](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort). This function can also accept a third parameter that is the data object passed to the chart.
### Filter Callback
-Allows filtering of [tooltip items](#chart-configuration-tooltip-item-interface). Must implement at minimum a function that can be passed to [Array.prototype.filter](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/filter). This function can also accept a second parameter that is the data object passed to the chart.
+Allows filtering of [tooltip items](#tooltip-item-interface). Must implement at minimum a function that can be passed to [Array.prototype.filter](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/filter). This function can also accept a second parameter that is the data object passed to the chart.
## Tooltip Callbacks
The tooltip label configuration is nested below the tooltip configuration using the `callbacks` key. The tooltip has the following callbacks for providing text. For all functions, 'this' will be the tooltip object created from the Chart.Tooltip constructor.
-All functions are called with the same arguments: a [tooltip item](#chart-configuration-tooltip-item-interface) and the data object passed to the chart. All functions must return either a string or an array of strings. Arrays of strings are treated as multiple lines of text.
+All functions are called with the same arguments: a [tooltip item](#tooltip-item-interface) and the data object passed to the chart. All functions must return either a string or an array of strings. Arrays of strings are treated as multiple lines of text.
| Name | Arguments | Description
| ---- | --------- | ----------- | true |
Other | chartjs | Chart.js | f16d8a32e2641bae8483a5194b7ddb1ec56ab5fa.json | Fix links in documentations (#4477)
* Fix relative links in documentation of configurations
* Fix relative link of 'Time Units'
* Fix relative links for chart types documentations
* Fix the release version link in developers/plugins | docs/developers/plugins.md | @@ -1,6 +1,6 @@
# Plugins
-Plugins are the most efficient way to customize or change the default behavior of a chart. They have been introduced at [version 2.1.0](https://github.com/chartjs/Chart.js/releases/tag/2.1.0) (global plugins only) and extended at [version 2.5.0](https://github.com/chartjs/Chart.js/releases/tag/2.5.0) (per chart plugins and options).
+Plugins are the most efficient way to customize or change the default behavior of a chart. They have been introduced at [version 2.1.0](https://github.com/chartjs/Chart.js/releases/tag/2.1.0) (global plugins only) and extended at [version 2.5.0](https://github.com/chartjs/Chart.js/releases/tag/v2.5.0) (per chart plugins and options).
## Using plugins
| true |
Other | chartjs | Chart.js | 463a8dd77899cde1a2c542c6c90d0c7614285f16.json | Simplify formulas based on code review | src/helpers/helpers.easing.js | @@ -131,9 +131,9 @@ var effects = {
return 1;
}
if (!p) {
- p = 1 * 0.3;
+ p = 0.3;
}
- if (a < Math.abs(1)) {
+ if (a < 1) {
a = 1;
s = p / 4;
} else {
@@ -153,9 +153,9 @@ var effects = {
return 1;
}
if (!p) {
- p = 1 * 0.3;
+ p = 0.3;
}
- if (a < Math.abs(1)) {
+ if (a < 1) {
a = 1;
s = p / 4;
} else {
@@ -175,9 +175,9 @@ var effects = {
return 1;
}
if (!p) {
- p = 0.3 * 1.5;
+ p = 0.45;
}
- if (a < Math.abs(1)) {
+ if (a < 1) {
a = 1;
s = p / 4;
} else { | false |
Other | chartjs | Chart.js | 56050dc9b7a17130efdbdcd3b8de46b728f25b84.json | Move easing effects in separate file + unit tests | src/chart.js | @@ -4,6 +4,7 @@
var Chart = require('./core/core')();
require('./helpers/helpers.core')(Chart);
+require('./helpers/helpers.easing')(Chart);
require('./core/core.helpers')(Chart);
require('./helpers/helpers.time')(Chart);
require('./helpers/helpers.canvas')(Chart); | true |
Other | chartjs | Chart.js | 56050dc9b7a17130efdbdcd3b8de46b728f25b84.json | Move easing effects in separate file + unit tests | src/core/core.controller.js | @@ -484,7 +484,7 @@ module.exports = function(Chart) {
easing: config.easing || animationOptions.easing,
render: function(chart, animationObject) {
- var easingFunction = helpers.easingEffects[animationObject.easing];
+ var easingFunction = helpers.easing.effects[animationObject.easing];
var currentStep = animationObject.currentStep;
var stepDecimal = currentStep / animationObject.numSteps;
| true |
Other | chartjs | Chart.js | 56050dc9b7a17130efdbdcd3b8de46b728f25b84.json | Move easing effects in separate file + unit tests | src/core/core.helpers.js | @@ -388,203 +388,6 @@ module.exports = function(Chart) {
return niceFraction * Math.pow(10, exponent);
};
- // Easing functions adapted from Robert Penner's easing equations
- // http://www.robertpenner.com/easing/
- var easingEffects = helpers.easingEffects = {
- linear: function(t) {
- return t;
- },
- easeInQuad: function(t) {
- return t * t;
- },
- easeOutQuad: function(t) {
- return -1 * t * (t - 2);
- },
- easeInOutQuad: function(t) {
- if ((t /= 1 / 2) < 1) {
- return 1 / 2 * t * t;
- }
- return -1 / 2 * ((--t) * (t - 2) - 1);
- },
- easeInCubic: function(t) {
- return t * t * t;
- },
- easeOutCubic: function(t) {
- return 1 * ((t = t / 1 - 1) * t * t + 1);
- },
- easeInOutCubic: function(t) {
- if ((t /= 1 / 2) < 1) {
- return 1 / 2 * t * t * t;
- }
- return 1 / 2 * ((t -= 2) * t * t + 2);
- },
- easeInQuart: function(t) {
- return t * t * t * t;
- },
- easeOutQuart: function(t) {
- return -1 * ((t = t / 1 - 1) * t * t * t - 1);
- },
- easeInOutQuart: function(t) {
- if ((t /= 1 / 2) < 1) {
- return 1 / 2 * t * t * t * t;
- }
- return -1 / 2 * ((t -= 2) * t * t * t - 2);
- },
- easeInQuint: function(t) {
- return 1 * (t /= 1) * t * t * t * t;
- },
- easeOutQuint: function(t) {
- return 1 * ((t = t / 1 - 1) * t * t * t * t + 1);
- },
- easeInOutQuint: function(t) {
- if ((t /= 1 / 2) < 1) {
- return 1 / 2 * t * t * t * t * t;
- }
- return 1 / 2 * ((t -= 2) * t * t * t * t + 2);
- },
- easeInSine: function(t) {
- return -1 * Math.cos(t / 1 * (Math.PI / 2)) + 1;
- },
- easeOutSine: function(t) {
- return 1 * Math.sin(t / 1 * (Math.PI / 2));
- },
- easeInOutSine: function(t) {
- return -1 / 2 * (Math.cos(Math.PI * t / 1) - 1);
- },
- easeInExpo: function(t) {
- return (t === 0) ? 1 : 1 * Math.pow(2, 10 * (t / 1 - 1));
- },
- easeOutExpo: function(t) {
- return (t === 1) ? 1 : 1 * (-Math.pow(2, -10 * t / 1) + 1);
- },
- easeInOutExpo: function(t) {
- if (t === 0) {
- return 0;
- }
- if (t === 1) {
- return 1;
- }
- if ((t /= 1 / 2) < 1) {
- return 1 / 2 * Math.pow(2, 10 * (t - 1));
- }
- return 1 / 2 * (-Math.pow(2, -10 * --t) + 2);
- },
- easeInCirc: function(t) {
- if (t >= 1) {
- return t;
- }
- return -1 * (Math.sqrt(1 - (t /= 1) * t) - 1);
- },
- easeOutCirc: function(t) {
- return 1 * Math.sqrt(1 - (t = t / 1 - 1) * t);
- },
- easeInOutCirc: function(t) {
- if ((t /= 1 / 2) < 1) {
- return -1 / 2 * (Math.sqrt(1 - t * t) - 1);
- }
- return 1 / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1);
- },
- easeInElastic: function(t) {
- var s = 1.70158;
- var p = 0;
- var a = 1;
- if (t === 0) {
- return 0;
- }
- if ((t /= 1) === 1) {
- return 1;
- }
- if (!p) {
- p = 1 * 0.3;
- }
- if (a < Math.abs(1)) {
- a = 1;
- s = p / 4;
- } else {
- s = p / (2 * Math.PI) * Math.asin(1 / a);
- }
- return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * 1 - s) * (2 * Math.PI) / p));
- },
- easeOutElastic: function(t) {
- var s = 1.70158;
- var p = 0;
- var a = 1;
- if (t === 0) {
- return 0;
- }
- if ((t /= 1) === 1) {
- return 1;
- }
- if (!p) {
- p = 1 * 0.3;
- }
- if (a < Math.abs(1)) {
- a = 1;
- s = p / 4;
- } else {
- s = p / (2 * Math.PI) * Math.asin(1 / a);
- }
- return a * Math.pow(2, -10 * t) * Math.sin((t * 1 - s) * (2 * Math.PI) / p) + 1;
- },
- easeInOutElastic: function(t) {
- var s = 1.70158;
- var p = 0;
- var a = 1;
- if (t === 0) {
- return 0;
- }
- if ((t /= 1 / 2) === 2) {
- return 1;
- }
- if (!p) {
- p = 1 * (0.3 * 1.5);
- }
- if (a < Math.abs(1)) {
- a = 1;
- s = p / 4;
- } else {
- s = p / (2 * Math.PI) * Math.asin(1 / a);
- }
- if (t < 1) {
- return -0.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * 1 - s) * (2 * Math.PI) / p));
- }
- return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * 1 - s) * (2 * Math.PI) / p) * 0.5 + 1;
- },
- easeInBack: function(t) {
- var s = 1.70158;
- return 1 * (t /= 1) * t * ((s + 1) * t - s);
- },
- easeOutBack: function(t) {
- var s = 1.70158;
- return 1 * ((t = t / 1 - 1) * t * ((s + 1) * t + s) + 1);
- },
- easeInOutBack: function(t) {
- var s = 1.70158;
- if ((t /= 1 / 2) < 1) {
- return 1 / 2 * (t * t * (((s *= (1.525)) + 1) * t - s));
- }
- return 1 / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2);
- },
- easeInBounce: function(t) {
- return 1 - easingEffects.easeOutBounce(1 - t);
- },
- easeOutBounce: function(t) {
- if ((t /= 1) < (1 / 2.75)) {
- return 1 * (7.5625 * t * t);
- } else if (t < (2 / 2.75)) {
- return 1 * (7.5625 * (t -= (1.5 / 2.75)) * t + 0.75);
- } else if (t < (2.5 / 2.75)) {
- return 1 * (7.5625 * (t -= (2.25 / 2.75)) * t + 0.9375);
- }
- return 1 * (7.5625 * (t -= (2.625 / 2.75)) * t + 0.984375);
- },
- easeInOutBounce: function(t) {
- if (t < 1 / 2) {
- return easingEffects.easeInBounce(t * 2) * 0.5;
- }
- return easingEffects.easeOutBounce(t * 2 - 1) * 0.5 + 1 * 0.5;
- }
- };
// Request animation polyfill - http://www.paulirish.com/2011/requestanimationframe-for-smart-animating/
helpers.requestAnimFrame = (function() {
if (typeof window === 'undefined') { | true |
Other | chartjs | Chart.js | 56050dc9b7a17130efdbdcd3b8de46b728f25b84.json | Move easing effects in separate file + unit tests | src/helpers/helpers.easing.js | @@ -0,0 +1,252 @@
+'use strict';
+
+/**
+ * Easing functions adapted from Robert Penner's easing equations.
+ * http://www.robertpenner.com/easing/
+ */
+var effects = {
+ linear: function(t) {
+ return t;
+ },
+
+ easeInQuad: function(t) {
+ return t * t;
+ },
+
+ easeOutQuad: function(t) {
+ return -t * (t - 2);
+ },
+
+ easeInOutQuad: function(t) {
+ if ((t /= 0.5) < 1) {
+ return 0.5 * t * t;
+ }
+ return -0.5 * ((--t) * (t - 2) - 1);
+ },
+
+ easeInCubic: function(t) {
+ return t * t * t;
+ },
+
+ easeOutCubic: function(t) {
+ return (t = t - 1) * t * t + 1;
+ },
+
+ easeInOutCubic: function(t) {
+ if ((t /= 0.5) < 1) {
+ return 0.5 * t * t * t;
+ }
+ return 0.5 * ((t -= 2) * t * t + 2);
+ },
+
+ easeInQuart: function(t) {
+ return t * t * t * t;
+ },
+
+ easeOutQuart: function(t) {
+ return -((t = t - 1) * t * t * t - 1);
+ },
+
+ easeInOutQuart: function(t) {
+ if ((t /= 0.5) < 1) {
+ return 0.5 * t * t * t * t;
+ }
+ return -0.5 * ((t -= 2) * t * t * t - 2);
+ },
+
+ easeInQuint: function(t) {
+ return t * t * t * t * t;
+ },
+
+ easeOutQuint: function(t) {
+ return (t = t - 1) * t * t * t * t + 1;
+ },
+
+ easeInOutQuint: function(t) {
+ if ((t /= 0.5) < 1) {
+ return 0.5 * t * t * t * t * t;
+ }
+ return 0.5 * ((t -= 2) * t * t * t * t + 2);
+ },
+
+ easeInSine: function(t) {
+ return -Math.cos(t * (Math.PI / 2)) + 1;
+ },
+
+ easeOutSine: function(t) {
+ return Math.sin(t * (Math.PI / 2));
+ },
+
+ easeInOutSine: function(t) {
+ return -0.5 * (Math.cos(Math.PI * t) - 1);
+ },
+
+ easeInExpo: function(t) {
+ return (t === 0) ? 0 : Math.pow(2, 10 * (t - 1));
+ },
+
+ easeOutExpo: function(t) {
+ return (t === 1) ? 1 : -Math.pow(2, -10 * t) + 1;
+ },
+
+ easeInOutExpo: function(t) {
+ if (t === 0) {
+ return 0;
+ }
+ if (t === 1) {
+ return 1;
+ }
+ if ((t /= 0.5) < 1) {
+ return 0.5 * Math.pow(2, 10 * (t - 1));
+ }
+ return 0.5 * (-Math.pow(2, -10 * --t) + 2);
+ },
+
+ easeInCirc: function(t) {
+ if (t >= 1) {
+ return t;
+ }
+ return -(Math.sqrt(1 - t * t) - 1);
+ },
+
+ easeOutCirc: function(t) {
+ return Math.sqrt(1 - (t = t - 1) * t);
+ },
+
+ easeInOutCirc: function(t) {
+ if ((t /= 0.5) < 1) {
+ return -0.5 * (Math.sqrt(1 - t * t) - 1);
+ }
+ return 0.5 * (Math.sqrt(1 - (t -= 2) * t) + 1);
+ },
+
+ easeInElastic: function(t) {
+ var s = 1.70158;
+ var p = 0;
+ var a = 1;
+ if (t === 0) {
+ return 0;
+ }
+ if (t === 1) {
+ return 1;
+ }
+ if (!p) {
+ p = 1 * 0.3;
+ }
+ if (a < Math.abs(1)) {
+ a = 1;
+ s = p / 4;
+ } else {
+ s = p / (2 * Math.PI) * Math.asin(1 / a);
+ }
+ return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t - s) * (2 * Math.PI) / p));
+ },
+
+ easeOutElastic: function(t) {
+ var s = 1.70158;
+ var p = 0;
+ var a = 1;
+ if (t === 0) {
+ return 0;
+ }
+ if (t === 1) {
+ return 1;
+ }
+ if (!p) {
+ p = 1 * 0.3;
+ }
+ if (a < Math.abs(1)) {
+ a = 1;
+ s = p / 4;
+ } else {
+ s = p / (2 * Math.PI) * Math.asin(1 / a);
+ }
+ return a * Math.pow(2, -10 * t) * Math.sin((t - s) * (2 * Math.PI) / p) + 1;
+ },
+
+ easeInOutElastic: function(t) {
+ var s = 1.70158;
+ var p = 0;
+ var a = 1;
+ if (t === 0) {
+ return 0;
+ }
+ if ((t /= 0.5) === 2) {
+ return 1;
+ }
+ if (!p) {
+ p = 0.3 * 1.5;
+ }
+ if (a < Math.abs(1)) {
+ a = 1;
+ s = p / 4;
+ } else {
+ s = p / (2 * Math.PI) * Math.asin(1 / a);
+ }
+ if (t < 1) {
+ return -0.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t - s) * (2 * Math.PI) / p));
+ }
+ return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t - s) * (2 * Math.PI) / p) * 0.5 + 1;
+ },
+ easeInBack: function(t) {
+ var s = 1.70158;
+ return t * t * ((s + 1) * t - s);
+ },
+
+ easeOutBack: function(t) {
+ var s = 1.70158;
+ return (t = t - 1) * t * ((s + 1) * t + s) + 1;
+ },
+
+ easeInOutBack: function(t) {
+ var s = 1.70158;
+ if ((t /= 0.5) < 1) {
+ return 0.5 * (t * t * (((s *= (1.525)) + 1) * t - s));
+ }
+ return 0.5 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2);
+ },
+
+ easeInBounce: function(t) {
+ return 1 - effects.easeOutBounce(1 - t);
+ },
+
+ easeOutBounce: function(t) {
+ if (t < (1 / 2.75)) {
+ return 7.5625 * t * t;
+ }
+ if (t < (2 / 2.75)) {
+ return 7.5625 * (t -= (1.5 / 2.75)) * t + 0.75;
+ }
+ if (t < (2.5 / 2.75)) {
+ return 7.5625 * (t -= (2.25 / 2.75)) * t + 0.9375;
+ }
+ return 7.5625 * (t -= (2.625 / 2.75)) * t + 0.984375;
+ },
+
+ easeInOutBounce: function(t) {
+ if (t < 0.5) {
+ return effects.easeInBounce(t * 2) * 0.5;
+ }
+ return effects.easeOutBounce(t * 2 - 1) * 0.5 + 0.5;
+ }
+};
+
+module.exports = function(Chart) {
+ /**
+ * @namespace Chart.helpers.easing.effects
+ */
+ Chart.helpers.easing = {
+ effects: effects
+ };
+
+ /**
+ * 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
+ */
+ Chart.helpers.easingEffects = effects;
+
+ return Chart.helpers.easing;
+}; | true |
Other | chartjs | Chart.js | 56050dc9b7a17130efdbdcd3b8de46b728f25b84.json | Move easing effects in separate file + unit tests | test/specs/global.deprecations.tests.js | @@ -84,6 +84,13 @@ describe('Deprecations', function() {
});
});
+ 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(Chart.helpers.drawRoundedRectangle).toBeDefined(); | true |
Other | chartjs | Chart.js | 56050dc9b7a17130efdbdcd3b8de46b728f25b84.json | Move easing effects in separate file + unit tests | test/specs/helpers.easing.tests.js | @@ -0,0 +1,61 @@
+'use strict';
+
+describe('Chart.helpers.easing', function() {
+ var easing = Chart.helpers.easing;
+
+ describe('effects', function() {
+ var expected = {
+ easeInOutBack: [-0, -0.03751855, -0.09255566, -0.07883348, 0.08992579, 0.5, 0.91007421, 1.07883348, 1.09255566, 1.03751855, 1],
+ easeInOutBounce: [0, 0.03, 0.11375, 0.045, 0.34875, 0.5, 0.65125, 0.955, 0.88625, 0.97, 1],
+ easeInOutCirc: [-0, 0.01010205, 0.04174243, 0.1, 0.2, 0.5, 0.8, 0.9, 0.95825757, 0.98989795, 1],
+ easeInOutCubic: [0, 0.004, 0.032, 0.108, 0.256, 0.5, 0.744, 0.892, 0.968, 0.996, 1],
+ easeInOutElastic: [0, 0.00033916, -0.00390625, 0.02393889, -0.11746158, 0.5, 1.11746158, 0.97606111, 1.00390625, 0.99966084, 1],
+ easeInOutExpo: [0, 0.00195313, 0.0078125, 0.03125, 0.125, 0.5, 0.875, 0.96875, 0.9921875, 0.99804688, 1],
+ easeInOutQuad: [0, 0.02, 0.08, 0.18, 0.32, 0.5, 0.68, 0.82, 0.92, 0.98, 1],
+ easeInOutQuart: [0, 0.0008, 0.0128, 0.0648, 0.2048, 0.5, 0.7952, 0.9352, 0.9872, 0.9992, 1],
+ easeInOutQuint: [0, 0.00016, 0.00512, 0.03888, 0.16384, 0.5, 0.83616, 0.96112, 0.99488, 0.99984, 1],
+ easeInOutSine: [-0, 0.02447174, 0.0954915, 0.20610737, 0.3454915, 0.5, 0.6545085, 0.79389263, 0.9045085, 0.97552826, 1],
+ easeInBack: [-0, -0.01431422, -0.04645056, -0.08019954, -0.09935168, -0.0876975, -0.02902752, 0.09286774, 0.29419776, 0.59117202, 1],
+ easeInBounce: [0, 0.011875, 0.06, 0.069375, 0.2275, 0.234375, 0.09, 0.319375, 0.6975, 0.924375, 1],
+ easeInCirc: [-0, 0.00501256, 0.0202041, 0.0460608, 0.08348486, 0.1339746, 0.2, 0.28585716, 0.4, 0.56411011, 1],
+ easeInCubic: [0, 0.001, 0.008, 0.027, 0.064, 0.125, 0.216, 0.343, 0.512, 0.729, 1],
+ easeInExpo: [0, 0.00195313, 0.00390625, 0.0078125, 0.015625, 0.03125, 0.0625, 0.125, 0.25, 0.5, 1],
+ easeInElastic: [0, 0.00195313, -0.00195313, -0.00390625, 0.015625, -0.015625, -0.03125, 0.125, -0.125, -0.25, 1],
+ easeInQuad: [0, 0.01, 0.04, 0.09, 0.16, 0.25, 0.36, 0.49, 0.64, 0.81, 1],
+ easeInQuart: [0, 0.0001, 0.0016, 0.0081, 0.0256, 0.0625, 0.1296, 0.2401, 0.4096, 0.6561, 1],
+ easeInQuint: [0, 0.00001, 0.00032, 0.00243, 0.01024, 0.03125, 0.07776, 0.16807, 0.32768, 0.59049, 1],
+ easeInSine: [0, 0.01231166, 0.04894348, 0.10899348, 0.19098301, 0.29289322, 0.41221475, 0.5460095, 0.69098301, 0.84356553, 1],
+ easeOutBack: [0, 0.40882798, 0.70580224, 0.90713226, 1.02902752, 1.0876975, 1.09935168, 1.08019954, 1.04645056, 1.01431422, 1],
+ easeOutBounce: [0, 0.075625, 0.3025, 0.680625, 0.91, 0.765625, 0.7725, 0.930625, 0.94, 0.988125, 1],
+ easeOutCirc: [0, 0.43588989, 0.6, 0.71414284, 0.8, 0.8660254, 0.91651514, 0.9539392, 0.9797959, 0.99498744, 1],
+ easeOutElastic: [0, 1.25, 1.125, 0.875, 1.03125, 1.015625, 0.984375, 1.00390625, 1.00195313, 0.99804688, 1],
+ easeOutExpo: [0, 0.5, 0.75, 0.875, 0.9375, 0.96875, 0.984375, 0.9921875, 0.99609375, 0.99804688, 1],
+ easeOutCubic: [0, 0.271, 0.488, 0.657, 0.784, 0.875, 0.936, 0.973, 0.992, 0.999, 1],
+ easeOutQuad: [0, 0.19, 0.36, 0.51, 0.64, 0.75, 0.84, 0.91, 0.96, 0.99, 1],
+ easeOutQuart: [-0, 0.3439, 0.5904, 0.7599, 0.8704, 0.9375, 0.9744, 0.9919, 0.9984, 0.9999, 1],
+ easeOutQuint: [0, 0.40951, 0.67232, 0.83193, 0.92224, 0.96875, 0.98976, 0.99757, 0.99968, 0.99999, 1],
+ easeOutSine: [0, 0.15643447, 0.30901699, 0.4539905, 0.58778525, 0.70710678, 0.80901699, 0.89100652, 0.95105652, 0.98768834, 1],
+ linear: [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1]
+ };
+
+ function generate(method) {
+ var fn = easing.effects[method];
+ var accuracy = Math.pow(10, 8);
+ var count = 10;
+ var values = [];
+ var i;
+
+ for (i=0; i<=count; ++i) {
+ values.push(Math.round(accuracy * fn(i/count)) / accuracy);
+ }
+
+ return values;
+ }
+
+ Object.keys(easing.effects).forEach(function(method) {
+ it ('"' + method + '" should return expected values', function() {
+ expect(generate(method)).toEqual(expected[method]);
+ });
+ });
+ });
+}); | true |
Other | chartjs | Chart.js | 7d60857819eaab2c16aea4ac7eb527a6ce8df844.json | Use proper reverse option in radial linear scale | src/scales/scale.radialLinear.js | @@ -244,7 +244,7 @@ module.exports = function(Chart) {
ctx.lineWidth = angleLineOpts.lineWidth;
ctx.strokeStyle = angleLineOpts.color;
- var outerDistance = scale.getDistanceFromCenterForValue(opts.reverse ? scale.min : scale.max);
+ var outerDistance = scale.getDistanceFromCenterForValue(opts.ticks.reverse ? scale.min : scale.max);
// Point Label Font
var plFont = getPointLabelFontOptions(scale);
@@ -366,6 +366,7 @@ module.exports = function(Chart) {
},
convertTicksToLabels: function() {
var me = this;
+
Chart.LinearScaleBase.prototype.convertTicksToLabels.call(me);
// Point labels
@@ -433,7 +434,7 @@ module.exports = function(Chart) {
// Take into account half font size + the yPadding of the top value
var scalingFactor = me.drawingArea / (me.max - me.min);
- if (me.options.reverse) {
+ if (me.options.ticks.reverse) {
return (me.max - value) * scalingFactor;
}
return (value - me.min) * scalingFactor;
@@ -480,7 +481,7 @@ module.exports = function(Chart) {
helpers.each(me.ticks, function(label, index) {
// Don't draw a centre value (if it is minimum)
- if (index > 0 || opts.reverse) {
+ if (index > 0 || tickOpts.reverse) {
var yCenterOffset = me.getDistanceFromCenterForValue(me.ticksAsNumbers[index]);
var yHeight = me.yCenter - yCenterOffset;
| true |
Other | chartjs | Chart.js | 7d60857819eaab2c16aea4ac7eb527a6ce8df844.json | Use proper reverse option in radial linear scale | test/specs/scale.radialLinear.tests.js | @@ -401,7 +401,7 @@ describe('Test the radial linear scale', function() {
y: 275,
});
- chart.scale.options.reverse = true;
+ chart.scale.options.ticks.reverse = true;
chart.update();
expect(chart.scale.getDistanceFromCenterForValue(chart.scale.min)).toBe(233); | true |
Other | chartjs | Chart.js | cc9e88aebcbef79f60b560213227792d4324871c.json | Support an array for line chart pointBorderWidth | src/controllers/controller.line.js | @@ -137,7 +137,7 @@ module.exports = function(Chart) {
if (!isNaN(custom.borderWidth)) {
borderWidth = custom.borderWidth;
- } else if (!isNaN(dataset.pointBorderWidth)) {
+ } else if (!isNaN(dataset.pointBorderWidth) || helpers.isArray(dataset.pointBorderWidth)) {
borderWidth = helpers.valueAtIndexOrDefault(dataset.pointBorderWidth, index, borderWidth);
} else if (!isNaN(dataset.borderWidth)) {
borderWidth = dataset.borderWidth; | true |
Other | chartjs | Chart.js | cc9e88aebcbef79f60b560213227792d4324871c.json | Support an array for line chart pointBorderWidth | test/specs/controller.line.tests.js | @@ -730,4 +730,24 @@ describe('Line controller tests', function() {
expect(point._model.borderWidth).toBe(0);
});
+
+ it('should allow an array as the point border width setting', function() {
+ var chart = window.acquireChart({
+ type: 'line',
+ data: {
+ datasets: [{
+ data: [10, 15, 0, -4],
+ label: 'dataset1',
+ pointBorderWidth: [1, 2, 3, 4]
+ }],
+ labels: ['label1', 'label2', 'label3', 'label4']
+ }
+ });
+
+ var meta = chart.getDatasetMeta(0);
+ expect(meta.data[0]._model.borderWidth).toBe(1);
+ expect(meta.data[1]._model.borderWidth).toBe(2);
+ expect(meta.data[2]._model.borderWidth).toBe(3);
+ expect(meta.data[3]._model.borderWidth).toBe(4);
+ });
}); | true |
Other | chartjs | Chart.js | 225bfd36f3daae2cfd0e2869658144ee6bfd988b.json | Rewrite the clone and merge helpers (#4422)
The `clone` method now accepts any type of input but also recursively perform a deep copy of the array items. Rewrite the `configMerge` and `scaleMerge` helpers which now rely on a new generic and customizable `merge` method, that one accepts a target object in which multiple sources are deep copied. Note that the target (first argument) is not cloned and will be modified after calling `merge(target, sources)`. Add a `mergeIf` helper which merge the source properties only if they do not exist in the target object. | src/core/core.helpers.js | @@ -8,19 +8,7 @@ module.exports = function(Chart) {
var helpers = Chart.helpers;
// -- Basic js utility methods
- helpers.clone = function(obj) {
- var objClone = {};
- helpers.each(obj, function(value, key) {
- if (helpers.isArray(value)) {
- objClone[key] = value.slice(0);
- } else if (typeof value === 'object' && value !== null) {
- objClone[key] = helpers.clone(value);
- } else {
- objClone[key] = value;
- }
- });
- return objClone;
- };
+
helpers.extend = function(base) {
var setFn = function(value, key) {
base[key] = value;
@@ -30,75 +18,60 @@ module.exports = function(Chart) {
}
return base;
};
- // Need a special merge function to chart configs since they are now grouped
- helpers.configMerge = function(_base) {
- var base = helpers.clone(_base);
- helpers.each(Array.prototype.slice.call(arguments, 1), function(extension) {
- helpers.each(extension, function(value, key) {
- var baseHasProperty = base.hasOwnProperty(key);
- var baseVal = baseHasProperty ? base[key] : {};
+
+ helpers.configMerge = function(/* objects ... */) {
+ return helpers.merge(helpers.clone(arguments[0]), [].slice.call(arguments, 1), {
+ merger: function(key, target, source, options) {
+ var tval = target[key] || {};
+ var sval = source[key];
if (key === 'scales') {
- // Scale config merging is complex. Add our own function here for that
- base[key] = helpers.scaleMerge(baseVal, value);
+ // scale config merging is complex. Add our own function here for that
+ target[key] = helpers.scaleMerge(tval, sval);
} else if (key === 'scale') {
- // Used in polar area & radar charts since there is only one scale
- base[key] = helpers.configMerge(baseVal, Chart.scaleService.getScaleDefaults(value.type), value);
- } else if (baseHasProperty
- && typeof baseVal === 'object'
- && !helpers.isArray(baseVal)
- && baseVal !== null
- && typeof value === 'object'
- && !helpers.isArray(value)) {
- // If we are overwriting an object with an object, do a merge of the properties.
- base[key] = helpers.configMerge(baseVal, value);
+ // used in polar area & radar charts since there is only one scale
+ target[key] = helpers.merge(tval, [Chart.scaleService.getScaleDefaults(sval.type), sval]);
} else {
- // can just overwrite the value in this case
- base[key] = value;
+ helpers._merger(key, target, source, options);
}
- });
+ }
});
-
- return base;
};
- helpers.scaleMerge = function(_base, extension) {
- var base = helpers.clone(_base);
-
- helpers.each(extension, function(value, key) {
- if (key === 'xAxes' || key === 'yAxes') {
- // These properties are arrays of items
- if (base.hasOwnProperty(key)) {
- helpers.each(value, function(valueObj, index) {
- var axisType = helpers.valueOrDefault(valueObj.type, key === 'xAxes' ? 'category' : 'linear');
- var axisDefaults = Chart.scaleService.getScaleDefaults(axisType);
- if (index >= base[key].length || !base[key][index].type) {
- base[key].push(helpers.configMerge(axisDefaults, valueObj));
- } else if (valueObj.type && valueObj.type !== base[key][index].type) {
- // Type changed. Bring in the new defaults before we bring in valueObj so that valueObj can override the correct scale defaults
- base[key][index] = helpers.configMerge(base[key][index], axisDefaults, valueObj);
+
+ helpers.scaleMerge = function(/* objects ... */) {
+ return helpers.merge(helpers.clone(arguments[0]), [].slice.call(arguments, 1), {
+ merger: function(key, target, source, options) {
+ if (key === 'xAxes' || key === 'yAxes') {
+ var slen = source[key].length;
+ var i, type, scale, defaults;
+
+ if (!target[key]) {
+ target[key] = [];
+ }
+
+ for (i = 0; i < slen; ++i) {
+ scale = source[key][i];
+ type = helpers.valueOrDefault(scale.type, key === 'xAxes'? 'category' : 'linear');
+ defaults = Chart.scaleService.getScaleDefaults(type);
+
+ if (i >= target[key].length) {
+ target[key].push({});
+ }
+
+ if (!target[key][i].type || (scale.type && scale.type !== target[key][i].type)) {
+ // new/untyped scale or type changed: let's apply the new defaults
+ // then merge source scale to correctly overwrite the defaults.
+ helpers.merge(target[key][i], [defaults, scale]);
} else {
- // Type is the same
- base[key][index] = helpers.configMerge(base[key][index], valueObj);
+ // scales type are the same
+ helpers.merge(target[key][i], scale);
}
- });
+ }
} else {
- base[key] = [];
- helpers.each(value, function(valueObj) {
- var axisType = helpers.valueOrDefault(valueObj.type, key === 'xAxes' ? 'category' : 'linear');
- base[key].push(helpers.configMerge(Chart.scaleService.getScaleDefaults(axisType), valueObj));
- });
+ helpers._merger(key, target, source, options);
}
- } else if (base.hasOwnProperty(key) && typeof base[key] === 'object' && base[key] !== null && typeof value === 'object') {
- // If we are overwriting an object with an object, do a merge of the properties.
- base[key] = helpers.configMerge(base[key], value);
-
- } else {
- // can just overwrite the value in this case
- base[key] = value;
}
});
-
- return base;
};
helpers.where = function(collection, filterCallback) { | true |
Other | chartjs | Chart.js | 225bfd36f3daae2cfd0e2869658144ee6bfd988b.json | Rewrite the clone and merge helpers (#4422)
The `clone` method now accepts any type of input but also recursively perform a deep copy of the array items. Rewrite the `configMerge` and `scaleMerge` helpers which now rely on a new generic and customizable `merge` method, that one accepts a target object in which multiple sources are deep copied. Note that the target (first argument) is not cloned and will be modified after calling `merge(target, sources)`. Add a `mergeIf` helper which merge the source properties only if they do not exist in the target object. | src/core/core.scaleService.js | @@ -22,7 +22,7 @@ module.exports = function(Chart) {
},
getScaleDefaults: function(type) {
// Return the scale defaults merged with the global settings so that we always use the latest ones
- return this.defaults.hasOwnProperty(type) ? helpers.scaleMerge(Chart.defaults.scale, this.defaults[type]) : {};
+ return this.defaults.hasOwnProperty(type) ? helpers.merge({}, [Chart.defaults.scale, this.defaults[type]]) : {};
},
updateScaleDefaults: function(type, additions) {
var defaults = this.defaults; | true |
Other | chartjs | Chart.js | 225bfd36f3daae2cfd0e2869658144ee6bfd988b.json | Rewrite the clone and merge helpers (#4422)
The `clone` method now accepts any type of input but also recursively perform a deep copy of the array items. Rewrite the `configMerge` and `scaleMerge` helpers which now rely on a new generic and customizable `merge` method, that one accepts a target object in which multiple sources are deep copied. Note that the target (first argument) is not cloned and will be modified after calling `merge(target, sources)`. Add a `mergeIf` helper which merge the source properties only if they do not exist in the target object. | src/helpers/helpers.core.js | @@ -147,6 +147,110 @@ module.exports = function(Chart) {
}
return true;
+ },
+
+ /**
+ * Returns a deep copy of `source` without keeping references on objects and arrays.
+ * @param {*} source - The value to clone.
+ * @returns {*}
+ */
+ clone: function(source) {
+ if (helpers.isArray(source)) {
+ return source.map(helpers.clone);
+ }
+
+ if (helpers.isObject(source)) {
+ var target = {};
+ var keys = Object.keys(source);
+ var klen = keys.length;
+ var k = 0;
+
+ for (; k<klen; ++k) {
+ target[keys[k]] = helpers.clone(source[keys[k]]);
+ }
+
+ return target;
+ }
+
+ return source;
+ },
+
+ /**
+ * The default merger when Chart.helpers.merge is called without merger option.
+ * Note(SB): this method is also used by configMerge and scaleMerge as fallback.
+ * @private
+ */
+ _merger: function(key, target, source, options) {
+ var tval = target[key];
+ var sval = source[key];
+
+ if (helpers.isObject(tval) && helpers.isObject(sval)) {
+ helpers.merge(tval, sval, options);
+ } else {
+ target[key] = helpers.clone(sval);
+ }
+ },
+
+ /**
+ * Merges source[key] in target[key] only if target[key] is undefined.
+ * @private
+ */
+ _mergerIf: function(key, target, source) {
+ var tval = target[key];
+ var sval = source[key];
+
+ if (helpers.isObject(tval) && helpers.isObject(sval)) {
+ helpers.mergeIf(tval, sval);
+ } else if (!target.hasOwnProperty(key)) {
+ target[key] = helpers.clone(sval);
+ }
+ },
+
+ /**
+ * Recursively deep copies `source` properties into `target` with the given `options`.
+ * IMPORTANT: `target` is not cloned and will be updated with `source` properties.
+ * @param {Object} target - The target object in which all sources are merged into.
+ * @param {Object|Array(Object)} source - Object(s) to merge into `target`.
+ * @param {Object} [options] - Merging options:
+ * @param {Function} [options.merger] - The merge method (key, target, source, options)
+ * @returns {Object} The `target` object.
+ */
+ merge: function(target, source, options) {
+ var sources = helpers.isArray(source)? source : [source];
+ var ilen = sources.length;
+ var merge, i, keys, klen, k;
+
+ if (!helpers.isObject(target)) {
+ return target;
+ }
+
+ options = options || {};
+ merge = options.merger || helpers._merger;
+
+ for (i=0; i<ilen; ++i) {
+ source = sources[i];
+ if (!helpers.isObject(source)) {
+ continue;
+ }
+
+ keys = Object.keys(source);
+ for (k=0, klen = keys.length; k<klen; ++k) {
+ merge(keys[k], target, source, options);
+ }
+ }
+
+ return target;
+ },
+
+ /**
+ * Recursively deep copies `source` properties into `target` *only* if not defined in target.
+ * IMPORTANT: `target` is not cloned and will be updated with `source` properties.
+ * @param {Object} target - The target object in which all sources are merged into.
+ * @param {Object|Array(Object)} source - Object(s) to merge into `target`.
+ * @returns {Object} The `target` object.
+ */
+ mergeIf: function(target, source) {
+ return helpers.merge(target, source, {merger: helpers._mergerIf});
}
};
| true |
Other | chartjs | Chart.js | 225bfd36f3daae2cfd0e2869658144ee6bfd988b.json | Rewrite the clone and merge helpers (#4422)
The `clone` method now accepts any type of input but also recursively perform a deep copy of the array items. Rewrite the `configMerge` and `scaleMerge` helpers which now rely on a new generic and customizable `merge` method, that one accepts a target object in which multiple sources are deep copied. Note that the target (first argument) is not cloned and will be modified after calling `merge(target, sources)`. Add a `mergeIf` helper which merge the source properties only if they do not exist in the target object. | src/plugins/plugin.legend.js | @@ -524,7 +524,7 @@ module.exports = function(Chart) {
var legend = chart.legend;
if (legendOpts) {
- legendOpts = helpers.configMerge(Chart.defaults.global.legend, legendOpts);
+ helpers.mergeIf(legendOpts, Chart.defaults.global.legend);
if (legend) {
layout.configure(chart, legend, legendOpts); | true |
Other | chartjs | Chart.js | 225bfd36f3daae2cfd0e2869658144ee6bfd988b.json | Rewrite the clone and merge helpers (#4422)
The `clone` method now accepts any type of input but also recursively perform a deep copy of the array items. Rewrite the `configMerge` and `scaleMerge` helpers which now rely on a new generic and customizable `merge` method, that one accepts a target object in which multiple sources are deep copied. Note that the target (first argument) is not cloned and will be modified after calling `merge(target, sources)`. Add a `mergeIf` helper which merge the source properties only if they do not exist in the target object. | src/plugins/plugin.title.js | @@ -224,7 +224,7 @@ module.exports = function(Chart) {
var titleBlock = chart.titleBlock;
if (titleOpts) {
- titleOpts = helpers.configMerge(Chart.defaults.global.title, titleOpts);
+ helpers.mergeIf(titleOpts, Chart.defaults.global.title);
if (titleBlock) {
layout.configure(chart, titleBlock, titleOpts); | true |
Other | chartjs | Chart.js | 225bfd36f3daae2cfd0e2869658144ee6bfd988b.json | Rewrite the clone and merge helpers (#4422)
The `clone` method now accepts any type of input but also recursively perform a deep copy of the array items. Rewrite the `configMerge` and `scaleMerge` helpers which now rely on a new generic and customizable `merge` method, that one accepts a target object in which multiple sources are deep copied. Note that the target (first argument) is not cloned and will be modified after calling `merge(target, sources)`. Add a `mergeIf` helper which merge the source properties only if they do not exist in the target object. | test/specs/core.helpers.tests.js | @@ -6,25 +6,6 @@ describe('Core helper tests', function() {
helpers = window.Chart.helpers;
});
- it('should clone an object', function() {
- var testData = {
- myProp1: 'abc',
- myProp2: ['a', 'b'],
- myProp3: {
- myProp4: 5,
- myProp5: [1, 2]
- }
- };
-
- var clone = helpers.clone(testData);
- expect(clone).toEqual(testData);
- expect(clone).not.toBe(testData);
-
- expect(clone.myProp2).not.toBe(testData.myProp2);
- expect(clone.myProp3).not.toBe(testData.myProp3);
- expect(clone.myProp3.myProp5).not.toBe(testData.myProp3.myProp5);
- });
-
it('should extend an object', function() {
var original = {
myProp1: 'abc', | true |
Other | chartjs | Chart.js | 225bfd36f3daae2cfd0e2869658144ee6bfd988b.json | Rewrite the clone and merge helpers (#4422)
The `clone` method now accepts any type of input but also recursively perform a deep copy of the array items. Rewrite the `configMerge` and `scaleMerge` helpers which now rely on a new generic and customizable `merge` method, that one accepts a target object in which multiple sources are deep copied. Note that the target (first argument) is not cloned and will be modified after calling `merge(target, sources)`. Add a `mergeIf` helper which merge the source properties only if they do not exist in the target object. | test/specs/helpers.core.tests.js | @@ -236,4 +236,137 @@ describe('Chart.helpers.core', function() {
expect(helpers.arrayEquals([o0, o1, o2], [o0, o1, o2])).toBeTruthy();
});
});
+
+ describe('clone', function() {
+ it('should clone primitive values', function() {
+ expect(helpers.clone()).toBe(undefined);
+ expect(helpers.clone(null)).toBe(null);
+ expect(helpers.clone(true)).toBe(true);
+ expect(helpers.clone(42)).toBe(42);
+ expect(helpers.clone('foo')).toBe('foo');
+ });
+ it('should perform a deep copy of arrays', function() {
+ var o0 = {a: 42};
+ var o1 = {s: 's'};
+ var a0 = ['bar'];
+ var a1 = [a0, o0, 2];
+ var f0 = function() {};
+ var input = [a1, o1, f0, 42, 'foo'];
+ var output = helpers.clone(input);
+
+ expect(output).toEqual(input);
+ expect(output).not.toBe(input);
+ expect(output[0]).not.toBe(a1);
+ expect(output[0][0]).not.toBe(a0);
+ expect(output[1]).not.toBe(o1);
+ });
+ it('should perform a deep copy of objects', function() {
+ var a0 = ['bar'];
+ var a1 = [1, 2, 3];
+ var o0 = {a: a1, i: 42};
+ var f0 = function() {};
+ var input = {o: o0, a: a0, f: f0, s: 'foo', i: 42};
+ var output = helpers.clone(input);
+
+ expect(output).toEqual(input);
+ expect(output).not.toBe(input);
+ expect(output.o).not.toBe(o0);
+ expect(output.o.a).not.toBe(a1);
+ expect(output.a).not.toBe(a0);
+ });
+ });
+
+ describe('merge', function() {
+ it('should update target and return it', function() {
+ var target = {a: 1};
+ var result = helpers.merge(target, {a: 2, b: 'foo'});
+ expect(target).toEqual({a: 2, b: 'foo'});
+ expect(target).toBe(result);
+ });
+ it('should return target if not an object', function() {
+ expect(helpers.merge(undefined, {a: 42})).toEqual(undefined);
+ expect(helpers.merge(null, {a: 42})).toEqual(null);
+ expect(helpers.merge('foo', {a: 42})).toEqual('foo');
+ expect(helpers.merge(['foo', 'bar'], {a: 42})).toEqual(['foo', 'bar']);
+ });
+ it('should ignore sources which are not objects', function() {
+ expect(helpers.merge({a: 42})).toEqual({a: 42});
+ expect(helpers.merge({a: 42}, null)).toEqual({a: 42});
+ expect(helpers.merge({a: 42}, 42)).toEqual({a: 42});
+ });
+ it('should recursively overwrite target with source properties', function() {
+ expect(helpers.merge({a: {b: 1}}, {a: {c: 2}})).toEqual({a: {b: 1, c: 2}});
+ expect(helpers.merge({a: {b: 1}}, {a: {b: 2}})).toEqual({a: {b: 2}});
+ expect(helpers.merge({a: [1, 2]}, {a: [3, 4]})).toEqual({a: [3, 4]});
+ expect(helpers.merge({a: 42}, {a: {b: 0}})).toEqual({a: {b: 0}});
+ expect(helpers.merge({a: 42}, {a: null})).toEqual({a: null});
+ expect(helpers.merge({a: 42}, {a: undefined})).toEqual({a: undefined});
+ });
+ it('should merge multiple sources in the correct order', function() {
+ var t0 = {a: {b: 1, c: [1, 2]}};
+ var s0 = {a: {d: 3}, e: {f: 4}};
+ var s1 = {a: {b: 5}};
+ var s2 = {a: {c: [6, 7]}, e: 'foo'};
+
+ expect(helpers.merge(t0, [s0, s1, s2])).toEqual({a: {b: 5, c: [6, 7], d: 3}, e: 'foo'});
+ });
+ it('should deep copy merged values from sources', function() {
+ var a0 = ['foo'];
+ var a1 = [1, 2, 3];
+ var o0 = {a: a1, i: 42};
+ var output = helpers.merge({}, {a: a0, o: o0});
+
+ expect(output).toEqual({a: a0, o: o0});
+ expect(output.a).not.toBe(a0);
+ expect(output.o).not.toBe(o0);
+ expect(output.o.a).not.toBe(a1);
+ });
+ });
+
+ describe('mergeIf', function() {
+ it('should update target and return it', function() {
+ var target = {a: 1};
+ var result = helpers.mergeIf(target, {a: 2, b: 'foo'});
+ expect(target).toEqual({a: 1, b: 'foo'});
+ expect(target).toBe(result);
+ });
+ it('should return target if not an object', function() {
+ expect(helpers.mergeIf(undefined, {a: 42})).toEqual(undefined);
+ expect(helpers.mergeIf(null, {a: 42})).toEqual(null);
+ expect(helpers.mergeIf('foo', {a: 42})).toEqual('foo');
+ expect(helpers.mergeIf(['foo', 'bar'], {a: 42})).toEqual(['foo', 'bar']);
+ });
+ it('should ignore sources which are not objects', function() {
+ expect(helpers.mergeIf({a: 42})).toEqual({a: 42});
+ expect(helpers.mergeIf({a: 42}, null)).toEqual({a: 42});
+ expect(helpers.mergeIf({a: 42}, 42)).toEqual({a: 42});
+ });
+ it('should recursively copy source properties in target only if they do not exist in target', function() {
+ expect(helpers.mergeIf({a: {b: 1}}, {a: {c: 2}})).toEqual({a: {b: 1, c: 2}});
+ expect(helpers.mergeIf({a: {b: 1}}, {a: {b: 2}})).toEqual({a: {b: 1}});
+ expect(helpers.mergeIf({a: [1, 2]}, {a: [3, 4]})).toEqual({a: [1, 2]});
+ expect(helpers.mergeIf({a: 0}, {a: {b: 2}})).toEqual({a: 0});
+ expect(helpers.mergeIf({a: null}, {a: 42})).toEqual({a: null});
+ expect(helpers.mergeIf({a: undefined}, {a: 42})).toEqual({a: undefined});
+ });
+ it('should merge multiple sources in the correct order', function() {
+ var t0 = {a: {b: 1, c: [1, 2]}};
+ var s0 = {a: {d: 3}, e: {f: 4}};
+ var s1 = {a: {b: 5}};
+ var s2 = {a: {c: [6, 7]}, e: 'foo'};
+
+ expect(helpers.mergeIf(t0, [s0, s1, s2])).toEqual({a: {b: 1, c: [1, 2], d: 3}, e: {f: 4}});
+ });
+ it('should deep copy merged values from sources', function() {
+ var a0 = ['foo'];
+ var a1 = [1, 2, 3];
+ var o0 = {a: a1, i: 42};
+ var output = helpers.mergeIf({}, {a: a0, o: o0});
+
+ expect(output).toEqual({a: a0, o: o0});
+ expect(output.a).not.toBe(a0);
+ expect(output.o).not.toBe(o0);
+ expect(output.o.a).not.toBe(a1);
+ });
+ });
}); | true |
Other | chartjs | Chart.js | 6f317135a3b87b6ff62660adccd1ee063240d46f.json | Clamp radius when drawing rounded rectangle (#4448) | src/helpers/helpers.canvas.js | @@ -24,20 +24,22 @@ module.exports = function(Chart) {
* @param {Number} width - The rectangle's width.
* @param {Number} height - The rectangle's height.
* @param {Number} radius - The rounded amount (in pixels) for the four corners.
- * @todo handler `radius` as top-left, top-right, bottom-right, bottom-left array/object?
- * @todo clamp `radius` to the maximum "correct" value.
+ * @todo handle `radius` as top-left, top-right, bottom-right, bottom-left array/object?
*/
roundedRect: function(ctx, x, y, width, height, radius) {
if (radius) {
- ctx.moveTo(x + radius, y);
- ctx.lineTo(x + width - radius, y);
- ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
- ctx.lineTo(x + width, y + height - radius);
- ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
- ctx.lineTo(x + radius, y + height);
- ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
- ctx.lineTo(x, y + radius);
- ctx.quadraticCurveTo(x, y, x + radius, y);
+ var rx = Math.min(radius, width/2);
+ var ry = Math.min(radius, height/2);
+
+ ctx.moveTo(x + rx, y);
+ ctx.lineTo(x + width - rx, y);
+ ctx.quadraticCurveTo(x + width, y, x + width, y + ry);
+ ctx.lineTo(x + width, y + height - ry);
+ ctx.quadraticCurveTo(x + width, y + height, x + width - rx, y + height);
+ ctx.lineTo(x + rx, y + height);
+ ctx.quadraticCurveTo(x, y + height, x, y + height - ry);
+ ctx.lineTo(x, y + ry);
+ ctx.quadraticCurveTo(x, y, x + rx, y);
} else {
ctx.rect(x, y, width, height);
} | false |
Other | chartjs | Chart.js | 548edc65ea96ac51ab17bde2942fd6f319f63e8c.json | Fix non-passive event listener warning in Chrome
Deprecate `addEvent` and `removeEvent`, and move implementation in `platform.dom.js`. Add 'options' feature detection to register event listeners as passive and prevent warning in Chrome. | src/core/core.helpers.js | @@ -666,24 +666,6 @@ module.exports = function(Chart) {
};
};
- helpers.addEvent = function(node, eventType, method) {
- if (node.addEventListener) {
- node.addEventListener(eventType, method);
- } else if (node.attachEvent) {
- node.attachEvent('on' + eventType, method);
- } else {
- node['on' + eventType] = method;
- }
- };
- helpers.removeEvent = function(node, eventType, handler) {
- if (node.removeEventListener) {
- node.removeEventListener(eventType, handler, false);
- } else if (node.detachEvent) {
- node.detachEvent('on' + eventType, handler);
- } else {
- node['on' + eventType] = helpers.noop;
- }
- };
// Private helper function to convert max-width/max-height values that may be percentages into a number
function parseMaxStyle(styleValue, node, parentProperty) { | true |
Other | chartjs | Chart.js | 548edc65ea96ac51ab17bde2942fd6f319f63e8c.json | Fix non-passive event listener warning in Chrome
Deprecate `addEvent` and `removeEvent`, and move implementation in `platform.dom.js`. Add 'options' feature detection to register event listeners as passive and prevent warning in Chrome. | src/platforms/platform.dom.js | @@ -92,6 +92,38 @@ module.exports = function(Chart) {
return canvas;
}
+ /**
+ * Detects support for options object argument in addEventListener.
+ * https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Safely_detecting_option_support
+ * @private
+ */
+ var supportsEventListenerOptions = (function() {
+ var supports = false;
+ try {
+ var options = Object.defineProperty({}, 'passive', {
+ get: function() {
+ supports = true;
+ }
+ });
+ window.addEventListener('e', null, options);
+ } catch (e) {
+ // continue regardless of error
+ }
+ return supports;
+ }());
+
+ // Default passive to true as expected by Chrome for 'touchstart' and 'touchend' events.
+ // https://github.com/chartjs/Chart.js/issues/4287
+ var eventListenerOptions = supportsEventListenerOptions? {passive: true} : false;
+
+ function addEventListener(node, type, listener) {
+ node.addEventListener(type, listener, eventListenerOptions);
+ }
+
+ function removeEventListener(node, type, listener) {
+ node.removeEventListener(type, listener, eventListenerOptions);
+ }
+
function createEvent(type, chart, x, y, nativeEvent) {
return {
type: type,
@@ -137,8 +169,8 @@ module.exports = function(Chart) {
// If the iframe is re-attached to the DOM, the resize listener is removed because the
// content is reloaded, so make sure to install the handler after the iframe is loaded.
// https://github.com/chartjs/Chart.js/issues/3521
- helpers.addEvent(iframe, 'load', function() {
- helpers.addEvent(iframe.contentWindow || iframe, 'resize', handler);
+ addEventListener(iframe, 'load', function() {
+ addEventListener(iframe.contentWindow || iframe, 'resize', handler);
// The iframe size might have changed while loading, which can also
// happen if the size has been changed while detached from the DOM.
@@ -186,6 +218,28 @@ module.exports = function(Chart) {
delete node._chartjs;
}
+ /**
+ * 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 = addEventListener;
+
+ /**
+ * 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 = removeEventListener;
+
return {
acquireContext: function(item, config) {
if (typeof item === 'string') {
@@ -263,7 +317,7 @@ module.exports = function(Chart) {
listener(fromNativeEvent(event, chart));
};
- helpers.addEvent(canvas, type, proxy);
+ addEventListener(canvas, type, proxy);
},
removeEventListener: function(chart, type, listener) {
@@ -281,7 +335,7 @@ module.exports = function(Chart) {
return;
}
- helpers.removeEvent(canvas, type, proxy);
+ removeEventListener(canvas, type, proxy);
}
};
}; | true |
Other | chartjs | Chart.js | 548edc65ea96ac51ab17bde2942fd6f319f63e8c.json | Fix non-passive event listener warning in Chrome
Deprecate `addEvent` and `removeEvent`, and move implementation in `platform.dom.js`. Add 'options' feature detection to register event listeners as passive and prevent warning in Chrome. | test/specs/global.deprecations.tests.js | @@ -101,6 +101,33 @@ describe('Deprecations', function() {
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(Chart.helpers.addEvent).toBeDefined();
+ 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(Chart.helpers.removeEvent).toBeDefined();
+ 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() { | true |
Other | chartjs | Chart.js | 961911065fe7ee6febb734ab91abd290086ab6ae.json | Fix arguments in plugin interface description
* Fixed arguments in IPlugin#before/afterDatasetUpdate description
* Fixed arguments in IPlugin#before/afterDatasetDraw description | src/core/core.plugin.js | @@ -215,8 +215,8 @@ module.exports = function(Chart) {
* returns `false`, the datasets update is cancelled until another `update` is triggered.
* @param {Chart} chart - The chart instance.
* @param {Object} args - The call arguments.
- * @param {Object} args.index - The dataset index.
- * @param {Number} args.meta - The dataset metadata.
+ * @param {Number} args.index - The dataset index.
+ * @param {Object} args.meta - The dataset metadata.
* @param {Object} options - The plugin options.
* @returns {Boolean} `false` to cancel the chart datasets drawing.
*/
@@ -226,8 +226,8 @@ module.exports = function(Chart) {
* that this hook will not be called if the datasets update has been previously cancelled.
* @param {Chart} chart - The chart instance.
* @param {Object} args - The call arguments.
- * @param {Object} args.index - The dataset index.
- * @param {Number} args.meta - The dataset metadata.
+ * @param {Number} args.index - The dataset index.
+ * @param {Object} args.meta - The dataset metadata.
* @param {Object} options - The plugin options.
*/
/**
@@ -302,8 +302,8 @@ module.exports = function(Chart) {
* is cancelled until another `render` is triggered.
* @param {Chart} chart - The chart instance.
* @param {Object} args - The call arguments.
- * @param {Object} args.index - The dataset index.
- * @param {Number} args.meta - The dataset metadata.
+ * @param {Number} args.index - The dataset index.
+ * @param {Object} args.meta - The dataset metadata.
* @param {Number} args.easingValue - The current animation value, between 0.0 and 1.0.
* @param {Object} options - The plugin options.
* @returns {Boolean} `false` to cancel the chart datasets drawing.
@@ -315,8 +315,8 @@ module.exports = function(Chart) {
* if the datasets drawing has been previously cancelled.
* @param {Chart} chart - The chart instance.
* @param {Object} args - The call arguments.
- * @param {Object} args.index - The dataset index.
- * @param {Number} args.meta - The dataset metadata.
+ * @param {Number} args.index - The dataset index.
+ * @param {Object} args.meta - The dataset metadata.
* @param {Number} args.easingValue - The current animation value, between 0.0 and 1.0.
* @param {Object} options - The plugin options.
*/ | false |
Other | chartjs | Chart.js | 7a02d93db4025387adfbc91fb2bc5e250f0a0672.json | Add note regarding non-existant fonts | docs/general/fonts.md | @@ -26,3 +26,7 @@ let chart = new Chart(ctx, {
| `defaultFontFamily` | `String` | `"'Helvetica Neue', 'Helvetica', 'Arial', sans-serif"` | Default font family for all text.
| `defaultFontSize` | `Number` | `12` | Default font size (in px) for text. Does not apply to radialLinear scale point labels.
| `defaultFontStyle` | `String` | `'normal'` | Default font style. Does not apply to tooltip title or footer. Does not apply to chart title.
+
+## Non-Existant Fonts
+
+If a font is specified for a chart that does exist on the system, the browser will not apply the font when it is set. If you notice odd fonts appearing in your charts, check that the font you are applying exists on your system. See [issue 3318](https://github.com/chartjs/Chart.js/issues/3318) for more details. | false |
Other | chartjs | Chart.js | 009ae4dec6db9d8b94a77cad3dffbf907e720ad4.json | Support hover animation duration during updates (#4300)
See discussion in the issue for context and possible approaches.
When invoking update() inside an event handler, such as onHover,
`options.hover.animationDuration` was not being respected. Given that
some use cases may require additional animation properties for the
manual update call, this commit changes that method signature to accept
a configuration object.
This object provides backwards compatibility with duration and lazy
properties, and also introduces the easing property so that the event
animation is different from the global one.
Add tests that guarantee that when update is called manually with
arguments, it properly builds the _bufferedRequest or calls render with
the proper arguments.
It includes test cases for when update is called with legacy arguments
(duration and lazy) instead of the config object.
.update() documentation was previously updated but .render() was left
out. Since the backwards compatible change was also made to render(),
this commit adds documentation for it. | docs/developers/api.md | @@ -17,7 +17,7 @@ This must be called before the canvas is reused for a new chart.
myLineChart.destroy();
```
-## .update(duration, lazy)
+## .update(config)
Triggers an update of the chart. This can be safely called after updating the data object. This will update all scales, legends, and then re-render the chart.
@@ -30,6 +30,21 @@ myLineChart.update(); // Calling update now animates the position of March from
> **Note:** replacing the data reference (e.g. `myLineChart.data = {datasets: [...]}` only works starting **version 2.6**. Prior that, replacing the entire data object could be achieved with the following workaround: `myLineChart.config.data = {datasets: [...]}`.
+A `config` object can be provided with additional configuration for the update process. This is useful when `update` is manually called inside an event handler and some different animation is desired.
+
+The following properties are supported:
+* **duration** (number): Time for the animation of the redraw in milliseconds
+* **lazy** (boolean): If true, the animation can be interrupted by other animations
+* **easing** (string): The animation easing function. See [Animation Easing](../configuration/animations.md) for possible values.
+
+Example:
+```javascript
+myChart.update({
+ duration: 800,
+ easing: 'easeOutBounce'
+})
+```
+
See [Updating Charts](updates.md) for more details.
## .reset()
@@ -40,14 +55,20 @@ Reset the chart to it's state before the initial animation. A new animation can
myLineChart.reset();
```
-## .render(duration, lazy)
+## .render(config)
Triggers a redraw of all chart elements. Note, this does not update elements for new data. Use `.update()` in that case.
+See `.update(config)` for more details on the config object.
+
```javascript
// duration is the time for the animation of the redraw in milliseconds
// lazy is a boolean. if true, the animation can be interrupted by other animations
-myLineChart.render(duration, lazy);
+myLineChart.render({
+ duration: 800,
+ lazy: false,
+ easing: 'easeOutBounce'
+});
```
## .stop() | true |
Other | chartjs | Chart.js | 009ae4dec6db9d8b94a77cad3dffbf907e720ad4.json | Support hover animation duration during updates (#4300)
See discussion in the issue for context and possible approaches.
When invoking update() inside an event handler, such as onHover,
`options.hover.animationDuration` was not being respected. Given that
some use cases may require additional animation properties for the
manual update call, this commit changes that method signature to accept
a configuration object.
This object provides backwards compatibility with duration and lazy
properties, and also introduces the easing property so that the event
animation is different from the global one.
Add tests that guarantee that when update is called manually with
arguments, it properly builds the _bufferedRequest or calls render with
the proper arguments.
It includes test cases for when update is called with legacy arguments
(duration and lazy) instead of the config object.
.update() documentation was previously updated but .render() was left
out. Since the backwards compatible change was also made to render(),
this commit adds documentation for it. | src/core/core.controller.js | @@ -334,9 +334,17 @@ module.exports = function(Chart) {
this.tooltip.initialize();
},
- update: function(animationDuration, lazy) {
+ update: function(config) {
var me = this;
+ if (!config || typeof config !== 'object') {
+ // backwards compatibility
+ config = {
+ duration: config,
+ lazy: arguments[1]
+ };
+ }
+
updateConfig(me);
if (plugins.notify(me, 'beforeUpdate') === false) {
@@ -368,11 +376,12 @@ module.exports = function(Chart) {
if (me._bufferedRender) {
me._bufferedRequest = {
- lazy: lazy,
- duration: animationDuration
+ duration: config.duration,
+ easing: config.easing,
+ lazy: config.lazy
};
} else {
- me.render(animationDuration, lazy);
+ me.render(config);
}
},
@@ -442,9 +451,20 @@ module.exports = function(Chart) {
plugins.notify(me, 'afterDatasetUpdate', [args]);
},
- render: function(duration, lazy) {
+ render: function(config) {
var me = this;
+ if (!config || typeof config !== 'object') {
+ // backwards compatibility
+ config = {
+ duration: config,
+ lazy: arguments[1]
+ };
+ }
+
+ var duration = config.duration;
+ var lazy = config.lazy;
+
if (plugins.notify(me, 'beforeRender') === false) {
return;
}
@@ -458,7 +478,7 @@ module.exports = function(Chart) {
if (animationOptions && ((typeof duration !== 'undefined' && duration !== 0) || (typeof duration === 'undefined' && animationOptions.duration !== 0))) {
var animation = new Chart.Animation({
numSteps: (duration || animationOptions.duration) / 16.66, // 60 fps
- easing: animationOptions.easing,
+ easing: config.easing || animationOptions.easing,
render: function(chart, animationObject) {
var easingFunction = helpers.easingEffects[animationObject.easing];
@@ -771,7 +791,7 @@ module.exports = function(Chart) {
var bufferedRequest = me._bufferedRequest;
if (bufferedRequest) {
// If we have an update that was triggered, we need to do a normal render
- me.render(bufferedRequest.duration, bufferedRequest.lazy);
+ me.render(bufferedRequest);
} else if (changed && !me.animating) {
// If entering, leaving, or changing elements, animate the change via pivot
me.stop(); | true |
Other | chartjs | Chart.js | 009ae4dec6db9d8b94a77cad3dffbf907e720ad4.json | Support hover animation duration during updates (#4300)
See discussion in the issue for context and possible approaches.
When invoking update() inside an event handler, such as onHover,
`options.hover.animationDuration` was not being respected. Given that
some use cases may require additional animation properties for the
manual update call, this commit changes that method signature to accept
a configuration object.
This object provides backwards compatibility with duration and lazy
properties, and also introduces the easing property so that the event
animation is different from the global one.
Add tests that guarantee that when update is called manually with
arguments, it properly builds the _bufferedRequest or calls render with
the proper arguments.
It includes test cases for when update is called with legacy arguments
(duration and lazy) instead of the config object.
.update() documentation was previously updated but .render() was left
out. Since the backwards compatible change was also made to render(),
this commit adds documentation for it. | test/specs/core.controller.tests.js | @@ -807,4 +807,46 @@ describe('Chart', function() {
]);
});
});
+
+ describe('controller.update', function() {
+ beforeEach(function() {
+ this.chart = acquireChart({
+ type: 'doughnut',
+ options: {
+ animation: {
+ easing: 'linear',
+ duration: 500
+ }
+ }
+ });
+
+ this.addAnimationSpy = spyOn(Chart.animationService, 'addAnimation');
+ });
+
+ it('should add an animation with the default options', function() {
+ this.chart.update();
+
+ expect(this.addAnimationSpy).toHaveBeenCalledWith(
+ this.chart,
+ jasmine.objectContaining({easing: 'linear'}),
+ undefined,
+ undefined
+ );
+ });
+
+ it('should add an animation with the provided options', function() {
+ this.chart.update({
+ duration: 800,
+ easing: 'easeOutBounce',
+ lazy: false,
+ });
+
+ expect(this.addAnimationSpy).toHaveBeenCalledWith(
+ this.chart,
+ jasmine.objectContaining({easing: 'easeOutBounce'}),
+ 800,
+ false
+ );
+ });
+ });
}); | true |
Other | chartjs | Chart.js | 009ae4dec6db9d8b94a77cad3dffbf907e720ad4.json | Support hover animation duration during updates (#4300)
See discussion in the issue for context and possible approaches.
When invoking update() inside an event handler, such as onHover,
`options.hover.animationDuration` was not being respected. Given that
some use cases may require additional animation properties for the
manual update call, this commit changes that method signature to accept
a configuration object.
This object provides backwards compatibility with duration and lazy
properties, and also introduces the easing property so that the event
animation is different from the global one.
Add tests that guarantee that when update is called manually with
arguments, it properly builds the _bufferedRequest or calls render with
the proper arguments.
It includes test cases for when update is called with legacy arguments
(duration and lazy) instead of the config object.
.update() documentation was previously updated but .render() was left
out. Since the backwards compatible change was also made to render(),
this commit adds documentation for it. | test/specs/global.deprecations.tests.js | @@ -1,4 +1,60 @@
describe('Deprecations', function() {
+ describe('Version 2.7.0', function() {
+ describe('Chart.Controller.update(duration, lazy)', function() {
+ beforeEach(function() {
+ this.chart = acquireChart({
+ type: 'doughnut',
+ options: {
+ animation: {
+ easing: 'linear',
+ duration: 500
+ }
+ }
+ });
+
+ this.addAnimationSpy = spyOn(Chart.animationService, 'addAnimation');
+ });
+
+ it('should add an animation with the provided options', function() {
+ this.chart.update(800, false);
+
+ expect(this.addAnimationSpy).toHaveBeenCalledWith(
+ this.chart,
+ jasmine.objectContaining({easing: 'linear'}),
+ 800,
+ false
+ );
+ });
+ });
+
+ describe('Chart.Controller.render(duration, lazy)', function() {
+ beforeEach(function() {
+ this.chart = acquireChart({
+ type: 'doughnut',
+ options: {
+ animation: {
+ easing: 'linear',
+ duration: 500
+ }
+ }
+ });
+
+ this.addAnimationSpy = spyOn(Chart.animationService, 'addAnimation');
+ });
+
+ it('should add an animation with the provided options', function() {
+ this.chart.render(800, true);
+
+ expect(this.addAnimationSpy).toHaveBeenCalledWith(
+ this.chart,
+ jasmine.objectContaining({easing: 'linear'}),
+ 800,
+ true
+ );
+ });
+ });
+ });
+
describe('Version 2.6.0', function() {
// https://github.com/chartjs/Chart.js/issues/2481
describe('Chart.Controller', function() { | true |
Other | chartjs | Chart.js | 9e6a6112a436143d353115e73c974a6f6b2f7713.json | Fix Tiny Typo in Labelling.md | docs/axes/labelling.md | @@ -9,7 +9,7 @@ The scale label configuration is nested under the scale configuration in the `sc
| Name | Type | Default | Description
| -----| ---- | --------| -----------
| `display` | `Boolean` | `false` | If true, display the axis title.
-| `labelString` | `String` | `''` | The text for the title. (i.e. "# of People" or "Respone Choices").
+| `labelString` | `String` | `''` | The text for the title. (i.e. "# of People" or "Response Choices").
| `fontColor` | Color | `'#666'` | Font color for scale title.
| `fontFamily` | `String` | `"'Helvetica Neue', 'Helvetica', 'Arial', sans-serif"` | Font family for the scale title, follows CSS font-family options.
| `fontSize` | `Number` | `12` | Font size for scale title.
@@ -39,4 +39,4 @@ var chart = new Chart(ctx, {
}
}
});
-```
\ No newline at end of file
+``` | false |
Other | chartjs | Chart.js | 7423c48eb7af78fb05008f49964d9520c0db83a4.json | Fix round option for time scales | src/scales/scale.time.js | @@ -125,7 +125,7 @@ module.exports = function(Chart) {
if (timeOpts.min) {
var minMoment = timeHelpers.parseTime(me, timeOpts.min);
if (timeOpts.round) {
- minMoment.round(timeOpts.round);
+ minMoment.startOf(timeOpts.round);
}
minTimestamp = minMoment.valueOf();
} | false |
Other | chartjs | Chart.js | 7ee8da9c7f5b6d48115c5b4afa30344ce9399e15.json | Fix broken link on animations page #4324 | docs/configuration/animations.md | @@ -93,4 +93,4 @@ var chart = new Chart(ctx, {
});
```
-Another example usage of these callbacks can be found on [Github](https://github.com/chartjs/Chart.js/blob/master/samples/animation/progress-bar.html): this sample displays a progress bar showing how far along the animation is.
+Another example usage of these callbacks can be found on [Github](https://github.com/chartjs/Chart.js/blob/master/samples/advanced/progress-bar.html): this sample displays a progress bar showing how far along the animation is. | false |
Other | chartjs | Chart.js | a9308301e34d3fb39462a8ed24e0fd09c7f388ef.json | Fix vertical alignment of legend labels (#4318)
Ensure that disabled legend style is drawn in the center of the text and that the text is correctly centered in the box. | src/plugins/plugin.legend.js | @@ -320,7 +320,7 @@ module.exports = function(Chart) {
// Canvas setup
ctx.textAlign = 'left';
- ctx.textBaseline = 'top';
+ ctx.textBaseline = 'middle';
ctx.lineWidth = 0.5;
ctx.strokeStyle = fontColor; // for strikethrough effect
ctx.fillStyle = fontColor; // render in correct colour
@@ -372,14 +372,18 @@ module.exports = function(Chart) {
ctx.restore();
};
var fillText = function(x, y, legendItem, textWidth) {
- ctx.fillText(legendItem.text, boxWidth + (fontSize / 2) + x, y);
+ 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(boxWidth + (fontSize / 2) + x, y + (fontSize / 2));
- ctx.lineTo(boxWidth + (fontSize / 2) + x + textWidth, y + (fontSize / 2));
+ ctx.moveTo(xLeft, yMiddle);
+ ctx.lineTo(xLeft + textWidth, yMiddle);
ctx.stroke();
}
}; | false |
Other | chartjs | Chart.js | 55e7b462da1cd8e3fd37eb38c95b3a65ed7d79af.json | Update bower.json to include correct homepage URL | bower.json | @@ -2,7 +2,7 @@
"name": "Chart.js",
"version": "2.1.0",
"description": "Simple HTML5 Charts using the canvas element",
- "homepage": "https://github.com/nnnick/Chart.js",
+ "homepage": "https://github.com/chartjs/Chart.js",
"author": "nnnick",
"license": "MIT",
"main": [ | false |
Other | chartjs | Chart.js | 38373300eef9fe31204e8421cae1263a5f3b94d0.json | Improve time scale for zoom and pan
* Improve time scale for zoom and pan
Improve category scale when zoomed
* Fix CI test | src/scales/scale.category.js | @@ -12,7 +12,7 @@ module.exports = function(Chart) {
// Implement this so that
determineDataLimits: function() {
this.minIndex = 0;
- this.maxIndex = this.chart.data.labels.length;
+ this.maxIndex = this.chart.data.labels.length - 1;
var findIndex;
if (this.options.ticks.min !== undefined) {
@@ -33,7 +33,7 @@ module.exports = function(Chart) {
buildTicks: function(index) {
// If we are viewing some subset of labels, slice the original array
- this.ticks = (this.minIndex === 0 && this.maxIndex === this.chart.data.labels.length) ? this.chart.data.labels : this.chart.data.labels.slice(this.minIndex, this.maxIndex + 1);
+ this.ticks = (this.minIndex === 0 && this.maxIndex === this.chart.data.labels.length - 1) ? this.chart.data.labels : this.chart.data.labels.slice(this.minIndex, this.maxIndex + 1);
},
getLabelForIndex: function(index, datasetIndex) {
@@ -43,7 +43,7 @@ module.exports = function(Chart) {
// Used to get data value locations. Value can either be an index or a numerical value
getPixelForValue: function(value, index, datasetIndex, includeOffset) {
// 1 is added because we need the length but we have the indexes
- var offsetAmt = Math.max((this.ticks.length - ((this.options.gridLines.offsetGridLines) ? 0 : 1)), 1);
+ var offsetAmt = Math.max((this.maxIndex + 1 - this.minIndex - ((this.options.gridLines.offsetGridLines) ? 0 : 1)), 1);
if (this.isHorizontal()) {
var innerWidth = this.width - (this.paddingLeft + this.paddingRight);
@@ -70,8 +70,7 @@ module.exports = function(Chart) {
getPixelForTick: function(index, includeOffset) {
return this.getPixelForValue(this.ticks[index], index + this.minIndex, null, includeOffset);
},
- getValueForPixel: function(pixel)
- {
+ getValueForPixel: function(pixel) {
var value
; var offsetAmt = Math.max((this.ticks.length - ((this.options.gridLines.offsetGridLines) ? 0 : 1)), 1);
var horz = this.isHorizontal(); | true |
Other | chartjs | Chart.js | 38373300eef9fe31204e8421cae1263a5f3b94d0.json | Improve time scale for zoom and pan
* Improve time scale for zoom and pan
Improve category scale when zoomed
* Fix CI test | src/scales/scale.time.js | @@ -208,8 +208,9 @@ module.exports = function(Chart) {
unitDefinition = time.units[unitDefinitionIndex];
this.tickUnit = unitDefinition.name;
- this.leadingUnitBuffer = this.firstTick.diff(this.firstTick.clone().startOf(this.tickUnit), this.tickUnit, true);
- this.scaleSizeInUnits = this.lastTick.diff(this.firstTick, this.tickUnit, true) + (this.leadingUnitBuffer > 0 ? 2 : 0);
+ var leadingUnitBuffer = this.firstTick.diff(this.firstTick.clone().startOf(this.tickUnit), this.tickUnit, true);
+ var trailingUnitBuffer = this.lastTick.clone().add(1, this.tickUnit).startOf(this.tickUnit).diff(this.lastTick, this.tickUnit, true);
+ this.scaleSizeInUnits = this.lastTick.diff(this.firstTick, this.tickUnit, true) + leadingUnitBuffer + trailingUnitBuffer;
this.displayFormat = this.options.time.displayFormats[unitDefinition.name];
}
}
@@ -227,7 +228,11 @@ module.exports = function(Chart) {
// Only round the last tick if we have no hard maximum
if (!this.options.time.max) {
- this.lastTick.endOf(this.tickUnit);
+ var roundedEnd = this.lastTick.clone().startOf(this.tickUnit);
+ if (roundedEnd.diff(this.lastTick, this.tickUnit, true) !== 0) {
+ // Do not use end of because we need this to be in the next time unit
+ this.lastTick.add(1, this.tickUnit).startOf(this.tickUnit);
+ }
}
this.smallestLabelSeparation = this.width;
@@ -247,7 +252,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.scaleSizeInUnits; ++i) {
+ for (var i = 1; i <= this.scaleSizeInUnits; ++i) {
var newTick = roundedStart.clone().add(i, this.tickUnit);
// Are we greater than the max time
@@ -261,18 +266,19 @@ module.exports = function(Chart) {
}
// Always show the right tick
- 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.
+ var diff = this.ticks[this.ticks.length - 1].diff(this.lastTick, this.tickUnit);
+ if (diff !== 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();
+ this.ticks.push(this.lastTick.clone());
+ this.scaleSizeInUnits = this.lastTick.diff(this.firstTick, this.tickUnit, true);
}
}
+
this.ctx.restore();
},
// Get tooltip label
@@ -304,12 +310,12 @@ module.exports = function(Chart) {
this.ticks = this.ticks.map(this.tickFormatFunction, this);
},
getPixelForValue: function(value, index, datasetIndex, includeOffset) {
- var labelMoment = this.getLabelMoment(datasetIndex, index);
+ var labelMoment = value && value.isValid && value.isValid() ? value : this.getLabelMoment(datasetIndex, index);
if (labelMoment) {
var offset = labelMoment.diff(this.firstTick, this.tickUnit, true);
- var decimal = offset / (this.scaleSizeInUnits - (this.leadingUnitBuffer > 0 ? 1 : 0));
+ var decimal = offset / this.scaleSizeInUnits;
if (this.isHorizontal()) {
var innerWidth = this.width - (this.paddingLeft + this.paddingRight);
@@ -329,7 +335,7 @@ module.exports = function(Chart) {
getValueForPixel: function(pixel) {
var innerDimension = this.isHorizontal() ? this.width - (this.paddingLeft + this.paddingRight) : this.height - (this.paddingTop + this.paddingBottom);
var offset = (pixel - (this.isHorizontal() ? this.left + this.paddingLeft : this.top + this.paddingTop)) / innerDimension;
- offset *= (this.scaleSizeInUnits - (this.leadingUnitBuffer > 0 ? 1 : 0));
+ offset *= this.scaleSizeInUnits;
return this.firstTick.clone().add(moment.duration(offset, this.tickUnit).asSeconds(), 'seconds');
},
parseTime: function(label) { | true |
Other | chartjs | Chart.js | 38373300eef9fe31204e8421cae1263a5f3b94d0.json | Improve time scale for zoom and pan
* Improve time scale for zoom and pan
Improve category scale when zoomed
* Fix CI test | test/scale.time.tests.js | @@ -13,7 +13,7 @@ describe('Time scale tests', function() {
var result = false;
var diff = actual.diff(expected.value, expected.unit, true);
- result = Math.abs(diff) < 0.5;
+ result = Math.abs(diff) < (expected.threshold !== undefined ? expected.threshold : 0.5);
return {
pass: result
@@ -118,7 +118,7 @@ describe('Time scale tests', function() {
scale.update(400, 50);
// Counts down because the lines are drawn top to bottom
- expect(scale.ticks).toEqual([ 'Dec 28, 2014', 'Jan 11, 2015' ]);
+ expect(scale.ticks).toEqual([ 'Dec 28, 2014', 'Jan 4, 2015', 'Jan 11, 2015' ]);
});
it('should build ticks using date objects', function() {
@@ -146,7 +146,7 @@ describe('Time scale tests', function() {
scale.update(400, 50);
// Counts down because the lines are drawn top to bottom
- expect(scale.ticks).toEqual([ 'Dec 28, 2014', 'Jan 11, 2015' ]);
+ expect(scale.ticks).toEqual([ 'Dec 28, 2014', 'Jan 4, 2015', 'Jan 11, 2015' ]);
});
it('should build ticks when the data is xy points', function() {
@@ -244,8 +244,8 @@ describe('Time scale tests', function() {
var xScale = chartInstance.scales.xScale0;
// Counts down because the lines are drawn top to bottom
- expect(xScale.ticks[0]).toEqualOneOf(['Nov 19, 1981', 'Nov 20, 1981']); // handle time zone changes
- expect(xScale.ticks[1]).toEqualOneOf(['Nov 19, 1981', 'Nov 20, 1981']); // handle time zone changes
+ expect(xScale.ticks[0]).toEqualOneOf(['Nov 19, 1981', 'Nov 20, 1981', 'Nov 21, 1981']); // handle time zone changes
+ expect(xScale.ticks[1]).toEqualOneOf(['Nov 19, 1981', 'Nov 20, 1981', 'Nov 21, 1981']); // handle time zone changes
});
it('should build ticks using the config unit', function() {
@@ -356,13 +356,14 @@ describe('Time scale tests', function() {
var xScale = chartInstance.scales.xScale0;
expect(xScale.getPixelForValue('', 0, 0)).toBeCloseToPixel(78);
- expect(xScale.getPixelForValue('', 6, 0)).toBeCloseToPixel(466);
+ expect(xScale.getPixelForValue('', 6, 0)).toBeCloseToPixel(452);
expect(xScale.getValueForPixel(78)).toBeCloseToTime({
value: moment(chartInstance.data.labels[0]),
- unit: 'hour'
+ unit: 'hour',
+ threshold: 0.75
});
- expect(xScale.getValueForPixel(466)).toBeCloseToTime({
+ expect(xScale.getValueForPixel(452)).toBeCloseToTime({
value: moment(chartInstance.data.labels[6]),
unit: 'hour'
}); | true |
Other | chartjs | Chart.js | cb54f30c970672488a239a2d371d55dfe3fb8864.json | Implement getValueForPixel for category scale | src/scales/scale.category.js | @@ -69,6 +69,27 @@ module.exports = function(Chart) {
},
getPixelForTick: function(index, includeOffset) {
return this.getPixelForValue(this.ticks[index], index + this.minIndex, null, includeOffset);
+ },
+ getValueForPixel: function(pixel)
+ {
+ var value
+; var offsetAmt = Math.max((this.ticks.length - ((this.options.gridLines.offsetGridLines) ? 0 : 1)), 1);
+ var horz = this.isHorizontal();
+ var innerDimension = horz ? this.width - (this.paddingLeft + this.paddingRight) : this.height - (this.paddingTop + this.paddingBottom);
+ var valueDimension = innerDimension / offsetAmt;
+
+ if (this.options.gridLines.offsetGridLines) {
+ pixel -= (valueDimension / 2);
+ }
+ pixel -= horz ? this.paddingLeft : this.paddingTop;
+
+ if (pixel <= 0) {
+ value = 0;
+ } else {
+ value = Math.round(pixel / valueDimension);
+ }
+
+ return value;
}
});
| true |
Other | chartjs | Chart.js | cb54f30c970672488a239a2d371d55dfe3fb8864.json | Implement getValueForPixel for category scale | test/scale.category.tests.js | @@ -146,17 +146,23 @@ describe('Category scale tests', function() {
expect(scale.getPixelForValue(0, 0, 0, false)).toBe(33);
expect(scale.getPixelForValue(0, 0, 0, true)).toBe(85);
+ expect(scale.getValueForPixel(33)).toBe(0);
+ expect(scale.getValueForPixel(85)).toBe(0);
expect(scale.getPixelForValue(0, 4, 0, false)).toBe(452);
expect(scale.getPixelForValue(0, 4, 0, true)).toBe(505);
+ expect(scale.getValueForPixel(452)).toBe(4);
+ expect(scale.getValueForPixel(505)).toBe(4);
config.gridLines.offsetGridLines = false;
expect(scale.getPixelForValue(0, 0, 0, false)).toBe(33);
expect(scale.getPixelForValue(0, 0, 0, true)).toBe(33);
+ expect(scale.getValueForPixel(33)).toBe(0);
expect(scale.getPixelForValue(0, 4, 0, false)).toBe(557);
expect(scale.getPixelForValue(0, 4, 0, true)).toBe(557);
+ expect(scale.getValueForPixel(557)).toBe(4);
});
it ('Should get the correct pixel for a value when horizontal and zoomed', function() {
@@ -268,17 +274,22 @@ describe('Category scale tests', function() {
expect(scale.getPixelForValue(0, 0, 0, false)).toBe(11);
expect(scale.getPixelForValue(0, 0, 0, true)).toBe(30);
+ expect(scale.getValueForPixel(11)).toBe(0);
+ expect(scale.getValueForPixel(30)).toBe(0);
expect(scale.getPixelForValue(0, 4, 0, false)).toBe(161);
expect(scale.getPixelForValue(0, 4, 0, true)).toBe(180);
+ expect(scale.getValueForPixel(161)).toBe(4);
config.gridLines.offsetGridLines = false;
expect(scale.getPixelForValue(0, 0, 0, false)).toBe(11);
expect(scale.getPixelForValue(0, 0, 0, true)).toBe(11);
+ expect(scale.getValueForPixel(11)).toBe(0);
expect(scale.getPixelForValue(0, 4, 0, false)).toBe(199);
expect(scale.getPixelForValue(0, 4, 0, true)).toBe(199);
+ expect(scale.getValueForPixel(199)).toBe(4);
});
it ('should get the correct pixel for a value when vertical and zoomed', function() { | true |
Other | chartjs | Chart.js | 56411bdcd48e9814c1a2d768e8c4eb0b449bd24a.json | Increase tolerance for CI | test/scale.time.tests.js | @@ -13,7 +13,7 @@ describe('Time scale tests', function() {
var result = false;
var diff = actual.diff(expected.value, expected.unit, true);
- result = Math.abs(diff) < 0.3;
+ result = Math.abs(diff) < 0.5;
return {
pass: result | false |
Other | chartjs | Chart.js | 314f398887d0858802c37a29d4866873e7b7de82.json | Fix tooltip body | src/core/core.controller.js | @@ -575,7 +575,7 @@ module.exports = function(Chart) {
// The usual updates
this.tooltip.initialize();
this.tooltip._active = this.tooltipActive;
- this.tooltip.update();
+ this.tooltip.update(true);
}
// Hover animations | false |
Other | chartjs | Chart.js | 7cbc08aed7698e82f041dd4464384a1b1b1ea816.json | Add license field to package files | bower.json | @@ -4,6 +4,7 @@
"description": "Simple HTML5 Charts using the canvas element",
"homepage": "https://github.com/nnnick/Chart.js",
"author": "nnnick",
+ "license": "MIT",
"main": [
"dist/Chart.js"
], | true |
Other | chartjs | Chart.js | 7cbc08aed7698e82f041dd4464384a1b1b1ea816.json | Add license field to package files | package.json | @@ -3,6 +3,7 @@
"homepage": "http://www.chartjs.org",
"description": "Simple HTML5 charts using the canvas element.",
"version": "2.0.2",
+ "license": "MIT",
"main": "src/chart.js",
"repository": {
"type": "git", | true |
Other | chartjs | Chart.js | 73bc52f196062f1998b7b5461f76eeb9a0fb4432.json | Update radial linear tests | gulpfile.js | @@ -47,8 +47,6 @@ var testFiles = [
'!./test/controller.line.tests.js',
'!./test/core.layoutService.tests.js',
'!./test/defaultConfig.tests.js',
- '!./test/scale.radialLinear.tests.js',
- //'!./test/scale.time.tests.js'
];
gulp.task('build', buildTask); | true |
Other | chartjs | Chart.js | 73bc52f196062f1998b7b5461f76eeb9a0fb4432.json | Update radial linear tests | test/scale.radialLinear.tests.js | @@ -1,5 +1,17 @@
// Tests for the radial linear scale used by the polar area and radar charts
describe('Test the radial linear scale', function() {
+ var chartInstance;
+
+ beforeEach(function() {
+ window.addDefaultMatchers(jasmine);
+ });
+
+ afterEach(function() {
+ if (chartInstance) {
+ releaseChart(chartInstance);
+ }
+ });
+
it('Should register the constructor with the scale service', function() {
var Constructor = Chart.scaleService.getScaleConstructor('radialLinear');
expect(Constructor).not.toBe(undefined);
@@ -60,124 +72,92 @@ describe('Test the radial linear scale', function() {
});
it('Should correctly determine the max & min data values', function() {
- var scaleID = 'myScale';
-
- var mockData = {
- datasets: [{
- yAxisID: scaleID,
- data: [10, 5, 0, -5, 78, -100]
- }, {
- yAxisID: scaleID,
- data: [150]
- }],
- labels: ['lablel1', 'label2', 'label3', 'label4', 'label5', 'label6']
- };
-
- var mockContext = window.createMockContext();
- var Constructor = Chart.scaleService.getScaleConstructor('radialLinear');
- var scale = new Constructor({
- ctx: mockContext,
- options: Chart.scaleService.getScaleDefaults('radialLinear'), // use default config for scale
- chart: {
- data: mockData
+ chartInstance = window.acquireChart({
+ type: 'radar',
+ data: {
+ datasets: [{
+ data: [10, 5, 0, -5, 78, -100]
+ }, {
+ data: [150]
+ }],
+ labels: ['lablel1', 'label2', 'label3', 'label4', 'label5', 'label6']
},
- id: scaleID,
+ options: {
+ scales: {
+
+ }
+ }
});
- scale.update(200, 300);
- expect(scale.min).toBe(-100);
- expect(scale.max).toBe(200);
+ expect(chartInstance.scale.min).toBe(-100);
+ expect(chartInstance.scale.max).toBe(150);
});
it('Should correctly determine the max & min of string data values', function() {
- var scaleID = 'myScale';
-
- var mockData = {
- datasets: [{
- yAxisID: scaleID,
- data: ['10', '5', '0', '-5', '78', '-100']
- }, {
- yAxisID: scaleID,
- data: ['150']
- }],
- labels: ['lablel1', 'label2', 'label3', 'label4', 'label5', 'label6']
- };
-
- var mockContext = window.createMockContext();
- var Constructor = Chart.scaleService.getScaleConstructor('radialLinear');
- var scale = new Constructor({
- ctx: mockContext,
- options: Chart.scaleService.getScaleDefaults('radialLinear'), // use default config for scale
- chart: {
- data: mockData
+ chartInstance = window.acquireChart({
+ type: 'radar',
+ data: {
+ datasets: [{
+ data: ['10', '5', '0', '-5', '78', '-100']
+ }, {
+ data: ['150']
+ }],
+ labels: ['lablel1', 'label2', 'label3', 'label4', 'label5', 'label6']
},
- id: scaleID,
+ options: {
+ scales: {
+
+ }
+ }
});
- scale.update(200, 300);
- expect(scale.min).toBe(-100);
- expect(scale.max).toBe(200);
+ expect(chartInstance.scale.min).toBe(-100);
+ expect(chartInstance.scale.max).toBe(150);
});
it('Should correctly determine the max & min data values when there are hidden datasets', function() {
- var scaleID = 'myScale';
-
- var mockData = {
- datasets: [{
- yAxisID: scaleID,
- data: [10, 5, 0, -5, 78, -100]
- }, {
- yAxisID: scaleID,
- data: [150]
- }, {
- yAxisID: scaleID,
- data: [1000],
- hidden: true
- }],
- labels: ['lablel1', 'label2', 'label3', 'label4', 'label5', 'label6']
- };
-
- var mockContext = window.createMockContext();
- var Constructor = Chart.scaleService.getScaleConstructor('radialLinear');
- var scale = new Constructor({
- ctx: mockContext,
- options: Chart.scaleService.getScaleDefaults('radialLinear'), // use default config for scale
- chart: {
- data: mockData
+ chartInstance = window.acquireChart({
+ type: 'radar',
+ data: {
+ datasets: [{
+ data: ['10', '5', '0', '-5', '78', '-100']
+ }, {
+ data: ['150']
+ }, {
+ data: [1000],
+ hidden: true
+ }],
+ labels: ['lablel1', 'label2', 'label3', 'label4', 'label5', 'label6']
},
- id: scaleID,
+ options: {
+ scales: {
+
+ }
+ }
});
- scale.update(200, 300);
- expect(scale.min).toBe(-100);
- expect(scale.max).toBe(200);
+ expect(chartInstance.scale.min).toBe(-100);
+ expect(chartInstance.scale.max).toBe(150);
});
it('Should correctly determine the max & min data values when there is NaN data', function() {
- var scaleID = 'myScale';
-
- var mockData = {
- datasets: [{
- yAxisID: scaleID,
- data: [50, 60, NaN, 70, null, undefined]
- }],
- labels: ['lablel1', 'label2', 'label3', 'label4', 'label5', 'label6']
- };
-
- var mockContext = window.createMockContext();
- var Constructor = Chart.scaleService.getScaleConstructor('radialLinear');
- var scale = new Constructor({
- ctx: mockContext,
- options: Chart.scaleService.getScaleDefaults('radialLinear'), // use default config for scale
- chart: {
- data: mockData
+ chartInstance = window.acquireChart({
+ type: 'radar',
+ data: {
+ datasets: [{
+ data: [50, 60, NaN, 70, null, undefined]
+ }],
+ labels: ['lablel1', 'label2', 'label3', 'label4', 'label5', 'label6']
},
- id: scaleID,
+ options: {
+ scales: {
+
+ }
+ }
});
- scale.update(200, 300);
- expect(scale.min).toBe(50);
- expect(scale.max).toBe(70);
+ expect(chartInstance.scale.min).toBe(50);
+ expect(chartInstance.scale.max).toBe(70);
});
it('Should ensure that the scale has a max and min that are not equal', function() {
@@ -205,804 +185,236 @@ describe('Test the radial linear scale', function() {
});
it('Should use the suggestedMin and suggestedMax options', function() {
- var scaleID = 'myScale';
-
- var mockData = {
- datasets: [{
- yAxisID: scaleID,
- data: [1, 1, 1, 2, 1, 0]
- }],
- labels: ['lablel1', 'label2', 'label3', 'label4', 'label5', 'label6']
- };
-
- var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('radialLinear'));
- config.ticks.suggestedMin = -10;
- config.ticks.suggestedMax = 10;
-
- var mockContext = window.createMockContext();
- var Constructor = Chart.scaleService.getScaleConstructor('radialLinear');
- var scale = new Constructor({
- ctx: mockContext,
- options: config,
- chart: {
- data: mockData
+ chartInstance = window.acquireChart({
+ type: 'radar',
+ data: {
+ datasets: [{
+ data: [1, 1, 1, 2, 1, 0]
+ }],
+ labels: ['lablel1', 'label2', 'label3', 'label4', 'label5', 'label6']
},
- id: scaleID
+ options: {
+ scale: {
+ ticks: {
+ suggestedMin: -10,
+ suggestedMax: 10
+ }
+ }
+ }
});
- // Set arbitrary width and height for now
- scale.update(200, 300);
- expect(scale.min).toBe(-10);
- expect(scale.max).toBe(10);
+ expect(chartInstance.scale.min).toBe(-10);
+ expect(chartInstance.scale.max).toBe(10);
});
it('Should use the min and max options', function() {
- var scaleID = 'myScale';
-
- var mockData = {
- datasets: [{
- yAxisID: scaleID,
- data: [1, 1, 1, 2, 1, 0]
- }],
- labels: ['lablel1', 'label2', 'label3', 'label4', 'label5', 'label6']
- };
-
- var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('radialLinear'));
- config.ticks.min = -1010;
- config.ticks.max = 1010;
-
- var mockContext = window.createMockContext();
- var Constructor = Chart.scaleService.getScaleConstructor('radialLinear');
- var scale = new Constructor({
- ctx: mockContext,
- options: config,
- chart: {
- data: mockData
+ chartInstance = window.acquireChart({
+ type: 'radar',
+ data: {
+ datasets: [{
+ data: [1, 1, 1, 2, 1, 0]
+ }],
+ labels: ['lablel1', 'label2', 'label3', 'label4', 'label5', 'label6']
},
- id: scaleID
+ options: {
+ scale: {
+ ticks: {
+ min: -1010,
+ max: 1010
+ }
+ }
+ }
});
- // Set arbitrary width and height for now
- scale.update(200, 300);
- expect(scale.min).toBe(-1010);
- expect(scale.max).toBe(1010);
- expect(scale.ticks[0]).toBe('-1010');
- expect(scale.ticks[scale.ticks.length - 1]).toBe('1010');
- expect(scale.ticks).toEqual(['-1010', '-1000', '0', '1000', '1010']);
+ expect(chartInstance.scale.min).toBe(-1010);
+ expect(chartInstance.scale.max).toBe(1010);
+ expect(chartInstance.scale.ticks).toEqual(['-1010', '-1000', '-500', '0', '500', '1000', '1010']);
});
it('should forcibly include 0 in the range if the beginAtZero option is used', function() {
- var scaleID = 'myScale';
-
- var mockData = {
- datasets: [{
- yAxisID: scaleID,
- data: [20, 30, 40, 50]
- }],
- labels: [],
- };
-
- var mockContext = window.createMockContext();
- var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('radialLinear'));
- var Constructor = Chart.scaleService.getScaleConstructor('radialLinear');
- var scale = new Constructor({
- ctx: mockContext,
- options: config,
- chart: {
- data: mockData
+ chartInstance = window.acquireChart({
+ type: 'radar',
+ data: {
+ datasets: [{
+ data: [20, 30, 40, 50]
+ }],
+ labels: ['lablel1', 'label2', 'label3', 'label4']
},
- id: scaleID,
+ options: {
+ scale: {
+ ticks: {
+ beginAtZero: false
+ }
+ }
+ }
});
- config.ticks.beginAtZero = false;
- scale.update(400, 400);
- expect(scale.ticks).toEqual(['20', '25', '30', '35', '40', '45', '50']);
+ expect(chartInstance.scale.ticks).toEqual(['20', '25', '30', '35', '40', '45', '50']);
- config.ticks.beginAtZero = true;
- scale.update(400, 400);
- expect(scale.ticks).toEqual(['0', '5', '10', '15', '20', '25', '30', '35', '40', '45', '50']);
+ chartInstance.scale.options.ticks.beginAtZero = true;
+ chartInstance.update();
- mockData.datasets[0].data = [-20, -30, -40, -50];
- scale.update(400, 400);
- expect(scale.ticks).toEqual(['-50', '-45', '-40', '-35', '-30', '-25', '-20', '-15', '-10', '-5', '0']);
+ expect(chartInstance.scale.ticks).toEqual(['0', '5', '10', '15', '20', '25', '30', '35', '40', '45', '50']);
- config.ticks.beginAtZero = false;
- scale.update(400, 400);
- expect(scale.ticks).toEqual(['-50', '-45', '-40', '-35', '-30', '-25', '-20']);
- });
+ chartInstance.data.datasets[0].data = [-20, -30, -40, -50];
+ chartInstance.update();
- it('Should generate tick marks in the correct order in reversed mode', function() {
- var scaleID = 'myScale';
+ expect(chartInstance.scale.ticks).toEqual(['-50', '-45', '-40', '-35', '-30', '-25', '-20', '-15', '-10', '-5', '0']);
- var mockData = {
- datasets: [{
- yAxisID: scaleID,
- data: [10, 5, 0, 25, 78]
- }],
- labels: []
- };
+ chartInstance.scale.options.ticks.beginAtZero = false;
+ chartInstance.update();
- var mockContext = window.createMockContext();
- var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('radialLinear'));
- config.ticks.reverse = true;
- var Constructor = Chart.scaleService.getScaleConstructor('radialLinear');
- var scale = new Constructor({
- ctx: mockContext,
- options: config,
- chart: {
- data: mockData
+ expect(chartInstance.scale.ticks).toEqual(['-50', '-45', '-40', '-35', '-30', '-25', '-20']);
+ });
+
+ it('Should generate tick marks in the correct order in reversed mode', function() {
+ chartInstance = window.acquireChart({
+ type: 'radar',
+ data: {
+ datasets: [{
+ data: [10, 5, 0, 25, 78]
+ }],
+ labels: ['lablel1', 'label2', 'label3', 'label4', 'label5']
},
- id: scaleID,
+ options: {
+ scale: {
+ ticks: {
+ reverse: true
+ }
+ }
+ }
});
- scale.update(200, 300);
-
- // Reverse mode makes this count up
- expect(scale.ticks).toEqual(['80', '60', '40', '20', '0']);
- expect(scale.start).toBe(80);
- expect(scale.end).toBe(0);
+ expect(chartInstance.scale.ticks).toEqual(['80', '70', '60', '50', '40', '30', '20', '10', '0']);
+ expect(chartInstance.scale.start).toBe(80);
+ expect(chartInstance.scale.end).toBe(0);
});
it('Should build labels using the user supplied callback', function() {
- var scaleID = 'myScale';
-
- var mockData = {
- datasets: [{
- yAxisID: scaleID,
- data: [10, 5, 0, 25, 78]
- }],
- labels: ['label1', 'label2', 'label3', 'label4', 'label5']
- };
-
- var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('radialLinear'));
- config.ticks.userCallback = function(value, index) {
- return index.toString();
- };
-
- var mockContext = window.createMockContext();
- var Constructor = Chart.scaleService.getScaleConstructor('radialLinear');
- var scale = new Constructor({
- ctx: mockContext,
- options: config,
- chart: {
- data: mockData
+ chartInstance = window.acquireChart({
+ type: 'radar',
+ data: {
+ datasets: [{
+ data: [10, 5, 0, 25, 78]
+ }],
+ labels: ['label1', 'label2', 'label3', 'label4', 'label5']
},
- id: scaleID,
+ options: {
+ scale: {
+ ticks: {
+ callback: function(value, index) {
+ return index.toString();
+ }
+ }
+ }
+ }
});
- scale.update(200, 300);
-
- // Just the index
- expect(scale.ticks).toEqual(['0', '1', '2', '3', '4']);
- expect(scale.pointLabels).toEqual(['label1', 'label2', 'label3', 'label4', 'label5']);
+ expect(chartInstance.scale.ticks).toEqual(['0', '1', '2', '3', '4', '5', '6', '7', '8']);
+ expect(chartInstance.scale.pointLabels).toEqual(['label1', 'label2', 'label3', 'label4', 'label5']);
});
it('Should build point labels using the user supplied callback', function() {
- var scaleID = 'myScale';
-
- var mockData = {
- datasets: [{
- yAxisID: scaleID,
- data: [10, 5, 0, 25, 78]
- }],
- labels: ['label1', 'label2', 'label3', 'label4', 'label5']
- };
-
- var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('radialLinear'));
- config.pointLabels.callback = function(value, index) {
- return index.toString();
- };
-
- var mockContext = window.createMockContext();
- var Constructor = Chart.scaleService.getScaleConstructor('radialLinear');
- var scale = new Constructor({
- ctx: mockContext,
- options: config,
- chart: {
- data: mockData
+ chartInstance = window.acquireChart({
+ type: 'radar',
+ data: {
+ datasets: [{
+ data: [10, 5, 0, 25, 78]
+ }],
+ labels: ['label1', 'label2', 'label3', 'label4', 'label5']
},
- id: scaleID,
+ options: {
+ scale: {
+ pointLabels: {
+ callback: function(value, index) {
+ return index.toString();
+ }
+ }
+ }
+ }
});
- scale.update(200, 300);
-
- // Just the index
- expect(scale.pointLabels).toEqual(['0', '1', '2', '3', '4']);
+ expect(chartInstance.scale.pointLabels).toEqual(['0', '1', '2', '3', '4']);
});
it('should correctly set the center point', function() {
- var scaleID = 'myScale';
-
- var mockData = {
- datasets: [{
- yAxisID: scaleID,
- data: [10, 5, 0, 25, 78]
- }],
- labels: ['point1', 'point2', 'point3', 'point4', 'point5'] // used in radar charts which use the same scales
- };
-
- var mockContext = window.createMockContext();
- var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('radialLinear'));
- var Constructor = Chart.scaleService.getScaleConstructor('radialLinear');
- var scale = new Constructor({
- ctx: mockContext,
- options: config,
- chart: {
- data: mockData
+ chartInstance = window.acquireChart({
+ type: 'radar',
+ data: {
+ datasets: [{
+ data: [10, 5, 0, 25, 78]
+ }],
+ labels: ['label1', 'label2', 'label3', 'label4', 'label5']
},
- id: scaleID,
+ options: {
+ scale: {
+ pointLabels: {
+ callback: function(value, index) {
+ return index.toString();
+ }
+ }
+ }
+ }
});
- scale.left = 10;
- scale.right = 210;
- scale.top = 5;
- scale.bottom = 305;
- scale.update(200, 300);
-
- expect(scale.drawingArea).toBe(37);
- expect(scale.xCenter).toBe(110);
- expect(scale.yCenter).toBe(155);
+ expect(chartInstance.scale.drawingArea).toBe(225);
+ expect(chartInstance.scale.xCenter).toBe(256);
+ expect(chartInstance.scale.yCenter).toBe(272);
});
it('should correctly get the label for a given data index', function() {
- var scaleID = 'myScale';
-
- var mockData = {
- datasets: [{
- yAxisID: scaleID,
- data: [10, 5, 0, 25, 78]
- }],
- labels: ['point1', 'point2', 'point3', 'point4', 'point5'] // used in radar charts which use the same scales
- };
-
- var mockContext = window.createMockContext();
- var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('radialLinear'));
- var Constructor = Chart.scaleService.getScaleConstructor('radialLinear');
- var scale = new Constructor({
- ctx: mockContext,
- options: config,
- chart: {
- data: mockData
+ chartInstance = window.acquireChart({
+ type: 'radar',
+ data: {
+ datasets: [{
+ data: [10, 5, 0, 25, 78]
+ }],
+ labels: ['label1', 'label2', 'label3', 'label4', 'label5']
},
- id: scaleID,
+ options: {
+ scale: {
+ pointLabels: {
+ callback: function(value, index) {
+ return index.toString();
+ }
+ }
+ }
+ }
});
-
- scale.left = 10;
- scale.right = 210;
- scale.top = 5;
- scale.bottom = 305;
- scale.update(200, 300);
-
- expect(scale.getLabelForIndex(1, 0)).toBe(5);
+ expect(chartInstance.scale.getLabelForIndex(1, 0)).toBe(5);
});
it('should get the correct distance from the center point', function() {
- var scaleID = 'myScale';
-
- var mockData = {
- datasets: [{
- yAxisID: scaleID,
- data: [10, 5, 0, 25, 78]
- }],
- labels: ['point1', 'point2', 'point3', 'point4', 'point5'] // used in radar charts which use the same scales
- };
-
- var mockContext = window.createMockContext();
- var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('radialLinear'));
- var Constructor = Chart.scaleService.getScaleConstructor('radialLinear');
- var scale = new Constructor({
- ctx: mockContext,
- options: config,
- chart: {
- data: mockData
+ chartInstance = window.acquireChart({
+ type: 'radar',
+ data: {
+ datasets: [{
+ data: [10, 5, 0, 25, 78]
+ }],
+ labels: ['label1', 'label2', 'label3', 'label4', 'label5']
},
- id: scaleID,
+ options: {
+ scale: {
+ pointLabels: {
+ callback: function(value, index) {
+ return index.toString();
+ }
+ }
+ }
+ }
});
- scale.left = 0;
- scale.right = 200;
- scale.top = 0;
- scale.bottom = 300;
- scale.update(200, 300);
-
- expect(scale.getDistanceFromCenterForValue(scale.min)).toBe(0);
- expect(scale.getDistanceFromCenterForValue(scale.max)).toBe(37);
- expect(scale.getPointPositionForValue(1, 5)).toEqual({
- x: 102,
- y: 149,
+ expect(chartInstance.scale.getDistanceFromCenterForValue(chartInstance.scale.min)).toBe(0);
+ expect(chartInstance.scale.getDistanceFromCenterForValue(chartInstance.scale.max)).toBe(225);
+ expect(chartInstance.scale.getPointPositionForValue(1, 5)).toEqual({
+ x: 269,
+ y: 268,
});
- config.reverse = true;
-
- scale.update(200, 300);
-
- expect(scale.getDistanceFromCenterForValue(scale.min)).toBe(37);
- expect(scale.getDistanceFromCenterForValue(scale.max)).toBe(0);
- });
-
- it('should draw correctly when there are no point labels', function() {
- var scaleID = 'myScale';
-
- var mockData = {
- datasets: [{
- yAxisID: scaleID,
- data: [10, 5, 0, 25, 78]
- }, ],
- labels: ['point1', 'point2', 'point3', 'point4', 'point5'] // used in radar charts which use the same scales
- };
-
- var mockContext = window.createMockContext();
- var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('radialLinear'));
- config.lineArc = true;
- var Constructor = Chart.scaleService.getScaleConstructor('radialLinear');
- var scale = new Constructor({
- ctx: mockContext,
- options: config,
- chart: {
- data: mockData
- },
- id: scaleID,
- });
-
- scale.left = 0;
- scale.right = 200;
- scale.top = 0;
- scale.bottom = 300;
- scale.update(200, 300);
+ chartInstance.scale.options.reverse = true;
+ chartInstance.update();
- scale.draw();
-
- var expected = [{
- "name": "measureText",
- "args": ["0"]
- }, {
- "name": "measureText",
- "args": ["80"]
- }, {
- "name": "measureText",
- "args": ["point1"]
- }, {
- "name": "measureText",
- "args": ["point2"]
- }, {
- "name": "measureText",
- "args": ["point3"]
- }, {
- "name": "measureText",
- "args": ["point4"]
- }, {
- "name": "measureText",
- "args": ["point5"]
- }, {
- "name": "setStrokeStyle",
- "args": ["rgba(0, 0, 0, 0.1)"]
- }, {
- "name": "setLineWidth",
- "args": [1]
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "arc",
- "args": [100, 150, 9.25, 0, 6.283185307179586]
- }, {
- "name": "closePath",
- "args": []
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "measureText",
- "args": ["20"]
- }, {
- "name": "setFillStyle",
- "args": ["rgba(255,255,255,0.75)"]
- }, {
- "name": "fillRect",
- "args": [88, 132.75, 24, 16]
- }, {
- "name": "setFillStyle",
- "args": ["#666"]
- }, {
- "name": "fillText",
- "args": ["20", 100, 140.75]
- }, {
- "name": "setStrokeStyle",
- "args": ["rgba(0, 0, 0, 0.1)"]
- }, {
- "name": "setLineWidth",
- "args": [1]
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "arc",
- "args": [100, 150, 18.5, 0, 6.283185307179586]
- }, {
- "name": "closePath",
- "args": []
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "measureText",
- "args": ["40"]
- }, {
- "name": "setFillStyle",
- "args": ["rgba(255,255,255,0.75)"]
- }, {
- "name": "fillRect",
- "args": [88, 123.5, 24, 16]
- }, {
- "name": "setFillStyle",
- "args": ["#666"]
- }, {
- "name": "fillText",
- "args": ["40", 100, 131.5]
- }, {
- "name": "setStrokeStyle",
- "args": ["rgba(0, 0, 0, 0.1)"]
- }, {
- "name": "setLineWidth",
- "args": [1]
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "arc",
- "args": [100, 150, 27.75, 0, 6.283185307179586]
- }, {
- "name": "closePath",
- "args": []
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "measureText",
- "args": ["60"]
- }, {
- "name": "setFillStyle",
- "args": ["rgba(255,255,255,0.75)"]
- }, {
- "name": "fillRect",
- "args": [88, 114.25, 24, 16]
- }, {
- "name": "setFillStyle",
- "args": ["#666"]
- }, {
- "name": "fillText",
- "args": ["60", 100, 122.25]
- }, {
- "name": "setStrokeStyle",
- "args": ["rgba(0, 0, 0, 0.1)"]
- }, {
- "name": "setLineWidth",
- "args": [1]
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "arc",
- "args": [100, 150, 37, 0, 6.283185307179586]
- }, {
- "name": "closePath",
- "args": []
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "measureText",
- "args": ["80"]
- }, {
- "name": "setFillStyle",
- "args": ["rgba(255,255,255,0.75)"]
- }, {
- "name": "fillRect",
- "args": [88, 105, 24, 16]
- }, {
- "name": "setFillStyle",
- "args": ["#666"]
- }, {
- "name": "fillText",
- "args": ["80", 100, 113]
- }];
- expect(mockContext.getCalls()).toEqual(expected);
-
- mockContext.resetCalls();
- config.lineArc = false;
- scale.draw();
-
- expect(mockContext.getCalls()).toEqual([{
- "name": "setStrokeStyle",
- "args": ["rgba(0, 0, 0, 0.1)"]
- }, {
- "name": "setLineWidth",
- "args": [1]
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "moveTo",
- "args": [100, 141]
- }, {
- "name": "lineTo",
- "args": [109, 147]
- }, {
- "name": "lineTo",
- "args": [105, 157]
- }, {
- "name": "lineTo",
- "args": [95, 157]
- }, {
- "name": "lineTo",
- "args": [91, 147]
- }, {
- "name": "closePath",
- "args": []
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "measureText",
- "args": ["20"]
- }, {
- "name": "setFillStyle",
- "args": ["rgba(255,255,255,0.75)"]
- }, {
- "name": "fillRect",
- "args": [88, 132.75, 24, 16]
- }, {
- "name": "setFillStyle",
- "args": ["#666"]
- }, {
- "name": "fillText",
- "args": ["20", 100, 140.75]
- }, {
- "name": "setStrokeStyle",
- "args": ["rgba(0, 0, 0, 0.1)"]
- }, {
- "name": "setLineWidth",
- "args": [1]
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "moveTo",
- "args": [100, 132]
- }, {
- "name": "lineTo",
- "args": [118, 144]
- }, {
- "name": "lineTo",
- "args": [111, 165]
- }, {
- "name": "lineTo",
- "args": [89, 165]
- }, {
- "name": "lineTo",
- "args": [82, 144]
- }, {
- "name": "closePath",
- "args": []
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "measureText",
- "args": ["40"]
- }, {
- "name": "setFillStyle",
- "args": ["rgba(255,255,255,0.75)"]
- }, {
- "name": "fillRect",
- "args": [88, 123.5, 24, 16]
- }, {
- "name": "setFillStyle",
- "args": ["#666"]
- }, {
- "name": "fillText",
- "args": ["40", 100, 131.5]
- }, {
- "name": "setStrokeStyle",
- "args": ["rgba(0, 0, 0, 0.1)"]
- }, {
- "name": "setLineWidth",
- "args": [1]
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "moveTo",
- "args": [100, 122]
- }, {
- "name": "lineTo",
- "args": [126, 141]
- }, {
- "name": "lineTo",
- "args": [116, 172]
- }, {
- "name": "lineTo",
- "args": [84, 172]
- }, {
- "name": "lineTo",
- "args": [74, 141]
- }, {
- "name": "closePath",
- "args": []
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "measureText",
- "args": ["60"]
- }, {
- "name": "setFillStyle",
- "args": ["rgba(255,255,255,0.75)"]
- }, {
- "name": "fillRect",
- "args": [88, 114.25, 24, 16]
- }, {
- "name": "setFillStyle",
- "args": ["#666"]
- }, {
- "name": "fillText",
- "args": ["60", 100, 122.25]
- }, {
- "name": "setStrokeStyle",
- "args": ["rgba(0, 0, 0, 0.1)"]
- }, {
- "name": "setLineWidth",
- "args": [1]
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "moveTo",
- "args": [100, 113]
- }, {
- "name": "lineTo",
- "args": [135, 139]
- }, {
- "name": "lineTo",
- "args": [122, 180]
- }, {
- "name": "lineTo",
- "args": [78, 180]
- }, {
- "name": "lineTo",
- "args": [65, 139]
- }, {
- "name": "closePath",
- "args": []
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "measureText",
- "args": ["80"]
- }, {
- "name": "setFillStyle",
- "args": ["rgba(255,255,255,0.75)"]
- }, {
- "name": "fillRect",
- "args": [88, 105, 24, 16]
- }, {
- "name": "setFillStyle",
- "args": ["#666"]
- }, {
- "name": "fillText",
- "args": ["80", 100, 113]
- }, {
- "name": "setLineWidth",
- "args": [1]
- }, {
- "name": "setStrokeStyle",
- "args": ["rgba(0, 0, 0, 0.1)"]
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "moveTo",
- "args": [100, 150]
- }, {
- "name": "lineTo",
- "args": [65, 139]
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "closePath",
- "args": []
- }, {
- "name": "setFillStyle",
- "args": ["#666"]
- }, {
- "name": "fillText",
- "args": ["point5", 60, 137]
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "moveTo",
- "args": [100, 150]
- }, {
- "name": "lineTo",
- "args": [78, 180]
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "closePath",
- "args": []
- }, {
- "name": "setFillStyle",
- "args": ["#666"]
- }, {
- "name": "fillText",
- "args": ["point4", 75, 184]
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "moveTo",
- "args": [100, 150]
- }, {
- "name": "lineTo",
- "args": [122, 180]
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "closePath",
- "args": []
- }, {
- "name": "setFillStyle",
- "args": ["#666"]
- }, {
- "name": "fillText",
- "args": ["point3", 125, 184]
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "moveTo",
- "args": [100, 150]
- }, {
- "name": "lineTo",
- "args": [135, 139]
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "closePath",
- "args": []
- }, {
- "name": "setFillStyle",
- "args": ["#666"]
- }, {
- "name": "fillText",
- "args": ["point2", 140, 137]
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "moveTo",
- "args": [100, 150]
- }, {
- "name": "lineTo",
- "args": [100, 113]
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "closePath",
- "args": []
- }, {
- "name": "setFillStyle",
- "args": ["#666"]
- }, {
- "name": "fillText",
- "args": ["point1", 100, 108]
- }]);
+ expect(chartInstance.scale.getDistanceFromCenterForValue(chartInstance.scale.min)).toBe(225);
+ expect(chartInstance.scale.getDistanceFromCenterForValue(chartInstance.scale.max)).toBe(0);
});
}); | true |
Other | chartjs | Chart.js | 7aa1463c1570507b337a14faa9166f78ddfa4f25.json | Remove bad tests from linear scale | test/scale.linear.tests.js | @@ -658,18 +658,18 @@ describe('Linear Scale', function() {
});
var xScale = chartInstance.scales.xScale0;
- expect(xScale.paddingTop).toBe(0);
- expect(xScale.paddingBottom).toBe(0);
- expect(xScale.paddingLeft).toBe(0);
- expect(xScale.paddingRight).toBe(13.5);
+ expect(xScale.paddingTop).toBeCloseToPixel(0);
+ expect(xScale.paddingBottom).toBeCloseToPixel(0);
+ expect(xScale.paddingLeft).toBeCloseToPixel(0);
+ expect(xScale.paddingRight).toBeCloseToPixel(13.5);
expect(xScale.width).toBeCloseToPixel(471);
expect(xScale.height).toBeCloseToPixel(28);
var yScale = chartInstance.scales.yScale0;
- expect(yScale.paddingTop).toBe(0);
- expect(yScale.paddingBottom).toBe(0);
- expect(yScale.paddingLeft).toBe(0);
- expect(yScale.paddingRight).toBe(0);
+ expect(yScale.paddingTop).toBeCloseToPixel(0);
+ expect(yScale.paddingBottom).toBeCloseToPixel(0);
+ expect(yScale.paddingLeft).toBeCloseToPixel(0);
+ expect(yScale.paddingRight).toBeCloseToPixel(0);
expect(yScale.width).toBeCloseToPixel(41);
expect(yScale.height).toBeCloseToPixel(452);
@@ -678,1116 +678,18 @@ describe('Linear Scale', function() {
yScale.options.scaleLabel.display = true;
chartInstance.update();
- expect(xScale.paddingTop).toBe(0);
- expect(xScale.paddingBottom).toBe(0);
- expect(xScale.paddingLeft).toBe(0);
- expect(xScale.paddingRight).toBe(13.5);
+ expect(xScale.paddingTop).toBeCloseToPixel(0);
+ expect(xScale.paddingBottom).toBeCloseToPixel(0);
+ expect(xScale.paddingLeft).toBeCloseToPixel(0);
+ expect(xScale.paddingRight).toBeCloseToPixel(13.5);
expect(xScale.width).toBeCloseToPixel(453);
expect(xScale.height).toBeCloseToPixel(46);
- expect(yScale.paddingTop).toBe(0);
- expect(yScale.paddingBottom).toBe(0);
- expect(yScale.paddingLeft).toBe(0);
- expect(yScale.paddingRight).toBe(0);
+ expect(yScale.paddingTop).toBeCloseToPixel(0);
+ expect(yScale.paddingBottom).toBeCloseToPixel(0);
+ expect(yScale.paddingLeft).toBeCloseToPixel(0);
+ expect(yScale.paddingRight).toBeCloseToPixel(0);
expect(yScale.width).toBeCloseToPixel(59);
expect(yScale.height).toBeCloseToPixel(434);
});
-
- it('Should draw correctly horizontally', function() {
- chartInstance = window.acquireChart({
- type: 'line',
- data: {
- datasets: [{
- xAxisID: 'xScale0',
- yAxisID: 'yScale0',
- data: [{
- x: 10,
- y: -5
- }, {
- x: -10,
- y: 0
- }, {
- x: 0,
- y: 2
- }, {
- x: 99,
- y: -3
- }]
- }],
- },
- options: {
- scales: {
- xAxes: [{
- id: 'xScale0',
- type: 'linear',
- position: 'bottom'
- }],
- yAxes: [{
- id: 'yScale0',
- type: 'linear'
- }]
- }
- }
- });
-
- var xScale = chartInstance.scales.xScale0;
- var mockContext = window.createMockContext();
- xScale.ctx = mockContext;
-
- chartInstance.draw();
-
- var expected = [{
- "name": "setFillStyle",
- "args": ["#666"]
- }, {
- "name": "setLineWidth",
- "args": [1]
- }, {
- "name": "setStrokeStyle",
- "args": ["rgba(0, 0, 0, 0.1)"]
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "moveTo",
- "args": [31.5, 484]
- }, {
- "name": "lineTo",
- "args": [31.5, 494]
- }, {
- "name": "moveTo",
- "args": [31.5, 32]
- }, {
- "name": "lineTo",
- "args": [31.5, 484]
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "save",
- "args": []
- }, {
- "name": "translate",
- "args": [31, 494]
- }, {
- "name": "rotate",
- "args": [-0]
- }, {
- "name": "fillText",
- "args": ["-20", 0, 0]
- }, {
- "name": "restore",
- "args": []
- }, {
- "name": "setLineWidth",
- "args": [1]
- }, {
- "name": "setStrokeStyle",
- "args": ["rgba(0,0,0,0.25)"]
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "moveTo",
- "args": [109.5, 484]
- }, {
- "name": "lineTo",
- "args": [109.5, 494]
- }, {
- "name": "moveTo",
- "args": [109.5, 32]
- }, {
- "name": "lineTo",
- "args": [109.5, 484]
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "save",
- "args": []
- }, {
- "name": "translate",
- "args": [109, 494]
- }, {
- "name": "rotate",
- "args": [-0]
- }, {
- "name": "fillText",
- "args": ["0", 0, 0]
- }, {
- "name": "restore",
- "args": []
- }, {
- "name": "setLineWidth",
- "args": [1]
- }, {
- "name": "setStrokeStyle",
- "args": ["rgba(0, 0, 0, 0.1)"]
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "moveTo",
- "args": [187.5, 484]
- }, {
- "name": "lineTo",
- "args": [187.5, 494]
- }, {
- "name": "moveTo",
- "args": [187.5, 32]
- }, {
- "name": "lineTo",
- "args": [187.5, 484]
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "save",
- "args": []
- }, {
- "name": "translate",
- "args": [187, 494]
- }, {
- "name": "rotate",
- "args": [-0]
- }, {
- "name": "fillText",
- "args": ["20", 0, 0]
- }, {
- "name": "restore",
- "args": []
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "moveTo",
- "args": [265.5, 484]
- }, {
- "name": "lineTo",
- "args": [265.5, 494]
- }, {
- "name": "moveTo",
- "args": [265.5, 32]
- }, {
- "name": "lineTo",
- "args": [265.5, 484]
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "save",
- "args": []
- }, {
- "name": "translate",
- "args": [265, 494]
- }, {
- "name": "rotate",
- "args": [-0]
- }, {
- "name": "fillText",
- "args": ["40", 0, 0]
- }, {
- "name": "restore",
- "args": []
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "moveTo",
- "args": [343.5, 484]
- }, {
- "name": "lineTo",
- "args": [343.5, 494]
- }, {
- "name": "moveTo",
- "args": [343.5, 32]
- }, {
- "name": "lineTo",
- "args": [343.5, 484]
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "save",
- "args": []
- }, {
- "name": "translate",
- "args": [343, 494]
- }, {
- "name": "rotate",
- "args": [-0]
- }, {
- "name": "fillText",
- "args": ["60", 0, 0]
- }, {
- "name": "restore",
- "args": []
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "moveTo",
- "args": [421.5, 484]
- }, {
- "name": "lineTo",
- "args": [421.5, 494]
- }, {
- "name": "moveTo",
- "args": [421.5, 32]
- }, {
- "name": "lineTo",
- "args": [421.5, 484]
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "save",
- "args": []
- }, {
- "name": "translate",
- "args": [421, 494]
- }, {
- "name": "rotate",
- "args": [-0]
- }, {
- "name": "fillText",
- "args": ["80", 0, 0]
- }, {
- "name": "restore",
- "args": []
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "moveTo",
- "args": [499.5, 484]
- }, {
- "name": "lineTo",
- "args": [499.5, 494]
- }, {
- "name": "moveTo",
- "args": [499.5, 32]
- }, {
- "name": "lineTo",
- "args": [499.5, 484]
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "save",
- "args": []
- }, {
- "name": "translate",
- "args": [499, 494]
- }, {
- "name": "rotate",
- "args": [-0]
- }, {
- "name": "fillText",
- "args": ["100", 0, 0]
- }, {
- "name": "restore",
- "args": []
- }, {
- "name": "setLineWidth",
- "args": [1]
- }, {
- "name": "setStrokeStyle",
- "args": ["rgba(0, 0, 0, 0.1)"]
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "moveTo",
- "args": [31, 484.5]
- }, {
- "name": "lineTo",
- "args": [512, 484.5]
- }, {
- "name": "stroke",
- "args": []
- }];
- expect(mockContext.getCalls()).toEqual(expected);
-
- // Turn off some drawing
- xScale.options.gridLines.drawTicks = false;
- xScale.options.gridLines.drawOnChartArea = false;
- xScale.options.ticks.display = false;
- xScale.options.scaleLabel.display = true;
- xScale.options.scaleLabel.labelString = 'myLabel';
-
- mockContext.resetCalls();
-
- chartInstance.draw();
- expect(mockContext.getCalls()).toEqual([{
- "name": "setFillStyle",
- "args": ["#666"]
- }, {
- "name": "setLineWidth",
- "args": [1]
- }, {
- "name": "setStrokeStyle",
- "args": ["rgba(0, 0, 0, 0.1)"]
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "setLineWidth",
- "args": [1]
- }, {
- "name": "setStrokeStyle",
- "args": ["rgba(0,0,0,0.25)"]
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "setLineWidth",
- "args": [1]
- }, {
- "name": "setStrokeStyle",
- "args": ["rgba(0, 0, 0, 0.1)"]
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "setFillStyle",
- "args": ["#666"]
- }, {
- "name": "fillText",
- "args": ["myLabel", 271.5, 506]
- }, {
- "name": "setLineWidth",
- "args": [1]
- }, {
- "name": "setStrokeStyle",
- "args": ["rgba(0, 0, 0, 0.1)"]
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "moveTo",
- "args": [31, 484.5]
- }, {
- "name": "lineTo",
- "args": [512, 484.5]
- }, {
- "name": "stroke",
- "args": []
- }]);
-
- // Turn off display
-
- mockContext.resetCalls();
- xScale.options.display = false;
- chartInstance.draw();
- expect(mockContext.getCalls()).toEqual([]);
- });
-
- it('Should draw correctly vertically', function() {
- chartInstance = window.acquireChart({
- type: 'line',
- data: {
- datasets: [{
- xAxisID: 'xScale0',
- yAxisID: 'yScale0',
- data: [{
- x: 10,
- y: -5
- }, {
- x: -10,
- y: 0
- }, {
- x: 0,
- y: 2
- }, {
- x: 99,
- y: -3
- }]
- }],
- },
- options: {
- scales: {
- xAxes: [{
- id: 'xScale0',
- type: 'linear',
- position: 'bottom'
- }],
- yAxes: [{
- id: 'yScale0',
- type: 'linear'
- }]
- }
- }
- });
-
- var yScale = chartInstance.scales.yScale0;
- var mockContext = window.createMockContext();
- yScale.ctx = mockContext;
-
- chartInstance.draw();
-
- expect(mockContext.getCalls()).toEqual([{
- "name": "setFillStyle",
- "args": ["#666"]
- }, {
- "name": "setLineWidth",
- "args": [1]
- }, {
- "name": "setStrokeStyle",
- "args": ["rgba(0, 0, 0, 0.1)"]
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "moveTo",
- "args": [26, 32.5]
- }, {
- "name": "lineTo",
- "args": [31, 32.5]
- }, {
- "name": "moveTo",
- "args": [31, 32.5]
- }, {
- "name": "lineTo",
- "args": [512, 32.5]
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "save",
- "args": []
- }, {
- "name": "translate",
- "args": [21, 32]
- }, {
- "name": "rotate",
- "args": [-0]
- }, {
- "name": "fillText",
- "args": ["2", 0, 0]
- }, {
- "name": "restore",
- "args": []
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "moveTo",
- "args": [26, 97.5]
- }, {
- "name": "lineTo",
- "args": [31, 97.5]
- }, {
- "name": "moveTo",
- "args": [31, 97.5]
- }, {
- "name": "lineTo",
- "args": [512, 97.5]
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "save",
- "args": []
- }, {
- "name": "translate",
- "args": [21, 97]
- }, {
- "name": "rotate",
- "args": [-0]
- }, {
- "name": "fillText",
- "args": ["1", 0, 0]
- }, {
- "name": "restore",
- "args": []
- }, {
- "name": "setLineWidth",
- "args": [1]
- }, {
- "name": "setStrokeStyle",
- "args": ["rgba(0,0,0,0.25)"]
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "moveTo",
- "args": [26, 161.5]
- }, {
- "name": "lineTo",
- "args": [31, 161.5]
- }, {
- "name": "moveTo",
- "args": [31, 161.5]
- }, {
- "name": "lineTo",
- "args": [512, 161.5]
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "save",
- "args": []
- }, {
- "name": "translate",
- "args": [21, 161]
- }, {
- "name": "rotate",
- "args": [-0]
- }, {
- "name": "fillText",
- "args": ["0", 0, 0]
- }, {
- "name": "restore",
- "args": []
- }, {
- "name": "setLineWidth",
- "args": [1]
- }, {
- "name": "setStrokeStyle",
- "args": ["rgba(0, 0, 0, 0.1)"]
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "moveTo",
- "args": [26, 226.5]
- }, {
- "name": "lineTo",
- "args": [31, 226.5]
- }, {
- "name": "moveTo",
- "args": [31, 226.5]
- }, {
- "name": "lineTo",
- "args": [512, 226.5]
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "save",
- "args": []
- }, {
- "name": "translate",
- "args": [21, 226]
- }, {
- "name": "rotate",
- "args": [-0]
- }, {
- "name": "fillText",
- "args": ["-1", 0, 0]
- }, {
- "name": "restore",
- "args": []
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "moveTo",
- "args": [26, 290.5]
- }, {
- "name": "lineTo",
- "args": [31, 290.5]
- }, {
- "name": "moveTo",
- "args": [31, 290.5]
- }, {
- "name": "lineTo",
- "args": [512, 290.5]
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "save",
- "args": []
- }, {
- "name": "translate",
- "args": [21, 290]
- }, {
- "name": "rotate",
- "args": [-0]
- }, {
- "name": "fillText",
- "args": ["-2", 0, 0]
- }, {
- "name": "restore",
- "args": []
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "moveTo",
- "args": [26, 355.5]
- }, {
- "name": "lineTo",
- "args": [31, 355.5]
- }, {
- "name": "moveTo",
- "args": [31, 355.5]
- }, {
- "name": "lineTo",
- "args": [512, 355.5]
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "save",
- "args": []
- }, {
- "name": "translate",
- "args": [21, 355]
- }, {
- "name": "rotate",
- "args": [-0]
- }, {
- "name": "fillText",
- "args": ["-3", 0, 0]
- }, {
- "name": "restore",
- "args": []
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "moveTo",
- "args": [26, 419.5]
- }, {
- "name": "lineTo",
- "args": [31, 419.5]
- }, {
- "name": "moveTo",
- "args": [31, 419.5]
- }, {
- "name": "lineTo",
- "args": [512, 419.5]
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "save",
- "args": []
- }, {
- "name": "translate",
- "args": [21, 419]
- }, {
- "name": "rotate",
- "args": [-0]
- }, {
- "name": "fillText",
- "args": ["-4", 0, 0]
- }, {
- "name": "restore",
- "args": []
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "moveTo",
- "args": [26, 484.5]
- }, {
- "name": "lineTo",
- "args": [31, 484.5]
- }, {
- "name": "moveTo",
- "args": [31, 484.5]
- }, {
- "name": "lineTo",
- "args": [512, 484.5]
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "save",
- "args": []
- }, {
- "name": "translate",
- "args": [21, 484]
- }, {
- "name": "rotate",
- "args": [-0]
- }, {
- "name": "fillText",
- "args": ["-5", 0, 0]
- }, {
- "name": "restore",
- "args": []
- }, {
- "name": "setLineWidth",
- "args": [1]
- }, {
- "name": "setStrokeStyle",
- "args": ["rgba(0, 0, 0, 0.1)"]
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "moveTo",
- "args": [31.5, 32]
- }, {
- "name": "lineTo",
- "args": [31.5, 484]
- }, {
- "name": "stroke",
- "args": []
- }]);
-
- // Turn off some drawing
- yScale.options.gridLines.drawTicks = false;
- yScale.options.gridLines.drawOnChartArea = false;
- yScale.options.ticks.display = false;
- yScale.options.scaleLabel.display = true;
-
- mockContext.resetCalls();
- chartInstance.draw();
-
- expect(mockContext.getCalls()).toEqual([{
- "name": "setFillStyle",
- "args": ["#666"]
- }, {
- "name": "setLineWidth",
- "args": [1]
- }, {
- "name": "setStrokeStyle",
- "args": ["rgba(0, 0, 0, 0.1)"]
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "setLineWidth",
- "args": [1]
- }, {
- "name": "setStrokeStyle",
- "args": ["rgba(0,0,0,0.25)"]
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "setLineWidth",
- "args": [1]
- }, {
- "name": "setStrokeStyle",
- "args": ["rgba(0, 0, 0, 0.1)"]
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "save",
- "args": []
- }, {
- "name": "translate",
- "args": [6, 258]
- }, {
- "name": "rotate",
- "args": [-1.5707963267948966]
- }, {
- "name": "setFillStyle",
- "args": ["#666"]
- }, {
- "name": "fillText",
- "args": ["", 0, 0]
- }, {
- "name": "restore",
- "args": []
- }, {
- "name": "setLineWidth",
- "args": [1]
- }, {
- "name": "setStrokeStyle",
- "args": ["rgba(0, 0, 0, 0.1)"]
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "moveTo",
- "args": [31.5, 32]
- }, {
- "name": "lineTo",
- "args": [31.5, 484]
- }, {
- "name": "stroke",
- "args": []
- }]);
- });
-
- it("should not draw lines where the callback function returned null or undefined", function() {
- chartInstance = window.acquireChart({
- type: 'line',
- data: {
- datasets: [{
- xAxisID: 'xScale0',
- yAxisID: 'yScale0',
- data: [{
- x: 10,
- y: -5
- }, {
- x: -10,
- y: 0
- }, {
- x: 0,
- y: 2
- }, {
- x: 99,
- y: -3
- }]
- }],
- },
- options: {
- scales: {
- xAxes: [{
- id: 'xScale0',
- type: 'linear',
- position: 'bottom'
- }],
- yAxes: [{
- id: 'yScale0',
- type: 'linear',
- ticks: {
- callback: function(tickValue, index) {
- return index % 2 === 0 ? null : tickValue.toString();
- }
- }
- }]
- }
- }
- });
-
- var yScale = chartInstance.scales.yScale0;
- var mockContext = window.createMockContext();
- yScale.ctx = mockContext;
-
- chartInstance.draw();
-
- expect(mockContext.getCalls()).toEqual([{
- "name": "setFillStyle",
- "args": ["#666"]
- }, {
- "name": "setLineWidth",
- "args": [1]
- }, {
- "name": "setStrokeStyle",
- "args": ["rgba(0, 0, 0, 0.1)"]
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "moveTo",
- "args": [26, 97.5]
- }, {
- "name": "lineTo",
- "args": [31, 97.5]
- }, {
- "name": "moveTo",
- "args": [31, 97.5]
- }, {
- "name": "lineTo",
- "args": [512, 97.5]
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "save",
- "args": []
- }, {
- "name": "translate",
- "args": [21, 97]
- }, {
- "name": "rotate",
- "args": [-0]
- }, {
- "name": "fillText",
- "args": ["1", 0, 0]
- }, {
- "name": "restore",
- "args": []
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "moveTo",
- "args": [26, 226.5]
- }, {
- "name": "lineTo",
- "args": [31, 226.5]
- }, {
- "name": "moveTo",
- "args": [31, 226.5]
- }, {
- "name": "lineTo",
- "args": [512, 226.5]
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "save",
- "args": []
- }, {
- "name": "translate",
- "args": [21, 226]
- }, {
- "name": "rotate",
- "args": [-0]
- }, {
- "name": "fillText",
- "args": ["-1", 0, 0]
- }, {
- "name": "restore",
- "args": []
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "moveTo",
- "args": [26, 355.5]
- }, {
- "name": "lineTo",
- "args": [31, 355.5]
- }, {
- "name": "moveTo",
- "args": [31, 355.5]
- }, {
- "name": "lineTo",
- "args": [512, 355.5]
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "save",
- "args": []
- }, {
- "name": "translate",
- "args": [21, 355]
- }, {
- "name": "rotate",
- "args": [-0]
- }, {
- "name": "fillText",
- "args": ["-3", 0, 0]
- }, {
- "name": "restore",
- "args": []
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "moveTo",
- "args": [26, 484.5]
- }, {
- "name": "lineTo",
- "args": [31, 484.5]
- }, {
- "name": "moveTo",
- "args": [31, 484.5]
- }, {
- "name": "lineTo",
- "args": [512, 484.5]
- }, {
- "name": "stroke",
- "args": []
- }, {
- "name": "save",
- "args": []
- }, {
- "name": "translate",
- "args": [21, 484]
- }, {
- "name": "rotate",
- "args": [-0]
- }, {
- "name": "fillText",
- "args": ["-5", 0, 0]
- }, {
- "name": "restore",
- "args": []
- }, {
- "name": "setLineWidth",
- "args": [1]
- }, {
- "name": "setStrokeStyle",
- "args": ["rgba(0, 0, 0, 0.1)"]
- }, {
- "name": "beginPath",
- "args": []
- }, {
- "name": "moveTo",
- "args": [31.5, 32]
- }, {
- "name": "lineTo",
- "args": [31.5, 484]
- }, {
- "name": "stroke",
- "args": []
- }])
- });
}); | false |
Other | chartjs | Chart.js | 34992bc4cbe53a7ca6f90912c406c52778ef86b0.json | Fix doughnut test | test/controller.doughnut.tests.js | @@ -65,7 +65,7 @@ describe('Doughnut controller tests', function() {
},
options: {
animation: {
- animateRotate: true,
+ animateRotate: false,
animateScale: false
},
cutoutPercentage: 50,
@@ -88,19 +88,19 @@ describe('Doughnut controller tests', function() {
expect(meta.data.length).toBe(4);
- [ { c: 1.7453292519 },
- { c: 2.0943951023 },
- { c: 0, },
- { c: 2.4434609527 }
+ [ { c: 1.7453292519, sA: Math.PI * -0.5, eA: 0.17453292519943298 },
+ { c: 2.0943951023, sA: 0.17453292519943298, eA: 2.2689280275926285 },
+ { c: 0, sA: 2.2689280275926285, eA: 2.2689280275926285},
+ { c: 2.4434609527, sA: 2.2689280275926285, eA: 4.71238898038469}
].forEach(function(expected, i) {
expect(meta.data[i]._model.x).toBeCloseToPixel(256);
expect(meta.data[i]._model.y).toBeCloseToPixel(272);
expect(meta.data[i]._model.outerRadius).toBeCloseToPixel(239);
expect(meta.data[i]._model.innerRadius).toBeCloseToPixel(179);
expect(meta.data[i]._model.circumference).toBeCloseTo(expected.c, 8);
+ expect(meta.data[i]._model.startAngle).toBeCloseTo(expected.sA, 8);
+ expect(meta.data[i]._model.endAngle).toBeCloseTo(expected.eA, 8);
expect(meta.data[i]._model).toEqual(jasmine.objectContaining({
- startAngle: Math.PI * -0.5,
- endAngle: Math.PI * -0.5,
label: chart.data.labels[i],
hoverBackgroundColor: 'rgb(255, 255, 255)',
backgroundColor: 'rgb(255, 0, 0)', | false |
Other | chartjs | Chart.js | 200abc184ba8a9ff1a5ac091e10fd024690392fb.json | update isDatasetVisible call | src/scales/scale.time.js | @@ -104,7 +104,7 @@ module.exports = function(Chart) {
helpers.each(this.chart.data.datasets, function(dataset, datasetIndex) {
var momentsForDataset = [];
- var datasetVisible = helpers.isDatasetVisible(dataset);
+ var datasetVisible = this.chart.isDatasetVisible(datasetIndex);
if (typeof dataset.data[0] === 'object') {
helpers.each(dataset.data, function(value, index) { | false |
Other | chartjs | Chart.js | 0447fda26d4276a92f01b13c341f0b785c346ea3.json | Update readme to link to previous versions
Note - this removed now not required mention of liquid tags in docs. | README.md | @@ -20,7 +20,7 @@ CDN: https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.0.0/Chart.js
## Documentation
-You can find documentation at [www.chartjs.org/docs](http://www.chartjs.org/docs). The markdown files that build the site are available under `/docs`. Please note - in some of the json examples of configuration you might notice some liquid tags - this is just for the generating the site html, please disregard.
+You can find documentation at [www.chartjs.org/docs](http://www.chartjs.org/docs). The markdown files that build the site are available under `/docs`. Previous version documentation is available at [www.chartjs.org/docs/#notes-previous-versions](http://www.chartjs.org/docs/#notes-previous-versions).
## Contributing
| false |
Other | chartjs | Chart.js | eb14481d02b42a35836306af6ff95baf022df360.json | Fix legend tests and disable other failing tests | gulpfile.js | @@ -40,7 +40,16 @@ var preTestFiles = [
var testFiles = [
'./test/mockContext.js',
- './test/*.js'
+ './test/*.js',
+
+ // Disable tests which need to be rewritten based on changes introduced by
+ // the following changes: https://github.com/chartjs/Chart.js/pull/2346
+ '!./test/controller.line.tests.js',
+ '!./test/controller.radar.tests.js',
+ '!./test/core.layoutService.tests.js',
+ '!./test/defaultConfig.tests.js',
+ '!./test/scale.linear.tests.js',
+ '!./test/scale.radialLinear.tests.js'
];
gulp.task('build', buildTask); | true |
Other | chartjs | Chart.js | eb14481d02b42a35836306af6ff95baf022df360.json | Fix legend tests and disable other failing tests | test/controller.bar.tests.js | @@ -265,10 +265,10 @@ describe('Bar controller tests', function() {
{ b: 290, w: 91, x: 322, y: 161 },
{ b: 290, w: 91, x: 436, y: 419 }
].forEach(function(values, i) {
- expect(meta0.data[i]._model.base).toBeCloseToPixel(values.b);
- expect(meta0.data[i]._model.width).toBeCloseToPixel(values.w);
- expect(meta0.data[i]._model.x).toBeCloseToPixel(values.x);
- expect(meta0.data[i]._model.y).toBeCloseToPixel(values.y);
+ expect(meta0.data[i]._model.base).toBeCloseToPixel(values.b);
+ expect(meta0.data[i]._model.width).toBeCloseToPixel(values.w);
+ expect(meta0.data[i]._model.x).toBeCloseToPixel(values.x);
+ expect(meta0.data[i]._model.y).toBeCloseToPixel(values.y);
});
var meta1 = chart.getDatasetMeta(1);
@@ -278,10 +278,10 @@ describe('Bar controller tests', function() {
{ b: 161, w: 91, x: 322, y: 161 },
{ b: 419, w: 91, x: 436, y: 471 }
].forEach(function(values, i) {
- expect(meta1.data[i]._model.base).toBeCloseToPixel(values.b);
- expect(meta1.data[i]._model.width).toBeCloseToPixel(values.w);
- expect(meta1.data[i]._model.x).toBeCloseToPixel(values.x);
- expect(meta1.data[i]._model.y).toBeCloseToPixel(values.y);
+ expect(meta1.data[i]._model.base).toBeCloseToPixel(values.b);
+ expect(meta1.data[i]._model.width).toBeCloseToPixel(values.w);
+ expect(meta1.data[i]._model.x).toBeCloseToPixel(values.x);
+ expect(meta1.data[i]._model.y).toBeCloseToPixel(values.y);
});
});
| true |
Other | chartjs | Chart.js | eb14481d02b42a35836306af6ff95baf022df360.json | Fix legend tests and disable other failing tests | test/core.layoutService.tests.js | @@ -228,7 +228,7 @@ describe('Test the layout service', function() {
expect(chart.scales.xScale1.bottom).toBeCloseToPixel(512);
expect(chart.scales.xScale1.left).toBeCloseToPixel(45);
expect(chart.scales.xScale1.right).toBeCloseToPixel(512);
- expect(chart.scales.x1.top).toBeCloseToPixel(484);
+ expect(chart.scales.xScale1.top).toBeCloseToPixel(484);
expect(chart.scales.xScale2.bottom).toBeCloseToPixel(28);
expect(chart.scales.xScale2.left).toBeCloseToPixel(0); | true |
Other | chartjs | Chart.js | eb14481d02b42a35836306af6ff95baf022df360.json | Fix legend tests and disable other failing tests | test/core.legend.tests.js | @@ -1,6 +1,14 @@
// Test the rectangle element
-
describe('Legend block tests', function() {
+
+ beforeEach(function() {
+ window.addDefaultMatchers(jasmine);
+ });
+
+ afterEach(function() {
+ window.releaseAllCharts();
+ });
+
it('Should be constructed', function() {
var legend = new Chart.Legend({});
expect(legend).not.toBe(undefined);
@@ -25,42 +33,35 @@ describe('Legend block tests', function() {
});
it('should update correctly', function() {
- var chart = {
+ var chart = window.acquireChart({
+ type: 'bar',
data: {
datasets: [{
label: 'dataset1',
backgroundColor: '#f31',
borderCapStyle: 'butt',
borderDash: [2, 2],
- borderDashOffset: 5.5
+ borderDashOffset: 5.5,
+ data: []
}, {
label: 'dataset2',
hidden: true,
borderJoinStyle: 'miter',
+ data: []
}, {
label: 'dataset3',
borderWidth: 10,
- borderColor: 'green'
- }]
+ borderColor: 'green',
+ data: []
+ }],
+ labels: []
}
- };
- var context = window.createMockContext();
- var options = Chart.helpers.clone(Chart.defaults.global.legend);
- var legend = new Chart.Legend({
- chart: chart,
- ctx: context,
- options: options
});
- var minSize = legend.update(400, 200);
- expect(minSize).toEqual({
- width: 400,
- height: 54
- });
- expect(legend.legendItems).toEqual([{
+ expect(chart.legend.legendItems).toEqual([{
text: 'dataset1',
fillStyle: '#f31',
- hidden: undefined,
+ hidden: false,
lineCap: 'butt',
lineDash: [2, 2],
lineDashOffset: 5.5,
@@ -82,7 +83,7 @@ describe('Legend block tests', function() {
}, {
text: 'dataset3',
fillStyle: undefined,
- hidden: undefined,
+ hidden: false,
lineCap: undefined,
lineDash: undefined,
lineDashOffset: undefined,
@@ -94,57 +95,59 @@ describe('Legend block tests', function() {
});
it('should draw correctly', function() {
- var chart = {
+ var chart = window.acquireChart({
+ type: 'bar',
data: {
datasets: [{
label: 'dataset1',
backgroundColor: '#f31',
borderCapStyle: 'butt',
borderDash: [2, 2],
- borderDashOffset: 5.5
+ borderDashOffset: 5.5,
+ data: []
}, {
label: 'dataset2',
hidden: true,
borderJoinStyle: 'miter',
+ data: []
}, {
label: 'dataset3',
borderWidth: 10,
- borderColor: 'green'
- }]
+ borderColor: 'green',
+ data: []
+ }],
+ labels: []
}
- };
- var context = window.createMockContext();
- var options = Chart.helpers.clone(Chart.defaults.global.legend);
- var legend = new Chart.Legend({
- chart: chart,
- ctx: context,
- options: options
});
- var minSize = legend.update(400, 200);
- legend.left = 50;
- legend.top = 100;
- legend.right = legend.left + minSize.width;
- legend.bottom = legend.top + minSize.height;
+ expect(chart.legend.legendHitBoxes.length).toBe(3);
- legend.draw();
- expect(legend.legendHitBoxes).toEqual([{
- left: 114,
- top: 110,
- width: 126,
- height: 12
- }, {
- left: 250,
- top: 110,
- width: 126,
- height: 12
- }, {
- left: 182,
- top: 132,
- width: 126,
- height: 12
- }]);
- expect(context.getCalls()).toEqual([{
+ [ { h: 12, l: 101, t: 10, w: 93 },
+ { h: 12, l: 205, t: 10, w: 93 },
+ { h: 12, l: 308, t: 10, w: 93 }
+ ].forEach(function(expected, i) {
+ expect(chart.legend.legendHitBoxes[i].height).toBeCloseToPixel(expected.h);
+ expect(chart.legend.legendHitBoxes[i].left).toBeCloseToPixel(expected.l);
+ expect(chart.legend.legendHitBoxes[i].top).toBeCloseToPixel(expected.t);
+ expect(chart.legend.legendHitBoxes[i].width).toBeCloseToPixel(expected.w);
+ })
+
+ // NOTE(SB) We should get ride of the following tests and use image diff instead.
+ // For now, as discussed with Evert Timberg, simply comment out.
+ // See http://humblesoftware.github.io/js-imagediff/test.html
+ /*chart.legend.ctx = window.createMockContext();
+ chart.update();
+
+ expect(chart.legend.ctx .getCalls()).toEqual([{
+ "name": "measureText",
+ "args": ["dataset1"]
+ }, {
+ "name": "measureText",
+ "args": ["dataset2"]
+ }, {
+ "name": "measureText",
+ "args": ["dataset3"]
+ }, {
"name": "measureText",
"args": ["dataset1"]
}, {
@@ -300,6 +303,6 @@ describe('Legend block tests', function() {
}, {
"name": "fillText",
"args": ["dataset3", 228, 132]
- }]);
+ }]);*/
});
}); | true |
Other | chartjs | Chart.js | a93b3f45ac0e25bdda01d558acbffbe1d1e36e24.json | Fix helpers, layoutService and logarithmic tests | test/core.helpers.tests.js | @@ -6,7 +6,7 @@ describe('Core helper tests', function() {
helpers = window.Chart.helpers;
});
- it('Should iterate over an array and pass the extra data to that function', function() {
+ it('should iterate over an array and pass the extra data to that function', function() {
var testData = [0, 9, "abc"];
var scope = {}; // fake out the scope and ensure that 'this' is the correct thing
@@ -33,7 +33,7 @@ describe('Core helper tests', function() {
expect(iterated.slice().reverse()).toEqual(testData);
});
- it('Should iterate over properties in an object', function() {
+ it('should iterate over properties in an object', function() {
var testData = {
myProp1: 'abc',
myProp2: 276,
@@ -59,7 +59,7 @@ describe('Core helper tests', function() {
}).not.toThrow();
});
- it('Should clone an object', function() {
+ it('should clone an object', function() {
var testData = {
myProp1: 'abc',
myProp2: ['a', 'b'],
@@ -98,7 +98,7 @@ describe('Core helper tests', function() {
});
});
- it('Should merge a normal config without scales', function() {
+ it('should merge a normal config without scales', function() {
var baseConfig = {
valueProp: 5,
arrayProp: [1, 2, 3, 4, 5, 6],
@@ -161,7 +161,7 @@ describe('Core helper tests', function() {
});
});
- it('Should merge scale configs', function() {
+ it('should merge scale configs', function() {
var baseConfig = {
scales: {
prop1: {
@@ -303,7 +303,7 @@ describe('Core helper tests', function() {
expect(helpers.findPreviousWhere(data, callback, 0)).toBe(undefined);
});
- it('Should get the correct sign', function() {
+ it('should get the correct sign', function() {
expect(helpers.sign(0)).toBe(0);
expect(helpers.sign(10)).toBe(1);
expect(helpers.sign(-5)).toBe(-1);
@@ -322,11 +322,12 @@ describe('Core helper tests', function() {
expect(helpers.almostEquals(1e30, 1e30 + Number.EPSILON, 2 * Number.EPSILON)).toBe(true);
});
- it('Should generate ids', function() {
- expect(helpers.uid()).toBe('chart-0');
- expect(helpers.uid()).toBe('chart-1');
- expect(helpers.uid()).toBe('chart-2');
- expect(helpers.uid()).toBe('chart-3');
+ it('should generate integer ids', function() {
+ var uid = helpers.uid();
+ expect(uid).toEqual(jasmine.any(Number));
+ expect(helpers.uid()).toBe(uid + 1);
+ expect(helpers.uid()).toBe(uid + 2);
+ expect(helpers.uid()).toBe(uid + 3);
});
it('should detect a number', function() { | true |
Other | chartjs | Chart.js | a93b3f45ac0e25bdda01d558acbffbe1d1e36e24.json | Fix helpers, layoutService and logarithmic tests | test/core.layoutService.tests.js | @@ -1,360 +1,244 @@
// Tests of the scale service
describe('Test the layout service', function() {
- it('should fit a simple chart with 2 scales', function() {
- var chartInstance = {
- boxes: [],
- };
-
- var xScaleID = 'xScale';
- var yScaleID = 'yScale';
- var mockData = {
- datasets: [{
- yAxisID: yScaleID,
- data: [10, 5, 0, 25, 78, -10]
- }],
- labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5']
- };
- var mockContext = window.createMockContext();
+ beforeEach(function() {
+ window.addDefaultMatchers(jasmine);
+ });
- var xScaleConfig = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('category'));
- var XConstructor = Chart.scaleService.getScaleConstructor('category');
- var xScale = new XConstructor({
- ctx: mockContext,
- options: xScaleConfig,
- chart: {
- data: mockData
- },
- id: xScaleID
- });
+ afterEach(function() {
+ window.releaseAllCharts();
+ });
- var yScaleConfig = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('linear'));
- var YConstructor = Chart.scaleService.getScaleConstructor('linear');
- var yScale = new YConstructor({
- ctx: mockContext,
- options: yScaleConfig,
- chart: {
- data: mockData
+ it('should fit a simple chart with 2 scales', function() {
+ var chart = window.acquireChart({
+ type: 'bar',
+ data: {
+ datasets: [
+ { data: [10, 5, 0, 25, 78, -10] }
+ ],
+ labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5', 'tick6']
},
- id: yScaleID
- });
-
- chartInstance.boxes.push(xScale);
- chartInstance.boxes.push(yScale);
-
- var canvasWidth = 250;
- var canvasHeight = 150;
- Chart.layoutService.update(chartInstance, canvasWidth, canvasHeight);
-
- expect(chartInstance.chartArea).toEqual({
- left: 50,
- right: 250,
- top: 0,
- bottom: 83.6977778440511,
- });
+ options: {
+ scales: {
+ xAxes: [{
+ id: 'xScale',
+ type: 'category'
+ }],
+ yAxes: [{
+ id: 'yScale',
+ type: 'linear'
+ }]
+ }
+ }
+ }, {
+ height: '150px',
+ width: '250px'
+ });
+
+ expect(chart.chartArea.bottom).toBeCloseToPixel(112);
+ expect(chart.chartArea.left).toBeCloseToPixel(41);
+ expect(chart.chartArea.right).toBeCloseToPixel(250);
+ expect(chart.chartArea.top).toBeCloseToPixel(32);
// Is xScale at the right spot
- expect(xScale.left).toBe(50);
- expect(xScale.right).toBe(250);
- expect(xScale.top).toBe(83.6977778440511);
- expect(xScale.bottom).toBe(150);
- expect(xScale.labelRotation).toBe(50);
+ expect(chart.scales.xScale.bottom).toBeCloseToPixel(150);
+ expect(chart.scales.xScale.left).toBeCloseToPixel(41);
+ expect(chart.scales.xScale.right).toBeCloseToPixel(250);
+ expect(chart.scales.xScale.top).toBeCloseToPixel(112);
+ expect(chart.scales.xScale.labelRotation).toBeCloseTo(25);
// Is yScale at the right spot
- expect(yScale.left).toBe(0);
- expect(yScale.right).toBe(50);
- expect(yScale.top).toBe(0);
- expect(yScale.bottom).toBe(83.6977778440511);
+ expect(chart.scales.yScale.bottom).toBeCloseToPixel(112);
+ expect(chart.scales.yScale.left).toBeCloseToPixel(0);
+ expect(chart.scales.yScale.right).toBeCloseToPixel(41);
+ expect(chart.scales.yScale.top).toBeCloseToPixel(32);
+ expect(chart.scales.yScale.labelRotation).toBeCloseTo(0);
});
it('should fit scales that are in the top and right positions', function() {
- var chartInstance = {
- boxes: [],
- };
-
- var xScaleID = 'xScale';
- var yScaleID = 'yScale';
- var mockData = {
- datasets: [{
- yAxisID: yScaleID,
- data: [10, 5, 0, 25, 78, -10]
- }],
- labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5']
- };
- var mockContext = window.createMockContext();
-
- var xScaleConfig = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('category'));
- xScaleConfig.position = 'top';
- var XConstructor = Chart.scaleService.getScaleConstructor('category');
- var xScale = new XConstructor({
- ctx: mockContext,
- options: xScaleConfig,
- chart: {
- data: mockData
- },
- id: xScaleID
- });
-
- var yScaleConfig = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('linear'));
- yScaleConfig.position = 'right';
- var YConstructor = Chart.scaleService.getScaleConstructor('linear');
- var yScale = new YConstructor({
- ctx: mockContext,
- options: yScaleConfig,
- chart: {
- data: mockData
+ var chart = window.acquireChart({
+ type: 'bar',
+ data: {
+ datasets: [
+ { data: [10, 5, 0, 25, 78, -10] }
+ ],
+ labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5', 'tick6']
},
- id: yScaleID
- });
-
- chartInstance.boxes.push(xScale);
- chartInstance.boxes.push(yScale);
-
- var canvasWidth = 250;
- var canvasHeight = 150;
- Chart.layoutService.update(chartInstance, canvasWidth, canvasHeight);
-
- expect(chartInstance.chartArea).toEqual({
- left: 0,
- right: 200,
- top: 66.3022221559489,
- bottom: 150,
- });
+ options: {
+ scales: {
+ xAxes: [{
+ id: 'xScale',
+ type: 'category',
+ position: 'top'
+ }],
+ yAxes: [{
+ id: 'yScale',
+ type: 'linear',
+ position: 'right'
+ }]
+ }
+ }
+ }, {
+ height: '150px',
+ width: '250px'
+ });
+
+ expect(chart.chartArea.bottom).toBeCloseToPixel(150);
+ expect(chart.chartArea.left).toBeCloseToPixel(0);
+ expect(chart.chartArea.right).toBeCloseToPixel(209);
+ expect(chart.chartArea.top).toBeCloseToPixel(71);
// Is xScale at the right spot
- expect(xScale.left).toBe(0);
- expect(xScale.right).toBe(200);
- expect(xScale.top).toBe(0);
- expect(xScale.bottom).toBe(66.3022221559489);
- expect(xScale.labelRotation).toBe(50);
+ expect(chart.scales.xScale.bottom).toBeCloseToPixel(71);
+ expect(chart.scales.xScale.left).toBeCloseToPixel(0);
+ expect(chart.scales.xScale.right).toBeCloseToPixel(209);
+ expect(chart.scales.xScale.top).toBeCloseToPixel(32);
+ expect(chart.scales.xScale.labelRotation).toBeCloseTo(25);
// Is yScale at the right spot
- expect(yScale.left).toBe(200);
- expect(yScale.right).toBe(250);
- expect(yScale.top).toBe(66.3022221559489);
- expect(yScale.bottom).toBe(150);
+ expect(chart.scales.yScale.bottom).toBeCloseToPixel(150);
+ expect(chart.scales.yScale.left).toBeCloseToPixel(209);
+ expect(chart.scales.yScale.right).toBeCloseToPixel(250);
+ expect(chart.scales.yScale.top).toBeCloseToPixel(71);
+ expect(chart.scales.yScale.labelRotation).toBeCloseTo(0);
});
- it('should fit multiple axes in the same position', function() {
- var chartInstance = {
- boxes: [],
- };
-
- var xScaleID = 'xScale';
- var yScaleID1 = 'yScale1';
- var yScaleID2 = 'yScale2';
- var mockData = {
- datasets: [{
- yAxisID: yScaleID1,
- data: [10, 5, 0, 25, 78, -10]
- }, {
- yAxisID: yScaleID2,
- data: [-19, -20, 0, -99, -50, 0]
- }],
- labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5']
- };
- var mockContext = window.createMockContext();
+ it('should fit scales that overlap the chart area', function() {
+ var chart = window.acquireChart({
+ type: 'radar',
+ data: {
+ datasets: [{
+ data: [10, 5, 0, 25, 78, -10]
+ }, {
+ data: [-19, -20, 0, -99, -50, 0]
+ }],
+ labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5', 'tick6']
+ }
+ });
+
+ expect(chart.chartArea.bottom).toBeCloseToPixel(512);
+ expect(chart.chartArea.left).toBeCloseToPixel(0);
+ expect(chart.chartArea.right).toBeCloseToPixel(512);
+ expect(chart.chartArea.top).toBeCloseToPixel(32);
+
+ expect(chart.scale.bottom).toBeCloseToPixel(512);
+ expect(chart.scale.left).toBeCloseToPixel(0);
+ expect(chart.scale.right).toBeCloseToPixel(512);
+ expect(chart.scale.top).toBeCloseToPixel(32);
+ expect(chart.scale.width).toBeCloseToPixel(512);
+ expect(chart.scale.height).toBeCloseToPixel(480)
+ });
- var xScaleConfig = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('category'));
- var XConstructor = Chart.scaleService.getScaleConstructor('category');
- var xScale = new XConstructor({
- ctx: mockContext,
- options: xScaleConfig,
- chart: {
- data: mockData
+ it('should fit multiple axes in the same position', function() {
+ var chart = window.acquireChart({
+ type: 'bar',
+ data: {
+ datasets: [{
+ yAxisID: 'yScale1',
+ data: [10, 5, 0, 25, 78, -10]
+ }, {
+ yAxisID: 'yScale2',
+ data: [-19, -20, 0, -99, -50, 0]
+ }],
+ labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5', 'tick6']
},
- id: xScaleID
- });
-
- var yScaleConfig = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('linear'));
- var YConstructor = Chart.scaleService.getScaleConstructor('linear');
- var yScale1 = new YConstructor({
- ctx: mockContext,
- options: yScaleConfig,
- chart: {
- data: mockData
- },
- id: yScaleID1
- });
- var yScale2 = new YConstructor({
- ctx: mockContext,
- options: yScaleConfig,
- chart: {
- data: mockData
- },
- id: yScaleID2
- });
-
- chartInstance.boxes.push(xScale);
- chartInstance.boxes.push(yScale1);
- chartInstance.boxes.push(yScale2);
-
- var canvasWidth = 250;
- var canvasHeight = 150;
- Chart.layoutService.update(chartInstance, canvasWidth, canvasHeight);
-
- expect(chartInstance.chartArea).toEqual({
- left: 110,
- right: 250,
- top: 0,
- bottom: 83.6977778440511,
- });
+ options: {
+ scales: {
+ xAxes: [{
+ id: 'xScale',
+ type: 'category'
+ }],
+ yAxes: [{
+ id: 'yScale1',
+ type: 'linear'
+ }, {
+ id: 'yScale2',
+ type: 'linear'
+ }]
+ }
+ }
+ }, {
+ height: '150px',
+ width: '250px'
+ });
+
+ expect(chart.chartArea.bottom).toBeCloseToPixel(102);
+ expect(chart.chartArea.left).toBeCloseToPixel(86);
+ expect(chart.chartArea.right).toBeCloseToPixel(250);
+ expect(chart.chartArea.top).toBeCloseToPixel(32);
// Is xScale at the right spot
- expect(xScale.left).toBe(110);
- expect(xScale.right).toBe(250);
- expect(xScale.top).toBe(83.6977778440511);
- expect(xScale.bottom).toBe(150);
+ expect(chart.scales.xScale.bottom).toBeCloseToPixel(150);
+ expect(chart.scales.xScale.left).toBeCloseToPixel(86);
+ expect(chart.scales.xScale.right).toBeCloseToPixel(250);
+ expect(chart.scales.xScale.top).toBeCloseToPixel(103);
+ expect(chart.scales.xScale.labelRotation).toBeCloseTo(50);
// Are yScales at the right spot
- expect(yScale1.left).toBe(0);
- expect(yScale1.right).toBe(50);
- expect(yScale1.top).toBe(0);
- expect(yScale1.bottom).toBe(83.6977778440511);
-
- expect(yScale2.left).toBe(50);
- expect(yScale2.right).toBe(110);
- expect(yScale2.top).toBe(0);
- expect(yScale2.bottom).toBe(83.6977778440511);
- });
-
- // This is an oddball case. What happens is, when the scales are fit the first time they must fit within the assigned size. In this case,
- // the labels on the xScale need to rotate to fit. However, when the scales are fit again after the width of the left axis is determined,
- // the labels do not need to rotate. Previously, the chart was too small because the chartArea did not expand to take up the space freed up
- // due to the lack of label rotation
- it('should fit scales that overlap the chart area', function() {
- var chartInstance = {
- boxes: [],
- };
-
- var scaleID = 'scaleID';
- var mockData = {
- datasets: [{
- yAxisID: scaleID,
- data: [10, 5, 0, 25, 78, -10]
- }, {
- yAxisID: scaleID,
- data: [-19, -20, 0, -99, -50, 0]
- }],
- labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5']
- };
- var mockContext = window.createMockContext();
-
- var scaleConfig = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('radialLinear'));
- var ScaleConstructor = Chart.scaleService.getScaleConstructor('radialLinear');
- var scale = new ScaleConstructor({
- ctx: mockContext,
- options: scaleConfig,
- chart: {
- data: mockData
- },
- id: scaleID
- });
-
- chartInstance.boxes.push(scale);
-
- var canvasWidth = 300;
- var canvasHeight = 350;
- Chart.layoutService.update(chartInstance, canvasWidth, canvasHeight);
-
- expect(chartInstance.chartArea).toEqual({
- left: 0,
- right: 300,
- top: 0,
- bottom: 350,
- });
-
- expect(scale.left).toBe(0);
- expect(scale.right).toBe(300);
- expect(scale.top).toBe(0);
- expect(scale.bottom).toBe(350);
- expect(scale.width).toBe(300);
- expect(scale.height).toBe(350)
+ expect(chart.scales.yScale1.bottom).toBeCloseToPixel(102);
+ expect(chart.scales.yScale1.left).toBeCloseToPixel(0);
+ expect(chart.scales.yScale1.right).toBeCloseToPixel(41);
+ expect(chart.scales.yScale1.top).toBeCloseToPixel(32);
+ expect(chart.scales.yScale1.labelRotation).toBeCloseTo(0);
+
+ expect(chart.scales.yScale2.bottom).toBeCloseToPixel(102);
+ expect(chart.scales.yScale2.left).toBeCloseToPixel(41);
+ expect(chart.scales.yScale2.right).toBeCloseToPixel(86);
+ expect(chart.scales.yScale2.top).toBeCloseToPixel(32);
+ expect(chart.scales.yScale2.labelRotation).toBeCloseTo(0);
});
it ('should fix a full width box correctly', function() {
- var chartInstance = {
- boxes: [],
- };
-
- var xScaleID1= 'xScale1';
- var xScaleID2 = 'xScale2';
- var yScaleID = 'yScale2';
-
- var mockData = {
- datasets: [{
- xAxisID: xScaleID1,
- data: [10, 5, 0, 25, 78, -10]
- }, {
- xAxisID: xScaleID2,
- data: [-19, -20, 0, -99, -50, 0]
- }],
- labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5']
- };
- var mockContext = window.createMockContext();
-
- var xScaleConfig = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('category'));
- var XConstructor = Chart.scaleService.getScaleConstructor('category');
- var xScale1 = new XConstructor({
- ctx: mockContext,
- options: xScaleConfig,
- chart: {
- data: mockData
- },
- id: xScaleID1
- });
- var xScale2 = new XConstructor({
- ctx: mockContext,
- options: Chart.helpers.extend(Chart.helpers.clone(xScaleConfig), {
- position: 'top',
- fullWidth: true
- }),
- chart: {
- data: mockData,
+ var chart = window.acquireChart({
+ type: 'bar',
+ data: {
+ datasets: [{
+ xAxisID: 'xScale1',
+ data: [10, 5, 0, 25, 78, -10]
+ }, {
+ xAxisID: 'xScale2',
+ data: [-19, -20, 0, -99, -50, 0]
+ }],
+ labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5', 'tick6']
},
- id: xScaleID2
- });
-
- var yScaleConfig = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('linear'));
- var YConstructor = Chart.scaleService.getScaleConstructor('linear');
- var yScale = new YConstructor({
- ctx: mockContext,
- options: yScaleConfig,
- chart: {
- data: mockData
- },
- id: yScaleID
- });
-
- chartInstance.boxes.push(xScale1);
- chartInstance.boxes.push(xScale2);
- chartInstance.boxes.push(yScale);
-
- var canvasWidth = 250;
- var canvasHeight = 150;
- Chart.layoutService.update(chartInstance, canvasWidth, canvasHeight);
-
- expect(chartInstance.chartArea).toEqual({
- left: 60,
- right: 250,
- top: 54.495963211660246,
- bottom: 83.6977778440511
- });
+ options: {
+ scales: {
+ xAxes: [{
+ id: 'xScale1',
+ type: 'category'
+ }, {
+ id: 'xScale2',
+ type: 'category',
+ position: 'top',
+ fullWidth: true
+ }],
+ yAxes: [{
+ id: 'yScale',
+ type: 'linear'
+ }]
+ }
+ }
+ });
+
+ expect(chart.chartArea.bottom).toBeCloseToPixel(484);
+ expect(chart.chartArea.left).toBeCloseToPixel(45);
+ expect(chart.chartArea.right).toBeCloseToPixel(512);
+ expect(chart.chartArea.top).toBeCloseToPixel(60);
// Are xScales at the right spot
- expect(xScale1.left).toBe(60);
- expect(xScale1.right).toBe(250);
- expect(xScale1.top).toBeCloseTo(83.69, 1e-3);
- expect(xScale1.bottom).toBe(150);
+ expect(chart.scales.xScale1.bottom).toBeCloseToPixel(512);
+ expect(chart.scales.xScale1.left).toBeCloseToPixel(45);
+ expect(chart.scales.xScale1.right).toBeCloseToPixel(512);
+ expect(chart.scales.x1.top).toBeCloseToPixel(484);
- expect(xScale2.left).toBe(0);
- expect(xScale2.right).toBe(250);
- expect(xScale2.top).toBe(0);
- expect(xScale2.bottom).toBeCloseTo(54.49, 1e-3);
+ expect(chart.scales.xScale2.bottom).toBeCloseToPixel(28);
+ expect(chart.scales.xScale2.left).toBeCloseToPixel(0);
+ expect(chart.scales.xScale2.right).toBeCloseToPixel(512);
+ expect(chart.scales.xScale2.top).toBeCloseToPixel(0);
// Is yScale at the right spot
- expect(yScale.left).toBe(0);
- expect(yScale.right).toBe(60);
- expect(yScale.top).toBeCloseTo(54.49, 1e-3);
- expect(yScale.bottom).toBeCloseTo(83.69, 1e-3);
+ expect(chart.scales.yScale.bottom).toBeCloseToPixel(484);
+ expect(chart.scales.yScale.left).toBeCloseToPixel(0);
+ expect(chart.scales.yScale.right).toBeCloseToPixel(45);
+ expect(chart.scales.yScale.top).toBeCloseToPixel(60);
});
}); | true |
Other | chartjs | Chart.js | a93b3f45ac0e25bdda01d558acbffbe1d1e36e24.json | Fix helpers, layoutService and logarithmic tests | test/scale.logarithmic.tests.js | @@ -1,12 +1,20 @@
describe('Logarithmic Scale tests', function() {
- it('Should register the constructor with the scale service', function() {
+ beforeEach(function() {
+ window.addDefaultMatchers(jasmine);
+ });
+
+ afterEach(function() {
+ window.releaseAllCharts();
+ });
+
+ it('should register the constructor with the scale service', function() {
var Constructor = Chart.scaleService.getScaleConstructor('logarithmic');
expect(Constructor).not.toBe(undefined);
expect(typeof Constructor).toBe('function');
});
- it('Should have the correct default config', function() {
+ it('should have the correct default config', function() {
var defaultConfig = Chart.scaleService.getScaleDefaults('logarithmic');
expect(defaultConfig).toEqual({
display: true,
@@ -43,588 +51,512 @@ describe('Logarithmic Scale tests', function() {
expect(defaultConfig.ticks.callback).toEqual(jasmine.any(Function));
});
- it('Should correctly determine the max & min data values', function() {
- var scaleID = 'myScale';
-
- var mockData = {
- datasets: [{
- yAxisID: scaleID,
- data: [10, 5, 5000, 78, 450]
- }, {
- yAxisID: 'second scale',
- data: [1, 1000, 10, 100],
- }, {
- yAxisID: scaleID,
- data: [150]
- }]
- };
-
- var mockContext = window.createMockContext();
- var Constructor = Chart.scaleService.getScaleConstructor('logarithmic');
- var scale = new Constructor({
- ctx: mockContext,
- options: Chart.scaleService.getScaleDefaults('logarithmic'), // use default config for scale
- chart: {
- data: mockData,
+ it('should correctly determine the max & min data values', function() {
+ var chart = window.acquireChart({
+ type: 'bar',
+ data: {
+ datasets: [{
+ yAxisID: 'yScale0',
+ data: [42, 1000, 64, 100],
+ }, {
+ yAxisID: 'yScale1',
+ data: [10, 5, 5000, 78, 450]
+ }, {
+ yAxisID: 'yScale1',
+ data: [150]
+ }],
+ labels: ['a', 'b', 'c', 'd', 'e']
},
- id: scaleID
+ options: {
+ scales: {
+ yAxes: [{
+ id: 'yScale0',
+ type: 'logarithmic'
+ }, {
+ id: 'yScale1',
+ type: 'logarithmic'
+ }]
+ }
+ }
});
- expect(scale).not.toEqual(undefined); // must construct
- expect(scale.min).toBe(undefined); // not yet set
- expect(scale.max).toBe(undefined);
+ expect(chart.scales.yScale0).not.toEqual(undefined); // must construct
+ expect(chart.scales.yScale0.min).toBe(10);
+ expect(chart.scales.yScale0.max).toBe(1000);
- scale.update(400, 400);
- expect(scale.min).toBe(1);
- expect(scale.max).toBe(5000);
+ expect(chart.scales.yScale1).not.toEqual(undefined); // must construct
+ expect(chart.scales.yScale1.min).toBe(1);
+ expect(chart.scales.yScale1.max).toBe(5000);
});
- it('Should correctly determine the max & min of string data values', function() {
- var scaleID = 'myScale';
-
- var mockData = {
- datasets: [{
- yAxisID: scaleID,
- data: ['10', '5', '5000', '78', '450']
- }, {
- yAxisID: 'second scale',
- data: ['1', '1000', '10', '100'],
- }, {
- yAxisID: scaleID,
- data: ['150']
- }]
- };
-
- var mockContext = window.createMockContext();
- var Constructor = Chart.scaleService.getScaleConstructor('logarithmic');
- var scale = new Constructor({
- ctx: mockContext,
- options: Chart.scaleService.getScaleDefaults('logarithmic'), // use default config for scale
- chart: {
- data: mockData,
+ it('should correctly determine the max & min of string data values', function() {
+ var chart = window.acquireChart({
+ type: 'line',
+ data: {
+ datasets: [{
+ yAxisID: 'yScale0',
+ data: ['42', '1000', '64', '100'],
+ }, {
+ yAxisID: 'yScale1',
+ data: ['10', '5', '5000', '78', '450']
+ }, {
+ yAxisID: 'yScale1',
+ data: ['150']
+ }],
+ labels: ['a', 'b', 'c', 'd', 'e']
},
- id: scaleID
+ options: {
+ scales: {
+ yAxes: [{
+ id: 'yScale0',
+ type: 'logarithmic'
+ }, {
+ id: 'yScale1',
+ type: 'logarithmic'
+ }]
+ }
+ }
});
- expect(scale).not.toEqual(undefined); // must construct
- expect(scale.min).toBe(undefined); // not yet set
- expect(scale.max).toBe(undefined);
+ expect(chart.scales.yScale0).not.toEqual(undefined); // must construct
+ expect(chart.scales.yScale0.min).toBe(10);
+ expect(chart.scales.yScale0.max).toBe(1000);
- scale.update(400, 400);
- expect(scale.min).toBe(1);
- expect(scale.max).toBe(5000);
+ expect(chart.scales.yScale1).not.toEqual(undefined); // must construct
+ expect(chart.scales.yScale1.min).toBe(1);
+ expect(chart.scales.yScale1.max).toBe(5000);
});
- it('Should correctly determine the max & min data values when there are hidden datasets', function() {
- var scaleID = 'myScale';
-
- var mockData = {
- datasets: [{
- yAxisID: scaleID,
- data: [10, 5, 5000, 78, 450]
- }, {
- yAxisID: 'second scale',
- data: [1, 1000, 10, 100],
- }, {
- yAxisID: scaleID,
- data: [50000],
- hidden: true
- }]
- };
-
- var mockContext = window.createMockContext();
- var Constructor = Chart.scaleService.getScaleConstructor('logarithmic');
- var scale = new Constructor({
- ctx: mockContext,
- options: Chart.scaleService.getScaleDefaults('logarithmic'), // use default config for scale
- chart: {
- data: mockData
+ it('should correctly determine the max & min data values when there are hidden datasets', function() {
+ var chart = window.acquireChart({
+ type: 'line',
+ data: {
+ datasets: [{
+ yAxisID: 'yScale1',
+ data: [10, 5, 5000, 78, 450]
+ }, {
+ yAxisID: 'yScale0',
+ data: [42, 1000, 64, 100],
+ }, {
+ yAxisID: 'yScale1',
+ data: [50000],
+ hidden: true
+ }],
+ labels: ['a', 'b', 'c', 'd', 'e']
},
- id: scaleID
+ options: {
+ scales: {
+ yAxes: [{
+ id: 'yScale0',
+ type: 'logarithmic'
+ }, {
+ id: 'yScale1',
+ type: 'logarithmic'
+ }]
+ }
+ }
});
- expect(scale).not.toEqual(undefined); // must construct
- expect(scale.min).toBe(undefined); // not yet set
- expect(scale.max).toBe(undefined);
-
- scale.update(400, 400);
- expect(scale.min).toBe(1);
- expect(scale.max).toBe(5000);
+ expect(chart.scales.yScale1).not.toEqual(undefined); // must construct
+ expect(chart.scales.yScale1.min).toBe(1);
+ expect(chart.scales.yScale1.max).toBe(5000);
});
- it('Should correctly determine the max & min data values when there is NaN data', function() {
- var scaleID = 'myScale';
-
- var mockData = {
- datasets: [{
- yAxisID: scaleID,
- data: [undefined, 10, null, 5, 5000, NaN, 78, 450]
- }]
- };
-
- var mockContext = window.createMockContext();
- var options = Chart.scaleService.getScaleDefaults('logarithmic');
- var Constructor = Chart.scaleService.getScaleConstructor('logarithmic');
- var scale = new Constructor({
- ctx: mockContext,
- options: options, // use default config for scale
- chart: {
- data: mockData
+ it('should correctly determine the max & min data values when there is NaN data', function() {
+ var chart = window.acquireChart({
+ type: 'bar',
+ data: {
+ datasets: [{
+ data: [undefined, 10, null, 5, 5000, NaN, 78, 450]
+ }, {
+ data: [undefined, 28, null, 1000, 500, NaN, 50, 42]
+ }],
+ labels: ['a', 'b', 'c', 'd', 'e', 'f' ,'g']
},
- id: scaleID
+ options: {
+ scales: {
+ yAxes: [{
+ id: 'yScale',
+ type: 'logarithmic'
+ }]
+ }
+ }
});
- expect(scale).not.toEqual(undefined); // must construct
- expect(scale.min).toBe(undefined); // not yet set
- expect(scale.max).toBe(undefined);
-
- scale.update(400, 400);
- expect(scale.min).toBe(1);
- expect(scale.max).toBe(5000);
+ expect(chart.scales.yScale).not.toEqual(undefined); // must construct
+ expect(chart.scales.yScale.min).toBe(1);
+ expect(chart.scales.yScale.max).toBe(5000);
// Turn on stacked mode since it uses it's own
- options.stacked = true;
+ chart.options.scales.yAxes[0].stacked = true;
+ chart.update();
- scale.update(400, 400);
- expect(scale.min).toBe(1);
- expect(scale.max).toBe(5000);
+ expect(chart.scales.yScale.min).toBe(10);
+ expect(chart.scales.yScale.max).toBe(6000);
});
-
- it('Should correctly determine the max & min for scatter data', function() {
- var scaleID = 'myScale';
-
- var mockData = {
- datasets: [{
- xAxisID: scaleID, // for the horizontal scale
- yAxisID: scaleID,
- data: [{
- x: 10,
- y: 100
- }, {
- x: 2,
- y: 6
- }, {
- x: 65,
- y: 121
- }, {
- x: 99,
- y: 7
+ it('should correctly determine the max & min for scatter data', function() {
+ var chart = window.acquireChart({
+ type: 'line',
+ data: {
+ datasets: [{
+ data: [
+ { x: 10, y: 100 },
+ { x: 2, y: 6 },
+ { x: 65, y: 121 },
+ { x: 99, y: 7 }
+ ]
}]
- }]
- };
-
- var mockContext = window.createMockContext();
- var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('logarithmic'));
- var Constructor = Chart.scaleService.getScaleConstructor('logarithmic');
- var verticalScale = new Constructor({
- ctx: mockContext,
- options: config,
- chart: {
- data: mockData
},
- id: scaleID
+ options: {
+ scales: {
+ xAxes: [{
+ id: 'xScale',
+ type: 'logarithmic',
+ position: 'bottom'
+ }],
+ yAxes: [{
+ id: 'yScale',
+ type: 'logarithmic'
+ }]
+ }
+ }
});
- verticalScale.update(400, 400);
- expect(verticalScale.min).toBe(1);
- expect(verticalScale.max).toBe(200);
-
- var horizontalConfig = Chart.helpers.clone(config);
- horizontalConfig.position = 'bottom';
- var horizontalScale = new Constructor({
- ctx: mockContext,
- options: horizontalConfig,
- chart: {
- data: mockData
- },
- id: scaleID,
- });
+ expect(chart.scales.xScale.min).toBe(1);
+ expect(chart.scales.xScale.max).toBe(100);
- horizontalScale.update(400, 400);
- expect(horizontalScale.min).toBe(1);
- expect(horizontalScale.max).toBe(100);
+ expect(chart.scales.yScale.min).toBe(1);
+ expect(chart.scales.yScale.max).toBe(200);
});
- it('Should correctly determine the min and max data values when stacked mode is turned on', function() {
- var scaleID = 'myScale';
-
- var mockData = {
- datasets: [{
- yAxisID: scaleID,
- data: [10, 5, 1, 5, 78, 100],
- type: 'bar'
- }, {
- yAxisID: 'second scale',
- data: [-1000, 1000],
- }, {
- yAxisID: scaleID,
- data: [150, 10, 10, 100, 10, 9],
- type: 'bar'
- }, {
- yAxisID: scaleID,
- data: [100, 100, 100, 100, 100, 100],
- type: 'line'
- }]
- };
-
- var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('logarithmic'));
- config.stacked = true; // enable scale stacked mode
-
- var mockContext = window.createMockContext();
- var Constructor = Chart.scaleService.getScaleConstructor('logarithmic');
- var scale = new Constructor({
- ctx: mockContext,
- options: config,
- chart: {
- data: mockData
+ it('should correctly determine the min and max data values when stacked mode is turned on', function() {
+ var chart = window.acquireChart({
+ type: 'bar',
+ data: {
+ datasets: [{
+ type: 'bar',
+ yAxisID: 'yScale0',
+ data: [10, 5, 1, 5, 78, 100]
+ }, {
+ yAxisID: 'yScale1',
+ data: [-1000, 1000],
+ }, {
+ type: 'bar',
+ yAxisID: 'yScale0',
+ data: [150, 10, 10, 100, 10, 9]
+ }, {
+ type: 'line',
+ yAxisID: 'yScale0',
+ data: [100, 100, 100, 100, 100, 100]
+ }],
+ labels: ['a', 'b', 'c', 'd', 'e', 'f']
},
- id: scaleID
+ options: {
+ scales: {
+ yAxes: [{
+ id: 'yScale0',
+ type: 'logarithmic',
+ stacked: true
+ }, {
+ id: 'yScale1',
+ type: 'logarithmic'
+ }]
+ }
+ }
});
- scale.update(400, 400);
- expect(scale.min).toBe(10);
- expect(scale.max).toBe(200);
+ expect(chart.scales.yScale0.min).toBe(10);
+ expect(chart.scales.yScale0.max).toBe(200);
});
- it('Should correctly determine the min and max data values when stacked mode is turned on ignoring hidden datasets', function() {
- var scaleID = 'myScale';
-
- var mockData = {
- datasets: [{
- yAxisID: scaleID,
- data: [10, 5, 1, 5, 78, 100],
- type: 'bar'
- }, {
- yAxisID: 'second scale',
- data: [-1000, 1000],
- type: 'bar'
- }, {
- yAxisID: scaleID,
- data: [150, 10, 10, 100, 10, 9],
- type: 'bar'
- }, {
- yAxisID: scaleID,
- data: [10000, 10000, 10000, 10000, 10000, 10000],
- hidden: true,
- type: 'bar'
- }]
- };
-
- var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('logarithmic'));
- config.stacked = true; // enable scale stacked mode
-
- var mockContext = window.createMockContext();
- var Constructor = Chart.scaleService.getScaleConstructor('logarithmic');
- var scale = new Constructor({
- ctx: mockContext,
- options: config,
- chart: {
- data: mockData
+ it('should correctly determine the min and max data values when stacked mode is turned on ignoring hidden datasets', function() {
+ var chart = window.acquireChart({
+ type: 'bar',
+ data: {
+ datasets: [{
+ yAxisID: 'yScale0',
+ data: [10, 5, 1, 5, 78, 100],
+ type: 'bar'
+ }, {
+ yAxisID: 'yScale1',
+ data: [-1000, 1000],
+ type: 'bar'
+ }, {
+ yAxisID: 'yScale0',
+ data: [150, 10, 10, 100, 10, 9],
+ type: 'bar'
+ }, {
+ yAxisID: 'yScale0',
+ data: [10000, 10000, 10000, 10000, 10000, 10000],
+ hidden: true,
+ type: 'bar'
+ }],
+ labels: ['a', 'b', 'c', 'd', 'e', 'f']
},
- id: scaleID
+ options: {
+ scales: {
+ yAxes: [{
+ id: 'yScale0',
+ type: 'logarithmic',
+ stacked: true
+ }, {
+ id: 'yScale1',
+ type: 'logarithmic'
+ }]
+ }
+ }
});
- scale.update(400, 400);
- expect(scale.min).toBe(10);
- expect(scale.max).toBe(200);
+ expect(chart.scales.yScale0.min).toBe(10);
+ expect(chart.scales.yScale0.max).toBe(200);
});
- it('Should ensure that the scale has a max and min that are not equal', function() {
- var scaleID = 'myScale';
-
- var mockData = {
- datasets: []
- };
-
- var mockContext = window.createMockContext();
- var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('logarithmic'));
- var Constructor = Chart.scaleService.getScaleConstructor('logarithmic');
- var scale = new Constructor({
- ctx: mockContext,
- options: config,
- chart: {
- data: mockData
+ it('should ensure that the scale has a max and min that are not equal', function() {
+ var chart = window.acquireChart({
+ type: 'bar',
+ data: {
+ datasets: [{
+ data: []
+ }],
+ labels: []
},
- id: scaleID
+ options: {
+ scales: {
+ yAxes: [{
+ id: 'yScale',
+ type: 'logarithmic'
+ }]
+ }
+ }
});
- scale.update(400, 00);
- expect(scale.min).toBe(1);
- expect(scale.max).toBe(10);
+ expect(chart.scales.yScale.min).toBe(1);
+ expect(chart.scales.yScale.max).toBe(10);
- mockData.datasets = [{
- yAxisID: scaleID,
- data: [0.15, 0.15]
- }];
+ chart.data.datasets[0].data = [0.15, 0.15];
+ chart.update();
- scale.update(400, 400);
- expect(scale.min).toBe(0.01);
- expect(scale.max).toBe(1);
+ expect(chart.scales.yScale.min).toBe(0.01);
+ expect(chart.scales.yScale.max).toBe(1);
});
-
- it('Should use the min and max options', function() {
- var scaleID = 'myScale';
-
- var mockData = {
- datasets: [{
- yAxisID: scaleID,
- data: [1, 1, 1, 2, 1, 0]
- }]
- };
-
- var mockContext = window.createMockContext();
- var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('logarithmic'));
-
- config.ticks.min = 10;
- config.ticks.max = 1010;
-
- var Constructor = Chart.scaleService.getScaleConstructor('logarithmic');
- var scale = new Constructor({
- ctx: mockContext,
- options: config,
- chart: {
- data: mockData
+ it('should use the min and max options', function() {
+ var chart = window.acquireChart({
+ type: 'bar',
+ data: {
+ datasets: [{
+ data: [1, 1, 1, 2, 1, 0]
+ }],
+ labels: []
},
- id: scaleID
+ options: {
+ scales: {
+ yAxes: [{
+ id: 'yScale',
+ type: 'logarithmic',
+ ticks: {
+ min: 10,
+ max: 1010,
+ callback: function(value) {
+ return value;
+ }
+ }
+ }]
+ }
+ }
});
- scale.update(400, 00);
- scale.buildTicks();
- expect(scale.min).toBe(10);
- expect(scale.max).toBe(1010);
- expect(scale.ticks[0]).toBe(1010);
- expect(scale.ticks[scale.ticks.length - 1]).toBe(10);
+ var yScale = chart.scales.yScale;
+ var tickCount = yScale.ticks.length;
+ expect(yScale.min).toBe(10);
+ expect(yScale.max).toBe(1010);
+ expect(yScale.ticks[0]).toBe(1010);
+ expect(yScale.ticks[tickCount - 1]).toBe(10);
});
- it('Should generate tick marks', function() {
- var scaleID = 'myScale';
-
- var mockData = {
- datasets: [{
- yAxisID: scaleID,
- data: [10, 5, 1, 25, 78]
- }, ]
- };
-
- var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('logarithmic'));
- var Constructor = Chart.scaleService.getScaleConstructor('logarithmic');
- var scale = new Constructor({
- ctx: {},
- options: config,
- chart: {
- data: mockData
+ it('should generate tick marks', function() {
+ var chart = window.acquireChart({
+ type: 'bar',
+ data: {
+ datasets: [{
+ data: [10, 5, 1, 25, 78]
+ }],
+ labels: []
},
- id: scaleID
+ options: {
+ scales: {
+ yAxes: [{
+ id: 'yScale',
+ type: 'logarithmic',
+ ticks: {
+ callback: function(value) {
+ return value;
+ }
+ }
+ }]
+ }
+ }
});
- // Set arbitrary width and height for now
- scale.width = 50;
- scale.height = 400;
-
- scale.determineDataLimits();
- scale.buildTicks();
-
// Counts down because the lines are drawn top to bottom
- expect(scale.ticks).toEqual([80, 70, 60, 50, 40, 30, 20, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]);
- expect(scale.start).toBe(1);
- expect(scale.end).toBe(80);
+ expect(chart.scales.yScale).toEqual(jasmine.objectContaining({
+ ticks: [80, 70, 60, 50, 40, 30, 20, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],
+ start: 1,
+ end: 80
+ }));
});
- it('Should generate tick marks in the correct order in reversed mode', function() {
- var scaleID = 'myScale';
-
- var mockData = {
- datasets: [{
- yAxisID: scaleID,
- data: [10, 5, 1, 25, 78]
- }, ]
- };
-
- var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('logarithmic'));
- config.ticks.reverse = true;
-
- var Constructor = Chart.scaleService.getScaleConstructor('logarithmic');
- var scale = new Constructor({
- ctx: {},
- options: config,
- chart: {
- data: mockData
+ it('should generate tick marks in the correct order in reversed mode', function() {
+ var chart = window.acquireChart({
+ type: 'line',
+ data: {
+ datasets: [{
+ data: [10, 5, 1, 25, 78]
+ }],
+ labels: []
},
- id: scaleID
+ options: {
+ scales: {
+ yAxes: [{
+ id: 'yScale',
+ type: 'logarithmic',
+ ticks: {
+ reverse: true,
+ callback: function(value) {
+ return value;
+ }
+ }
+ }]
+ }
+ }
});
- // Set arbitrary width and height for now
- scale.width = 50;
- scale.height = 400;
-
- scale.determineDataLimits();
- scale.buildTicks();
-
// Counts down because the lines are drawn top to bottom
- expect(scale.ticks).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 60, 70, 80]);
- expect(scale.start).toBe(80);
- expect(scale.end).toBe(1);
+ expect(chart.scales.yScale).toEqual(jasmine.objectContaining({
+ ticks: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 60, 70, 80],
+ start: 80,
+ end: 1
+ }));
});
- it('Should build labels using the default template', function() {
- var scaleID = 'myScale';
-
- var mockData = {
- datasets: [{
- yAxisID: scaleID,
- data: [10, 5, 1, 25, 78]
- }, ]
- };
-
- var mockContext = window.createMockContext();
- var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('logarithmic'));
- var Constructor = Chart.scaleService.getScaleConstructor('logarithmic');
- var scale = new Constructor({
- ctx: mockContext,
- options: config,
- chart: {
- data: mockData
+ it('should build labels using the default template', function() {
+ var chart = window.acquireChart({
+ type: 'line',
+ data: {
+ datasets: [{
+ data: [10, 5, 1, 25, 78]
+ }],
+ labels: []
},
- id: scaleID
+ options: {
+ scales: {
+ yAxes: [{
+ id: 'yScale',
+ type: 'logarithmic'
+ }]
+ }
+ }
});
- scale.update(400, 400);
-
- expect(scale.ticks).toEqual(['8e+1', '', '', '5e+1', '', '', '2e+1', '1e+1', '', '', '', '', '5e+0', '', '', '2e+0', '1e+0']);
+ expect(chart.scales.yScale.ticks).toEqual(['8e+1', '', '', '5e+1', '', '', '2e+1', '1e+1', '', '', '', '', '5e+0', '', '', '2e+0', '1e+0']);
});
- it('Should build labels using the user supplied callback', function() {
- var scaleID = 'myScale';
-
- var mockData = {
- datasets: [{
- yAxisID: scaleID,
- data: [10, 5, 1, 25, 78]
- }, ]
- };
-
- var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('logarithmic'));
- config.ticks.userCallback = function(value, index) {
- return index.toString();
- };
-
- var mockContext = window.createMockContext();
- var Constructor = Chart.scaleService.getScaleConstructor('logarithmic');
- var scale = new Constructor({
- ctx: mockContext,
- options: config,
- chart: {
- data: mockData
+ it('should build labels using the user supplied callback', function() {
+ var chart = window.acquireChart({
+ type: 'bar',
+ data: {
+ datasets: [{
+ data: [10, 5, 1, 25, 78]
+ }],
+ labels: []
},
- id: scaleID
+ options: {
+ scales: {
+ yAxes: [{
+ id: 'yScale',
+ type: 'logarithmic',
+ ticks: {
+ callback: function(value, index) {
+ return index.toString();
+ }
+ }
+ }]
+ }
+ }
});
- scale.update(400, 400);
-
// Just the index
- expect(scale.ticks).toEqual(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16']);
+ expect(chart.scales.yScale.ticks).toEqual(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16']);
});
- it('Should correctly get the correct label for a data item', function() {
- var scaleID = 'myScale';
-
- var mockData = {
- datasets: [{
- yAxisID: scaleID,
- data: [10, 5, 5000, 78, 450]
- }, {
- yAxisID: 'second scale',
- data: [1, 1000, 10, 100],
- }, {
- yAxisID: scaleID,
- data: [150]
- }]
- };
-
- var mockContext = window.createMockContext();
- var Constructor = Chart.scaleService.getScaleConstructor('logarithmic');
- var scale = new Constructor({
- ctx: mockContext,
- options: Chart.scaleService.getScaleDefaults('logarithmic'), // use default config for scale
- chart: {
- data: mockData,
+ it('should correctly get the correct label for a data item', function() {
+ var chart = window.acquireChart({
+ type: 'bar',
+ data: {
+ datasets: [{
+ yAxisID: 'yScale0',
+ data: [10, 5, 5000, 78, 450]
+ }, {
+ yAxisID: 'yScale1',
+ data: [1, 1000, 10, 100],
+ }, {
+ yAxisID: 'yScale0',
+ data: [150]
+ }],
+ labels: []
},
- id: scaleID
+ options: {
+ scales: {
+ yAxes: [{
+ id: 'yScale0',
+ type: 'logarithmic'
+ }, {
+ id: 'yScale1',
+ type: 'logarithmic'
+ }]
+ }
+ }
});
- scale.update(400, 400);
-
- expect(scale.getLabelForIndex(0, 2)).toBe(150);
+ expect(chart.scales.yScale1.getLabelForIndex(0, 2)).toBe(150);
});
- it('Should get the correct pixel value for a point', function() {
- var scaleID = 'myScale';
-
- var mockData = {
- datasets: [{
- xAxisID: scaleID, // for the horizontal scale
- yAxisID: scaleID,
- data: [10, 5, 1, 25, 78]
- }]
- };
-
- var mockContext = window.createMockContext();
- var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('logarithmic'));
- var Constructor = Chart.scaleService.getScaleConstructor('logarithmic');
- var verticalScale = new Constructor({
- ctx: mockContext,
- options: config,
- chart: {
- data: mockData
- },
- id: scaleID
- });
-
- verticalScale.update(50, 100);
-
- // Fake out positioning of the scale service
- verticalScale.left = 0;
- verticalScale.top = 0;
- verticalScale.right = 50;
- verticalScale.bottom = 110;
- verticalScale.paddingTop = 5;
- verticalScale.paddingBottom = 5;
- verticalScale.width = 50;
- verticalScale.height = 110;
-
- expect(verticalScale.getPixelForValue(80, 0, 0)).toBe(5); // top + paddingTop
- expect(verticalScale.getPixelForValue(1, 0, 0)).toBe(105); // bottom - paddingBottom
- expect(verticalScale.getPixelForValue(10, 0, 0)).toBeCloseTo(52.4, 1e-4); // halfway
- expect(verticalScale.getPixelForValue(0, 0, 0)).toBe(5); // 0 is invalid. force it on top
-
- var horizontalConfig = Chart.helpers.clone(config);
- horizontalConfig.position = 'bottom';
- var horizontalScale = new Constructor({
- ctx: mockContext,
- options: horizontalConfig,
- chart: {
- data: mockData
+ it('should get the correct pixel value for a point', function() {
+ var chart = window.acquireChart({
+ type: 'bar',
+ data: {
+ datasets: [{
+ xAxisID: 'xScale', // for the horizontal scale
+ yAxisID: 'yScale',
+ data: [10, 5, 1, 25, 78]
+ }],
+ labels: []
},
- id: scaleID,
+ options: {
+ scales: {
+ yAxes: [{
+ id: 'xScale',
+ type: 'logarithmic',
+ position: 'bottom'
+ }, {
+ id: 'yScale',
+ type: 'logarithmic'
+ }]
+ }
+ }
});
- horizontalScale.update(100, 50);
-
- // Fake out positioning of the scale service
- horizontalScale.left = 0;
- horizontalScale.top = 0;
- horizontalScale.right = 110;
- horizontalScale.bottom = 50;
- horizontalScale.paddingLeft = 5;
- horizontalScale.paddingRight = 5;
- horizontalScale.width = 110;
- horizontalScale.height = 50;
-
- expect(horizontalScale.getPixelForValue(80, 0, 0)).toBe(105); // right - paddingRight
- expect(horizontalScale.getPixelForValue(1, 0, 0)).toBe(5); // left + paddingLeft
- expect(horizontalScale.getPixelForValue(10, 0, 0)).toBeCloseTo(57.5, 1e-4); // halfway
- expect(horizontalScale.getPixelForValue(0, 0, 0)).toBe(5); // 0 is invalid, put it on the left.
+ var xScale = chart.scales.xScale;
+ expect(xScale.getPixelForValue(80, 0, 0)).toBeCloseToPixel(495); // right - paddingRight
+ expect(xScale.getPixelForValue( 1, 0, 0)).toBeCloseToPixel(48); // left + paddingLeft
+ expect(xScale.getPixelForValue(10, 0, 0)).toBeCloseToPixel(283); // halfway
+ expect(xScale.getPixelForValue( 0, 0, 0)).toBeCloseToPixel(48); // 0 is invalid, put it on the left.
+
+ var yScale = chart.scales.yScale;
+ expect(yScale.getPixelForValue(80, 0, 0)).toBeCloseToPixel(32); // top + paddingTop
+ expect(yScale.getPixelForValue( 1, 0, 0)).toBeCloseToPixel(456); // bottom - paddingBottom
+ expect(yScale.getPixelForValue(10, 0, 0)).toBeCloseToPixel(234); // halfway
+ expect(yScale.getPixelForValue( 0, 0, 0)).toBeCloseToPixel(32); // 0 is invalid. force it on top
});
}); | true |
Other | chartjs | Chart.js | aa0933e040b456e23557a999408f6047578e631c.json | Avoid meta data access in calculateCircumference
Fix access of uninitialized meta data while calculating circumference in the polar area chart by caching the number of visible elements in the update() method. Also make the calculateTotal() of the doughnut chart tolerant of uninitialized meta data. | src/controllers/controller.doughnut.js | @@ -265,11 +265,14 @@ module.exports = function(Chart) {
},
calculateTotal: function() {
+ var dataset = this.getDataset();
var meta = this.getMeta();
var total = 0;
+ var value;
- this.getDataset().data.forEach(function(value, index) {
- if (!isNaN(value) && !meta.data[index].hidden) {
+ helpers.each(meta.data, function(element, index) {
+ value = dataset.data[index];
+ if (!isNaN(value) && !element.hidden) {
total += Math.abs(value);
}
}); | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.