},
options: {
scales: {
- yAxes: [{
+ y: {
beginAtZero: true
- }]
+ }
}
}
});
| `padding` | `number` | `0` | Padding between the tick label and the axis. When set on a vertical axis, this applies in the horizontal (X) direction. When set on a horizontal axis, this applies in the vertical (Y) direction.
### Axis ID
-The properties `dataset.xAxisID` or `dataset.yAxisID` have to match the scale properties `scales.xAxes.id` or `scales.yAxes.id`. This is especially needed if multi-axes charts are used.
+
+The properties `dataset.xAxisID` or `dataset.yAxisID` have to match to `scales` property. This is especially needed if multi-axes charts are used.
```javascript
var myChart = new Chart(ctx, {
},
options: {
scales: {
- yAxes: [{
- id: 'first-y-axis',
+ 'first-y-axis': {
type: 'linear'
- }, {
- id: 'second-y-axis',
+ },
+ 'second-y-axis': {
type: 'linear'
}]
}
},
options: {
scales: {
- yAxes: [{
- id: 'left-y-axis',
+ 'left-y-axis': {
type: 'linear',
position: 'left'
- }, {
- id: 'right-y-axis',
+ },
+ 'right-y-axis': {
type: 'linear',
position: 'right'
}]
data: ...
options: {
scales: {
- xAxes: [{
+ x: {
type: 'category',
labels: ['January', 'February', 'March', 'April', 'May', 'June']
- }]
+ }
}
}
});
},
options: {
scales: {
- xAxes: [{
+ x: {
min: 'March'
- }]
+ }
}
}
});
},
options: {
scales: {
- yAxes: [{
+ y: {
suggestedMin: 50,
suggestedMax: 100
- }]
+ }
}
}
});
```javascript
let options = {
scales: {
- yAxes: [{
+ y: {
max: 5,
min: 0,
ticks: {
stepSize: 0.5
}
- }]
+ }
}
};
```
data: data,
options: {
scales: {
- xAxes: [{
+ x: {
type: 'time',
time: {
unit: 'month'
}
- }]
+ }
}
}
});
```
### Display Formats
+
The following display formats are used to configure how different time units are formed into strings for the axis tick marks. See [Moment.js](https://momentjs.com/docs/#/displaying/format/) for the allowable format strings.
Name | Default | Example
data: data,
options: {
scales: {
- xAxes: [{
+ x: {
type: 'time',
time: {
displayFormats: {
quarter: 'MMM YYYY'
}
}
- }]
+ }
}
}
});
data: data,
options: {
scales: {
- xAxes: [{
+ x: {
type: 'time',
distribution: 'series'
- }]
+ }
}
}
});
data: data,
options: {
scales: {
- yAxes: [{
+ y: {
ticks: {
// Include a dollar sign in the ticks
callback: function(value, index, values) {
return '$' + value;
}
}
- }]
+ }
}
}
});
},
"options": {
"scales": {
- "yAxes": [{
+ "y": {
"beginAtZero": true
- }]
+ }
}
}
}
}]
};
```
+
### barThickness
+
If this value is a number, it is applied to the width of each bar, in pixels. When this is enforced, `barPercentage` and `categoryPercentage` are ignored.
If set to `'flex'`, the base sample widths are calculated automatically based on the previous and following samples so that they take the full available widths without overlap. Then, bars are sized using `barPercentage` and `categoryPercentage`. There is no gap when the percentage options are 1. This mode generates bars with different widths when data are not evenly spaced.
If not set (default), the base sample widths are calculated using the smallest interval that prevents bar overlapping, and bars are sized using `barPercentage` and `categoryPercentage`. This mode always generates bars equally sized.
## Scale Configuration
+
The bar chart sets unique default values for the following configuration from the associated `scale` options:
| Name | Type | Default | Description
```javascript
options = {
scales: {
- xAxes: [{
+ x: {
gridLines: {
offsetGridLines: true
}
- }]
+ }
}
};
```
### offsetGridLines
+
If true, the bars for a particular data point fall between the grid lines. The grid line will move to the left by one half of the tick interval, which is the space between the grid lines. If false, the grid line will go right down the middle of the bars. This is set to true for a category scale in a bar chart while false for other scales or chart types by default.
## Default Options
data: data,
options: {
scales: {
- xAxes: [{
+ x: {
stacked: true
- }],
- yAxes: [{
+ },
+ y: {
stacked: true
- }]
+ }
}
}
});
| `stack` | `string` | The ID of the group to which this dataset belongs to (when stacked, each group will be a separate stack).
## Horizontal Bar Chart
+
A horizontal bar chart is a variation on a vertical bar chart. It is sometimes used to show trend data, and the comparison of multiple data sets side by side.
{% chartjs %}
{
},
"options": {
"scales": {
- "xAxes": [{
+ "x": {
"beginAtZero": true
- }]
+ }
}
}
}
data: data,
options: {
scales: {
- yAxes: [{
+ y: {
stacked: true
- }]
+ }
}
}
});
},
"options": {
"scales": {
- "yAxes": [{
+ "y": {
"beginAtZero": true
- }]
+ }
}
}
}
},
options: {
scales: {
- xAxes: [{
+ x: {
type: 'linear',
position: 'bottom'
- }]
+ }
}
}
});
type: 'line',
options: {
scales: {
- yAxes: [{
+ y: {
type: 'myScale' // this is the same key that was passed to the registerScaleType function
- }]
+ }
}
}
});
text: 'Chart.js'
},
scales: {
- xAxes: [{
+ x: {
display: true
- }],
- yAxes: [{
+ },
+ y: {
display: true
- }]
+ }
}
};
chart.update();
```javascript
function updateScales(chart) {
- var xScale = chart.scales['x-axis-0'];
- var yScale = chart.scales['y-axis-0'];
+ var xScale = chart.scales.x;
+ var yScale = chart.scales.y;
chart.options.scales = {
- xAxes: [{
- id: 'newId',
+ newId: {
display: true
- }],
- yAxes: [{
+ },
+ y: {
display: true,
type: 'logarithmic'
- }]
+ }
};
chart.update();
// need to update the reference
- xScale = chart.scales['newId'];
- yScale = chart.scales['y-axis-0'];
+ xScale = chart.scales.newId;
+ yScale = chart.scales.y;
}
```
-You can also update a specific scale either by specifying its index or id.
+You can also update a specific scale either by its id.
```javascript
function updateScale(chart) {
- chart.options.scales.yAxes[0] = {
+ chart.options.scales.y = {
type: 'logarithmic'
};
chart.update();
},
options: {
scales: {
- yAxes: [{
+ y: {
beginAtZero: true
- }]
+ }
}
}
});
### Options
* The dataset option `tension` was renamed to `lineTension`
+* `scales.[x/y]Axes` arrays were removed. Scales are now configured directly to `options.scales` object with the object key being the scale Id.
* `scales.[x/y]Axes.barPercentage` was moved to dataset option `barPercentage`
* `scales.[x/y]Axes.barThickness` was moved to dataset option `barThickness`
* `scales.[x/y]Axes.categoryPercentage` was moved to dataset option `categoryPercentage`
* `scales.[x/y]Axes.minBarLength` was moved to dataset option `minBarLength`
* `scales.[x/y]Axes.maxBarThickness` was moved to dataset option `maxBarThickness`
-* `scales.[x/y]Axes.ticks.beginAtZero` was renamed to `scales.[x/y]Axes.beginAtZero`
-* `scales.[x/y]Axes.ticks.max` was renamed to `scales.[x/y]Axes.max`
-* `scales.[x/y]Axes.ticks.min` was renamed to `scales.[x/y]Axes.min`
-* `scales.[x/y]Axes.ticks.reverse` was renamed to `scales.[x/y]Axes.reverse`
-* `scales.[x/y]Axes.ticks.suggestedMax` was renamed to `scales.[x/y]Axes.suggestedMax`
-* `scales.[x/y]Axes.ticks.suggestedMin` was renamed to `scales.[x/y]Axes.suggestedMin`
-* `scales.[x/y]Axes.time.format` was renamed to `scales.[x/y]Axes.time.parser`
-* `scales.[x/y]Axes.time.max` was renamed to `scales.[x/y]Axes.max`
-* `scales.[x/y]Axes.time.min` was renamed to `scales.[x/y]Axes.min`
+* `scales.[x/y]Axes.ticks.beginAtZero` was renamed to `scales[id].beginAtZero`
+* `scales.[x/y]Axes.ticks.max` was renamed to `scales[id].max`
+* `scales.[x/y]Axes.ticks.min` was renamed to `scales[id].min`
+* `scales.[x/y]Axes.ticks.reverse` was renamed to `scales[id].reverse`
+* `scales.[x/y]Axes.ticks.suggestedMax` was renamed to `scales[id].suggestedMax`
+* `scales.[x/y]Axes.ticks.suggestedMin` was renamed to `scales[id].suggestedMin`
+* `scales.[x/y]Axes.time.format` was renamed to `scales[id].time.parser`
+* `scales.[x/y]Axes.time.max` was renamed to `scales[id].max`
+* `scales.[x/y]Axes.time.min` was renamed to `scales[id].min`
## Developer migration
}
},
scales: {
- xAxes: [{
+ x: {
ticks: {
autoSkip: false,
maxRotation: 0
}
- }]
+ }
}
};
}
},
scales: {
- yAxes: [{
- stacked: true
- }]
+ y: {
+ stacked: true,
+ }
},
plugins: {
filler: {
mode: 'index'
},
scales: {
- xAxes: [{
+ x: {
scaleLabel: {
display: true,
labelString: 'Month'
}
- }],
- yAxes: [{
+ },
+ y: {
stacked: true,
scaleLabel: {
display: true,
labelString: 'Value'
}
- }]
+ }
}
}
};
window.chartColors.purple,
window.chartColors.red
],
- yAxisID: 'y-axis-1',
+ yAxisID: 'y',
data: [
randomScalingFactor(),
randomScalingFactor(),
}, {
label: 'Dataset 2',
backgroundColor: window.chartColors.grey,
- yAxisID: 'y-axis-2',
+ yAxisID: 'y1',
data: [
randomScalingFactor(),
randomScalingFactor(),
intersect: true
},
scales: {
- yAxes: [{
- type: 'linear', // only linear but allow scale type registration. This allows extensions to exist solely for log scale for instance
+ y: {
+ type: 'linear',
display: true,
position: 'left',
- id: 'y-axis-1',
- }, {
- type: 'linear', // only linear but allow scale type registration. This allows extensions to exist solely for log scale for instance
+ },
+ y1: {
+ type: 'linear',
display: true,
position: 'right',
- id: 'y-axis-2',
gridLines: {
drawOnChartArea: false
}
- }],
+ },
}
}
});
},
responsive: true,
scales: {
- xAxes: [{
+ x: {
stacked: true,
- }],
- yAxes: [{
+ },
+ y: {
stacked: true
- }]
+ }
}
}
});
},
responsive: true,
scales: {
- xAxes: [{
+ x: {
stacked: true,
- }],
- yAxes: [{
+ },
+ y: {
stacked: true
- }]
+ }
}
}
});
intersect: true
},
scales: {
- xAxes: [{
+ x: {
display: true,
scaleLabel: {
display: true,
labelString: 'Month'
}
- }],
- yAxes: [{
+ },
+ y: {
display: true,
scaleLabel: {
display: true,
labelString: 'Value'
}
- }]
+ }
}
}
};
mode: 'index'
},
scales: {
- xAxes: [{
+ x: {
display: true,
scaleLabel: {
display: true
}
- }],
- yAxes: [{
+ },
+ y: {
display: true,
scaleLabel: {
display: true,
labelString: 'Value'
},
suggestedMin: -10,
- suggestedMax: 200,
- }]
+ suggestedMax: 200
+ }
}
}
};
intersect: true
},
scales: {
- xAxes: [{
+ x: {
display: true,
scaleLabel: {
display: true,
labelString: 'Month'
}
- }],
- yAxes: [{
+ },
+ y: {
display: true,
scaleLabel: {
display: true,
labelString: 'Value'
}
- }]
+ }
}
}
};
randomScalingFactor(),
randomScalingFactor()
],
- yAxisID: 'y-axis-1',
+ yAxisID: 'y',
}, {
label: 'My Second dataset',
borderColor: window.chartColors.blue,
randomScalingFactor(),
randomScalingFactor()
],
- yAxisID: 'y-axis-2'
+ yAxisID: 'y1'
}]
};
text: 'Chart.js Line Chart - Multi Axis'
},
scales: {
- yAxes: [{
+ y: {
type: 'linear', // only linear but allow scale type registration. This allows extensions to exist solely for log scale for instance
display: true,
position: 'left',
- id: 'y-axis-1',
- }, {
+ },
+ y1: {
type: 'linear', // only linear but allow scale type registration. This allows extensions to exist solely for log scale for instance
display: true,
position: 'right',
- id: 'y-axis-2',
// grid line settings
gridLines: {
drawOnChartArea: false, // only want the grid lines for one axis to show up
},
- }],
+ },
}
}
});
mode: 'index'
},
scales: {
- xAxes: [{
+ x: {
display: true,
scaleLabel: {
display: true,
labelString: 'Month'
}
- }],
- yAxes: [{
+ },
+ y: {
display: true,
scaleLabel: {
display: true,
labelString: 'Value'
}
- }]
+ }
},
title: {
display: true,
mode: 'index'
},
scales: {
- xAxes: [{
+ x: {
display: true,
scaleLabel: {
display: true,
labelString: 'Month'
}
- }],
- yAxes: [{
+ },
+ y: {
display: true,
scaleLabel: {
display: true,
labelString: 'Value'
},
- }]
+ }
}
}
};
var scatterChartData = {
datasets: [{
label: 'My First dataset',
- xAxisID: 'x-axis-1',
- yAxisID: 'y-axis-1',
+ xAxisID: 'x',
+ yAxisID: 'y',
borderColor: window.chartColors.red,
backgroundColor: color(window.chartColors.red).alpha(0.2).rgbString(),
data: [{
}]
}, {
label: 'My Second dataset',
- xAxisID: 'x-axis-1',
- yAxisID: 'y-axis-2',
+ xAxisID: 'x',
+ yAxisID: 'y2',
borderColor: window.chartColors.blue,
backgroundColor: color(window.chartColors.blue).alpha(0.2).rgbString(),
data: [{
text: 'Chart.js Scatter Chart - Multi Axis'
},
scales: {
- xAxes: [{
+ x: {
position: 'bottom',
- }],
- yAxes: [{
+ },
+ y: {
type: 'linear', // only linear but allow scale type registration. This allows extensions to exist solely for log scale for instance
display: true,
- position: 'left',
- id: 'y-axis-1',
- }, {
+ position: 'left'
+ },
+ y2: {
type: 'linear', // only linear but allow scale type registration. This allows extensions to exist solely for log scale for instance
display: true,
position: 'right',
reverse: true,
- id: 'y-axis-2',
// grid line settings
gridLines: {
drawOnChartArea: false, // only want the grid lines for one axis to show up
- },
- }],
+ }
+ }
}
}
});
text: 'Chart.js Line Chart'
},
scales: {
- xAxes: [{
+ x: {
display: true,
scaleLabel: {
display: true,
labelString: 'Month'
}
- }],
- yAxes: [{
+ },
+ y: {
display: true,
scaleLabel: {
display: true,
labelString: 'Value'
}
- }]
+ }
}
}
};
}
},
scales: {
- xAxes: [{
+ x: {
display: true,
scaleLabel: {
display: true,
labelString: 'Month'
}
- }],
- yAxes: [{
+ },
+ y: {
display: true,
scaleLabel: {
display: true,
labelString: 'Value'
}
- }]
+ }
},
title: {
display: true,
position: legendPosition,
},
scales: {
- xAxes: [{
+ x: {
display: true,
scaleLabel: {
display: true,
labelString: 'Month'
}
- }],
- yAxes: [{
+ },
+ y: {
display: true,
scaleLabel: {
display: true,
labelString: 'Value'
}
- }]
+ }
},
title: {
display: true,
text: 'Chart.js Line Chart - X-Axis Filter'
},
scales: {
- xAxes: [{
+ x: {
display: true,
ticks: {
callback: function(dataLabel, index) {
return index % 2 === 0 ? dataLabel : '';
}
}
- }],
- yAxes: [{
+ },
+ y: {
display: true,
beginAtZero: false
- }]
+ }
}
}
};
text: title
},
scales: {
- xAxes: [{
+ x: {
gridLines: gridlines
- }],
- yAxes: [{
+ },
+ y: {
gridLines: gridlines,
min: 0,
max: 100,
ticks: {
stepSize: 10
}
- }]
+ }
}
}
};
text: 'Grid Line Settings'
},
scales: {
- yAxes: [{
+ y: {
gridLines: {
drawBorder: false,
color: ['pink', 'red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'purple']
ticks: {
stepSize: 10
}
- }]
+ }
}
}
};
text: 'Min and Max Settings'
},
scales: {
- yAxes: [{
+ y: {
// the data minimum used for determining the ticks is Math.min(dataMin, suggestedMin)
suggestedMin: 10,
// the data maximum used for determining the ticks is Math.max(dataMax, suggestedMax)
suggestedMax: 50
- }]
+ }
}
}
};
text: 'Min and Max Settings'
},
scales: {
- yAxes: [{
+ y: {
min: 10,
max: 50
- }]
+ }
}
}
};
intersect: true
},
scales: {
- xAxes: [{
+ x: {
display: true,
scaleLabel: {
display: true,
labelString: 'Month'
}
- }],
- yAxes: [{
+ },
+ y: {
display: true,
scaleLabel: {
display: true,
// forces step size to be 5 units
stepSize: 5
}
- }]
+ }
}
}
};
text: 'Chart.js Line Chart - Logarithmic'
},
scales: {
- xAxes: [{
+ x: {
display: true,
- }],
- yAxes: [{
+ },
+ y: {
display: true,
type: 'logarithmic',
- }]
+ }
}
}
};
text: 'Chart.js Scatter Chart - Logarithmic X-Axis'
},
scales: {
- xAxes: [{
+ x: {
type: 'logarithmic',
position: 'bottom',
ticks: {
labelString: 'Frequency',
display: true,
}
- }],
- yAxes: [{
+ },
+ y: {
type: 'linear',
ticks: {
userCallback: function(tick) {
labelString: 'Voltage',
display: true
}
- }]
+ }
}
}
});
text: 'Chart with Non Numeric Y Axis'
},
scales: {
- xAxes: [{
+ x: {
display: true,
scaleLabel: {
display: true,
labelString: 'Month'
}
- }],
- yAxes: [{
+ },
+ y: {
type: 'category',
position: 'left',
display: true,
labelString: 'Request State'
},
reverse: true
- }]
+ }
}
}
};
text: 'Chart.js Combo Time Scale'
},
scales: {
- xAxes: [{
+ x: {
type: 'time',
display: true,
offset: true,
time: {
unit: 'day'
}
- }],
+ },
},
}
};
duration: 0
},
scales: {
- xAxes: [{
+ x: {
type: 'time',
distribution: 'series',
offset: true,
lastMajor = currMajor;
}
}
- }],
- yAxes: [{
+ },
+ y: {
+ type: 'linear',
gridLines: {
drawBorder: false
},
display: true,
labelString: 'Closing price ($)'
}
- }]
+ }
},
tooltips: {
intersect: false,
text: 'Chart.js Time Point Data'
},
scales: {
- xAxes: [{
+ x: {
type: 'time',
display: true,
scaleLabel: {
fontColor: '#FF0000'
}
}
- }],
- yAxes: [{
+ },
+ y: {
display: true,
scaleLabel: {
display: true,
labelString: 'value'
}
- }]
+ }
}
}
};
text: 'Chart.js Time Scale'
},
scales: {
- xAxes: [{
+ x: {
type: 'time',
time: {
parser: timeFormat,
display: true,
labelString: 'Date'
}
- }],
- yAxes: [{
+ },
+ y: {
scaleLabel: {
display: true,
labelString: 'value'
}
- }]
+ }
},
}
};
text: 'Chart.js Line Chart - ' + type
},
scales: {
- xAxes: [{
+ x: {
display: true,
- }],
- yAxes: [{
+ },
+ y: {
display: true,
type: type
- }]
+ }
}
}
};
document.getElementById('toggleScale').addEventListener('click', function() {
type = type === 'linear' ? 'logarithmic' : 'linear';
window.myLine.options.title.text = 'Chart.js Line Chart - ' + type;
- window.myLine.options.scales.yAxes[0] = {
+ window.myLine.options.scales.y = {
display: true,
type: type
};
intersect: true
},
scales: {
- xAxes: [{
+ x: {
display: true,
scaleLabel: {
show: true,
labelString: 'Month'
}
- }],
- yAxes: [{
+ },
+ y: {
display: true,
scaleLabel: {
show: true,
labelString: 'Value'
}
- }]
+ }
}
}
};
},
scales: {
- xAxes: [{
+ x: {
type: 'category',
offset: true,
gridLines: {
offsetGridLines: true
}
- }],
-
- yAxes: [{
- type: 'linear'
- }]
+ },
+ y: {
+ type: 'linear',
+ }
}
});
_parseObjectData: function(meta, data, start, count) {
const iScale = meta.iScale;
const vScale = meta.vScale;
- const vProp = vScale._getAxis();
+ const vProp = vScale.axis;
const parsed = [];
let i, ilen, item, obj, value;
for (i = start, ilen = start + count; i < ilen; ++i) {
obj = data[i];
item = {};
- item[iScale.id] = iScale._parseObject(obj, iScale._getAxis(), i);
+ item[iScale.id] = iScale._parseObject(obj, iScale.axis, i);
value = obj[vProp];
if (helpers.isArray(value)) {
parseFloatBar(value, item, vScale, i);
defaults._set('bubble', {
scales: {
- xAxes: [{
- type: 'linear', // bubble should probably use a linear scale by default
- position: 'bottom',
- id: 'x-axis-0' // need an ID so datasets can reference the scale
- }],
- yAxes: [{
+ x: {
type: 'linear',
- position: 'left',
- id: 'y-axis-0'
- }]
+ position: 'bottom'
+ },
+ y: {
+ type: 'linear',
+ position: 'left'
+ }
},
tooltips: {
},
scales: {
- xAxes: [{
+ x: {
type: 'linear',
position: 'bottom'
- }],
-
- yAxes: [{
+ },
+ y: {
type: 'category',
position: 'left',
offset: true,
gridLines: {
offsetGridLines: true
}
- }]
+ }
},
elements: {
},
scales: {
- xAxes: [{
+ x: {
type: 'category',
- id: 'x-axis-0'
- }],
- yAxes: [{
+ },
+ y: {
type: 'linear',
- id: 'y-axis-0'
- }]
+ },
}
});
var resolve = helpers.options.resolve;
defaults._set('polarArea', {
- scale: {
- type: 'radialLinear',
- angleLines: {
- display: false
- },
- beginAtZero: true,
- gridLines: {
- circular: true
- },
- pointLabels: {
- display: false
+ scales: {
+ r: {
+ type: 'radialLinear',
+ angleLines: {
+ display: false
+ },
+ beginAtZero: true,
+ gridLines: {
+ circular: true
+ },
+ pointLabels: {
+ display: false
+ }
}
},
* @private
*/
_getIndexScaleId: function() {
- return this.chart.scale.id;
+ return this._cachedMeta.rAxisID;
},
/**
* @private
*/
_getValueScaleId: function() {
- return this.chart.scale.id;
+ return this._cachedMeta.rAxisID;
},
update: function(reset) {
const dataset = me.getDataset();
const opts = chart.options;
const animationOpts = opts.animation;
- const scale = chart.scale;
+ const scale = chart.scales.r;
const centerX = scale.xCenter;
const centerY = scale.yCenter;
var i;
defaults._set('radar', {
spanGaps: false,
- scale: {
- type: 'radialLinear'
+ scales: {
+ r: {
+ type: 'radialLinear',
+ }
},
elements: {
line: {
* @private
*/
_getIndexScaleId: function() {
- return this.chart.scale.id;
+ return this._cachedMeta.rAxisID;
},
/**
* @private
*/
_getValueScaleId: function() {
- return this.chart.scale.id;
+ return this._cachedMeta.rAxisID;
},
/**
updateElements: function(points, start, count, reset) {
const me = this;
const dataset = me.getDataset();
- const scale = me.chart.scale;
+ const scale = me.chart.scales.r;
var i;
for (i = start; i < start + count; i++) {
defaults._set('scatter', {
scales: {
- xAxes: [{
- id: 'x-axis-1', // need an ID so datasets can reference the scale
- type: 'linear', // scatter should not use a category axis
+ x: {
+ type: 'linear',
position: 'bottom'
- }],
- yAxes: [{
- id: 'y-axis-1',
+ },
+ y: {
type: 'linear',
position: 'left'
- }]
+ }
},
tooltips: {
responsiveAnimationDuration: 0
});
-/**
- * Recursively merge the given config objects representing the `scales` option
- * by incorporating scale defaults in `xAxes` and `yAxes` array items, then
- * returns a deep copy of the result, thus doesn't alter inputs.
- */
-function mergeScaleConfig(/* config objects ... */) {
- return helpers.merge({}, [].slice.call(arguments), {
- merger: function(key, target, source, options) {
- if (key === 'xAxes' || key === 'yAxes') {
- var slen = source[key].length;
- var i, type, scale;
+function mergeScaleConfig(config, options) {
+ options = options || {};
+ const chartDefaults = defaults[config.type] || {scales: {}};
+ const configScales = options.scales || {};
+ const firstIDs = {};
+ const scales = {};
+
+ // First figure out first scale id's per axis.
+ // Note: for now, axis is determined from first letter of scale id!
+ Object.entries(configScales).forEach(([id, scale]) => {
+ const axis = id[0];
+ firstIDs[axis] = firstIDs[axis] || id;
+ scales[id] = helpers.mergeIf({}, [scale, chartDefaults.scales[axis]]);
+ });
- if (!target[key]) {
- target[key] = [];
- }
+ // Backward compatibility
+ if (options.scale) {
+ scales[options.scale.id || 'r'] = helpers.mergeIf({}, [options.scale, chartDefaults.scales.r]);
+ firstIDs.r = firstIDs.r || options.scale.id || 'r';
+ }
- for (i = 0; i < slen; ++i) {
- scale = source[key][i];
- type = valueOrDefault(scale.type, key === 'xAxes' ? 'category' : 'linear');
-
- 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], [scaleService.getScaleDefaults(type), scale]);
- } else {
- // scales type are the same
- helpers.merge(target[key][i], scale);
- }
- }
- } else {
- helpers._merger(key, target, source, options);
- }
- }
+ // Then merge dataset defaults to scale configs
+ config.data.datasets.forEach(dataset => {
+ const datasetDefaults = defaults[dataset.type || config.type] || {scales: {}};
+ Object.entries(datasetDefaults.scales || {}).forEach(([defaultID, defaultScaleOptions]) => {
+ const id = dataset[defaultID + 'AxisID'] || firstIDs[defaultID] || defaultID;
+ scales[id] = scales[id] || {};
+ helpers.mergeIf(scales[id], [
+ configScales[id],
+ defaultScaleOptions
+ ]);
+ });
});
+
+ // apply scale defaults, if not overridden by dataset defaults
+ Object.values(scales).forEach(scale => {
+ helpers.mergeIf(scale, scaleService.getScaleDefaults(scale.type));
+ });
+
+ return scales;
}
/**
function mergeConfig(/* config objects ... */) {
return helpers.merge({}, [].slice.call(arguments), {
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
- target[key] = mergeScaleConfig(tval, sval);
- } else if (key === 'scale') {
- // used in polar area & radar charts since there is only one scale
- target[key] = helpers.merge(tval, [scaleService.getScaleDefaults(sval.type), sval]);
- } else {
+ if (key !== 'scales' && key !== 'scale') {
helpers._merger(key, target, source, options);
}
}
// Do NOT use mergeConfig for the data object because this method merges arrays
// and so would change references to labels and datasets, preventing data updates.
- var data = config.data = config.data || {};
+ const data = config.data = config.data || {};
data.datasets = data.datasets || [];
data.labels = data.labels || [];
+ const scaleConfig = mergeScaleConfig(config, config.options);
+
config.options = mergeConfig(
defaults.global,
defaults[config.type],
config.options || {});
+ config.options.scales = scaleConfig;
+
return config;
}
layouts.removeBox(chart, scale);
});
+ const scaleConfig = mergeScaleConfig(chart.config, newOptions);
+
newOptions = mergeConfig(
defaults.global,
defaults[chart.config.type],
newOptions);
chart.options = chart.config.options = newOptions;
+ chart.options.scales = scaleConfig;
+
chart._animationsDisabled = isAnimationDisabled(newOptions);
chart.ensureScalesHaveIDs();
chart.buildOrUpdateScales();
chart.tooltip.initialize();
}
-function nextAvailableScaleId(axesOpts, prefix, index) {
- var id;
- var hasId = function(obj) {
- return obj.id === id;
- };
-
- do {
- id = prefix + index++;
- } while (helpers.findIndex(axesOpts, hasId) >= 0);
-
- return id;
-}
-
function positionIsHorizontal(position) {
return position === 'top' || position === 'bottom';
}
var scalesOptions = options.scales || {};
var scaleOptions = options.scale;
- helpers.each(scalesOptions.xAxes, function(xAxisOptions, index) {
- if (!xAxisOptions.id) {
- xAxisOptions.id = nextAvailableScaleId(scalesOptions.xAxes, 'x-axis-', index);
- }
- });
-
- helpers.each(scalesOptions.yAxes, function(yAxisOptions, index) {
- if (!yAxisOptions.id) {
- yAxisOptions.id = nextAvailableScaleId(scalesOptions.yAxes, 'y-axis-', index);
- }
+ helpers.each(scalesOptions, function(axisOptions, axisID) {
+ axisOptions.id = axisID;
});
if (scaleOptions) {
if (options.scales) {
items = items.concat(
- (options.scales.xAxes || []).map(function(xAxisOptions) {
- return {options: xAxisOptions, dtype: 'category', dposition: 'bottom'};
- }),
- (options.scales.yAxes || []).map(function(yAxisOptions) {
- return {options: yAxisOptions, dtype: 'linear', dposition: 'left'};
+ Object.entries(options.scales).map(function(entry) {
+ var axisID = entry[0];
+ var axisOptions = entry[1];
+ var isRadial = axisID.charAt(0).toLowerCase === 'r';
+ var isHorizontal = axisID.charAt(0).toLowerCase() === 'x';
+ return {
+ options: axisOptions,
+ dposition: isRadial ? 'chartArea' : isHorizontal ? 'bottom' : 'left',
+ dtype: isRadial ? 'radialLinear' : isHorizontal ? 'category' : 'linear'
+ };
})
);
}
- if (options.scale) {
- items.push({
- options: options.scale,
- dtype: 'radialLinear',
- isDefault: true,
- dposition: 'chartArea'
- });
- }
-
helpers.each(items, function(item) {
var scaleOptions = item.options;
var id = scaleOptions.id;
scales[scale.id] = scale;
}
+ scale.axis = scale.options.position === 'chartArea' ? 'r' : scale.isHorizontal() ? 'x' : 'y';
+
// parse min/max value, so we can properly determine min/max for other scales
scale._userMin = scale._parse(scale.options.min);
scale._userMax = scale._parse(scale.options.max);
return indexScale.id + '.' + valueScale.id + '.' + meta.stack + '.' + meta.type;
}
-function getFirstScaleId(chart, axis) {
- var scalesOpts = chart.options.scales;
- var scale = chart.options.scale;
- var scaleId = scale && scale.id;
- var prop = axis + 'Axes';
-
- return (scalesOpts && scalesOpts[prop] && scalesOpts[prop].length && scalesOpts[prop][0].id) || scaleId;
-}
-
function getUserBounds(scale) {
var {min, max, minDefined, maxDefined} = scale._getUserBounds();
return {
}
}
+function getFirstScaleId(chart, axis) {
+ const scales = chart.scales;
+ return Object.keys(scales).filter(key => {
+ return scales[key].axis === axis;
+ }).shift();
+}
+
// Base class for all dataset controllers (line, bar, etc)
var DatasetController = function(chart, datasetIndex) {
this.initialize(chart, datasetIndex);
const chart = me.chart;
const meta = me._cachedMeta;
const dataset = me.getDataset();
+
const xid = meta.xAxisID = dataset.xAxisID || getFirstScaleId(chart, 'x');
const yid = meta.yAxisID = dataset.yAxisID || getFirstScaleId(chart, 'y');
+ const rid = meta.rAxisID = dataset.rAxisID || getFirstScaleId(chart, 'r');
meta.xScale = me.getScaleForId(xid);
meta.yScale = me.getScaleForId(yid);
+ meta.rScale = me.getScaleForId(rid);
meta.iScale = me._getIndexScale();
meta.vScale = me._getValueScale();
},
}];
}
- /**
- * @private
- */
- _getAxis() {
- return this.isHorizontal() ? 'x' : 'y';
- }
-
/**
* Returns visible dataset metas that are attached to this scale
* @param {string} [type] - if specified, also filter by dataset type
_getMatchingVisibleMetas(type) {
var me = this;
var metas = me.chart._getSortedVisibleDatasetMetas();
- var axisID = me._getAxis() + 'AxisID';
+ var axisID = me.axis + 'AxisID';
var result = [];
var i, ilen, meta;
visible: chart.isDatasetVisible(i),
fill: decodeFill(el, i, count),
chart: chart,
- scale: meta.controller.getScaleForId(meta.yAxisID) || chart.scale,
+ scale: meta.yScale || meta.rScale,
el: el
};
}
}
},
scales: {
- xAxes: [{display: false}],
- yAxes: [{display: false}]
+ x: {display: false},
+ y: {display: false}
}
}
},
}
},
scales: {
- xAxes: [{display: false}],
- yAxes: [
- {
- display: false,
- beginAtZero: true
- }
- ]
+ x: {display: false},
+ y: {
+ display: false,
+ beginAtZero: true
+ }
}
}
},
}
},
scales: {
- xAxes: [{display: false}],
- yAxes: [{display: false}]
+ x: {display: false},
+ y: {display: false}
}
}
},
"legend": false,
"title": false,
"scales": {
- "xAxes": [{
+ "x": {
"type": "time",
"offset": true,
"display": false,
"ticks": {
"source": "labels"
}
- }],
- "yAxes": [{
+ },
+ "y": {
"display": false,
"beginAtZero": true
- }]
+ }
}
}
},
"legend": false,
"title": false,
"scales": {
- "xAxes": [{
+ "x": {
"type": "time",
"offset": true,
"display": false,
"ticks": {
"source": "labels"
}
- }],
- "yAxes": [{
+ },
+ "y": {
"display": false,
"beginAtZero": true
- }]
+ }
}
}
},
"legend": false,
"title": false,
"scales": {
- "xAxes": [{
+ "x": {
"type": "time",
"display": false,
+ "offset": false,
"time": {
"parser": "YYYY"
},
"ticks": {
"source": "labels"
}
- }],
- "yAxes": [{
+ },
+ "y": {
"display": false,
"beginAtZero": true
- }]
+ }
}
}
},
"legend": false,
"title": false,
"scales": {
- "xAxes": [{
+ "x": {
"type": "time",
"display": false,
+ "offset": false,
"time": {
"parser": "YYYY"
},
"ticks": {
"source": "labels"
}
- }],
- "yAxes": [{
+ },
+ "y": {
"display": false,
"beginAtZero": true
- }]
+ }
}
}
},
"legend": false,
"title": false,
"scales": {
- "xAxes": [{
+ "x": {
"type": "time",
"display": false,
+ "offset": false,
"time": {
"parser": "YYYY"
},
"ticks": {
"source": "labels"
}
- }],
- "yAxes": [{
+ },
+ "y": {
"display": false,
"beginAtZero": true
- }]
+ }
}
}
},
"legend": false,
"title": false,
"scales": {
- "xAxes": [{
+ "x": {
"type": "time",
"display": false,
+ "offset": false,
"time": {
"parser": "YYYY"
},
"ticks": {
"source": "labels"
}
- }],
- "yAxes": [{
+ },
+ "y": {
"display": false,
"beginAtZero": true
- }]
+ }
}
}
},
"legend": false,
"title": false,
"scales": {
- "xAxes": [{
+ "x": {
"type": "time",
"display": false,
+ "offset": false,
"time": {
"parser": "YYYY"
},
"ticks": {
"source": "labels"
}
- }],
- "yAxes": [{
+ },
+ "y": {
"display": false,
"beginAtZero": true
- }]
+ }
}
}
},
}
},
"scales": {
- "xAxes": [{
+ "x": {
"type": "time",
"display": false,
+ "offset": false,
"time": {
"parser": "YYYY"
},
"ticks": {
"source": "labels"
}
- }],
- "yAxes": [{
+ },
+ "y": {
"display": false,
"beginAtZero": true
- }]
+ }
}
}
},
}
},
"scales": {
- "xAxes": [{
+ "x": {
"type": "time",
"display": false,
+ "offset": false,
"time": {
"parser": "YYYY-MM"
},
"ticks": {
"source": "labels"
}
- }],
- "yAxes": [{
+ },
+ "y": {
"display": false,
"beginAtZero": true
- }]
+ }
}
}
},
}
},
"scales": {
- "xAxes": [{
+ "x": {
"type": "time",
"offset": true,
"display": false,
"ticks": {
"source": "labels"
}
- }],
- "yAxes": [{
+ },
+ "y": {
"display": false,
"beginAtZero": true
- }]
+ }
}
}
},
"legend": false,
"title": false,
"scales": {
- "xAxes": [{
+ "x": {
"type": "time",
"offset": true,
"stacked": true,
"ticks": {
"source": "labels"
}
- }],
- "yAxes": [{
+ },
+ "y": {
"display": false,
"stacked": true,
"beginAtZero": true
- }]
+ }
}
}
},
"legend": false,
"title": false,
"scales": {
- "xAxes": [{
+ "x": {
"type": "time",
"offset": true,
"display": false,
"ticks": {
"source": "labels"
}
- }],
- "yAxes": [{
+ },
+ "y": {
"display": false,
"beginAtZero": true
- }]
+ }
}
}
},
}
},
"scales": {
- "xAxes": [{
+ "x": {
"type": "time",
"display": false,
+ "offset": false,
"time": {
"parser": "YYYY"
},
"ticks": {
"source": "labels"
}
- }],
- "yAxes": [{
+ },
+ "y": {
"display": false,
"beginAtZero": true
- }]
+ }
}
}
},
"legend": false,
"title": false,
"scales": {
- "xAxes": [{
+ "x": {
"type": "time",
"display": false,
+ "offset": false,
"time": {
"parser": "YYYY"
},
"ticks": {
"source": "labels"
}
- }],
- "yAxes": [{
+ },
+ "y": {
"display": false,
"beginAtZero": true
- }]
+ }
}
}
},
"legend": false,
"title": false,
"scales": {
- "xAxes": [{
+ "x": {
"type": "time",
"display": false,
+ "offset": false,
"time": {
"parser": "YYYY"
},
"ticks": {
"source": "labels"
}
- }],
- "yAxes": [{
+ },
+ "y": {
"display": false,
"beginAtZero": true
- }]
+ }
}
}
},
}
},
"scales": {
- "xAxes": [{
+ "x": {
"type": "time",
"stacked": true,
"display": false,
+ "offset": false,
"time": {
"parser": "YYYY"
},
"ticks": {
"source": "labels"
}
- }],
- "yAxes": [{
+ },
+ "y": {
"display": false,
"stacked": true,
"beginAtZero": true
- }]
+ }
}
}
},
}
},
scales: {
- xAxes: [{display: false}],
- yAxes: [{display: false}]
+ x: {display: false},
+ y: {display: false}
}
}
},
}
},
scales: {
- xAxes: [{display: false}],
- yAxes: [
- {
- display: false,
- beginAtZero: true
- }
- ]
+ x: {display: false},
+ y: {
+ display: false,
+ beginAtZero: true
+ }
}
}
},
}
},
scales: {
- xAxes: [{display: false}],
- yAxes: [{display: false}]
+ x: {display: false},
+ y: {display: false}
}
}
},
}
},
scales: {
- xAxes: [{display: false}],
- yAxes: [{display: false}]
+ x: {display: false},
+ y: {display: false}
}
}
},
}
},
scales: {
- xAxes: [{display: false}],
- yAxes: [
- {
- display: false,
- beginAtZero: true
- }
- ]
+ x: {display: false},
+ y: {
+ display: false,
+ beginAtZero: true
+ }
}
}
},
}
},
scales: {
- xAxes: [{display: false}],
- yAxes: [{display: false}]
+ x: {display: false},
+ y: {display: false}
}
}
},
}
},
scales: {
- xAxes: [{display: false}],
- yAxes: [{display: false}]
+ x: {display: false},
+ y: {display: false}
}
}
},
}
},
scales: {
- xAxes: [{display: false}],
- yAxes: [{display: false}]
+ x: {display: false},
+ y: {display: false}
}
}
},
}
},
scales: {
- xAxes: [{display: false}],
- yAxes: [{display: false}]
+ x: {display: false},
+ y: {display: false}
}
}
},
}
},
scales: {
- xAxes: [{display: false}],
- yAxes: [{display: false}]
+ x: {display: false},
+ y: {display: false}
}
}
},
}
},
scales: {
- xAxes: [{display: false}],
- yAxes: [
- {
- display: false,
- beginAtZero: true
- }
- ]
+ x: {display: false},
+ y: {
+ display: false,
+ beginAtZero: true
+ }
}
}
},
}
},
scales: {
- xAxes: [{display: false}],
- yAxes: [
- {
- display: false,
- beginAtZero: true
- }
- ]
+ x: {display: false},
+ y: {
+ display: false,
+ beginAtZero: true
+ }
}
}
},
}
},
scales: {
- xAxes: [{display: false}],
- yAxes: [{display: false}]
+ x: {display: false},
+ y: {display: false}
}
}
},
}
},
scales: {
- xAxes: [{display: false}],
- yAxes: [{display: false, min: -10, max: 10}]
+ x: {display: false},
+ y: {display: false, min: -10, max: 10}
}
}
},
legend: false,
title: false,
scales: {
- xAxes: [{display: false}],
- yAxes: [{display: false}]
+ x: {display: false},
+ y: {display: false}
}
}
},
legend: false,
title: false,
scales: {
- xAxes: [{display: false, min: 0}],
- yAxes: [{display: false, stacked: true}]
+ x: {display: false, min: 0},
+ y: {display: false, stacked: true}
}
}
},
legend: false,
title: false,
scales: {
- xAxes: [{display: false, stacked: true}],
- yAxes: [{display: false, min: 0}]
+ x: {display: false, stacked: true},
+ y: {display: false, min: 0}
}
}
},
"title": false,
"legend": false,
"scales": {
- "xAxes": [{
+ "x": {
"display": false,
"min": -8,
"max": 12
- }],
- "yAxes": [{
+ },
+ "y": {
"display": false
- }]
+ }
}
}
},
"title": false,
"legend": false,
"scales": {
- "xAxes": [{
+ "x": {
"display": false,
"stacked": true
- }],
- "yAxes": [{
+ },
+ "y": {
"display": false,
"stacked": true,
"min": -8,
"max": 12
- }]
+ }
}
}
},
"title": false,
"legend": false,
"scales": {
- "xAxes": [{
+ "x": {
"display": false,
"stacked": true,
"min": -8,
"max": 12
- }],
- "yAxes": [{
+ },
+ "y": {
"display": false,
"stacked": true
- }]
+ }
}
}
},
"title": false,
"legend": false,
"scales": {
- "xAxes": [{
+ "x": {
"display": false,
"min": -8,
"max": 12
- }],
- "yAxes": [{
+ },
+ "y": {
"display": false
- }]
+ }
}
}
},
}
},
scales: {
- xAxes: [{display: false}],
- yAxes: [{display: false}]
+ x: {display: false},
+ y: {display: false}
}
}
},
"legend": false,
"title": false,
"scales": {
- "xAxes": [{
+ "x": {
"display": false,
"stacked": true
- }],
- "yAxes": [{
+ },
+ "y": {
"display": false,
"stacked": true,
"beginAtZero": true
- }]
+ }
}
}
},
"legend": false,
"title": false,
"scales": {
- "xAxes": [{
+ "x": {
"display": false,
"stacked": true
- }],
- "yAxes": [{
+ },
+ "y": {
"display": false,
"stacked": true,
"beginAtZero": true
- }]
+ }
}
}
},
options: {
legend: false,
scales: {
- xAxes: [{ticks: {display: false}}],
- yAxes: [{
+ x: {ticks: {display: false}},
+ y: {
min: 8,
max: 25,
beginAtZero: true,
ticks: {
display: false
}
- }]
+ }
}
}
},
"legend": false,
"title": false,
"scales": {
- "xAxes": [{"display": false}],
- "yAxes": [{
+ "x": {"display": false},
+ "y": {
"display": false,
"min": 0,
"max": 4
- }]
+ }
},
"elements": {
"line": {
legend: false,
title: false,
scales: {
- xAxes: [{display: false}],
- yAxes: [{display: false}]
+ x: {display: false},
+ y: {display: false}
},
elements: {
point: {
legend: false,
title: false,
scales: {
- xAxes: [{display: false}],
- yAxes: [{display: false}]
+ x: {display: false},
+ y: {display: false}
},
elements: {
point: {
padding: 32
},
scales: {
- xAxes: [{display: false}],
- yAxes: [
- {
- display: false,
- beginAtZero: true
- }
- ]
+ x: {display: false},
+ y: {
+ display: false,
+ beginAtZero: true
+ }
}
}
},
padding: 32
},
scales: {
- xAxes: [{display: false}],
- yAxes: [{display: false}]
+ x: {display: false},
+ y: {display: false}
}
}
},
padding: 32
},
scales: {
- xAxes: [{display: false}],
- yAxes: [
- {
- display: false,
- beginAtZero: true
- }
- ]
+ x: {display: false},
+ y: {
+ display: false,
+ beginAtZero: true
+ }
}
}
},
padding: 32
},
scales: {
- xAxes: [{display: false}],
- yAxes: [{display: false}]
+ x: {display: false},
+ y: {display: false}
}
}
},
padding: 32
},
scales: {
- xAxes: [{display: false}],
- yAxes: [
- {
- display: false,
- beginAtZero: true
- }
- ]
+ x: {display: false},
+ y: {
+ display: false,
+ beginAtZero: true
+ }
}
}
},
padding: 32
},
scales: {
- xAxes: [{display: false}],
- yAxes: [{display: false}]
+ x: {display: false},
+ y: {display: false}
}
}
},
padding: 32
},
scales: {
- xAxes: [{display: false}],
- yAxes: [
- {
- display: false,
- beginAtZero: true
- }
- ]
+ x: {display: false},
+ y: {
+ display: false,
+ beginAtZero: true
+ }
}
}
},
padding: 32
},
scales: {
- xAxes: [{display: false}],
- yAxes: [{display: false}]
+ x: {display: false},
+ y: {display: false}
}
}
},
padding: 32
},
scales: {
- xAxes: [{display: false}],
- yAxes: [{display: false}]
+ x: {display: false},
+ y: {display: false}
}
}
},
padding: 32
},
scales: {
- xAxes: [{display: false}],
- yAxes: [{display: false}]
+ x: {display: false},
+ y: {display: false}
}
}
},
padding: 32
},
scales: {
- xAxes: [{display: false}],
- yAxes: [{display: false}]
+ x: {display: false},
+ y: {display: false}
}
}
},
padding: 32
},
scales: {
- xAxes: [{display: false}],
- yAxes: [{display: false}]
+ x: {display: false},
+ y: {display: false}
}
}
},
padding: 32
},
scales: {
- xAxes: [{display: false}],
- yAxes: [
- {
- display: false,
- beginAtZero: true
- }
- ]
+ x: {display: false},
+ y: {
+ display: false,
+ beginAtZero: true
+ }
}
}
},
padding: 32
},
scales: {
- xAxes: [{display: false}],
- yAxes: [{display: false}]
+ x: {display: false},
+ y: {display: false}
}
}
},
"legend": false,
"title": false,
"scales": {
- "xAxes": [{
+ "x": {
"max": 3,
"ticks": {
"display": false
}
- }],
- "yAxes": [{"ticks": {"display": false}}]
+ },
+ "y": {"ticks": {"display": false}}
},
"layout": {
"padding": 24
"legend": false,
"title": false,
"scales": {
- "xAxes": [{
+ "x": {
"min": -2,
"ticks": {
"display": false
}
- }],
- "yAxes": [{"ticks": {"display": false}}]
+ },
+ "y": {"ticks": {"display": false}}
},
"layout": {
"padding": 24
"legend": false,
"title": false,
"scales": {
- "xAxes": [{
+ "x": {
"min": -2,
"max": 3,
"ticks": {
"display": false
}
- }],
- "yAxes": [{"ticks": {"display": false}}]
+ },
+ "y": {"ticks": {"display": false}}
},
"layout": {
"padding": 24
"legend": false,
"title": false,
"scales": {
- "xAxes": [{"ticks": {"display": false}}],
- "yAxes": [{
+ "x": {"ticks": {"display": false}},
+ "y": {
"max": 6,
"ticks": {
"display": false
}
- }]
+ }
},
"layout": {
"padding": 24
"legend": false,
"title": false,
"scales": {
- "xAxes": [{"ticks": {"display": false}}],
- "yAxes": [{
+ "x": {"ticks": {"display": false}},
+ "y": {
"min": 2,
"ticks": {
"display": false
}
- }]
+ }
},
"layout": {
"padding": 24
"legend": false,
"title": false,
"scales": {
- "xAxes": [{"ticks": {"display": false}}],
- "yAxes": [{
+ "x": {"ticks": {"display": false}},
+ "y": {
"min": 2,
"max": 6,
"ticks": {
"display": false
}
- }]
+ }
},
"layout": {
"padding": 24
"legend": false,
"title": false,
"scales": {
- "xAxes": [{
+ "x": {
"min": -2,
"max": 2,
"ticks": {
"display": false
}
- }],
- "yAxes": [{
+ },
+ "y": {
"min": -2,
"max": 2,
"ticks": {
"display": false
}
- }]
+ }
},
"layout": {
"padding": 24
padding: 32
},
scales: {
- xAxes: [{display: false}],
- yAxes: [{display: false}]
+ x: {display: false},
+ y: {display: false}
}
}
},
padding: 32
},
scales: {
- xAxes: [{display: false}],
- yAxes: [{display: false}]
+ x: {display: false},
+ y: {display: false}
}
}
},
padding: 32
},
scales: {
- xAxes: [{display: false}],
- yAxes: [{display: false}]
+ x: {display: false},
+ y: {display: false}
}
}
},
padding: 32
},
scales: {
- xAxes: [{display: false}],
- yAxes: [{display: false}]
+ x: {display: false},
+ y: {display: false}
}
}
},
padding: 32
},
scales: {
- xAxes: [{display: false}],
- yAxes: [{display: false}]
+ x: {display: false},
+ y: {display: false}
}
}
},
padding: 32
},
scales: {
- xAxes: [{display: false}],
- yAxes: [{display: false}]
+ x: {display: false},
+ y: {display: false}
}
}
},
"legend": false,
"title": false,
"scales": {
- "xAxes": [{"display": false}],
- "yAxes": [{
+ "x": {"display": false},
+ "y": {
"type": "category",
"display": false
- }]
+ }
}
}
},
"legend": false,
"title": false,
"scales": {
- "xAxes": [{"display": false}],
- "yAxes": [{
+ "x": {"display": false},
+ "y": {
"display": false,
"min": 0,
"max": 4
- }]
+ }
},
"elements": {
"line": {
}
},
scales: {
- xAxes: [{display: false}],
- yAxes: [{display: false}]
+ x: {display: false},
+ y: {display: false}
}
}
},
}
},
scales: {
- xAxes: [{display: false}],
- yAxes: [
- {
- display: false,
- beginAtZero: true
- }
- ]
+ x: {display: false},
+ y: {
+ display: false,
+ beginAtZero: true
+ }
}
}
},
}
},
scales: {
- xAxes: [{display: false}],
- yAxes: [{display: false}]
+ x: {display: false},
+ y: {display: false}
}
}
},
}
},
scales: {
- xAxes: [{display: false}],
- yAxes: [{display: false}]
+ x: {display: false},
+ y: {display: false}
}
}
},
}
},
scales: {
- xAxes: [{display: false}],
- yAxes: [
- {
- display: false,
- beginAtZero: true
- }
- ]
+ x: {display: false},
+ y: {
+ display: false,
+ beginAtZero: true
+ }
}
}
},
}
},
scales: {
- xAxes: [{display: false}],
- yAxes: [{display: false}]
+ x: {display: false},
+ y: {display: false}
}
}
},
}
},
scales: {
- xAxes: [{display: false}],
- yAxes: [{display: false}]
+ x: {display: false},
+ y: {display: false}
}
}
},
}
},
scales: {
- xAxes: [{display: false}],
- yAxes: [
- {
- display: false,
- beginAtZero: true
- }
- ]
+ x: {display: false},
+ y: {
+ display: false,
+ beginAtZero: true
+ }
}
}
},
}
},
scales: {
- xAxes: [{display: false}],
- yAxes: [{display: false}]
+ x: {display: false},
+ y: {display: false}
}
}
},
}
},
scales: {
- xAxes: [{display: false}],
- yAxes: [{display: false}]
+ x: {display: false},
+ y: {display: false}
}
}
},
}
},
scales: {
- xAxes: [{display: false}],
- yAxes: [
- {
- display: false,
- beginAtZero: true
- }
- ]
+ x: {display: false},
+ y: {
+ display: false,
+ beginAtZero: true
+ }
}
}
},
}
},
scales: {
- xAxes: [{display: false}],
- yAxes: [{display: false}]
+ x: {display: false},
+ y: {display: false}
}
}
},
}
},
scales: {
- xAxes: [{display: false}],
- yAxes: [{display: false}]
+ x: {display: false},
+ y: {display: false}
}
}
},
}
},
scales: {
- xAxes: [{display: false}],
- yAxes: [
- {
- display: false,
- beginAtZero: true
- }
- ]
+ x: {display: false},
+ y: {
+ display: false,
+ beginAtZero: true
+ }
}
}
},
}
},
scales: {
- xAxes: [{display: false}],
- yAxes: [{display: false}]
+ x: {display: false},
+ y: {display: false}
}
}
},
}
},
scales: {
- xAxes: [{display: false}],
- yAxes: [{display: false}]
+ x: {display: false},
+ y: {display: false}
}
}
},
}
},
scales: {
- xAxes: [{display: false}],
- yAxes: [
- {
- display: false,
- beginAtZero: true
- }
- ]
+ x: {display: false},
+ y: {
+ display: false,
+ beginAtZero: true
+ }
}
}
},
}
},
scales: {
- xAxes: [{display: false}],
- yAxes: [{display: false}]
+ x: {display: false},
+ y: {display: false}
}
}
},
padding: 32
},
scales: {
- xAxes: [{stacked: true, display: false}],
- yAxes: [{stacked: true, display: false}]
+ x: {stacked: true, display: false},
+ y: {stacked: true, display: false}
}
}
},
padding: 32
},
scales: {
- xAxes: [{stacked: true, display: false}],
- yAxes: [{stacked: true, display: false}]
+ x: {stacked: true, display: false},
+ y: {stacked: true, display: false}
}
}
},
"legend": false,
"title": false,
"scales": {
- "xAxes": [{
+ "x": {
"ticks": {
"display": false
},
"display": false,
"drawBorder": false
}
- }],
- "yAxes": [{
+ },
+ "y": {
"ticks": {
"labelOffset": 25
},
"display": false,
"drawBorder": false
}
- }]
+ }
}
}
},
"legend": false,
"title": false,
"scales": {
- "xAxes": [{
+ "x": {
"type": "category",
"position": "top",
"id": "x-axis-1",
"drawBorder": false,
"color": "rgba(0, 0, 0, 1)"
}
- }, {
+ },
+ "x2": {
"type": "category",
"position": "bottom",
- "id": "x-axis-2",
"ticks": {
"display": false
},
"drawBorder": false,
"color": "rgba(0, 0, 0, 1)"
}
- }],
- "yAxes": [{
+ },
+ "y": {
"position": "left",
"id": "y-axis-1",
"type": "linear",
+ "offset": false,
"min": -100,
"max": 100,
"ticks": {
"display": false
},
"gridLines":{
+ "offsetGridLines": false,
"drawOnChartArea": false,
"drawBorder": false,
"color": "rgba(0, 0, 0, 1)"
}
- }, {
+ },
+ "y2": {
"type": "linear",
- "id": "y-axis-2",
"position": "right",
+ "offset": false,
"min": 0,
"max": 50,
"ticks": {
"display": false
},
"gridLines":{
+ "offsetGridLines": false,
"drawOnChartArea": false,
"drawBorder": false,
"color": "rgba(0, 0, 0, 1)"
}
- }]
+ }
}
}
},
legend: false,
title: false,
scales: {
- xAxes: [{display: false}],
- yAxes: [{display: false}]
+ x: {display: false},
+ y: {display: false}
},
elements: {
line: {
legend: false,
title: false,
scales: {
- xAxes: [{type: 'linear', display: false, min: 0, max: 20}],
- yAxes: [{display: false, min: -15, max: 15}]
+ x: {type: 'linear', display: false, min: 0, max: 20},
+ y: {display: false, min: -15, max: 15}
}
}
},
legend: false,
title: false,
scales: {
- xAxes: [{type: 'linear', display: false, min: 0, max: 20}],
- yAxes: [{display: false, min: -15, max: 15}]
+ x: {type: 'linear', display: false, min: 0, max: 20},
+ y: {display: false, min: -15, max: 15}
}
}
},
legend: false,
title: false,
scales: {
- xAxes: [{type: 'linear', display: false, min: 0, max: 20}],
- yAxes: [{display: false, min: -15, max: 15}]
+ x: {type: 'linear', display: false, min: 0, max: 20},
+ y: {display: false, min: -15, max: 15}
}
}
},
legend: false,
title: false,
scales: {
- xAxes: [{type: 'linear', display: false, min: 0, max: 20}],
- yAxes: [{display: false, min: -15, max: 15}]
+ x: {type: 'linear', display: false, min: 0, max: 20},
+ y: {display: false, min: -15, max: 15}
}
}
},
legend: false,
title: false,
scales: {
- xAxes: [{type: 'linear', display: false, min: 0, max: 20}],
- yAxes: [{display: false, min: -15, max: 15}]
+ x: {type: 'linear', display: false, min: 0, max: 20},
+ y: {display: false, min: -15, max: 15}
}
}
},
legend: false,
title: false,
scales: {
- xAxes: [{type: 'linear', display: false, min: 0, max: 20}],
- yAxes: [{display: false, min: -15, max: 15}]
+ x: {type: 'linear', display: false, min: 0, max: 20},
+ y: {display: false, min: -15, max: 15}
}
}
},
legend: false,
title: false,
scales: {
- xAxes: [{type: 'linear', display: false, min: 0, max: 20}],
- yAxes: [{display: false, min: -15, max: 15}]
+ x: {type: 'linear', display: false, min: 0, max: 20},
+ y: {display: false, min: -15, max: 15}
}
}
},
legend: false,
title: false,
scales: {
- xAxes: [{type: 'linear', display: false, min: 0, max: 20}],
- yAxes: [{display: false, min: -15, max: 15}]
+ x: {type: 'linear', display: false, min: 0, max: 20},
+ y: {display: false, min: -15, max: 15}
}
}
},
legend: false,
title: false,
scales: {
- xAxes: [{type: 'linear', display: false, min: 0, max: 20}],
- yAxes: [{display: false, min: -15, max: 15}]
+ x: {type: 'linear', display: false, min: 0, max: 20},
+ y: {display: false, min: -15, max: 15}
}
}
},
legend: false,
title: false,
scales: {
- xAxes: [{type: 'linear', display: false, min: 0, max: 20}],
- yAxes: [{display: false, min: -15, max: 15}]
+ x: {type: 'linear', display: false, min: 0, max: 20},
+ y: {display: false, min: -15, max: 15}
}
}
},
legend: false,
title: false,
scales: {
- xAxes: [{type: 'linear', display: false, min: 0, max: 20}],
- yAxes: [{display: false, min: -15, max: 15}]
+ x: {type: 'linear', display: false, min: 0, max: 20},
+ y: {display: false, min: -15, max: 15}
}
}
},
legend: false,
title: false,
scales: {
- xAxes: [{type: 'linear', display: false, min: 0, max: 20}],
- yAxes: [{display: false, min: -15, max: 15}]
+ x: {type: 'linear', display: false, min: 0, max: 20},
+ y: {display: false, min: -15, max: 15}
}
}
},
legend: false,
title: false,
scales: {
- xAxes: [{type: 'linear', display: false, min: 0, max: 20}],
- yAxes: [{display: false, min: -15, max: 15}]
+ x: {type: 'linear', display: false, min: 0, max: 20},
+ y: {display: false, min: -15, max: 15}
}
}
},
legend: false,
title: false,
scales: {
- xAxes: [{type: 'linear', display: false, min: 0, max: 20}],
- yAxes: [{display: false, min: -15, max: 15}]
+ x: {type: 'linear', display: false, min: 0, max: 20},
+ y: {display: false, min: -15, max: 15}
}
}
},
legend: false,
title: false,
scales: {
- xAxes: [{type: 'linear', display: false, min: 0, max: 20}],
- yAxes: [{display: false, min: -15, max: 15}]
+ x: {type: 'linear', display: false, min: 0, max: 20},
+ y: {display: false, min: -15, max: 15}
}
}
},
"padding": 40
},
"scales": {
- "xAxes": [{"display": false}],
- "yAxes": [{"display": false}]
+ "x": {"display": false},
+ "y": {"display": false}
}
}
},
"padding": 40
},
"scales": {
- "xAxes": [{"display": false}],
- "yAxes": [{"display": false}]
+ "x": {"display": false},
+ "y": {"display": false}
}
}
},
"padding": 40
},
"scales": {
- "xAxes": [{"display": false}],
- "yAxes": [{"display": false}]
+ "x": {"display": false},
+ "y": {"display": false}
}
}
},
"padding": 40
},
"scales": {
- "xAxes": [{"display": false}],
- "yAxes": [{"display": false}]
+ "x": {"display": false},
+ "y": {"display": false}
}
}
},
padding: 20
},
scales: {
- xAxes: [{display: false}],
- yAxes: [{display: false}]
+ x: {display: false},
+ y: {display: false}
}
}
},
"padding": 40
},
"scales": {
- "xAxes": [{"display": false}],
- "yAxes": [{"display": false}]
+ "x": {"display": false},
+ "y": {"display": false}
}
}
},
"padding": 40
},
"scales": {
- "xAxes": [{"display": false}],
- "yAxes": [{"display": false}]
+ "x": {"display": false},
+ "y": {"display": false}
}
}
},
"padding": 40
},
"scales": {
- "xAxes": [{"display": false}],
- "yAxes": [{"display": false}]
+ "x": {"display": false},
+ "y": {"display": false}
}
}
},
"padding": 40
},
"scales": {
- "xAxes": [{"display": false}],
- "yAxes": [{"display": false}]
+ "x": {"display": false},
+ "y": {"display": false}
}
}
},
"padding": 40
},
"scales": {
- "xAxes": [{"display": false}],
- "yAxes": [{"display": false}]
+ "x": {"display": false},
+ "y": {"display": false}
}
}
},
"padding": 40
},
"scales": {
- "xAxes": [{"display": false}],
- "yAxes": [{"display": false}]
+ "x": {"display": false},
+ "y": {"display": false}
}
}
},
padding: 20
},
scales: {
- xAxes: [{display: false}],
- yAxes: [{display: false}]
+ x: {display: false},
+ y: {display: false}
}
}
},
"legend": false,
"title": false,
"scales": {
- "xAxes": [{
+ "x": {
"display": false
- }],
- "yAxes": [{
+ },
+ "y": {
"display": false
- }]
+ }
},
"elements": {
"point": {
"legend": false,
"title": false,
"scales": {
- "xAxes": [{
+ "x": {
"display": false
- }],
- "yAxes": [{
+ },
+ "y": {
"display": false
- }]
+ }
},
"elements": {
"point": {
"legend": false,
"title": false,
"scales": {
- "xAxes": [{
+ "x": {
"display": false
- }],
- "yAxes": [{
+ },
+ "y": {
"display": false
- }]
+ }
},
"elements": {
"point": {
"legend": false,
"title": false,
"scales": {
- "xAxes": [{
+ "x": {
"display": false
- }],
- "yAxes": [{
+ },
+ "y": {
"display": false
- }]
+ }
},
"elements": {
"point": {
"legend": false,
"title": false,
"scales": {
- "xAxes": [{
+ "x": {
"display": false
- }],
- "yAxes": [{
+ },
+ "y": {
"display": false
- }]
+ }
},
"elements": {
"point": {
"legend": false,
"title": false,
"scales": {
- "xAxes": [{
+ "x": {
"display": false
- }],
- "yAxes": [{
+ },
+ "y": {
"display": false
- }]
+ }
},
"elements": {
"point": {
"legend": false,
"title": false,
"scales": {
- "xAxes": [{
+ "x": {
"display": false
- }],
- "yAxes": [{
+ },
+ "y": {
"display": false
- }]
+ }
},
"elements": {
"point": {
"legend": false,
"title": false,
"scales": {
- "xAxes": [{
+ "x": {
"display": false
- }],
- "yAxes": [{
+ },
+ "y": {
"display": false
- }]
+ }
},
"elements": {
"point": {
"legend": false,
"title": false,
"scales": {
- "xAxes": [{
+ "x": {
"display": false
- }],
- "yAxes": [{
+ },
+ "y": {
"display": false
- }]
+ }
},
"elements": {
"point": {
"legend": false,
"title": false,
"scales": {
- "xAxes": [{
+ "x": {
"display": false
- }],
- "yAxes": [{
+ },
+ "y": {
"display": false
- }]
+ }
},
"elements": {
"point": {
"legend": false,
"title": false,
"scales": {
- "xAxes": [{
+ "x": {
"display": false
- }],
- "yAxes": [{
+ },
+ "y": {
"display": false
- }]
+ }
},
"elements": {
"point": {
"legend": false,
"title": false,
"scales": {
- "xAxes": [{
+ "x": {
"display": false
- }],
- "yAxes": [{
+ },
+ "y": {
"display": false
- }]
+ }
},
"elements": {
"point": {
"legend": false,
"title": false,
"scales": {
- "xAxes": [{
+ "x": {
"display": false
- }],
- "yAxes": [{
+ },
+ "y": {
"display": false
- }]
+ }
},
"elements": {
"point": {
"legend": false,
"title": false,
"scales": {
- "xAxes": [{
+ "x": {
"display": false
- }],
- "yAxes": [{
+ },
+ "y": {
"display": false
- }]
+ }
},
"elements": {
"point": {
"legend": false,
"title": false,
"scales": {
- "xAxes": [{
+ "x": {
"display": false
- }],
- "yAxes": [{
+ },
+ "y": {
"display": false
- }]
+ }
},
"elements": {
"point": {
"title": false,
"scale": {
"gridLines": {
+ "display": true,
"color": [
"rgba(0, 0, 0, 0.5)",
"rgba(255, 255, 255, 0.5)",
],
labels: []
},
- options: {
- scales: {
- xAxes: [{
- id: 'firstXScaleID'
- }],
- yAxes: [{
- id: 'firstYScaleID'
- }]
- }
- }
});
var meta = chart.getDatasetMeta(1);
- expect(meta.xAxisID).toBe('firstXScaleID');
- expect(meta.yAxisID).toBe('firstYScaleID');
+ expect(meta.xAxisID).toBe('x');
+ expect(meta.yAxisID).toBe('y');
});
it('should correctly count the number of stacks ignoring datasets of other types and hidden datasets', function() {
},
options: {
scales: {
- xAxes: [{
+ x: {
stacked: true
- }],
- yAxes: [{
+ },
+ y: {
stacked: true
- }]
+ }
}
}
});
},
options: {
scales: {
- xAxes: [{
+ x: {
stacked: false
- }],
- yAxes: [{
+ },
+ y: {
stacked: false
- }]
+ }
}
}
});
},
options: {
scales: {
- xAxes: [{
+ x: {
stacked: true
- }],
- yAxes: [{
+ },
+ y: {
stacked: true
- }]
+ }
}
}
});
},
options: {
scales: {
- xAxes: [{
+ x: {
stacked: false
- }],
- yAxes: [{
+ },
+ y: {
stacked: false
- }]
+ }
}
}
});
},
options: {
scales: {
- xAxes: [{
+ x: {
stacked: true
- }],
- yAxes: [{
+ },
+ y: {
stacked: true
- }]
+ }
}
}
});
},
options: {
scales: {
- xAxes: [{
+ x: {
stacked: false
- }],
- yAxes: [{
+ },
+ y: {
stacked: false
- }]
+ }
}
}
});
},
options: {
scales: {
- xAxes: [{
+ x: {
stacked: true
- }],
- yAxes: [{
+ },
+ y: {
stacked: true
- }]
+ }
}
}
});
},
options: {
scales: {
- xAxes: [{
+ x: {
stacked: false
- }],
- yAxes: [{
+ },
+ y: {
stacked: false
- }]
+ }
}
}
});
},
options: {
scales: {
- xAxes: [{
+ x: {
stacked: true
- }],
- yAxes: [{
+ },
+ y: {
stacked: true
- }]
+ }
}
}
});
},
options: {
scales: {
- xAxes: [{
+ x: {
stacked: false
- }],
- yAxes: [{
+ },
+ y: {
stacked: false
- }]
+ }
}
}
});
},
options: {
scales: {
- xAxes: [{
+ x: {
stacked: true
- }],
- yAxes: [{
+ },
+ y: {
stacked: true
- }]
+ }
}
}
});
},
options: {
scales: {
- xAxes: [{
+ x: {
stacked: false
- }],
- yAxes: [{
+ },
+ y: {
stacked: false
- }]
+ }
}
}
});
}
},
scales: {
- xAxes: [{
- id: 'firstXScaleID',
+ x: {
type: 'category',
display: false
- }],
- yAxes: [{
- id: 'firstYScaleID',
+ },
+ y: {
type: 'linear',
display: false
- }]
+ }
}
}
});
legend: false,
title: false,
scales: {
- xAxes: [{
+ x: {
type: 'category',
display: false
- }],
- yAxes: [{
+ },
+ y: {
type: 'linear',
display: false
- }]
+ }
}
}
});
legend: false,
title: false,
scales: {
- xAxes: [{
+ x: {
type: 'category',
display: false
- }],
- yAxes: [{
+ },
+ y: {
type: 'linear',
display: false,
stacked: true
- }]
+ }
}
}
});
legend: false,
title: false,
scales: {
- xAxes: [{
+ x: {
type: 'category',
display: false
- }],
- yAxes: [{
+ },
+ y: {
type: 'linear',
display: false,
stacked: true,
min: 50,
max: 100
- }]
+ }
}
}
});
legend: false,
title: false,
scales: {
- xAxes: [{
+ x: {
type: 'category',
display: false,
stacked: true
- }],
- yAxes: [{
+ },
+ y: {
type: 'linear',
display: false
- }]
+ }
}
}
});
legend: false,
title: false,
scales: {
- xAxes: [{
+ x: {
type: 'category',
display: false
- }],
- yAxes: [{
+ },
+ y: {
type: 'linear',
display: false,
stacked: true
- }]
+ }
}
}
});
legend: false,
title: false,
scales: {
- xAxes: [{
+ x: {
type: 'category',
display: false
- }],
- yAxes: [{
+ },
+ y: {
type: 'linear',
display: false,
stacked: true
- }]
+ }
}
}
});
legend: false,
title: false,
scales: {
- xAxes: [{
+ x: {
type: 'category',
display: false
- }],
- yAxes: [{
+ },
+ y: {
type: 'linear',
display: false,
stacked: true,
- }]
+ }
}
}
});
legend: false,
title: false,
scales: {
- xAxes: [{
+ x: {
type: 'category',
display: false
- }],
- yAxes: [{
+ },
+ y: {
type: 'linear',
display: false,
stacked: true
- }]
+ }
}
}
});
}
},
scales: {
- xAxes: [{
+ x: {
type: 'category',
display: false,
stacked: true,
- }],
- yAxes: [{
+ },
+ y: {
type: 'logarithmic',
display: false,
stacked: true
- }]
+ }
}
}
});
}
},
scales: {
- xAxes: [{
+ x: {
type: 'category',
display: false,
stacked: true,
- }],
- yAxes: [{
+ },
+ y: {
type: 'logarithmic',
display: false,
stacked: true
- }]
+ }
}
}
});
data: this.data,
options: {
scales: {
- xAxes: [{
+ x: {
min: 'March',
max: 'May',
- }]
+ }
}
}
};
data: this.data,
options: {
scales: {
- xAxes: [{
+ x: {
min: 'March',
max: 'May',
- }],
- yAxes: [{
+ },
+ y: {
stacked: true
- }]
+ }
}
}
};
data: this.data,
options: {
scales: {
- yAxes: [{
+ y: {
min: 'March',
max: 'May',
- }]
+ }
}
}
};
data: this.data,
options: {
scales: {
- xAxes: [{
+ x: {
stacked: true
- }],
- yAxes: [{
+ },
+ y: {
min: 'March',
max: 'May',
- }]
+ }
}
}
};
}
},
scales: {
- xAxes: [{
+ x: {
id: 'x',
type: 'category',
- }],
- yAxes: [{
+ },
+ y: {
type: 'linear',
- }]
+ }
}
}
});
expect(data[0]._model.base + minBarLength).toEqual(data[0]._model.x);
expect(data[1]._model.base - minBarLength).toEqual(data[1]._model.x);
});
-
});
data: []
}]
},
- options: {
- scales: {
- xAxes: [{
- id: 'firstXScaleID'
- }],
- yAxes: [{
- id: 'firstYScaleID'
- }]
- }
- }
});
var meta = chart.getDatasetMeta(0);
- expect(meta.xAxisID).toBe('firstXScaleID');
- expect(meta.yAxisID).toBe('firstYScaleID');
+ expect(meta.xAxisID).toBe('x');
+ expect(meta.yAxisID).toBe('y');
});
it('should create point elements for each data item during initialization', function() {
legend: false,
title: false,
scales: {
- xAxes: [{
+ x: {
type: 'category',
display: false
- }],
- yAxes: [{
+ },
+ y: {
type: 'linear',
display: false
- }]
+ }
}
}
});
}],
labels: []
},
- options: {
- scales: {
- xAxes: [{
- id: 'firstXScaleID'
- }],
- yAxes: [{
- id: 'firstYScaleID'
- }]
- }
- }
});
var meta = chart.getDatasetMeta(0);
- expect(meta.xAxisID).toBe('firstXScaleID');
- expect(meta.yAxisID).toBe('firstYScaleID');
+ expect(meta.xAxisID).toBe('x');
+ expect(meta.yAxisID).toBe('y');
});
it('Should create line elements and point elements for each data item during initialization', function() {
datasets: [{
data: [10, 15, 0, -4],
label: 'dataset',
- xAxisID: 'firstXScaleID',
- yAxisID: 'firstYScaleID'
+ xAxisID: 'x',
+ yAxisID: 'y'
}],
labels: ['label1', 'label2', 'label3', 'label4']
},
}
},
scales: {
- xAxes: [{
- id: 'firstXScaleID',
+ x: {
display: false
- }],
- yAxes: [{
- id: 'firstYScaleID',
+ },
+ y: {
display: false
- }]
+ }
}
},
});
intersect: true
},
scales: {
- xAxes: [{
+ x: {
display: false,
- }],
- yAxes: [{
+ },
+ y: {
display: false,
beginAtZero: true
- }]
+ }
}
}
});
legend: false,
title: false,
scales: {
- xAxes: [{
+ x: {
display: false,
- }],
- yAxes: [{
+ },
+ y: {
display: false,
stacked: true
- }]
+ }
}
}
});
}, {
data: [10, 10, -10, -10],
label: 'dataset3',
- yAxisID: 'secondAxis'
+ yAxisID: 'y2'
}],
labels: ['label1', 'label2', 'label3', 'label4']
},
legend: false,
title: false,
scales: {
- xAxes: [{
+ x: {
display: false,
- }],
- yAxes: [{
+ },
+ y: {
display: false,
stacked: true
- }, {
- id: 'secondAxis',
+ },
+ y2: {
type: 'linear',
+ position: 'right',
display: false
- }]
+ }
}
}
});
legend: false,
title: false,
scales: {
- xAxes: [{
+ x: {
display: false,
- }],
- yAxes: [{
+ },
+ y: {
display: false,
stacked: true
- }]
+ }
}
}
});
legend: false,
title: false,
scales: {
- xAxes: [{
+ x: {
display: false,
- }],
- yAxes: [{
+ },
+ y: {
display: false,
stacked: true
- }]
+ }
}
}
});
type: 'line',
options: {
scales: {
- xAxes: [{
+ x: {
position: 'left',
- }],
- yAxes: [{
+ },
+ y: {
position: 'bottom'
- }]
+ }
}
}
});
var scaleOptions = chart.options.scales;
- expect(scaleOptions.xAxes[0].position).toBe('bottom');
- expect(scaleOptions.yAxes[0].position).toBe('left');
+ expect(scaleOptions.x.position).toBe('bottom');
+ expect(scaleOptions.y.position).toBe('left');
});
it('should throw an error if the chart type is incorrect', function() {
},
options: {
scales: {
- xAxes: [{
+ x: {
+ type: 'linear',
position: 'left',
- }],
- yAxes: [{
+ },
+ y: {
+ type: 'category',
position: 'bottom'
- }]
+ }
}
}
});
type: 'line',
options: {
scales: {
- xAxes: [
- {id: 'foo0'},
- {id: 'foo1'}
- ],
- yAxes: [
- {id: 'bar0'},
- {id: 'bar1'}
- ]
+ xFoo0: {},
+ xFoo1: {},
+ yBar0: {},
+ yBar1: {},
}
}
});
- expect(chart.scales.foo0.type).toBe('category');
- expect(chart.scales.foo1.type).toBe('category');
- expect(chart.scales.bar0.type).toBe('linear');
- expect(chart.scales.bar1.type).toBe('linear');
+ expect(chart.scales.xFoo0.type).toBe('category');
+ expect(chart.scales.xFoo1.type).toBe('category');
+ expect(chart.scales.yBar0.type).toBe('linear');
+ expect(chart.scales.yBar1.type).toBe('linear');
});
it('should correctly apply defaults on central scale', function() {
// let's check a few values from the user options and defaults
expect(chart.scales.foo.type).toBe('logarithmic');
- expect(chart.scales.foo.options).toBe(chart.options.scale);
+ expect(chart.scales.foo.options).toEqual(chart.options.scales.foo);
expect(chart.scales.foo.options).toEqual(
jasmine.objectContaining({
_jasmineCheckA: 'a0',
type: 'line',
options: {
scales: {
- xAxes: [{
- id: 'foo',
+ x: {
type: 'logarithmic',
_jasmineCheckC: 'c2',
_jasmineCheckD: 'd2'
- }],
- yAxes: [{
- id: 'bar',
+ },
+ y: {
type: 'time',
_jasmineCheckC: 'c2',
_jasmineCheckE: 'e2'
- }]
+ }
}
}
});
- expect(chart.scales.foo.type).toBe('logarithmic');
- expect(chart.scales.foo.options).toBe(chart.options.scales.xAxes[0]);
- expect(chart.scales.foo.options).toEqual(
+ expect(chart.scales.x.type).toBe('logarithmic');
+ expect(chart.scales.x.options).toBe(chart.options.scales.x);
+ expect(chart.scales.x.options).toEqual(
jasmine.objectContaining({
_jasmineCheckA: 'a0',
_jasmineCheckB: 'b1',
_jasmineCheckD: 'd2'
}));
- expect(chart.scales.bar.type).toBe('time');
- expect(chart.scales.bar.options).toBe(chart.options.scales.yAxes[0]);
- expect(chart.scales.bar.options).toEqual(
+ expect(chart.scales.y.type).toBe('time');
+ expect(chart.scales.y.options).toBe(chart.options.scales.y);
+ expect(chart.scales.y.options).toEqual(
jasmine.objectContaining({
_jasmineCheckA: 'a0',
_jasmineCheckB: 'b0',
options: {
_jasmineCheck: 42,
scales: {
- xAxes: [{
- id: 'foo',
+ x: {
type: 'linear',
_jasmineCheck: 42,
- }],
- yAxes: [{
- id: 'bar',
+ },
+ y: {
type: 'category',
_jasmineCheck: 42,
- }]
+ }
}
}
});
expect(chart.options._jasmineCheck).toBeDefined();
- expect(chart.scales.foo.options._jasmineCheck).toBeDefined();
- expect(chart.scales.bar.options._jasmineCheck).toBeDefined();
+ expect(chart.scales.x.options._jasmineCheck).toBeDefined();
+ expect(chart.scales.y.options._jasmineCheck).toBeDefined();
expect(Chart.defaults.line._jasmineCheck).not.toBeDefined();
expect(Chart.defaults.global._jasmineCheck).not.toBeDefined();
chart.options = {
responsive: false,
scales: {
- yAxes: [{
+ y: {
min: 0,
max: 10
- }]
+ }
}
};
chart.update();
- var yScale = chart.scales['y-axis-0'];
+ var yScale = chart.scales.y;
expect(yScale.options.min).toBe(0);
expect(yScale.options.max).toBe(10);
});
}
});
- chart.options.scales.yAxes[0].min = 0;
- chart.options.scales.yAxes[0].max = 10;
+ chart.options.scales.y.min = 0;
+ chart.options.scales.y.max = 10;
chart.update();
- var yScale = chart.scales['y-axis-0'];
+ var yScale = chart.scales.y;
expect(yScale.options.min).toBe(0);
expect(yScale.options.max).toBe(10);
});
});
var newScalesConfig = {
- yAxes: [{
+ y: {
min: 0,
max: 10
- }]
+ }
};
chart.options.scales = newScalesConfig;
chart.update();
- var yScale = chart.scales['y-axis-0'];
+ var yScale = chart.scales.y;
expect(yScale.options.min).toBe(0);
expect(yScale.options.max).toBe(10);
});
- it ('should assign unique scale IDs', function() {
- var chart = acquireChart({
- type: 'line',
- options: {
- scales: {
- xAxes: [{id: 'x-axis-0'}, {}, {}],
- yAxes: [{id: 'y-axis-1'}, {}, {}]
- }
- }
- });
-
- expect(Object.keys(chart.scales).sort()).toEqual([
- 'x-axis-0', 'x-axis-1', 'x-axis-2',
- 'y-axis-1', 'y-axis-2', 'y-axis-3'
- ]);
- });
-
it ('should remove discarded scale', function() {
var chart = acquireChart({
type: 'line',
options: {
responsive: true,
scales: {
- yAxes: [{
- id: 'yAxis0',
+ y: {
min: 0,
max: 10
- }]
+ }
}
}
});
var newScalesConfig = {
- yAxes: [{
+ y: {
min: 0,
max: 10
- }]
+ }
};
chart.options.scales = newScalesConfig;
var yScale = chart.scales.yAxis0;
expect(yScale).toBeUndefined();
- var newyScale = chart.scales['y-axis-0'];
+ var newyScale = chart.scales.y;
expect(newyScale.options.min).toBe(0);
expect(newyScale.options.max).toBe(10);
});
options: {
responsive: true,
scales: {
- xAxes: [{
+ x: {
type: 'category'
- }],
- yAxes: [{
+ },
+ y: {
+ type: 'linear',
scaleLabel: {
display: true,
labelString: 'Value'
}
- }]
+ }
}
}
};
},
options: {
scales: {
- xAxes: [{
- id: 'firstXScaleID'
- }, {
- id: 'secondXScaleID'
- }],
- yAxes: [{
- id: 'firstYScaleID'
- }, {
- id: 'secondYScaleID'
- }]
+ firstXScaleID: {
+ type: 'category',
+ position: 'bottom'
+ },
+ secondXScaleID: {
+ type: 'category',
+ position: 'bottom'
+ },
+ firstYScaleID: {
+ type: 'linear',
+ position: 'left'
+ },
+ secondYScaleID: {
+ type: 'linear',
+ position: 'left'
+ },
}
}
});
{data: [10, 5, 0, 25, 78, -10]}
],
labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5', 'tick6']
- },
- options: {
- scales: {
- xAxes: [{
- id: 'xScale',
- type: 'category'
- }],
- yAxes: [{
- id: 'yScale',
- type: 'linear'
- }]
- }
}
}, {
canvas: {
expect(chart.chartArea.top).toBeCloseToPixel(32);
// Is xScale at the right spot
- expect(chart.scales.xScale.bottom).toBeCloseToPixel(150);
- expect(chart.scales.xScale.left).toBeCloseToPixel(34);
- expect(chart.scales.xScale.right).toBeCloseToPixel(247);
- expect(chart.scales.xScale.top).toBeCloseToPixel(120);
- expect(chart.scales.xScale.labelRotation).toBeCloseTo(0);
+ expect(chart.scales.x.bottom).toBeCloseToPixel(150);
+ expect(chart.scales.x.left).toBeCloseToPixel(34);
+ expect(chart.scales.x.right).toBeCloseToPixel(247);
+ expect(chart.scales.x.top).toBeCloseToPixel(120);
+ expect(chart.scales.x.labelRotation).toBeCloseTo(0);
// Is yScale at the right spot
- expect(chart.scales.yScale.bottom).toBeCloseToPixel(120);
- expect(chart.scales.yScale.left).toBeCloseToPixel(0);
- expect(chart.scales.yScale.right).toBeCloseToPixel(34);
- expect(chart.scales.yScale.top).toBeCloseToPixel(32);
- expect(chart.scales.yScale.labelRotation).toBeCloseTo(0);
+ expect(chart.scales.y.bottom).toBeCloseToPixel(120);
+ expect(chart.scales.y.left).toBeCloseToPixel(0);
+ expect(chart.scales.y.right).toBeCloseToPixel(34);
+ expect(chart.scales.y.top).toBeCloseToPixel(32);
+ expect(chart.scales.y.labelRotation).toBeCloseTo(0);
});
it('should fit scales that are in the top and right positions', function() {
},
options: {
scales: {
- xAxes: [{
- id: 'xScale',
+ x: {
type: 'category',
position: 'top'
- }],
- yAxes: [{
- id: 'yScale',
+ },
+ y: {
type: 'linear',
position: 'right'
- }]
+ }
}
}
}, {
expect(chart.chartArea.top).toBeCloseToPixel(62);
// Is xScale at the right spot
- expect(chart.scales.xScale.bottom).toBeCloseToPixel(62);
- expect(chart.scales.xScale.left).toBeCloseToPixel(3);
- expect(chart.scales.xScale.right).toBeCloseToPixel(216);
- expect(chart.scales.xScale.top).toBeCloseToPixel(32);
- expect(chart.scales.xScale.labelRotation).toBeCloseTo(0);
+ expect(chart.scales.x.bottom).toBeCloseToPixel(62);
+ expect(chart.scales.x.left).toBeCloseToPixel(3);
+ expect(chart.scales.x.right).toBeCloseToPixel(216);
+ expect(chart.scales.x.top).toBeCloseToPixel(32);
+ expect(chart.scales.x.labelRotation).toBeCloseTo(0);
// Is yScale at the right spot
- expect(chart.scales.yScale.bottom).toBeCloseToPixel(142);
- expect(chart.scales.yScale.left).toBeCloseToPixel(216);
- expect(chart.scales.yScale.right).toBeCloseToPixel(250);
- expect(chart.scales.yScale.top).toBeCloseToPixel(62);
- expect(chart.scales.yScale.labelRotation).toBeCloseTo(0);
+ expect(chart.scales.y.bottom).toBeCloseToPixel(142);
+ expect(chart.scales.y.left).toBeCloseToPixel(216);
+ expect(chart.scales.y.right).toBeCloseToPixel(250);
+ expect(chart.scales.y.top).toBeCloseToPixel(62);
+ expect(chart.scales.y.labelRotation).toBeCloseTo(0);
});
it('should fit scales with long labels correctly', function() {
display: false
},
scales: {
- xAxes: [{
- id: 'xScale',
+ x: {
type: 'category',
ticks: {
maxRotation: 0,
autoSkip: false
}
- }],
- yAxes: [{
- id: 'yScale',
+ },
+ y: {
type: 'linear',
position: 'right'
- }]
+ }
}
}
}, {
expect(chart.chartArea.top).toBeCloseToPixel(7);
// Is xScale at the right spot
- expect(chart.scales.xScale.bottom).toBeCloseToPixel(150);
- expect(chart.scales.xScale.left).toBeCloseToPixel(60);
- expect(chart.scales.xScale.right).toBeCloseToPixel(452);
- expect(chart.scales.xScale.top).toBeCloseToPixel(120);
- expect(chart.scales.xScale.labelRotation).toBeCloseTo(0);
-
- expect(chart.scales.xScale.height).toBeCloseToPixel(30);
- expect(chart.scales.xScale.paddingLeft).toBeCloseToPixel(60);
- expect(chart.scales.xScale.paddingTop).toBeCloseToPixel(0);
- expect(chart.scales.xScale.paddingRight).toBeCloseToPixel(60);
- expect(chart.scales.xScale.paddingBottom).toBeCloseToPixel(0);
+ expect(chart.scales.x.bottom).toBeCloseToPixel(150);
+ expect(chart.scales.x.left).toBeCloseToPixel(60);
+ expect(chart.scales.x.right).toBeCloseToPixel(452);
+ expect(chart.scales.x.top).toBeCloseToPixel(120);
+ expect(chart.scales.x.labelRotation).toBeCloseTo(0);
+
+ expect(chart.scales.x.height).toBeCloseToPixel(30);
+ expect(chart.scales.x.paddingLeft).toBeCloseToPixel(60);
+ expect(chart.scales.x.paddingTop).toBeCloseToPixel(0);
+ expect(chart.scales.x.paddingRight).toBeCloseToPixel(60);
+ expect(chart.scales.x.paddingBottom).toBeCloseToPixel(0);
// Is yScale at the right spot
- expect(chart.scales.yScale.bottom).toBeCloseToPixel(120);
- expect(chart.scales.yScale.left).toBeCloseToPixel(452);
- expect(chart.scales.yScale.right).toBeCloseToPixel(486);
- expect(chart.scales.yScale.top).toBeCloseToPixel(7);
- expect(chart.scales.yScale.labelRotation).toBeCloseTo(0);
-
- expect(chart.scales.yScale.width).toBeCloseToPixel(34);
- expect(chart.scales.yScale.paddingLeft).toBeCloseToPixel(0);
- expect(chart.scales.yScale.paddingTop).toBeCloseToPixel(7);
- expect(chart.scales.yScale.paddingRight).toBeCloseToPixel(0);
- expect(chart.scales.yScale.paddingBottom).toBeCloseToPixel(7);
+ expect(chart.scales.y.bottom).toBeCloseToPixel(120);
+ expect(chart.scales.y.left).toBeCloseToPixel(452);
+ expect(chart.scales.y.right).toBeCloseToPixel(486);
+ expect(chart.scales.y.top).toBeCloseToPixel(7);
+ expect(chart.scales.y.labelRotation).toBeCloseTo(0);
+
+ expect(chart.scales.y.width).toBeCloseToPixel(34);
+ expect(chart.scales.y.paddingLeft).toBeCloseToPixel(0);
+ expect(chart.scales.y.paddingTop).toBeCloseToPixel(7);
+ expect(chart.scales.y.paddingRight).toBeCloseToPixel(0);
+ expect(chart.scales.y.paddingBottom).toBeCloseToPixel(7);
});
it('should fit scales that overlap the chart area', function() {
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 scale = chart.scales.r;
+ expect(scale.bottom).toBeCloseToPixel(512);
+ expect(scale.left).toBeCloseToPixel(0);
+ expect(scale.right).toBeCloseToPixel(512);
+ expect(scale.top).toBeCloseToPixel(32);
+ expect(scale.width).toBeCloseToPixel(512);
+ expect(scale.height).toBeCloseToPixel(480);
});
it('should fit multiple axes in the same position', function() {
type: 'bar',
data: {
datasets: [{
- yAxisID: 'yScale1',
+ yAxisID: 'y',
data: [10, 5, 0, 25, 78, -10]
}, {
- yAxisID: 'yScale2',
+ yAxisID: 'y2',
data: [-19, -20, 0, -99, -50, 0]
}],
labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5', 'tick6']
},
options: {
scales: {
- xAxes: [{
- id: 'xScale',
+ x: {
type: 'category'
- }],
- yAxes: [{
- id: 'yScale1',
+ },
+ y: {
type: 'linear'
- }, {
- id: 'yScale2',
+ },
+ y2: {
type: 'linear'
- }]
+ }
}
}
}, {
expect(chart.chartArea.top).toBeCloseToPixel(32);
// Is xScale at the right spot
- expect(chart.scales.xScale.bottom).toBeCloseToPixel(150);
- expect(chart.scales.xScale.left).toBeCloseToPixel(73);
- expect(chart.scales.xScale.right).toBeCloseToPixel(247);
- expect(chart.scales.xScale.top).toBeCloseToPixel(118);
- expect(chart.scales.xScale.labelRotation).toBeCloseTo(40, -1);
+ expect(chart.scales.x.bottom).toBeCloseToPixel(150);
+ expect(chart.scales.x.left).toBeCloseToPixel(73);
+ expect(chart.scales.x.right).toBeCloseToPixel(247);
+ expect(chart.scales.x.top).toBeCloseToPixel(118);
+ expect(chart.scales.x.labelRotation).toBeCloseTo(40, -1);
// Are yScales at the right spot
- expect(chart.scales.yScale1.bottom).toBeCloseToPixel(118);
- expect(chart.scales.yScale1.left).toBeCloseToPixel(41);
- expect(chart.scales.yScale1.right).toBeCloseToPixel(73);
- expect(chart.scales.yScale1.top).toBeCloseToPixel(32);
- expect(chart.scales.yScale1.labelRotation).toBeCloseTo(0);
-
- expect(chart.scales.yScale2.bottom).toBeCloseToPixel(118);
- expect(chart.scales.yScale2.left).toBeCloseToPixel(0);
- expect(chart.scales.yScale2.right).toBeCloseToPixel(41);
- expect(chart.scales.yScale2.top).toBeCloseToPixel(32);
- expect(chart.scales.yScale2.labelRotation).toBeCloseTo(0);
+ expect(chart.scales.y.bottom).toBeCloseToPixel(118);
+ expect(chart.scales.y.left).toBeCloseToPixel(41);
+ expect(chart.scales.y.right).toBeCloseToPixel(73);
+ expect(chart.scales.y.top).toBeCloseToPixel(32);
+ expect(chart.scales.y.labelRotation).toBeCloseTo(0);
+
+ expect(chart.scales.y2.bottom).toBeCloseToPixel(118);
+ expect(chart.scales.y2.left).toBeCloseToPixel(0);
+ expect(chart.scales.y2.right).toBeCloseToPixel(41);
+ expect(chart.scales.y2.top).toBeCloseToPixel(32);
+ expect(chart.scales.y2.labelRotation).toBeCloseTo(0);
});
it ('should fit a full width box correctly', function() {
type: 'bar',
data: {
datasets: [{
- xAxisID: 'xScale1',
+ xAxisID: 'x',
data: [10, 5, 0, 25, 78, -10]
}, {
- xAxisID: 'xScale2',
+ xAxisID: 'x2',
data: [-19, -20, 0, -99, -50, 0]
}],
labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5', 'tick6']
},
options: {
scales: {
- xAxes: [{
- id: 'xScale1',
- type: 'category'
- }, {
- id: 'xScale2',
+ x: {
+ type: 'category',
+ offset: false
+ },
+ x2: {
type: 'category',
position: 'top',
- fullWidth: true
- }],
- yAxes: [{
- id: 'yScale',
+ fullWidth: true,
+ offset: false
+ },
+ y: {
type: 'linear'
- }]
+ }
}
}
});
expect(chart.chartArea.top).toBeCloseToPixel(62);
// Are xScales at the right spot
- expect(chart.scales.xScale1.bottom).toBeCloseToPixel(512);
- expect(chart.scales.xScale1.left).toBeCloseToPixel(40);
- expect(chart.scales.xScale1.right).toBeCloseToPixel(496);
- expect(chart.scales.xScale1.top).toBeCloseToPixel(484);
+ expect(chart.scales.x.bottom).toBeCloseToPixel(512);
+ expect(chart.scales.x.left).toBeCloseToPixel(40);
+ expect(chart.scales.x.right).toBeCloseToPixel(496);
+ expect(chart.scales.x.top).toBeCloseToPixel(484);
- expect(chart.scales.xScale2.bottom).toBeCloseToPixel(62);
- expect(chart.scales.xScale2.left).toBeCloseToPixel(0);
- expect(chart.scales.xScale2.right).toBeCloseToPixel(512);
- expect(chart.scales.xScale2.top).toBeCloseToPixel(32);
+ expect(chart.scales.x2.bottom).toBeCloseToPixel(62);
+ expect(chart.scales.x2.left).toBeCloseToPixel(0);
+ expect(chart.scales.x2.right).toBeCloseToPixel(512);
+ expect(chart.scales.x2.top).toBeCloseToPixel(32);
// Is yScale at the right spot
- expect(chart.scales.yScale.bottom).toBeCloseToPixel(484);
- expect(chart.scales.yScale.left).toBeCloseToPixel(0);
- expect(chart.scales.yScale.right).toBeCloseToPixel(40);
- expect(chart.scales.yScale.top).toBeCloseToPixel(62);
+ expect(chart.scales.y.bottom).toBeCloseToPixel(484);
+ expect(chart.scales.y.left).toBeCloseToPixel(0);
+ expect(chart.scales.y.right).toBeCloseToPixel(40);
+ expect(chart.scales.y.top).toBeCloseToPixel(62);
});
describe('padding settings', function() {
},
options: {
scales: {
- xAxes: [{
- id: 'xScale',
+ x: {
type: 'category',
display: false
- }],
- yAxes: [{
- id: 'yScale',
+ },
+ y: {
type: 'linear',
display: false
- }]
+ }
},
legend: {
display: false
},
options: {
scales: {
- xAxes: [{
- id: 'xScale',
+ x: {
type: 'category',
display: false
- }],
- yAxes: [{
- id: 'yScale',
+ },
+ y: {
type: 'linear',
display: false
- }]
+ }
},
legend: {
display: false
},
options: {
scales: {
- xAxes: [{
- id: 'xScale',
+ x: {
type: 'category',
display: false
- }],
- yAxes: [{
- id: 'yScale',
+ },
+ y: {
type: 'linear',
display: false
- }]
+ }
},
legend: {
display: false
}
});
- var xAxis = chart.scales['x-axis-0'];
- var yAxis = chart.scales['y-axis-0'];
+ var xAxis = chart.scales.x;
+ var yAxis = chart.scales.y;
var legend = chart.legend;
var title = chart.titleBlock;
},
options: {
scales: {
- xAxes: [{
- id: 'xScale0',
+ x: {
type: 'category',
+ position: 'bottom',
display: true,
weight: 1
- }, {
- id: 'xScale1',
+ },
+ x1: {
type: 'category',
+ position: 'bottom',
display: true,
weight: 2
- }, {
- id: 'xScale2',
+ },
+ x2: {
type: 'category',
+ position: 'bottom',
display: true
- }, {
- id: 'xScale3',
+ },
+ x3: {
type: 'category',
display: true,
position: 'top',
weight: 1
- }, {
- id: 'xScale4',
+ },
+ x4: {
type: 'category',
display: true,
position: 'top',
weight: 2
- }],
- yAxes: [{
- id: 'yScale0',
+ },
+ y: {
type: 'linear',
display: true,
weight: 1
- }, {
- id: 'yScale1',
+ },
+ y1: {
type: 'linear',
+ position: 'left',
display: true,
weight: 2
- }, {
- id: 'yScale2',
+ },
+ y2: {
type: 'linear',
+ position: 'left',
display: true
- }, {
- id: 'yScale3',
+ },
+ y3: {
type: 'linear',
display: true,
position: 'right',
weight: 1
- }, {
- id: 'yScale4',
+ },
+ y4: {
type: 'linear',
display: true,
position: 'right',
weight: 2
- }]
+ }
}
}
}, {
}
});
- var xScale0 = chart.scales.xScale0;
- var xScale1 = chart.scales.xScale1;
- var xScale2 = chart.scales.xScale2;
- var xScale3 = chart.scales.xScale3;
- var xScale4 = chart.scales.xScale4;
+ var xScale0 = chart.scales.x;
+ var xScale1 = chart.scales.x1;
+ var xScale2 = chart.scales.x2;
+ var xScale3 = chart.scales.x3;
+ var xScale4 = chart.scales.x4;
- var yScale0 = chart.scales.yScale0;
- var yScale1 = chart.scales.yScale1;
- var yScale2 = chart.scales.yScale2;
- var yScale3 = chart.scales.yScale3;
- var yScale4 = chart.scales.yScale4;
+ var yScale0 = chart.scales.y;
+ var yScale1 = chart.scales.y1;
+ var yScale2 = chart.scales.y2;
+ var yScale3 = chart.scales.y3;
+ var yScale4 = chart.scales.y4;
expect(xScale0.weight).toBe(1);
expect(xScale1.weight).toBe(2);
width: 256
}
});
- var yAxis = chart.scales['y-axis-0'];
+ var yAxis = chart.scales.y;
// issue #4441: y-axis labels partially hidden.
// minimum horizontal space required to fit labels
data: data,
options: {
scales: {
- xAxes: [{
+ x: {
ticks: {
autoSkip: true
}
- }]
+ }
}
}
});
}
function lastTick(chart) {
- var xAxis = chart.scales['x-axis-0'];
+ var xAxis = chart.scales.x;
var ticks = xAxis.getTicks();
return ticks[ticks.length - 1];
}
},
options: {
scales: {
- xAxes: [{
- id: 'xScale0',
+ x: {
gridLines: {
offsetGridLines: test.offsetGridLines,
drawTicks: false
display: false
},
offset: test.offset
- }],
- yAxes: [{
+ },
+ y: {
display: false
- }]
+ }
},
legend: {
display: false
}
});
- var xScale = chart.scales.xScale0;
+ var xScale = chart.scales.x;
xScale.ctx = window.createMockContext();
chart.draw();
},
options: {
scales: {
- xAxes: [{
+ x: {
display: false
- }],
- yAxes: [{
+ },
+ y: {
type: 'category',
- id: 'yScale0',
gridLines: {
offsetGridLines: test.offsetGridLines,
drawTicks: false
display: false
},
offset: test.offset
- }]
+ }
},
legend: {
display: false
}
});
- var yScale = chart.scales.yScale0;
+ var yScale = chart.scales.y;
yScale.ctx = window.createMockContext();
chart.draw();
},
options: {
scales: {
- xAxes: [{
- id: 'foo'
- }],
- yAxes: [{
+ y: {
display: false
- }]
+ }
},
legend: {
display: false
}
});
- var scale = chart.scales.foo;
+ var scale = chart.scales.x;
expect(scale.left).toBeGreaterThan(100);
expect(scale.right).toBeGreaterThan(190);
});
},
options: {
scales: {
- xAxes: [{
- id: 'foo',
+ x: {
display: 'auto'
- }],
- yAxes: [{
+ },
+ y: {
type: 'category',
- id: 'yScale0'
- }]
+ }
}
}
});
- var scale = chart.scales.foo;
+ var scale = chart.scales.x;
scale.ctx = window.createMockContext();
chart.draw();
},
options: {
scales: {
- xAxes: [{
- id: 'foo',
+ x: {
display: 'auto'
- }]
+ }
}
}
});
- var scale = chart.scales.foo;
+ var scale = chart.scales.x;
scale.ctx = window.createMockContext();
chart.draw();
},
options: {
scales: {
- yAxes: [{
- id: 'foo',
+ y: {
display: 'auto'
- }]
+ }
}
}
});
- var scale = chart.scales.foo;
+ var scale = chart.scales.y;
scale.ctx = window.createMockContext();
chart.draw();
},
options: {
scales: {
- yAxes: [{
- id: 'foo',
+ y: {
display: 'auto'
- }]
+ }
}
}
});
- var scale = chart.scales.foo;
+ var scale = chart.scales.y;
scale.ctx = window.createMockContext();
chart.draw();
type: 'line',
options: {
scales: {
- xAxes: [{
- id: 'x',
+ x: {
type: 'category',
labels: labels,
afterBuildTicks: function(scale) {
scale.ticks = scale.ticks.slice(1);
}
- }]
+ }
}
}
});
type: 'line',
options: {
scales: {
- xAxes: [{
- id: 'x',
+ x: {
type: 'category',
labels: labels,
afterBuildTicks: function() { }
- }]
+ }
}
}
});
type: 'line',
options: {
scales: {
- xAxes: [{
- id: 'x',
+ x: {
type: 'category',
labels: labels,
afterBuildTicks: function(scale) {
scale.ticks = [];
}
- }]
+ }
}
}
});
type: 'line',
options: {
scales: {
- xAxes: [{
- id: 'x',
+ x: {
type: 'linear',
- }]
+ }
}
}
});
type: 'line',
options: {
scales: {
- xAxes: [{
- id: 'x',
+ x: {
type: 'customScale',
gridLines: {
z: 10
ticks: {
z: 20
}
- }]
+ }
}
}
});
type: 'line',
options: {
scales: {
- xAxes: [{
- id: 'x',
+ x: {
type: 'linear',
ticks: {
z: 10
gridLines: {
z: 10
}
- }]
+ }
}
}
});
type: 'line',
options: {
scales: {
- xAxes: [{
- id: 'x',
+ x: {
type: 'linear',
ticks: {
z: 10
}
- }]
+ }
}
}
});
type: 'line',
options: {
scales: {
- xAxes: [{
- id: 'x',
+ x: {
type: 'linear',
gridLines: {
z: 11
}
- }]
+ }
}
}
});
type: 'line',
options: {
scales: {
- xAxes: [{
- id: 'x',
+ x: {
type: 'linear',
ticks: {
z: 10
gridLines: {
z: 11
}
- }]
+ }
}
}
});
},
options: {
scales: {
- xAxes: [{
+ x: {
id: 'x',
type: 'linear',
min: -20,
max: 20
- }],
- yAxes: [{
+ },
+ y: {
id: 'y',
type: 'linear'
- }]
+ }
}
}
});
display: false,
},
scales: {
- xAxes: [{
+ x: {
type: 'linear',
position: 'bottom',
ticks: {
return value.toString();
}
}
- }],
- yAxes: [{
+ },
+ y: {
type: 'linear',
ticks: {
callback: function(value) {
return value.toString();
}
}
- }]
+ }
}
}
});
- var xLabels = getLabels(chart.scales['x-axis-0']);
- var yLabels = getLabels(chart.scales['y-axis-0']);
+ var xLabels = getLabels(chart.scales.x);
+ var yLabels = getLabels(chart.scales.y);
expect(xLabels).toEqual(['0', '0.1', '0.2', '0.3', '0.4', '0.5', '0.6', '0.7', '0.8', '0.9', '1']);
expect(yLabels).toEqual(['1', '0.9', '0.8', '0.7', '0.6', '0.5', '0.4', '0.3', '0.2', '0.1', '0']);
display: false,
},
scales: {
- xAxes: [{
+ x: {
type: 'logarithmic',
position: 'bottom',
min: 0.1,
return value.toString();
}
}
- }],
- yAxes: [{
+ },
+ y: {
type: 'logarithmic',
min: 0.1,
max: 1,
return value.toString();
}
}
- }]
+ }
}
}
});
- var xLabels = getLabels(chart.scales['x-axis-0']);
- var yLabels = getLabels(chart.scales['y-axis-0']);
+ var xLabels = getLabels(chart.scales.x);
+ var yLabels = getLabels(chart.scales.y);
expect(xLabels).toEqual(['0.1', '0.2', '0.3', '0.4', '0.5', '0.6', '0.7', '0.8', '0.9', '1']);
expect(yLabels).toEqual(['1', '0.9', '0.8', '0.7', '0.6', '0.5', '0.4', '0.3', '0.2', '0.1']);
},
options: {
scales: {
- xAxes: [{
- id: 'x',
+ x: {
type: 'category',
labels: labels
- }]
+ }
}
}
});
type: 'line',
data: {
datasets: [{
- xAxisID: 'xScale0',
- yAxisID: 'yScale0',
+ xAxisID: 'x',
+ yAxisID: 'y',
data: [10, 5, 0, 25, 78]
}],
labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5']
},
options: {
scales: {
- xAxes: [{
- id: 'xScale0',
+ x: {
type: 'category',
position: 'bottom'
- }],
- yAxes: [{
- id: 'yScale0',
+ },
+ y: {
type: 'linear'
- }]
+ }
}
}
});
- var scale = chart.scales.xScale0;
+ var scale = chart.scales.x;
expect(scale.getLabelForValue(1)).toBe('tick2');
});
type: 'line',
data: {
datasets: [{
- xAxisID: 'xScale0',
- yAxisID: 'yScale0',
+ xAxisID: 'x',
+ yAxisID: 'y',
data: [10, 5, 0, 25, 78]
}],
labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick_last']
},
options: {
scales: {
- xAxes: [{
- id: 'xScale0',
+ x: {
type: 'category',
position: 'bottom'
- }],
- yAxes: [{
- id: 'yScale0',
+ },
+ y: {
type: 'linear'
- }]
+ }
}
}
});
- var xScale = chart.scales.xScale0;
+ var xScale = chart.scales.x;
expect(xScale.getPixelForValue(0)).toBeCloseToPixel(23 + 6); // plus lineHeight
expect(xScale.getValueForPixel(23)).toBe(0);
type: 'line',
data: {
datasets: [{
- xAxisID: 'xScale0',
- yAxisID: 'yScale0',
+ xAxisID: 'x',
+ yAxisID: 'y',
data: [10, 5, 0, 25, 78]
}],
labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick_last']
},
options: {
scales: {
- xAxes: [{
- id: 'xScale0',
+ x: {
type: 'category',
position: 'bottom'
- }],
- yAxes: [{
- id: 'yScale0',
+ },
+ y: {
type: 'linear'
- }]
+ }
}
}
});
- var xScale = chart.scales.xScale0;
+ var xScale = chart.scales.x;
expect(xScale.getPixelForValue('tick1')).toBeCloseToPixel(23 + 6); // plus lineHeight
});
type: 'line',
data: {
datasets: [{
- xAxisID: 'xScale0',
- yAxisID: 'yScale0',
+ xAxisID: 'x',
+ yAxisID: 'y',
data: [10, 5, 0, 25, 78]
}],
labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick_last']
},
options: {
scales: {
- xAxes: [{
- id: 'xScale0',
+ x: {
type: 'category',
position: 'bottom',
min: 'tick2',
max: 'tick4'
- }],
- yAxes: [{
- id: 'yScale0',
+ },
+ y: {
type: 'linear'
- }]
+ }
}
}
});
- var xScale = chart.scales.xScale0;
+ var xScale = chart.scales.x;
expect(xScale.getPixelForValue(1)).toBeCloseToPixel(23 + 6); // plus lineHeight
expect(xScale.getPixelForValue(3)).toBeCloseToPixel(496);
type: 'line',
data: {
datasets: [{
- xAxisID: 'xScale0',
- yAxisID: 'yScale0',
+ xAxisID: 'x',
+ yAxisID: 'y',
data: ['3', '5', '1', '4', '2']
}],
labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5'],
},
options: {
scales: {
- xAxes: [{
- id: 'xScale0',
+ x: {
type: 'category',
position: 'bottom',
- }],
- yAxes: [{
- id: 'yScale0',
+ },
+ y: {
type: 'category',
position: 'left'
- }]
+ }
}
}
});
- var yScale = chart.scales.yScale0;
+ var yScale = chart.scales.y;
expect(yScale.getPixelForValue(0)).toBeCloseToPixel(32);
expect(yScale.getValueForPixel(257)).toBe(2);
type: 'line',
data: {
datasets: [{
- xAxisID: 'xScale0',
- yAxisID: 'yScale0',
+ xAxisID: 'x',
+ yAxisID: 'y',
data: ['3', '5', '1', '4', '2']
}],
labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5'],
},
options: {
scales: {
- xAxes: [{
- id: 'xScale0',
+ x: {
type: 'category',
position: 'bottom',
- }],
- yAxes: [{
- id: 'yScale0',
+ },
+ y: {
type: 'category',
position: 'left',
min: '2',
max: '4'
- }]
+ }
}
}
});
- var yScale = chart.scales.yScale0;
+ var yScale = chart.scales.y;
expect(yScale.getPixelForValue(1)).toBeCloseToPixel(32);
expect(yScale.getPixelForValue(3)).toBeCloseToPixel(482);
type: 'line',
data: {
datasets: [{
- xAxisID: 'xScale0',
- yAxisID: 'yScale0',
+ xAxisID: 'x',
+ yAxisID: 'y',
data: [
{x: 0, y: 10},
{x: 1, y: 5},
},
options: {
scales: {
- xAxes: [{
- id: 'xScale0',
+ x: {
type: 'category',
position: 'bottom'
- }],
- yAxes: [{
- id: 'yScale0',
+ },
+ y: {
type: 'linear'
- }]
+ }
}
}
});
- var xScale = chart.scales.xScale0;
+ var xScale = chart.scales.x;
expect(xScale.getPixelForValue(0)).toBeCloseToPixel(29);
expect(xScale.getPixelForValue(3)).toBeCloseToPixel(506);
expect(xScale.getPixelForValue(4)).toBeCloseToPixel(664);
type: 'line',
data: {
datasets: [{
- xAxisID: 'xScale0',
- yAxisID: 'yScale0',
+ xAxisID: 'x',
+ yAxisID: 'y',
data: [
{x: 0, y: 2},
{x: 1, y: 4},
},
options: {
scales: {
- xAxes: [{
- id: 'xScale0',
+ x: {
type: 'category',
position: 'bottom'
- }],
- yAxes: [{
- id: 'yScale0',
+ },
+ y: {
type: 'category',
position: 'left'
- }]
+ }
}
}
});
- var yScale = chart.scales.yScale0;
+ var yScale = chart.scales.y;
expect(yScale.getPixelForValue(0)).toBeCloseToPixel(32);
expect(yScale.getPixelForValue(4)).toBeCloseToPixel(481);
});
type: 'bar',
data: {
datasets: [{
- xAxisID: 'xScale0',
- yAxisID: 'yScale0',
+ xAxisID: 'x',
+ yAxisID: 'y',
data: [
{x: 0, y: 10},
{x: 1, y: 5},
},
options: {
scales: {
- xAxes: [{
- id: 'xScale0',
+ x: {
type: 'category',
position: 'bottom'
- }],
- yAxes: [{
- id: 'yScale0',
+ },
+ y: {
type: 'linear'
- }]
+ }
}
}
});
- var xScale = chart.scales.xScale0;
+ var xScale = chart.scales.x;
expect(xScale.getPixelForValue(0)).toBeCloseToPixel(89);
expect(xScale.getPixelForValue(3)).toBeCloseToPixel(449);
expect(xScale.getPixelForValue(4)).toBeCloseToPixel(569);
type: 'horizontalBar',
data: {
datasets: [{
- xAxisID: 'xScale0',
- yAxisID: 'yScale0',
+ xAxisID: 'x',
+ yAxisID: 'y',
data: [
{x: 10, y: 0},
{x: 5, y: 1},
},
options: {
scales: {
- xAxes: [{
- id: 'xScale0',
+ x: {
type: 'linear',
position: 'bottom'
- }],
- yAxes: [{
- id: 'yScale0',
+ },
+ y: {
type: 'category'
- }]
+ }
}
}
});
- var yScale = chart.scales.yScale0;
+ var yScale = chart.scales.y;
expect(yScale.getPixelForValue(0)).toBeCloseToPixel(88);
expect(yScale.getPixelForValue(3)).toBeCloseToPixel(426);
expect(yScale.getPixelForValue(4)).toBeCloseToPixel(538);
type: 'bar',
data: {
datasets: [{
- yAxisID: 'yScale0',
+ yAxisID: 'y',
data: [10, 5, 0, -5, 78, -100]
}, {
- yAxisID: 'yScale1',
+ yAxisID: 'y2',
data: [-1000, 1000],
}, {
- yAxisID: 'yScale0',
+ yAxisID: 'y',
data: [150]
}],
labels: ['a', 'b', 'c', 'd', 'e', 'f']
},
options: {
scales: {
- yAxes: [{
- id: 'yScale0',
+ y: {
type: 'linear'
- }, {
- id: 'yScale1',
- type: 'linear'
- }]
+ },
+ y2: {
+ type: 'linear',
+ position: 'right',
+ }
}
}
});
- expect(chart.scales.yScale0).not.toEqual(undefined); // must construct
- expect(chart.scales.yScale0.min).toBe(-100);
- expect(chart.scales.yScale0.max).toBe(150);
+ expect(chart.scales.y).not.toEqual(undefined); // must construct
+ expect(chart.scales.y.min).toBe(-100);
+ expect(chart.scales.y.max).toBe(150);
});
it('Should correctly determine the max & min of string data values', function() {
type: 'bar',
data: {
datasets: [{
- yAxisID: 'yScale0',
+ yAxisID: 'y',
data: ['10', '5', '0', '-5', '78', '-100']
}, {
- yAxisID: 'yScale1',
+ yAxisID: 'y2',
data: ['-1000', '1000'],
}, {
- yAxisID: 'yScale0',
+ yAxisID: 'y',
data: ['150']
}],
labels: ['a', 'b', 'c', 'd', 'e', 'f']
},
options: {
scales: {
- yAxes: [{
- id: 'yScale0',
+ y: {
type: 'linear'
- }, {
- id: 'yScale1',
- type: 'linear'
- }]
+ },
+ y2: {
+ type: 'linear',
+ position: 'right'
+ }
}
}
});
- expect(chart.scales.yScale0).not.toEqual(undefined); // must construct
- expect(chart.scales.yScale0.min).toBe(-100);
- expect(chart.scales.yScale0.max).toBe(150);
+ expect(chart.scales.y).not.toEqual(undefined); // must construct
+ expect(chart.scales.y.min).toBe(-100);
+ expect(chart.scales.y.max).toBe(150);
});
it('Should correctly determine the max & min when no values provided and suggested minimum and maximum are set', function() {
type: 'bar',
data: {
datasets: [{
- yAxisID: 'yScale0',
+ yAxisID: 'y',
data: []
}],
labels: ['a', 'b', 'c', 'd', 'e', 'f']
},
options: {
scales: {
- yAxes: [{
- id: 'yScale0',
+ y: {
type: 'linear',
suggestedMin: -10,
suggestedMax: 15
- }]
+ }
}
}
});
- expect(chart.scales.yScale0).not.toEqual(undefined); // must construct
- expect(chart.scales.yScale0.min).toBe(-10);
- expect(chart.scales.yScale0.max).toBe(15);
+ expect(chart.scales.y).not.toEqual(undefined); // must construct
+ expect(chart.scales.y.min).toBe(-10);
+ expect(chart.scales.y.max).toBe(15);
});
it('Should correctly determine the max & min data values ignoring hidden datasets', function() {
type: 'bar',
data: {
datasets: [{
- yAxisID: 'yScale0',
+ yAxisID: 'y',
data: ['10', '5', '0', '-5', '78', '-100']
}, {
- yAxisID: 'yScale1',
+ yAxisID: 'y2',
data: ['-1000', '1000'],
}, {
- yAxisID: 'yScale0',
+ yAxisID: 'y',
data: ['150'],
hidden: true
}],
},
options: {
scales: {
- yAxes: [{
- id: 'yScale0',
+ y: {
type: 'linear'
- }, {
- id: 'yScale1',
+ },
+ y2: {
+ position: 'right',
type: 'linear'
- }]
+ }
}
}
});
- expect(chart.scales.yScale0).not.toEqual(undefined); // must construct
- expect(chart.scales.yScale0.min).toBe(-100);
- expect(chart.scales.yScale0.max).toBe(80);
+ expect(chart.scales.y).not.toEqual(undefined); // must construct
+ expect(chart.scales.y.min).toBe(-100);
+ expect(chart.scales.y.max).toBe(80);
});
it('Should correctly determine the max & min data values ignoring data that is NaN', function() {
type: 'bar',
data: {
datasets: [{
- yAxisID: 'yScale0',
+ yAxisID: 'y',
data: [null, 90, NaN, undefined, 45, 30, Infinity, -Infinity]
}],
labels: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
},
options: {
scales: {
- yAxes: [{
- id: 'yScale0',
+ y: {
type: 'linear'
- }]
+ }
}
}
});
- expect(chart.scales.yScale0.min).toBe(30);
- expect(chart.scales.yScale0.max).toBe(90);
+ expect(chart.scales.y.min).toBe(30);
+ expect(chart.scales.y.max).toBe(90);
// Scale is now stacked
- chart.scales.yScale0.options.stacked = true;
+ chart.scales.y.options.stacked = true;
chart.update();
- expect(chart.scales.yScale0.min).toBe(0);
- expect(chart.scales.yScale0.max).toBe(90);
+ expect(chart.scales.y.min).toBe(0);
+ expect(chart.scales.y.max).toBe(90);
});
it('Should correctly determine the max & min data values for small numbers', function() {
type: 'bar',
data: {
datasets: [{
- yAxisID: 'yScale0',
+ yAxisID: 'y',
data: [-1e-8, 3e-8, -4e-8, 6e-8]
}],
labels: ['a', 'b', 'c', 'd']
},
options: {
scales: {
- yAxes: [{
- id: 'yScale0',
+ y: {
type: 'linear'
- }]
+ }
}
}
});
- expect(chart.scales.yScale0).not.toEqual(undefined); // must construct
- expect(chart.scales.yScale0.min * 1e8).toBeCloseTo(-4);
- expect(chart.scales.yScale0.max * 1e8).toBeCloseTo(6);
+ expect(chart.scales.y).not.toEqual(undefined); // must construct
+ expect(chart.scales.y.min * 1e8).toBeCloseTo(-4);
+ expect(chart.scales.y.max * 1e8).toBeCloseTo(6);
});
it('Should correctly determine the max & min for scatter data', function() {
type: 'line',
data: {
datasets: [{
- xAxisID: 'xScale0',
- yAxisID: 'yScale0',
+ xAxisID: 'x',
+ yAxisID: 'y',
data: [{
x: 10,
y: 100
},
options: {
scales: {
- xAxes: [{
- id: 'xScale0',
+ x: {
type: 'linear',
position: 'bottom'
- }],
- yAxes: [{
- id: 'yScale0',
+ },
+ y: {
type: 'linear'
- }]
+ }
}
}
});
chart.update();
- expect(chart.scales.xScale0.min).toBe(-20);
- expect(chart.scales.xScale0.max).toBe(100);
- expect(chart.scales.yScale0.min).toBe(0);
- expect(chart.scales.yScale0.max).toBe(100);
+ expect(chart.scales.x.min).toBe(-20);
+ expect(chart.scales.x.max).toBe(100);
+ expect(chart.scales.y.min).toBe(0);
+ expect(chart.scales.y.max).toBe(100);
});
it('Should correctly get the label for the given index', function() {
type: 'line',
data: {
datasets: [{
- xAxisID: 'xScale0',
- yAxisID: 'yScale0',
+ xAxisID: 'x',
+ yAxisID: 'y',
data: [{
x: 10,
y: 100
},
options: {
scales: {
- xAxes: [{
- id: 'xScale0',
+ x: {
type: 'linear',
position: 'bottom'
- }],
- yAxes: [{
- id: 'yScale0',
+ },
+ y: {
type: 'linear'
- }]
+ }
}
}
});
chart.update();
- expect(chart.scales.yScale0.getLabelForValue(7)).toBe(7);
+ expect(chart.scales.y.getLabelForValue(7)).toBe(7);
});
it('Should correctly determine the min and max data values when stacked mode is turned on', function() {
type: 'line',
data: {
datasets: [{
- yAxisID: 'yScale0',
+ yAxisID: 'y',
data: [10, 5, 0, -5, 78, -100],
type: 'bar'
}, {
- yAxisID: 'yScale1',
+ yAxisID: 'y2',
data: [-1000, 1000],
}, {
- yAxisID: 'yScale0',
+ yAxisID: 'y',
data: [150, 0, 0, -100, -10, 9],
type: 'bar'
}, {
- yAxisID: 'yScale0',
+ yAxisID: 'y',
data: [10, 10, 10, 10, 10, 10],
type: 'line'
}],
},
options: {
scales: {
- yAxes: [{
- id: 'yScale0',
+ y: {
type: 'linear',
stacked: true
- }, {
- id: 'yScale1',
+ },
+ y2: {
+ position: 'right',
type: 'linear'
- }]
+ }
}
}
});
chart.update();
- expect(chart.scales.yScale0.min).toBe(-150);
- expect(chart.scales.yScale0.max).toBe(200);
+ expect(chart.scales.y.min).toBe(-150);
+ expect(chart.scales.y.max).toBe(200);
});
it('Should correctly determine the min and max data values when stacked mode is turned on and there are hidden datasets', function() {
type: 'bar',
data: {
datasets: [{
- yAxisID: 'yScale0',
+ yAxisID: 'y',
data: [10, 5, 0, -5, 78, -100],
}, {
- yAxisID: 'yScale1',
+ yAxisID: 'y2',
data: [-1000, 1000],
}, {
- yAxisID: 'yScale0',
+ yAxisID: 'y',
data: [150, 0, 0, -100, -10, 9],
}, {
- yAxisID: 'yScale0',
+ yAxisID: 'y',
data: [10, 20, 30, 40, 50, 60],
hidden: true
}],
},
options: {
scales: {
- yAxes: [{
- id: 'yScale0',
+ y: {
type: 'linear',
stacked: true
- }, {
- id: 'yScale1',
+ },
+ y2: {
+ position: 'right',
type: 'linear'
- }]
+ }
}
}
});
chart.update();
- expect(chart.scales.yScale0.min).toBe(-150);
- expect(chart.scales.yScale0.max).toBe(200);
+ expect(chart.scales.y.min).toBe(-150);
+ expect(chart.scales.y.max).toBe(200);
});
it('Should correctly determine the min and max data values when stacked mode is turned on there are multiple types of datasets', function() {
type: 'bar',
data: {
datasets: [{
- yAxisID: 'yScale0',
+ yAxisID: 'y',
type: 'bar',
data: [10, 5, 0, -5, 78, -100]
}, {
},
options: {
scales: {
- yAxes: [{
- id: 'yScale0',
+ y: {
type: 'linear',
stacked: true
- }]
+ }
}
}
});
- chart.scales.yScale0.determineDataLimits();
- expect(chart.scales.yScale0.min).toBe(-105);
- expect(chart.scales.yScale0.max).toBe(160);
+ chart.scales.y.determineDataLimits();
+ expect(chart.scales.y.min).toBe(-105);
+ expect(chart.scales.y.max).toBe(160);
});
it('Should ensure that the scale has a max and min that are not equal', function() {
},
options: {
scales: {
- yAxes: [{
- id: 'yScale0',
+ y: {
type: 'linear'
- }]
+ }
}
}
});
- expect(chart.scales.yScale0).not.toEqual(undefined); // must construct
- expect(chart.scales.yScale0.min).toBe(0);
- expect(chart.scales.yScale0.max).toBe(1);
+ expect(chart.scales.y).not.toEqual(undefined); // must construct
+ expect(chart.scales.y.min).toBe(0);
+ expect(chart.scales.y.max).toBe(1);
});
it('Should ensure that the scale has a max and min that are not equal when beginAtZero is set', function() {
},
options: {
scales: {
- yAxes: [{
- id: 'yScale0',
+ y: {
type: 'linear',
beginAtZero: true
- }]
+ }
}
}
});
- expect(chart.scales.yScale0).not.toEqual(undefined); // must construct
- expect(chart.scales.yScale0.min).toBe(0);
- expect(chart.scales.yScale0.max).toBe(1);
+ expect(chart.scales.y).not.toEqual(undefined); // must construct
+ expect(chart.scales.y.min).toBe(0);
+ expect(chart.scales.y.max).toBe(1);
});
it('Should use the suggestedMin and suggestedMax options', function() {
type: 'bar',
data: {
datasets: [{
- yAxisID: 'yScale0',
+ yAxisID: 'y',
data: [1, 1, 1, 2, 1, 0]
}],
labels: ['a', 'b', 'c', 'd', 'e', 'f']
},
options: {
scales: {
- yAxes: [{
- id: 'yScale0',
+ y: {
type: 'linear',
suggestedMax: 10,
suggestedMin: -10
- }]
+ }
}
}
});
- expect(chart.scales.yScale0).not.toEqual(undefined); // must construct
- expect(chart.scales.yScale0.min).toBe(-10);
- expect(chart.scales.yScale0.max).toBe(10);
+ expect(chart.scales.y).not.toEqual(undefined); // must construct
+ expect(chart.scales.y.min).toBe(-10);
+ expect(chart.scales.y.max).toBe(10);
});
it('Should use the min and max options', function() {
type: 'bar',
data: {
datasets: [{
- yAxisID: 'yScale0',
+ yAxisID: 'y',
data: [1, 1, 1, 2, 1, 0]
}],
labels: ['a', 'b', 'c', 'd', 'e', 'f']
},
options: {
scales: {
- yAxes: [{
- id: 'yScale0',
+ y: {
type: 'linear',
max: 1010,
min: -1010
- }]
+ }
}
}
});
- expect(chart.scales.yScale0).not.toEqual(undefined); // must construct
- expect(chart.scales.yScale0.min).toBe(-1010);
- expect(chart.scales.yScale0.max).toBe(1010);
- var labels = getLabels(chart.scales.yScale0);
+ expect(chart.scales.y).not.toEqual(undefined); // must construct
+ expect(chart.scales.y.min).toBe(-1010);
+ expect(chart.scales.y.max).toBe(1010);
+ var labels = getLabels(chart.scales.y);
expect(labels[0]).toBe('1010');
expect(labels[labels.length - 1]).toBe('-1010');
});
type: 'bar',
data: {
datasets: [{
- yAxisID: 'yScale0',
+ yAxisID: 'y',
data: [10, 3, 6, 8, 3, 1]
}],
labels: ['a', 'b', 'c', 'd', 'e', 'f']
},
options: {
scales: {
- yAxes: [{
- id: 'yScale0',
+ y: {
type: 'linear',
min: 1,
max: 11,
ticks: {
stepSize: 2
}
- }]
+ }
}
}
});
- expect(chart.scales.yScale0).not.toEqual(undefined); // must construct
- expect(chart.scales.yScale0.min).toBe(1);
- expect(chart.scales.yScale0.max).toBe(11);
- expect(getLabels(chart.scales.yScale0)).toEqual(['11', '10', '8', '6', '4', '2', '1']);
+ expect(chart.scales.y).not.toEqual(undefined); // must construct
+ expect(chart.scales.y.min).toBe(1);
+ expect(chart.scales.y.max).toBe(11);
+ expect(getLabels(chart.scales.y)).toEqual(['11', '10', '8', '6', '4', '2', '1']);
});
it('Should create decimal steps if stepSize is a decimal number', function() {
type: 'bar',
data: {
datasets: [{
- yAxisID: 'yScale0',
+ yAxisID: 'y',
data: [10, 3, 6, 8, 3, 1]
}],
labels: ['a', 'b', 'c', 'd', 'e', 'f']
},
options: {
scales: {
- yAxes: [{
- id: 'yScale0',
+ y: {
type: 'linear',
ticks: {
stepSize: 2.5
}
- }]
+ }
}
}
});
- expect(chart.scales.yScale0).not.toEqual(undefined); // must construct
- expect(chart.scales.yScale0.min).toBe(0);
- expect(chart.scales.yScale0.max).toBe(10);
- expect(getLabels(chart.scales.yScale0)).toEqual(['10', '7.5', '5', '2.5', '0']);
+ expect(chart.scales.y).not.toEqual(undefined); // must construct
+ expect(chart.scales.y.min).toBe(0);
+ expect(chart.scales.y.max).toBe(10);
+ expect(getLabels(chart.scales.y)).toEqual(['10', '7.5', '5', '2.5', '0']);
});
describe('precision', function() {
type: 'bar',
data: {
datasets: [{
- yAxisID: 'yScale0',
+ yAxisID: 'y',
data: [0, 1, 2, 1, 0, 1]
}],
labels: ['a', 'b', 'c', 'd', 'e', 'f']
},
options: {
scales: {
- yAxes: [{
- id: 'yScale0',
+ y: {
type: 'linear',
ticks: {
precision: 0
}
- }]
+ }
}
}
});
- expect(chart.scales.yScale0).not.toEqual(undefined); // must construct
- expect(chart.scales.yScale0.min).toBe(0);
- expect(chart.scales.yScale0.max).toBe(2);
- expect(getLabels(chart.scales.yScale0)).toEqual(['2', '1', '0']);
+ expect(chart.scales.y).not.toEqual(undefined); // must construct
+ expect(chart.scales.y.min).toBe(0);
+ expect(chart.scales.y.max).toBe(2);
+ expect(getLabels(chart.scales.y)).toEqual(['2', '1', '0']);
});
it('Should round the step size to the given number of decimal places', function() {
type: 'bar',
data: {
datasets: [{
- yAxisID: 'yScale0',
+ yAxisID: 'y',
data: [0, 0.001, 0.002, 0.003, 0, 0.001]
}],
labels: ['a', 'b', 'c', 'd', 'e', 'f']
},
options: {
scales: {
- yAxes: [{
- id: 'yScale0',
+ y: {
type: 'linear',
ticks: {
precision: 2
}
- }]
+ }
}
}
});
- expect(chart.scales.yScale0).not.toEqual(undefined); // must construct
- expect(chart.scales.yScale0.min).toBe(0);
- expect(chart.scales.yScale0.max).toBe(0.01);
- expect(getLabels(chart.scales.yScale0)).toEqual(['0.01', '0']);
+ expect(chart.scales.y).not.toEqual(undefined); // must construct
+ expect(chart.scales.y.min).toBe(0);
+ expect(chart.scales.y.max).toBe(0.01);
+ expect(getLabels(chart.scales.y)).toEqual(['0.01', '0']);
});
});
type: 'bar',
data: {
datasets: [{
- yAxisID: 'yScale0',
+ yAxisID: 'y',
data: [20, 30, 40, 50]
}],
labels: ['a', 'b', 'c', 'd']
},
options: {
scales: {
- yAxes: [{
- id: 'yScale0',
+ y: {
type: 'linear',
- }]
+ }
}
}
});
- expect(chart.scales.yScale0).not.toEqual(undefined); // must construct
- expect(getLabels(chart.scales.yScale0)).toEqual(['50', '45', '40', '35', '30', '25', '20']);
+ expect(chart.scales.y).not.toEqual(undefined); // must construct
+ expect(getLabels(chart.scales.y)).toEqual(['50', '45', '40', '35', '30', '25', '20']);
- chart.scales.yScale0.options.beginAtZero = true;
+ chart.scales.y.options.beginAtZero = true;
chart.update();
- expect(getLabels(chart.scales.yScale0)).toEqual(['50', '45', '40', '35', '30', '25', '20', '15', '10', '5', '0']);
+ expect(getLabels(chart.scales.y)).toEqual(['50', '45', '40', '35', '30', '25', '20', '15', '10', '5', '0']);
chart.data.datasets[0].data = [-20, -30, -40, -50];
chart.update();
- expect(getLabels(chart.scales.yScale0)).toEqual(['0', '-5', '-10', '-15', '-20', '-25', '-30', '-35', '-40', '-45', '-50']);
+ expect(getLabels(chart.scales.y)).toEqual(['0', '-5', '-10', '-15', '-20', '-25', '-30', '-35', '-40', '-45', '-50']);
- chart.scales.yScale0.options.beginAtZero = false;
+ chart.scales.y.options.beginAtZero = false;
chart.update();
- expect(getLabels(chart.scales.yScale0)).toEqual(['-20', '-25', '-30', '-35', '-40', '-45', '-50']);
+ expect(getLabels(chart.scales.y)).toEqual(['-20', '-25', '-30', '-35', '-40', '-45', '-50']);
});
it('Should generate tick marks in the correct order in reversed mode', function() {
type: 'bar',
data: {
datasets: [{
- yAxisID: 'yScale0',
+ yAxisID: 'y',
data: [10, 5, 0, 25, 78]
}],
labels: ['a', 'b', 'c', 'd']
},
options: {
scales: {
- yAxes: [{
- id: 'yScale0',
+ y: {
type: 'linear',
reverse: true
- }]
+ }
}
}
});
- expect(getLabels(chart.scales.yScale0)).toEqual(['0', '10', '20', '30', '40', '50', '60', '70', '80']);
- expect(chart.scales.yScale0.start).toBe(80);
- expect(chart.scales.yScale0.end).toBe(0);
+ expect(getLabels(chart.scales.y)).toEqual(['0', '10', '20', '30', '40', '50', '60', '70', '80']);
+ expect(chart.scales.y.start).toBe(80);
+ expect(chart.scales.y.end).toBe(0);
});
it('should use the correct number of decimal places in the default format function', function() {
type: 'bar',
data: {
datasets: [{
- yAxisID: 'yScale0',
+ yAxisID: 'y',
data: [0.06, 0.005, 0, 0.025, 0.0078]
}],
labels: ['a', 'b', 'c', 'd']
},
options: {
scales: {
- yAxes: [{
- id: 'yScale0',
+ y: {
type: 'linear',
- }]
+ }
}
}
});
- expect(getLabels(chart.scales.yScale0)).toEqual(['0.06', '0.05', '0.04', '0.03', '0.02', '0.01', '0']);
+ expect(getLabels(chart.scales.y)).toEqual(['0.06', '0.05', '0.04', '0.03', '0.02', '0.01', '0']);
});
it('Should correctly limit the maximum number of ticks', function() {
},
options: {
scales: {
- yAxes: [{
- id: 'yScale'
- }]
+ y: {}
}
}
});
- expect(getLabels(chart.scales.yScale)).toEqual(['2.5', '2.0', '1.5', '1.0', '0.5']);
+ expect(getLabels(chart.scales.y)).toEqual(['2.5', '2.0', '1.5', '1.0', '0.5']);
- chart.options.scales.yAxes[0].ticks.maxTicksLimit = 11;
+ chart.options.scales.y.ticks.maxTicksLimit = 11;
chart.update();
- expect(getLabels(chart.scales.yScale)).toEqual(['2.5', '2.0', '1.5', '1.0', '0.5']);
+ expect(getLabels(chart.scales.y)).toEqual(['2.5', '2.0', '1.5', '1.0', '0.5']);
- chart.options.scales.yAxes[0].ticks.maxTicksLimit = 21;
+ chart.options.scales.y.ticks.maxTicksLimit = 21;
chart.update();
- expect(getLabels(chart.scales.yScale)).toEqual([
+ expect(getLabels(chart.scales.y)).toEqual([
'2.5', '2.4', '2.3', '2.2', '2.1', '2.0', '1.9', '1.8', '1.7', '1.6',
'1.5', '1.4', '1.3', '1.2', '1.1', '1.0', '0.9', '0.8', '0.7', '0.6',
'0.5'
]);
- chart.options.scales.yAxes[0].ticks.maxTicksLimit = 11;
- chart.options.scales.yAxes[0].ticks.stepSize = 0.01;
+ chart.options.scales.y.ticks.maxTicksLimit = 11;
+ chart.options.scales.y.ticks.stepSize = 0.01;
chart.update();
- expect(getLabels(chart.scales.yScale)).toEqual(['2.5', '2.0', '1.5', '1.0', '0.5']);
+ expect(getLabels(chart.scales.y)).toEqual(['2.5', '2.0', '1.5', '1.0', '0.5']);
- chart.options.scales.yAxes[0].min = 0.3;
- chart.options.scales.yAxes[0].max = 2.8;
+ chart.options.scales.y.min = 0.3;
+ chart.options.scales.y.max = 2.8;
chart.update();
- expect(getLabels(chart.scales.yScale)).toEqual(['2.8', '2.5', '2.0', '1.5', '1.0', '0.5', '0.3']);
+ expect(getLabels(chart.scales.y)).toEqual(['2.8', '2.5', '2.0', '1.5', '1.0', '0.5', '0.3']);
});
it('Should build labels using the user supplied callback', function() {
type: 'bar',
data: {
datasets: [{
- yAxisID: 'yScale0',
+ yAxisID: 'y',
data: [10, 5, 0, 25, 78]
}],
labels: ['a', 'b', 'c', 'd']
},
options: {
scales: {
- yAxes: [{
- id: 'yScale0',
+ y: {
type: 'linear',
ticks: {
callback: function(value, index) {
return index.toString();
}
}
- }]
+ }
}
}
});
// Just the index
- expect(getLabels(chart.scales.yScale0)).toEqual(['0', '1', '2', '3', '4', '5', '6', '7', '8']);
+ expect(getLabels(chart.scales.y)).toEqual(['0', '1', '2', '3', '4', '5', '6', '7', '8']);
});
it('Should get the correct pixel value for a point', function() {
data: {
labels: [-1, 1],
datasets: [{
- xAxisID: 'xScale0',
- yAxisID: 'yScale0',
+ xAxisID: 'x',
+ yAxisID: 'y',
data: [-1, 1]
}],
},
options: {
scales: {
- xAxes: [{
- id: 'xScale0',
+ x: {
type: 'linear',
position: 'bottom'
- }],
- yAxes: [{
- id: 'yScale0',
+ },
+ y: {
type: 'linear'
- }]
+ }
}
}
});
- var xScale = chart.scales.xScale0;
+ var xScale = chart.scales.x;
expect(xScale.getPixelForValue(1)).toBeCloseToPixel(501); // right - paddingRight
expect(xScale.getPixelForValue(-1)).toBeCloseToPixel(31 + 6); // left + paddingLeft + lineSpace
expect(xScale.getPixelForValue(0)).toBeCloseToPixel(266 + 6 / 2); // halfway*/
expect(xScale.getValueForPixel(31)).toBeCloseTo(-1, 1e-2);
expect(xScale.getValueForPixel(266)).toBeCloseTo(0, 1e-2);
- var yScale = chart.scales.yScale0;
+ var yScale = chart.scales.y;
expect(yScale.getPixelForValue(1)).toBeCloseToPixel(32); // right - paddingRight
expect(yScale.getPixelForValue(-1)).toBeCloseToPixel(484); // left + paddingLeft
expect(yScale.getPixelForValue(0)).toBeCloseToPixel(258); // halfway*/
type: 'line',
data: {
datasets: [{
- xAxisID: 'xScale0',
- yAxisID: 'yScale0',
+ xAxisID: 'x',
+ yAxisID: 'y',
data: [{
x: 10,
y: 100
},
options: {
scales: {
- xAxes: [{
- id: 'xScale0',
+ x: {
type: 'linear',
position: 'bottom'
- }],
- yAxes: [{
- id: 'yScale0',
+ },
+ y: {
type: 'linear'
- }]
+ }
}
}
});
- var xScale = chart.scales.xScale0;
- var yScale = chart.scales.yScale0;
+ var xScale = chart.scales.x;
+ var yScale = chart.scales.y;
expect(xScale.paddingTop).toBeCloseToPixel(0);
expect(xScale.paddingBottom).toBeCloseToPixel(0);
expect(xScale.paddingLeft).toBeCloseToPixel(12);
type: 'line',
data: {
datasets: [{
- xAxisID: 'xScale0',
- yAxisID: 'yScale0',
+ xAxisID: 'x',
+ yAxisID: 'y',
data: [{
x: 10,
y: 100
},
options: {
scales: {
- xAxes: [{
- id: 'xScale0',
+ x: {
type: 'linear',
position: 'bottom'
- }],
- yAxes: [{
- id: 'yScale0',
+ },
+ y: {
type: 'linear',
gridLines: {
drawTicks: false,
display: false,
padding: 0
}
- }]
+ }
}
}
});
- var yScale = chart.scales.yScale0;
+ var yScale = chart.scales.y;
expect(yScale.width).toBeCloseToPixel(0);
});
data: barData,
options: {
scales: {
- xAxes: [{
+ x: {
stacked: true
- }],
- yAxes: [{
+ },
+ y: {
stacked: true
- }]
+ }
}
}
});
chart.update();
});
- expect(chart.scales['x-axis-0'].min).toEqual(0);
- expect(chart.scales['x-axis-0'].max).toEqual(1);
+ expect(chart.scales.x.min).toEqual(0);
+ expect(chart.scales.x.max).toEqual(1);
});
it('max and min value should be valid when min is set and all datasets are hidden', function() {
data: barData,
options: {
scales: {
- xAxes: [{
+ x: {
min: 20
- }]
+ }
}
}
});
- expect(chart.scales['x-axis-0'].min).toEqual(20);
- expect(chart.scales['x-axis-0'].max).toEqual(21);
+ expect(chart.scales.x.min).toEqual(20);
+ expect(chart.scales.x.max).toEqual(21);
});
it('min settings should be used if set to zero', function() {
data: barData,
options: {
scales: {
- xAxes: [{
+ x: {
min: 0,
max: 3000
- }]
+ }
}
}
});
- expect(chart.scales['x-axis-0'].min).toEqual(0);
+ expect(chart.scales.x.min).toEqual(0);
});
it('max settings should be used if set to zero', function() {
data: barData,
options: {
scales: {
- xAxes: [{
+ x: {
min: -3000,
max: 0
- }]
+ }
}
}
});
- expect(chart.scales['x-axis-0'].max).toEqual(0);
+ expect(chart.scales.x.max).toEqual(0);
});
it('Should generate max and min that are not equal when data contains values that are very close to each other', function() {
},
options: {
scales: {
- yAxes: [{
- id: 'yScale0',
+ y: {
type: 'linear',
- }]
+ }
}
}
});
- expect(chart.scales.yScale0).not.toEqual(undefined); // must construct
- expect(chart.scales.yScale0.max).toBeGreaterThan(chart.scales.yScale0.min);
+ expect(chart.scales.y).not.toEqual(undefined); // must construct
+ expect(chart.scales.y.max).toBeGreaterThan(chart.scales.y.min);
});
it('Should get correct pixel values when horizontal', function() {
},
options: {
scales: {
- xAxes: [{
- id: 'x',
+ x: {
type: 'linear',
- }]
+ }
}
}
});
},
options: {
scales: {
- yAxes: [{
- id: 'y',
+ y: {
type: 'linear',
- }]
+ }
}
}
});
type: 'bar',
data: {
datasets: [{
- yAxisID: 'yScale0',
+ yAxisID: 'y',
data: [42, 1000, 64, 100],
}, {
- yAxisID: 'yScale1',
+ yAxisID: 'y1',
data: [10, 5, 5000, 78, 450]
}, {
- yAxisID: 'yScale1',
+ yAxisID: 'y1',
data: [150]
}, {
- yAxisID: 'yScale2',
+ yAxisID: 'y2',
data: [20, 0, 150, 1800, 3040]
}, {
- yAxisID: 'yScale3',
+ yAxisID: 'y3',
data: [67, 0.0004, 0, 820, 0.001]
}],
labels: ['a', 'b', 'c', 'd', 'e']
},
options: {
scales: {
- yAxes: [{
- id: 'yScale0',
+ y: {
+ id: 'y',
type: 'logarithmic'
- }, {
- id: 'yScale1',
- type: 'logarithmic'
- }, {
- id: 'yScale2',
- type: 'logarithmic'
- }, {
- id: 'yScale3',
+ },
+ y1: {
+ type: 'logarithmic',
+ position: 'right'
+ },
+ y2: {
+ type: 'logarithmic',
+ position: 'right'
+ },
+ y3: {
+ position: 'right',
type: 'logarithmic'
- }]
+ }
}
}
});
- expect(chart.scales.yScale0).not.toEqual(undefined); // must construct
- expect(chart.scales.yScale0.min).toBe(10);
- expect(chart.scales.yScale0.max).toBe(1000);
+ expect(chart.scales.y).not.toEqual(undefined); // must construct
+ expect(chart.scales.y.min).toBe(10);
+ expect(chart.scales.y.max).toBe(1000);
- expect(chart.scales.yScale1).not.toEqual(undefined); // must construct
- expect(chart.scales.yScale1.min).toBe(1);
- expect(chart.scales.yScale1.max).toBe(5000);
+ expect(chart.scales.y1).not.toEqual(undefined); // must construct
+ expect(chart.scales.y1.min).toBe(1);
+ expect(chart.scales.y1.max).toBe(5000);
- expect(chart.scales.yScale2).not.toEqual(undefined); // must construct
- expect(chart.scales.yScale2.min).toBe(0);
- expect(chart.scales.yScale2.max).toBe(4000);
+ expect(chart.scales.y2).not.toEqual(undefined); // must construct
+ expect(chart.scales.y2.min).toBe(0);
+ expect(chart.scales.y2.max).toBe(4000);
- expect(chart.scales.yScale3).not.toEqual(undefined); // must construct
- expect(chart.scales.yScale3.min).toBe(0);
- expect(chart.scales.yScale3.max).toBe(900);
+ expect(chart.scales.y3).not.toEqual(undefined); // must construct
+ expect(chart.scales.y3.min).toBe(0);
+ expect(chart.scales.y3.max).toBe(900);
});
it('should correctly determine the max & min of string data values', function() {
type: 'line',
data: {
datasets: [{
- yAxisID: 'yScale0',
+ yAxisID: 'y',
data: ['42', '1000', '64', '100'],
}, {
- yAxisID: 'yScale1',
+ yAxisID: 'y1',
data: ['10', '5', '5000', '78', '450']
}, {
- yAxisID: 'yScale1',
+ yAxisID: 'y1',
data: ['150']
}, {
- yAxisID: 'yScale2',
+ yAxisID: 'y2',
data: ['20', '0', '150', '1800', '3040']
}, {
- yAxisID: 'yScale3',
+ yAxisID: 'y3',
data: ['67', '0.0004', '0', '820', '0.001']
}],
labels: ['a', 'b', 'c', 'd', 'e']
},
options: {
scales: {
- yAxes: [{
- id: 'yScale0',
+ y: {
type: 'logarithmic'
- }, {
- id: 'yScale1',
+ },
+ y1: {
+ position: 'right',
type: 'logarithmic'
- }, {
- id: 'yScale2',
+ },
+ y2: {
+ position: 'right',
type: 'logarithmic'
- }, {
- id: 'yScale3',
+ },
+ y3: {
+ position: 'right',
type: 'logarithmic'
- }]
+ }
}
}
});
- expect(chart.scales.yScale0).not.toEqual(undefined); // must construct
- expect(chart.scales.yScale0.min).toBe(10);
- expect(chart.scales.yScale0.max).toBe(1000);
+ expect(chart.scales.y).not.toEqual(undefined); // must construct
+ expect(chart.scales.y.min).toBe(10);
+ expect(chart.scales.y.max).toBe(1000);
- expect(chart.scales.yScale1).not.toEqual(undefined); // must construct
- expect(chart.scales.yScale1.min).toBe(1);
- expect(chart.scales.yScale1.max).toBe(5000);
+ expect(chart.scales.y1).not.toEqual(undefined); // must construct
+ expect(chart.scales.y1.min).toBe(1);
+ expect(chart.scales.y1.max).toBe(5000);
- expect(chart.scales.yScale2).not.toEqual(undefined); // must construct
- expect(chart.scales.yScale2.min).toBe(0);
- expect(chart.scales.yScale2.max).toBe(4000);
+ expect(chart.scales.y2).not.toEqual(undefined); // must construct
+ expect(chart.scales.y2.min).toBe(0);
+ expect(chart.scales.y2.max).toBe(4000);
- expect(chart.scales.yScale3).not.toEqual(undefined); // must construct
- expect(chart.scales.yScale3.min).toBe(0);
- expect(chart.scales.yScale3.max).toBe(900);
+ expect(chart.scales.y3).not.toEqual(undefined); // must construct
+ expect(chart.scales.y3.min).toBe(0);
+ expect(chart.scales.y3.max).toBe(900);
});
it('should correctly determine the max & min data values when there are hidden datasets', function() {
type: 'line',
data: {
datasets: [{
- yAxisID: 'yScale1',
+ yAxisID: 'y1',
data: [10, 5, 5000, 78, 450]
}, {
- yAxisID: 'yScale0',
+ yAxisID: 'y',
data: [42, 1000, 64, 100],
}, {
- yAxisID: 'yScale1',
+ yAxisID: 'y1',
data: [50000],
hidden: true
}, {
- yAxisID: 'yScale2',
+ yAxisID: 'y2',
data: [20, 0, 7400, 14, 291]
}, {
- yAxisID: 'yScale2',
+ yAxisID: 'y2',
data: [6, 0.0007, 9, 890, 60000],
hidden: true
}],
},
options: {
scales: {
- yAxes: [{
- id: 'yScale0',
+ y: {
type: 'logarithmic'
- }, {
- id: 'yScale1',
+ },
+ y1: {
+ position: 'right',
type: 'logarithmic'
- }, {
- id: 'yScale2',
+ },
+ y2: {
+ position: 'right',
type: 'logarithmic'
- }]
+ }
}
}
});
- expect(chart.scales.yScale1).not.toEqual(undefined); // must construct
- expect(chart.scales.yScale1.min).toBe(1);
- expect(chart.scales.yScale1.max).toBe(5000);
+ expect(chart.scales.y1).not.toEqual(undefined); // must construct
+ expect(chart.scales.y1.min).toBe(1);
+ expect(chart.scales.y1.max).toBe(5000);
- expect(chart.scales.yScale2).not.toEqual(undefined); // must construct
- expect(chart.scales.yScale2.min).toBe(0);
- expect(chart.scales.yScale2.max).toBe(8000);
+ expect(chart.scales.y2).not.toEqual(undefined); // must construct
+ expect(chart.scales.y2.min).toBe(0);
+ expect(chart.scales.y2.max).toBe(8000);
});
it('should correctly determine the max & min data values when there is NaN data', function() {
type: 'bar',
data: {
datasets: [{
- yAxisID: 'yScale0',
+ yAxisID: 'y',
data: [undefined, 10, null, 5, 5000, NaN, 78, 450]
}, {
- yAxisID: 'yScale0',
+ yAxisID: 'y',
data: [undefined, 28, null, 1000, 500, NaN, 50, 42, Infinity, -Infinity]
}, {
- yAxisID: 'yScale1',
+ yAxisID: 'y1',
data: [undefined, 30, null, 9400, 0, NaN, 54, 836]
}, {
- yAxisID: 'yScale1',
+ yAxisID: 'y1',
data: [undefined, 0, null, 800, 9, NaN, 894, 21]
}],
labels: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']
},
options: {
scales: {
- yAxes: [{
- id: 'yScale0',
+ y: {
type: 'logarithmic'
- }, {
- id: 'yScale1',
+ },
+ y1: {
+ position: 'right',
type: 'logarithmic'
- }]
+ }
}
}
});
- expect(chart.scales.yScale0).not.toEqual(undefined); // must construct
- expect(chart.scales.yScale0.min).toBe(1);
- expect(chart.scales.yScale0.max).toBe(5000);
+ expect(chart.scales.y).not.toEqual(undefined); // must construct
+ expect(chart.scales.y.min).toBe(1);
+ expect(chart.scales.y.max).toBe(5000);
// Turn on stacked mode since it uses it's own
- chart.options.scales.yAxes[0].stacked = true;
+ chart.options.scales.y.stacked = true;
chart.update();
- expect(chart.scales.yScale0.min).toBe(10);
- expect(chart.scales.yScale0.max).toBe(6000);
+ expect(chart.scales.y.min).toBe(10);
+ expect(chart.scales.y.max).toBe(6000);
- expect(chart.scales.yScale1).not.toEqual(undefined); // must construct
- expect(chart.scales.yScale1.min).toBe(0);
- expect(chart.scales.yScale1.max).toBe(10000);
+ expect(chart.scales.y1).not.toEqual(undefined); // must construct
+ expect(chart.scales.y1.min).toBe(0);
+ expect(chart.scales.y1.max).toBe(10000);
});
it('should correctly determine the max & min for scatter data', function() {
},
options: {
scales: {
- xAxes: [{
- id: 'xScale',
+ x: {
type: 'logarithmic',
position: 'bottom'
- }],
- yAxes: [{
- id: 'yScale',
+ },
+ y: {
type: 'logarithmic'
- }]
+ }
}
}
});
- expect(chart.scales.xScale.min).toBe(1);
- expect(chart.scales.xScale.max).toBe(100);
+ expect(chart.scales.x.min).toBe(1);
+ expect(chart.scales.x.max).toBe(100);
- expect(chart.scales.yScale.min).toBe(1);
- expect(chart.scales.yScale.max).toBe(200);
+ expect(chart.scales.y.min).toBe(1);
+ expect(chart.scales.y.max).toBe(200);
});
it('should correctly determine the max & min for scatter data when 0 values are present', function() {
},
options: {
scales: {
- xAxes: [{
- id: 'xScale',
+ x: {
type: 'logarithmic',
position: 'bottom'
- }],
- yAxes: [{
- id: 'yScale',
+ },
+ y: {
type: 'logarithmic'
- }]
+ }
}
}
});
- expect(chart.scales.xScale.min).toBe(0);
- expect(chart.scales.xScale.max).toBe(300);
+ expect(chart.scales.x.min).toBe(0);
+ expect(chart.scales.x.max).toBe(300);
- expect(chart.scales.yScale.min).toBe(0);
- expect(chart.scales.yScale.max).toBe(1000);
+ expect(chart.scales.y.min).toBe(0);
+ expect(chart.scales.y.max).toBe(1000);
});
it('should correctly determine the min and max data values when stacked mode is turned on', function() {
data: {
datasets: [{
type: 'bar',
- yAxisID: 'yScale0',
+ yAxisID: 'y',
data: [10, 5, 1, 5, 78, 100]
}, {
- yAxisID: 'yScale1',
+ yAxisID: 'y1',
data: [0, 1000],
}, {
type: 'bar',
- yAxisID: 'yScale0',
+ yAxisID: 'y',
data: [150, 10, 10, 100, 10, 9]
}, {
type: 'line',
- yAxisID: 'yScale0',
+ yAxisID: 'y',
data: [100, 100, 100, 100, 100, 100]
}],
labels: ['a', 'b', 'c', 'd', 'e', 'f']
},
options: {
scales: {
- yAxes: [{
- id: 'yScale0',
+ y: {
type: 'logarithmic',
stacked: true
- }, {
- id: 'yScale1',
+ },
+ y1: {
+ position: 'right',
type: 'logarithmic'
- }]
+ }
}
}
});
- expect(chart.scales.yScale0.min).toBe(10);
- expect(chart.scales.yScale0.max).toBe(200);
+ expect(chart.scales.y.min).toBe(10);
+ expect(chart.scales.y.max).toBe(200);
});
it('should correctly determine the min and max data values when stacked mode is turned on ignoring hidden datasets', function() {
type: 'bar',
data: {
datasets: [{
- yAxisID: 'yScale0',
+ yAxisID: 'y',
data: [10, 5, 1, 5, 78, 100],
type: 'bar'
}, {
- yAxisID: 'yScale1',
+ yAxisID: 'y1',
data: [0, 1000],
type: 'bar'
}, {
- yAxisID: 'yScale0',
+ yAxisID: 'y',
data: [150, 10, 10, 100, 10, 9],
type: 'bar'
}, {
- yAxisID: 'yScale0',
+ yAxisID: 'y',
data: [10000, 10000, 10000, 10000, 10000, 10000],
hidden: true,
type: 'bar'
},
options: {
scales: {
- yAxes: [{
- id: 'yScale0',
+ y: {
type: 'logarithmic',
stacked: true
- }, {
- id: 'yScale1',
+ },
+ y1: {
+ position: 'right',
type: 'logarithmic'
- }]
+ }
}
}
});
- expect(chart.scales.yScale0.min).toBe(10);
- expect(chart.scales.yScale0.max).toBe(200);
+ expect(chart.scales.y.min).toBe(10);
+ expect(chart.scales.y.max).toBe(200);
});
it('should ensure that the scale has a max and min that are not equal', function() {
},
options: {
scales: {
- yAxes: [{
- id: 'yScale',
+ y: {
type: 'logarithmic'
- }]
+ }
}
}
});
- expect(chart.scales.yScale.min).toBe(1);
- expect(chart.scales.yScale.max).toBe(10);
+ expect(chart.scales.y.min).toBe(1);
+ expect(chart.scales.y.max).toBe(10);
chart.data.datasets[0].data = [0.15, 0.15];
chart.update();
- expect(chart.scales.yScale.min).toBe(0.01);
- expect(chart.scales.yScale.max).toBe(1);
+ expect(chart.scales.y.min).toBe(0.01);
+ expect(chart.scales.y.max).toBe(1);
});
it('should use the min and max options', function() {
},
options: {
scales: {
- yAxes: [{
- id: 'yScale',
+ y: {
type: 'logarithmic',
min: 10,
max: 1010,
return value;
}
}
- }]
+ }
}
}
});
- var yScale = chart.scales.yScale;
+ var yScale = chart.scales.y;
var tickCount = yScale.ticks.length;
expect(yScale.min).toBe(10);
expect(yScale.max).toBe(1010);
},
options: {
scales: {
- yAxes: [{
- id: 'yScale',
+ y: {
type: 'logarithmic',
min: -10,
max: -1010,
return value;
}
}
- }]
+ }
}
}
});
- var yScale = chart.scales.yScale;
- expect(yScale.min).toBe(0);
- expect(yScale.max).toBe(2);
+ var y = chart.scales.y;
+ expect(y.min).toBe(0);
+ expect(y.max).toBe(2);
});
it('should ignore invalid min and max options', function() {
},
options: {
scales: {
- yAxes: [{
- id: 'yScale',
+ y: {
type: 'logarithmic',
min: 'zero',
max: null,
return value;
}
}
- }]
+ }
}
}
});
- var yScale = chart.scales.yScale;
- expect(yScale.min).toBe(0);
- expect(yScale.max).toBe(2);
+ var y = chart.scales.y;
+ expect(y.min).toBe(0);
+ expect(y.max).toBe(2);
});
it('should generate tick marks', function() {
},
options: {
scales: {
- yAxes: [{
- id: 'yScale',
+ y: {
type: 'logarithmic',
ticks: {
callback: function(value) {
return value;
}
}
- }]
+ }
}
}
});
// Counts down because the lines are drawn top to bottom
- var scale = chart.scales.yScale;
+ var scale = chart.scales.y;
expect(getLabels(scale)).toEqual([80, 70, 60, 50, 40, 30, 20, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]);
expect(scale.start).toEqual(1);
expect(scale.end).toEqual(80);
},
options: {
scales: {
- yAxes: [{
- id: 'yScale',
+ y: {
type: 'logarithmic',
ticks: {
callback: function(value) {
return value;
}
}
- }]
+ }
}
}
});
- var scale = chart.scales.yScale;
+ var scale = chart.scales.y;
// Counts down because the lines are drawn top to bottom
expect(getLabels(scale)).toEqual([30, 20, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0.9, 0.8, 0]);
expect(scale.start).toEqual(0);
},
options: {
scales: {
- yAxes: [{
- id: 'yScale',
+ y: {
type: 'logarithmic',
reverse: true,
ticks: {
return value;
}
}
- }]
+ }
}
}
});
- var scale = chart.scales.yScale;
+ var scale = chart.scales.y;
expect(getLabels(scale)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 60, 70, 80]);
expect(scale.start).toEqual(80);
expect(scale.end).toEqual(1);
},
options: {
scales: {
- yAxes: [{
- id: 'yScale',
+ y: {
type: 'logarithmic',
reverse: true,
ticks: {
return value;
}
}
- }]
+ }
}
}
});
- var scale = chart.scales.yScale;
+ var scale = chart.scales.y;
expect(getLabels(scale)).toEqual([0, 9, 10, 20, 30]);
expect(scale.start).toEqual(30);
expect(scale.end).toEqual(0);
},
options: {
scales: {
- yAxes: [{
- id: 'yScale',
+ y: {
type: 'logarithmic'
- }]
+ }
}
}
});
- expect(getLabels(chart.scales.yScale)).toEqual(['8e+1', '', '', '5e+1', '', '', '2e+1', '1e+1', '', '', '', '', '5e+0', '', '', '2e+0', '1e+0', '0']);
+ expect(getLabels(chart.scales.y)).toEqual(['8e+1', '', '', '5e+1', '', '', '2e+1', '1e+1', '', '', '', '', '5e+0', '', '', '2e+0', '1e+0', '0']);
});
it('should build labels using the user supplied callback', function() {
},
options: {
scales: {
- yAxes: [{
- id: 'yScale',
+ y: {
type: 'logarithmic',
ticks: {
callback: function(value, index) {
return index.toString();
}
}
- }]
+ }
}
}
});
// Just the index
- expect(getLabels(chart.scales.yScale)).toEqual(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16']);
+ expect(getLabels(chart.scales.y)).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() {
type: 'bar',
data: {
datasets: [{
- yAxisID: 'yScale0',
+ yAxisID: 'y',
data: [10, 5, 5000, 78, 450]
}, {
- yAxisID: 'yScale1',
+ yAxisID: 'y1',
data: [1, 1000, 10, 100],
}, {
- yAxisID: 'yScale0',
+ yAxisID: 'y',
data: [150]
}],
labels: []
},
options: {
scales: {
- yAxes: [{
- id: 'yScale0',
+ y: {
type: 'logarithmic'
- }, {
- id: 'yScale1',
+ },
+ y1: {
+ position: 'right',
type: 'logarithmic'
- }]
+ }
}
}
});
- expect(chart.scales.yScale0.getLabelForValue(150)).toBe(150);
+ expect(chart.scales.y.getLabelForValue(150)).toBe(150);
});
describe('when', function() {
{
axis: 'y',
scale: {
- yAxes: [{
+ y: {
min: 0
- }]
+ }
},
firstTick: 0,
describe: 'all stacks are defined and min: 0'
axis: 'y',
data: dataWithEmptyStacks,
scale: {
- yAxes: [{
+ y: {
min: 0
- }]
+ }
},
firstTick: 0,
describe: 'not stacks are defined and min: 0'
{
axis: 'x',
scale: {
- xAxes: [{
+ x: {
min: 0
- }]
+ }
},
firstTick: 0,
describe: 'all stacks are defined and min: 0'
axis: 'x',
data: dataWithEmptyStacks,
scale: {
- xAxes: [{
+ x: {
min: 0
- }]
+ }
},
firstTick: 0,
describe: 'not all stacks are defined and min: 0'
chartStart = 'bottom';
chartEnd = 'top';
}
- scaleConfig[setup.axis + 'Axes'] = [{
+ scaleConfig[setup.axis] = {
type: 'logarithmic'
- }];
+ };
Chart.helpers.extend(scaleConfig, setup.scale);
- scaleConfig[setup.axis + 'Axes'][0].type = 'logarithmic';
+ scaleConfig[setup.axis].type = 'logarithmic';
var description = 'dataset has stack option and ' + setup.describe
+ ' and axis is "' + setup.axis + '";';
}
});
- var axisID = setup.axis + '-axis-0';
+ var axisID = setup.axis;
var scale = chart.scales[axisID];
var firstTick = setup.firstTick;
var lastTick = 80; // last tick (should be first available tick after: 2 * 39)
var expectation = 'min = ' + setup.firstTick + ', max = ' + setup.lastTick;
describe(setup.describe + ' and axis is "' + axis.id + '"; expect: ' + expectation + ';', function() {
beforeEach(function() {
- var xScaleConfig = {
+ var xConfig = {
type: 'logarithmic',
+ position: 'bottom'
};
- var yScaleConfig = {
+ var yConfig = {
type: 'logarithmic',
+ position: 'left'
};
var data = setup.data || {
datasets: [{
data: setup.dataset
}],
};
- Chart.helpers.extend(xScaleConfig, setup.scale);
- Chart.helpers.extend(yScaleConfig, setup.scale);
+ Chart.helpers.extend(xConfig, setup.scale);
+ Chart.helpers.extend(yConfig, setup.scale);
Chart.helpers.extend(data, setup.data || {});
this.chart = window.acquireChart({
type: 'line',
data: data,
options: {
scales: {
- xAxes: [xScaleConfig],
- yAxes: [yScaleConfig]
+ x: xConfig,
+ y: yConfig
}
}
});
it('should get the correct pixel value for a point', function() {
var chart = this.chart;
- var axisID = axis.id + '-axis-0';
+ var axisID = axis.id;
var scale = chart.scales[axisID];
var firstTick = setup.firstTick;
var lastTick = setup.lastTick;
var expectation = 'min = 0, max = ' + setup.lastTick + ', first tick = ' + setup.firstTick;
describe(setup.describe + ' and axis is "' + axis.id + '"; expect: ' + expectation + ';', function() {
beforeEach(function() {
- var xScaleConfig = {
+ var xConfig = {
type: 'logarithmic',
+ position: 'bottom'
};
- var yScaleConfig = {
+ var yConfig = {
type: 'logarithmic',
+ position: 'left'
};
var data = setup.data || {
datasets: [{
data: setup.dataset
}],
};
- Chart.helpers.extend(xScaleConfig, setup.scale);
- Chart.helpers.extend(yScaleConfig, setup.scale);
+ Chart.helpers.extend(xConfig, setup.scale);
+ Chart.helpers.extend(yConfig, setup.scale);
Chart.helpers.extend(data, setup.data || {});
this.chart = window.acquireChart({
type: 'line',
data: data,
options: {
scales: {
- xAxes: [xScaleConfig],
- yAxes: [yScaleConfig]
+ x: xConfig,
+ y: yConfig
}
}
});
it('should get the correct pixel value for a point', function() {
var chart = this.chart;
- var axisID = axis.id + '-axis-0';
+ var axisID = axis.id;
var scale = chart.scales[axisID];
var firstTick = setup.firstTick;
var lastTick = setup.lastTick;
}
});
- expect(chart.scale.min).toBe(-100);
- expect(chart.scale.max).toBe(150);
+ expect(chart.scales.r.min).toBe(-100);
+ expect(chart.scales.r.max).toBe(150);
});
it('Should correctly determine the max & min of string data values', function() {
}
});
- expect(chart.scale.min).toBe(-100);
- expect(chart.scale.max).toBe(150);
+ expect(chart.scales.r.min).toBe(-100);
+ expect(chart.scales.r.max).toBe(150);
});
it('Should correctly determine the max & min data values when there are hidden datasets', function() {
}
});
- expect(chart.scale.min).toBe(-100);
- expect(chart.scale.max).toBe(150);
+ expect(chart.scales.r.min).toBe(-100);
+ expect(chart.scales.r.max).toBe(150);
});
it('Should correctly determine the max & min data values when there is NaN data', function() {
}
});
- expect(chart.scale.min).toBe(50);
- expect(chart.scale.max).toBe(70);
+ expect(chart.scales.r.min).toBe(50);
+ expect(chart.scales.r.max).toBe(70);
});
it('Should ensure that the scale has a max and min that are not equal', function() {
labels: []
},
options: {
- scale: {
- id: 'myScale'
+ scales: {
+ rScale: {}
}
}
});
- var scale = chart.scales.myScale;
+ var scale = chart.scales.rScale;
expect(scale.min).toBe(-1);
expect(scale.max).toBe(1);
}
});
- expect(chart.scale.min).toBe(-10);
- expect(chart.scale.max).toBe(10);
+ expect(chart.scales.r.min).toBe(-10);
+ expect(chart.scales.r.max).toBe(10);
});
it('Should use the min and max options', function() {
}
});
- expect(chart.scale.min).toBe(-1010);
- expect(chart.scale.max).toBe(1010);
- expect(getLabels(chart.scale)).toEqual(['-1010', '-1000', '-500', '0', '500', '1000', '1010']);
+ expect(chart.scales.r.min).toBe(-1010);
+ expect(chart.scales.r.max).toBe(1010);
+ expect(getLabels(chart.scales.r)).toEqual(['-1010', '-1000', '-500', '0', '500', '1000', '1010']);
});
it('should forcibly include 0 in the range if the beginAtZero option is used', function() {
}
});
- expect(getLabels(chart.scale)).toEqual(['20', '25', '30', '35', '40', '45', '50']);
+ expect(getLabels(chart.scales.r)).toEqual(['20', '25', '30', '35', '40', '45', '50']);
- chart.scale.options.beginAtZero = true;
+ chart.scales.r.options.beginAtZero = true;
chart.update();
- expect(getLabels(chart.scale)).toEqual(['0', '5', '10', '15', '20', '25', '30', '35', '40', '45', '50']);
+ expect(getLabels(chart.scales.r)).toEqual(['0', '5', '10', '15', '20', '25', '30', '35', '40', '45', '50']);
chart.data.datasets[0].data = [-20, -30, -40, -50];
chart.update();
- expect(getLabels(chart.scale)).toEqual(['-50', '-45', '-40', '-35', '-30', '-25', '-20', '-15', '-10', '-5', '0']);
+ expect(getLabels(chart.scales.r)).toEqual(['-50', '-45', '-40', '-35', '-30', '-25', '-20', '-15', '-10', '-5', '0']);
- chart.scale.options.beginAtZero = false;
+ chart.scales.r.options.beginAtZero = false;
chart.update();
- expect(getLabels(chart.scale)).toEqual(['-50', '-45', '-40', '-35', '-30', '-25', '-20']);
+ expect(getLabels(chart.scales.r)).toEqual(['-50', '-45', '-40', '-35', '-30', '-25', '-20']);
});
it('Should generate tick marks in the correct order in reversed mode', function() {
}
});
- expect(getLabels(chart.scale)).toEqual(['80', '70', '60', '50', '40', '30', '20', '10', '0']);
- expect(chart.scale.start).toBe(80);
- expect(chart.scale.end).toBe(0);
+ expect(getLabels(chart.scales.r)).toEqual(['80', '70', '60', '50', '40', '30', '20', '10', '0']);
+ expect(chart.scales.r.start).toBe(80);
+ expect(chart.scales.r.end).toBe(0);
});
it('Should correctly limit the maximum number of ticks', function() {
}
});
- expect(getLabels(chart.scale)).toEqual(['0.5', '1.0', '1.5', '2.0', '2.5']);
+ expect(getLabels(chart.scales.r)).toEqual(['0.5', '1.0', '1.5', '2.0', '2.5']);
- chart.options.scale.ticks.maxTicksLimit = 11;
+ chart.options.scales.r.ticks.maxTicksLimit = 11;
chart.update();
- expect(getLabels(chart.scale)).toEqual(['0.5', '1.0', '1.5', '2.0', '2.5']);
+ expect(getLabels(chart.scales.r)).toEqual(['0.5', '1.0', '1.5', '2.0', '2.5']);
- chart.options.scale.ticks.stepSize = 0.01;
+ chart.options.scales.r.ticks.stepSize = 0.01;
chart.update();
- expect(getLabels(chart.scale)).toEqual(['0.5', '1.0', '1.5', '2.0', '2.5']);
+ expect(getLabels(chart.scales.r)).toEqual(['0.5', '1.0', '1.5', '2.0', '2.5']);
- chart.options.scale.min = 0.3;
- chart.options.scale.max = 2.8;
+ chart.options.scales.r.min = 0.3;
+ chart.options.scales.r.max = 2.8;
chart.update();
- expect(getLabels(chart.scale)).toEqual(['0.3', '0.5', '1.0', '1.5', '2.0', '2.5', '2.8']);
+ expect(getLabels(chart.scales.r)).toEqual(['0.3', '0.5', '1.0', '1.5', '2.0', '2.5', '2.8']);
});
it('Should build labels using the user supplied callback', function() {
}
});
- expect(getLabels(chart.scale)).toEqual(['0', '1', '2', '3', '4', '5', '6', '7', '8']);
- expect(chart.scale.pointLabels).toEqual(['label1', 'label2', 'label3', 'label4', 'label5']);
+ expect(getLabels(chart.scales.r)).toEqual(['0', '1', '2', '3', '4', '5', '6', '7', '8']);
+ expect(chart.scales.r.pointLabels).toEqual(['label1', 'label2', 'label3', 'label4', 'label5']);
});
it('Should build point labels using the user supplied callback', function() {
}
});
- expect(chart.scale.pointLabels).toEqual(['0', '1', '2', '3', '4']);
+ expect(chart.scales.r.pointLabels).toEqual(['0', '1', '2', '3', '4']);
});
it('Should build point labels from falsy values', function() {
}
});
- expect(chart.scale.pointLabels).toEqual([0, '', '', '', '', '']);
+ expect(chart.scales.r.pointLabels).toEqual([0, '', '', '', '', '']);
});
it('should correctly set the center point', function() {
}
});
- expect(chart.scale.drawingArea).toBe(227);
- expect(chart.scale.xCenter).toBe(256);
- expect(chart.scale.yCenter).toBe(284);
+ expect(chart.scales.r.drawingArea).toBe(227);
+ expect(chart.scales.r.xCenter).toBe(256);
+ expect(chart.scales.r.yCenter).toBe(284);
});
it('should correctly get the label for a given data index', function() {
}
}
});
- expect(chart.scale.getLabelForValue(5)).toBe(5);
+ expect(chart.scales.r.getLabelForValue(5)).toBe(5);
});
it('should get the correct distance from the center point', function() {
}
});
- expect(chart.scale.getDistanceFromCenterForValue(chart.scale.min)).toBe(0);
- expect(chart.scale.getDistanceFromCenterForValue(chart.scale.max)).toBe(227);
+ expect(chart.scales.r.getDistanceFromCenterForValue(chart.scales.r.min)).toBe(0);
+ expect(chart.scales.r.getDistanceFromCenterForValue(chart.scales.r.max)).toBe(227);
- var position = chart.scale.getPointPositionForValue(1, 5);
+ var position = chart.scales.r.getPointPositionForValue(1, 5);
expect(position.x).toBeCloseToPixel(270);
expect(position.y).toBeCloseToPixel(278);
- chart.scale.options.reverse = true;
+ chart.scales.r.options.reverse = true;
chart.update();
- expect(chart.scale.getDistanceFromCenterForValue(chart.scale.min)).toBe(227);
- expect(chart.scale.getDistanceFromCenterForValue(chart.scale.max)).toBe(0);
+ expect(chart.scales.r.getDistanceFromCenterForValue(chart.scales.r.min)).toBe(227);
+ expect(chart.scales.r.getDistanceFromCenterForValue(chart.scales.r.max)).toBe(0);
});
it('should correctly get angles for all points', function() {
var slice = 72; // (360 / 5)
for (var i = 0; i < 5; i++) {
- expect(radToNearestDegree(chart.scale.getIndexAngle(i))).toBe(15 + (slice * i));
+ expect(radToNearestDegree(chart.scales.r.getIndexAngle(i))).toBe(15 + (slice * i));
}
chart.options.startAngle = 0;
chart.update();
for (var x = 0; x < 5; x++) {
- expect(radToNearestDegree(chart.scale.getIndexAngle(x))).toBe((slice * x));
+ expect(radToNearestDegree(chart.scales.r.getIndexAngle(x))).toBe((slice * x));
}
});
}
});
- var scale = chart.scale;
+ var scale = chart.scales.r;
[{
startAngle: 30,
data: data,
options: {
scales: {
- xAxes: [options]
+ x: options
}
}
}, {canvas: {width: width, height: height}});
- return chart.scales.xScale0;
+ return chart.scales.x;
}
function getLabels(scale) {
type: 'line',
data: {
datasets: [{
- xAxisID: 'xScale0',
+ xAxisID: 'x',
data: [{
x: newDateFromRef(0),
y: 1
},
options: {
scales: {
- xAxes: [{
- id: 'xScale0',
+ x: {
type: 'time',
position: 'bottom'
- }],
+ },
}
}
}, {canvas: {width: 800, height: 200}});
- var xScale = chart.scales.xScale0;
+ var xScale = chart.scales.x;
var ticks = getLabels(xScale);
// `bounds === 'data'`: first and last ticks removed since outside the data range
type: 'line',
data: {
datasets: [{
- xAxisID: 'tScale0',
+ xAxisID: 'x',
data: [{
t: newDateFromRef(0),
y: 1
},
options: {
scales: {
- xAxes: [{
- id: 'tScale0',
+ x: {
type: 'time',
position: 'bottom'
- }],
+ },
}
}
}, {canvas: {width: 800, height: 200}});
- var tScale = chart.scales.tScale0;
+ var tScale = chart.scales.x;
var ticks = getLabels(tScale);
// `bounds === 'data'`: first and last ticks removed since outside the data range
data: {
labels: ['foo', 'bar'],
datasets: [{
- xAxisID: 'xScale0',
+ xAxisID: 'x',
data: [0, 1]
}],
},
options: {
scales: {
- xAxes: [{
- id: 'xScale0',
+ x: {
type: 'time',
position: 'bottom',
time: {
ticks: {
source: 'labels'
}
- }],
+ },
}
}
});
// Counts down because the lines are drawn top to bottom
- var labels = getLabels(chart.scales.xScale0);
+ var labels = getLabels(chart.scales.x);
// Counts down because the lines are drawn top to bottom
expect(labels[0]).toBe('Jan 2');
type: 'line',
data: {
datasets: [{
- xAxisID: 'xScale0',
+ xAxisID: 'x',
data: data
}],
},
options: {
scales: {
- xAxes: [{
- id: 'xScale0',
+ x: {
type: 'time',
ticks: {
source: 'data',
autoSkip: true
}
- }],
+ },
}
}
});
- var scale = chart.scales.xScale0;
+ var scale = chart.scales.x;
expect(scale._unit).toEqual('month');
});
type: 'line',
data: {
datasets: [{
- xAxisID: 'xScale0',
+ xAxisID: 'x',
data: []
}],
labels: [
},
options: {
scales: {
- xAxes: [{
- id: 'xScale0',
+ x: {
type: 'time',
- position: 'bottom',
- }],
+ position: 'bottom'
+ },
}
}
});
- this.scale = this.chart.scales.xScale0;
+ this.scale = this.chart.scales.x;
});
it('should be bounded by the nearest week beginnings', function() {
},
options: {
scales: {
- xAxes: [{
- id: 'xScale0',
+ x: {
type: 'time',
bounds: 'ticks',
position: 'bottom'
- }],
+ },
}
}
}, {canvas: {width: 800, height: 200}});
- this.scale = this.chart.scales.xScale0;
+ this.scale = this.chart.scales.x;
});
it('should be bounded by nearest step\'s year start and end', function() {
type: 'line',
data: {
datasets: [{
- xAxisID: 'xScale0',
+ xAxisID: 'x',
data: [null, 10, 3]
}],
labels: ['2015-01-01T20:00:00', '2015-01-02T21:00:00', '2015-01-03T22:00:00', '2015-01-05T23:00:00', '2015-01-07T03:00', '2015-01-08T10:00', '2015-01-10T12:00'], // days
},
options: {
scales: {
- xAxes: [{
- id: 'xScale0',
+ x: {
type: 'time',
position: 'bottom',
ticks: {
source: 'labels',
autoSkip: false
}
- }],
+ }
}
}
});
- var xScale = chart.scales.xScale0;
+ var xScale = chart.scales.x;
var controller = chart.getDatasetMeta(0).controller;
expect(xScale.getLabelForValue(controller._getParsed(0)[xScale.id])).toBeTruthy();
expect(xScale.getLabelForValue(controller._getParsed(0)[xScale.id])).toBe('Jan 1, 2015, 8:00:00 pm');
type: 'line',
data: {
datasets: [{
- xAxisID: 'xScale0',
+ xAxisID: 'x',
data: [0, 0]
}],
labels: ['2015-01-01T20:00:00', '2015-01-01T20:01:00']
},
options: {
scales: {
- xAxes: [{
- id: 'xScale0',
+ x: {
type: 'time',
time: {
displayFormats: {
return '<' + value + '>';
}
}
- }]
+ }
}
}
});
- this.scale = this.chart.scales.xScale0;
+ this.scale = this.chart.scales.x;
});
it('should get the correct labels for ticks', function() {
it('should update ticks.callback correctly', function() {
var chart = this.chart;
- chart.options.scales.xAxes[0].ticks.callback = function(value) {
+ chart.options.scales.x.ticks.callback = function(value) {
return '{' + value + '}';
};
chart.update();
type: 'line',
data: {
datasets: [{
- xAxisID: 'xScale0',
+ xAxisID: 'x',
data: [0, 0]
}],
labels: ['2015-01-01T20:00:00', '2015-01-01T20:01:00']
},
options: {
scales: {
- xAxes: [{
- id: 'xScale0',
+ x: {
type: 'time',
ticks: {
callback: function(value) {
}
}
}
- }]
+ }
}
}
});
- this.scale = this.chart.scales.xScale0;
+ this.scale = this.chart.scales.x;
});
it('should get the correct labels for major and minor ticks', function() {
it('should only use ticks.minor callback if ticks.major.enabled is false', function() {
var chart = this.chart;
- chart.options.scales.xAxes[0].ticks.major.enabled = false;
+ chart.options.scales.x.ticks.major.enabled = false;
chart.update();
var labels = getLabels(this.scale);
it('should use ticks.callback if ticks.major.callback is omitted', function() {
var chart = this.chart;
- chart.options.scales.xAxes[0].ticks.major.callback = undefined;
+ chart.options.scales.x.ticks.major.callback = undefined;
chart.update();
var labels = getLabels(this.scale);
it('should use ticks.callback if ticks.minor.callback is omitted', function() {
var chart = this.chart;
- chart.options.scales.xAxes[0].ticks.minor.callback = undefined;
+ chart.options.scales.x.ticks.minor.callback = undefined;
chart.update();
var labels = getLabels(this.scale);
type: 'line',
data: {
datasets: [{
- xAxisID: 'xScale0',
+ xAxisID: 'x',
data: [{t: '2015-01-01T20:00:00', y: 10}, {t: '2015-01-02T21:00:00', y: 3}]
}],
},
options: {
scales: {
- xAxes: [{
- id: 'xScale0',
+ x: {
type: 'time',
position: 'bottom'
- }],
+ },
}
}
});
- var xScale = chart.scales.xScale0;
+ var xScale = chart.scales.x;
var controller = chart.getDatasetMeta(0).controller;
var value = controller._getParsed(0)[xScale.id];
expect(xScale.getLabelForValue(value)).toBeTruthy();
type: 'line',
data: {
datasets: [{
- xAxisID: 'xScale0',
+ xAxisID: 'x',
data: [
{t: +new Date('2018-01-08 05:14:23.234'), y: 10},
{t: +new Date('2018-01-09 06:17:43.426'), y: 3}
},
options: {
scales: {
- xAxes: [{
- id: 'xScale0',
+ x: {
type: 'time',
position: 'bottom'
- }],
+ },
}
}
});
- var xScale = chart.scales.xScale0;
+ var xScale = chart.scales.x;
var controller = chart.getDatasetMeta(0).controller;
var label = xScale.getLabelForValue(controller._getParsed(0)[xScale.id]);
expect(label).toEqual('Jan 8, 2018, 5:14:23 am');
data: {
labels: ['2016-05-27'],
datasets: [{
- xAxisID: 'xScale0',
+ xAxisID: 'x',
data: [5]
}]
},
options: {
scales: {
- xAxes: [{
- id: 'xScale0',
+ x: {
display: true,
type: 'time'
- }]
+ }
}
}
});
- var xScale = chart.scales.xScale0;
+ var xScale = chart.scales.x;
var pixel = xScale.getPixelForValue(moment('2016-05-27').valueOf());
expect(xScale.getValueForPixel(pixel)).toEqual(moment(chart.data.labels[0]).valueOf());
},
options: {
scales: {
- xAxes: [{
+ x: {
type: 'time',
ticks: {
min: moment().subtract(1, 'months'),
max: moment(),
}
- }],
+ },
},
responsive: true,
},
style: 'display: none',
},
});
- expect(chart.scales['y-axis-0'].width).toEqual(0);
- expect(chart.scales['y-axis-0'].maxWidth).toEqual(0);
+ expect(chart.scales.y.width).toEqual(0);
+ expect(chart.scales.y.maxWidth).toEqual(0);
expect(chart.width).toEqual(0);
});
},
options: {
scales: {
- xAxes: [{
- id: 'x',
+ x: {
type: 'time',
time: {
parser: 'YYYY'
ticks: {
source: 'labels'
}
- }]
+ }
}
}
});
it ('should not add ticks for min and max if they extend the labels range', function() {
var chart = this.chart;
var scale = chart.scales.x;
- var options = chart.options.scales.xAxes[0];
+ var options = chart.options.scales.x;
options.min = '2012';
options.max = '2051';
it ('should not duplicate ticks if min and max are the labels limits', function() {
var chart = this.chart;
var scale = chart.scales.x;
- var options = chart.options.scales.xAxes[0];
+ var options = chart.options.scales.x;
options.min = '2017';
options.max = '2042';
it ('should correctly handle empty `data.labels` using `time.unit`', function() {
var chart = this.chart;
var scale = chart.scales.x;
- var options = chart.options.scales.xAxes[0];
+ var options = chart.options.scales.x;
options.time.unit = 'year';
chart.data.labels = [];
},
options: {
scales: {
- xAxes: [{
- id: 'x',
+ x: {
type: 'time',
time: {
parser: 'YYYY'
ticks: {
source: 'data'
}
- }]
+ }
}
}
});
it ('should not add ticks for min and max if they extend the labels range', function() {
var chart = this.chart;
var scale = chart.scales.x;
- var options = chart.options.scales.xAxes[0];
+ var options = chart.options.scales.x;
options.min = '2012';
options.max = '2051';
it ('should not duplicate ticks if min and max are the labels limits', function() {
var chart = this.chart;
var scale = chart.scales.x;
- var options = chart.options.scales.xAxes[0];
+ var options = chart.options.scales.x;
options.min = '2017';
options.max = '2043';
it ('should correctly handle empty `data.labels` and hidden datasets using `time.unit`', function() {
var chart = this.chart;
var scale = chart.scales.x;
- var options = chart.options.scales.xAxes[0];
+ var options = chart.options.scales.x;
options.time.unit = 'year';
chart.data.labels = [];
},
options: {
scales: {
- xAxes: [{
- id: 'x',
+ x: {
type: 'time',
time: {
parser: 'YYYY'
ticks: {
source: 'labels'
}
- }],
- yAxes: [{
+ },
+ y: {
display: false
- }]
+ }
}
}
});
it ('should add a step before if scale.min is before the first data', function() {
var chart = this.chart;
var scale = chart.scales.x;
- var options = chart.options.scales.xAxes[0];
+ var options = chart.options.scales.x;
options.min = '2012';
chart.update();
it ('should add a step after if scale.max is after the last data', function() {
var chart = this.chart;
var scale = chart.scales.x;
- var options = chart.options.scales.xAxes[0];
+ var options = chart.options.scales.x;
options.max = '2050';
chart.update();
it ('should add steps before and after if scale.min/max are outside the data range', function() {
var chart = this.chart;
var scale = chart.scales.x;
- var options = chart.options.scales.xAxes[0];
+ var options = chart.options.scales.x;
options.min = '2012';
options.max = '2050';
},
options: {
scales: {
- xAxes: [{
- id: 'x',
+ x: {
type: 'time',
time: {
parser: 'YYYY'
ticks: {
source: 'labels'
}
- }],
- yAxes: [{
+ },
+ y: {
display: false
- }]
+ }
}
}
});
it ('should take in account scale min and max if outside the ticks range', function() {
var chart = this.chart;
var scale = chart.scales.x;
- var options = chart.options.scales.xAxes[0];
+ var options = chart.options.scales.x;
options.min = '2012';
options.max = '2050';
},
options: {
scales: {
- xAxes: [{
- id: 'x',
+ x: {
type: 'time',
bounds: 'data',
time: {
parser: 'MM/DD HH:mm',
unit: 'day'
}
- }],
- yAxes: [{
+ },
+ y: {
display: false
- }]
+ }
}
}
});
},
options: {
scales: {
- xAxes: [{
- id: 'x',
+ x: {
type: 'time',
bounds: 'ticks',
time: {
parser: 'MM/DD HH:mm',
unit: 'day'
}
- }],
- yAxes: [{
+ },
+ y: {
display: false
- }]
+ }
}
}
});
},
options: {
scales: {
- xAxes: [{
- id: 'x',
+ x: {
type: 'time',
bounds: bounds,
time: {
ticks: {
source: source
}
- }],
- yAxes: [{
+ },
+ y: {
display: false
- }]
+ }
}
}
});
it ('should expand scale to the min/max range', function() {
var chart = this.chart;
var scale = chart.scales.x;
- var options = chart.options.scales.xAxes[0];
+ var options = chart.options.scales.x;
var min = '02/19 07:00';
var max = '02/24 08:00';
var minMillis = +moment(min, 'MM/DD HH:mm');
it ('should shrink scale to the min/max range', function() {
var chart = this.chart;
var scale = chart.scales.x;
- var options = chart.options.scales.xAxes[0];
+ var options = chart.options.scales.x;
var min = '02/21 07:00';
var max = '02/22 20:00';
var minMillis = +moment(min, 'MM/DD HH:mm');
},
options: {
scales: {
- xAxes: [{
- id: 'x',
+ x: {
type: 'time',
time: {
parser: 'YYYY'
source: source
},
distribution: distribution
- }]
+ }
}
}
});
it ('should add offset from the edges if offset is true', function() {
var chart = this.chart;
var scale = chart.scales.x;
- var options = chart.options.scales.xAxes[0];
+ var options = chart.options.scales.x;
options.offset = true;
chart.update();
it ('should not add offset if min and max extend the labels range', function() {
var chart = this.chart;
var scale = chart.scales.x;
- var options = chart.options.scales.xAxes[0];
+ var options = chart.options.scales.x;
options.min = '2012';
options.max = '2051';
},
options: {
scales: {
- xAxes: [{
+ x: {
id: 'x',
type: 'time',
time: {
source: source
},
distribution: distribution
- }]
+ }
}
}
});
it ('should add offset if min and max extend the labels range and offset is true', function() {
var chart = this.chart;
var scale = chart.scales.x;
- var options = chart.options.scales.xAxes[0];
+ var options = chart.options.scales.x;
options.min = '2012';
options.max = '2051';
},
options: {
scales: {
- xAxes: [{
- id: 'x',
+ x: {
type: 'time',
reverse: true,
time: {
ticks: {
source: 'labels',
}
- }],
- yAxes: [{
+ },
+ y: {
display: false
- }]
+ }
}
}
});
it ('should reverse the bars and add offsets if offset is true', function() {
var chart = this.chart;
var scale = chart.scales.x;
- var options = chart.options.scales.xAxes[0];
+ var options = chart.options.scales.x;
options.offset = true;
chart.update();
it ('should reverse the values for pixels if offset is true', function() {
var chart = this.chart;
var scale = chart.scales.x;
- var options = chart.options.scales.xAxes[0];
+ var options = chart.options.scales.x;
options.offset = true;
chart.update();
},
options: {
scales: {
- xAxes: [{
- id: 'x',
+ x: {
type: 'time',
time: {
parser: 'YYYY'
ticks: {
source: 'labels'
}
- }],
- yAxes: [{
+ },
+ y: {
display: false
- }]
+ }
}
}
});
it ('should reverse the labels and should add a step before if scale.min is before the first data', function() {
var chart = this.chart;
var scale = chart.scales.x;
- var options = chart.options.scales.xAxes[0];
+ var options = chart.options.scales.x;
options.min = '2012';
chart.update();
it ('should reverse the labels and should add a step after if scale.max is after the last data', function() {
var chart = this.chart;
var scale = chart.scales.x;
- var options = chart.options.scales.xAxes[0];
+ var options = chart.options.scales.x;
options.max = '2050';
chart.update();
it ('should reverse the labels and should add steps before and after if scale.min/max are outside the data range', function() {
var chart = this.chart;
var scale = chart.scales.x;
- var options = chart.options.scales.xAxes[0];
+ var options = chart.options.scales.x;
options.min = '2012';
options.max = '2050';
},
options: {
scales: {
- xAxes: [{
- id: 'x',
+ x: {
type: 'time',
time: {
parser: 'YYYY'
ticks: {
source: 'labels'
}
- }],
- yAxes: [{
+ },
+ y: {
display: false
- }]
+ }
}
}
});
it ('should reverse the labels and should take in account scale min and max if outside the ticks range', function() {
var chart = this.chart;
var scale = chart.scales.x;
- var options = chart.options.scales.xAxes[0];
+ var options = chart.options.scales.x;
options.min = '2012';
options.max = '2050';
},
options: {
scales: {
- xAxes: [{
- id: 'x',
+ x: {
type: 'time',
labels: ['2015', '2016', '2017'],
time: timeOpts
},
- {
- id: 'x2',
+ x2: {
type: 'time',
+ position: 'bottom',
time: timeOpts
- }],
- yAxes: [{
- id: 'y',
+ },
+ y: {
type: 'time',
time: timeOpts
},
- {
- id: 'y2',
+ y2: {
+ position: 'left',
type: 'time',
labels: ['2005', '2006', '2007'],
time: timeOpts
- }]
+ }
}
}
});
type: 'line',
data: {
datasets: [{
- xAxisID: 'xScale0',
+ xAxisID: 'x',
data: data
}],
},
options: {
scales: {
- xAxes: [{
- id: 'xScale0',
+ x: {
type: 'time',
ticks: {
major: {
source: 'data',
autoSkip: true
}
- }],
+ },
}
}
});
- var scale = chart.scales.xScale0;
+ var scale = chart.scales.x;
var labels = scale.ticks.map(function(t) {
return t.label;
data: {},
options: {
scales: {
- xAxes: [{
- id: 'x',
+ x: {
type: 'time'
- }]
+ }
}
}
});
};
expect(chart.scales.x.options.time.displayFormats).toEqual(expected);
- expect(chart.options.scales.xAxes[0].time.displayFormats).toEqual(expected);
+ expect(chart.options.scales.x.time.displayFormats).toEqual(expected);
});
it('should merge user formats with adapter presets', function() {
data: {},
options: {
scales: {
- xAxes: [{
- id: 'x',
+ x: {
type: 'time',
time: {
displayFormats: {
month: 'bla'
}
}
- }]
+ }
}
}
});
};
expect(chart.scales.x.options.time.displayFormats).toEqual(expected);
- expect(chart.options.scales.xAxes[0].time.displayFormats).toEqual(expected);
+ expect(chart.options.scales.x.time.displayFormats).toEqual(expected);
});
});
});