2017-08-27 22:43:16 +02:00
|
|
|
describe('Chart.controllers.bar', function() {
|
2018-10-20 11:38:48 +02:00
|
|
|
describe('auto', jasmine.fixture.specs('controller.bar'));
|
2017-12-02 12:38:36 +01:00
|
|
|
|
2018-11-29 21:06:34 +01:00
|
|
|
it('should be registered as dataset controller', function() {
|
|
|
|
expect(typeof Chart.controllers.bar).toBe('function');
|
|
|
|
});
|
|
|
|
|
2016-04-25 19:59:32 +02:00
|
|
|
it('should be constructed', function() {
|
|
|
|
var chart = window.acquireChart({
|
|
|
|
type: 'bar',
|
|
|
|
data: {
|
|
|
|
datasets: [
|
2016-10-16 23:34:59 +02:00
|
|
|
{data: []},
|
|
|
|
{data: []}
|
2016-04-25 19:59:32 +02:00
|
|
|
],
|
|
|
|
labels: []
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var meta = chart.getDatasetMeta(1);
|
|
|
|
expect(meta.type).toEqual('bar');
|
|
|
|
expect(meta.data).toEqual([]);
|
|
|
|
expect(meta.hidden).toBe(null);
|
|
|
|
expect(meta.controller).not.toBe(undefined);
|
|
|
|
expect(meta.controller.index).toBe(1);
|
|
|
|
expect(meta.xAxisID).not.toBe(null);
|
|
|
|
expect(meta.yAxisID).not.toBe(null);
|
|
|
|
|
|
|
|
meta.controller.updateIndex(0);
|
|
|
|
expect(meta.controller.index).toBe(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should use the first scale IDs if the dataset does not specify them', function() {
|
|
|
|
var chart = window.acquireChart({
|
|
|
|
type: 'bar',
|
|
|
|
data: {
|
|
|
|
datasets: [
|
2016-10-16 23:34:59 +02:00
|
|
|
{data: []},
|
|
|
|
{data: []}
|
2016-04-25 19:59:32 +02:00
|
|
|
],
|
|
|
|
labels: []
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
var meta = chart.getDatasetMeta(1);
|
2019-11-22 00:46:49 +01:00
|
|
|
expect(meta.xAxisID).toBe('x');
|
|
|
|
expect(meta.yAxisID).toBe('y');
|
2016-04-25 19:59:32 +02:00
|
|
|
});
|
|
|
|
|
2017-01-01 15:36:01 +01:00
|
|
|
it('should correctly count the number of stacks ignoring datasets of other types and hidden datasets', function() {
|
2020-06-18 23:35:52 +02:00
|
|
|
var chart = window.acquireChart({
|
|
|
|
type: 'bar',
|
|
|
|
data: {
|
|
|
|
datasets: [
|
|
|
|
{data: [], type: 'line'},
|
|
|
|
{data: [], hidden: true},
|
|
|
|
{data: []},
|
|
|
|
{data: []}
|
|
|
|
],
|
|
|
|
labels: []
|
|
|
|
}
|
2016-04-25 19:59:32 +02:00
|
|
|
});
|
2020-06-18 23:35:52 +02:00
|
|
|
|
|
|
|
var meta = chart.getDatasetMeta(1);
|
|
|
|
expect(meta.controller._getStackCount()).toBe(2);
|
2017-01-01 15:36:01 +01:00
|
|
|
});
|
2016-04-25 19:59:32 +02:00
|
|
|
|
2017-01-01 15:36:01 +01:00
|
|
|
it('should correctly count the number of stacks when a group is not specified', function() {
|
2020-06-18 23:35:52 +02:00
|
|
|
var chart = window.acquireChart({
|
|
|
|
type: 'bar',
|
|
|
|
data: {
|
|
|
|
datasets: [
|
|
|
|
{data: []},
|
|
|
|
{data: []},
|
|
|
|
{data: []},
|
|
|
|
{data: []}
|
|
|
|
],
|
|
|
|
labels: []
|
|
|
|
}
|
2017-01-01 15:36:01 +01:00
|
|
|
});
|
2020-06-18 23:35:52 +02:00
|
|
|
|
|
|
|
var meta = chart.getDatasetMeta(1);
|
|
|
|
expect(meta.controller._getStackCount()).toBe(4);
|
2016-04-25 19:59:32 +02:00
|
|
|
});
|
|
|
|
|
2017-01-01 15:36:01 +01:00
|
|
|
it('should correctly count the number of stacks when a group is not specified and the scale is stacked', function() {
|
2020-06-18 23:35:52 +02:00
|
|
|
var chart = window.acquireChart({
|
|
|
|
type: 'bar',
|
|
|
|
data: {
|
|
|
|
datasets: [
|
|
|
|
{data: []},
|
|
|
|
{data: []},
|
|
|
|
{data: []},
|
|
|
|
{data: []}
|
|
|
|
],
|
|
|
|
labels: []
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
scales: {
|
|
|
|
x: {
|
|
|
|
stacked: true
|
|
|
|
},
|
|
|
|
y: {
|
|
|
|
stacked: true
|
2017-01-01 15:36:01 +01:00
|
|
|
}
|
|
|
|
}
|
2020-06-18 23:35:52 +02:00
|
|
|
}
|
2016-04-25 19:59:32 +02:00
|
|
|
});
|
2020-06-18 23:35:52 +02:00
|
|
|
|
|
|
|
var meta = chart.getDatasetMeta(1);
|
|
|
|
expect(meta.controller._getStackCount()).toBe(1);
|
2017-01-01 15:36:01 +01:00
|
|
|
});
|
2016-04-25 19:59:32 +02:00
|
|
|
|
2017-01-01 15:36:01 +01:00
|
|
|
it('should correctly count the number of stacks when a group is not specified and the scale is not stacked', function() {
|
2020-06-18 23:35:52 +02:00
|
|
|
var chart = window.acquireChart({
|
|
|
|
type: 'bar',
|
|
|
|
data: {
|
|
|
|
datasets: [
|
|
|
|
{data: []},
|
|
|
|
{data: []},
|
|
|
|
{data: []},
|
|
|
|
{data: []}
|
|
|
|
],
|
|
|
|
labels: []
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
scales: {
|
|
|
|
x: {
|
|
|
|
stacked: false
|
|
|
|
},
|
|
|
|
y: {
|
|
|
|
stacked: false
|
2017-01-01 15:36:01 +01:00
|
|
|
}
|
|
|
|
}
|
2020-06-18 23:35:52 +02:00
|
|
|
}
|
2017-01-01 15:36:01 +01:00
|
|
|
});
|
2020-06-18 23:35:52 +02:00
|
|
|
|
|
|
|
var meta = chart.getDatasetMeta(1);
|
|
|
|
expect(meta.controller._getStackCount()).toBe(4);
|
2017-01-01 15:36:01 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should correctly count the number of stacks when a group is specified for some', function() {
|
2020-06-18 23:35:52 +02:00
|
|
|
var chart = window.acquireChart({
|
|
|
|
type: 'bar',
|
|
|
|
data: {
|
|
|
|
datasets: [
|
|
|
|
{data: [], stack: 'stack1'},
|
|
|
|
{data: [], stack: 'stack1'},
|
|
|
|
{data: []},
|
|
|
|
{data: []}
|
|
|
|
],
|
|
|
|
labels: []
|
|
|
|
}
|
2017-01-01 15:36:01 +01:00
|
|
|
});
|
2020-06-18 23:35:52 +02:00
|
|
|
|
|
|
|
var meta = chart.getDatasetMeta(3);
|
|
|
|
expect(meta.controller._getStackCount()).toBe(3);
|
2017-01-01 15:36:01 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should correctly count the number of stacks when a group is specified for some and the scale is stacked', function() {
|
2020-06-18 23:35:52 +02:00
|
|
|
var chart = window.acquireChart({
|
|
|
|
type: 'bar',
|
|
|
|
data: {
|
|
|
|
datasets: [
|
|
|
|
{data: [], stack: 'stack1'},
|
|
|
|
{data: [], stack: 'stack1'},
|
|
|
|
{data: []},
|
|
|
|
{data: []}
|
|
|
|
],
|
|
|
|
labels: []
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
scales: {
|
|
|
|
x: {
|
|
|
|
stacked: true
|
|
|
|
},
|
|
|
|
y: {
|
|
|
|
stacked: true
|
2017-01-01 15:36:01 +01:00
|
|
|
}
|
|
|
|
}
|
2020-06-18 23:35:52 +02:00
|
|
|
}
|
2017-01-01 15:36:01 +01:00
|
|
|
});
|
2020-06-18 23:35:52 +02:00
|
|
|
|
|
|
|
var meta = chart.getDatasetMeta(3);
|
|
|
|
expect(meta.controller._getStackCount()).toBe(2);
|
2017-01-01 15:36:01 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should correctly count the number of stacks when a group is specified for some and the scale is not stacked', function() {
|
2020-06-18 23:35:52 +02:00
|
|
|
var chart = window.acquireChart({
|
|
|
|
type: 'bar',
|
|
|
|
data: {
|
|
|
|
datasets: [
|
|
|
|
{data: [], stack: 'stack1'},
|
|
|
|
{data: [], stack: 'stack1'},
|
|
|
|
{data: []},
|
|
|
|
{data: []}
|
|
|
|
],
|
|
|
|
labels: []
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
scales: {
|
|
|
|
x: {
|
|
|
|
stacked: false
|
|
|
|
},
|
|
|
|
y: {
|
|
|
|
stacked: false
|
2017-01-01 15:36:01 +01:00
|
|
|
}
|
|
|
|
}
|
2020-06-18 23:35:52 +02:00
|
|
|
}
|
2017-01-01 15:36:01 +01:00
|
|
|
});
|
2020-06-18 23:35:52 +02:00
|
|
|
|
|
|
|
var meta = chart.getDatasetMeta(3);
|
|
|
|
expect(meta.controller._getStackCount()).toBe(4);
|
2017-01-01 15:36:01 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should correctly count the number of stacks when a group is specified for all', function() {
|
2020-06-18 23:35:52 +02:00
|
|
|
var chart = window.acquireChart({
|
|
|
|
type: 'bar',
|
|
|
|
data: {
|
|
|
|
datasets: [
|
|
|
|
{data: [], stack: 'stack1'},
|
|
|
|
{data: [], stack: 'stack1'},
|
|
|
|
{data: [], stack: 'stack2'},
|
|
|
|
{data: [], stack: 'stack2'}
|
|
|
|
],
|
|
|
|
labels: []
|
|
|
|
}
|
2017-01-01 15:36:01 +01:00
|
|
|
});
|
2020-06-18 23:35:52 +02:00
|
|
|
|
|
|
|
var meta = chart.getDatasetMeta(3);
|
|
|
|
expect(meta.controller._getStackCount()).toBe(2);
|
2017-01-01 15:36:01 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should correctly count the number of stacks when a group is specified for all and the scale is stacked', function() {
|
2020-06-18 23:35:52 +02:00
|
|
|
var chart = window.acquireChart({
|
|
|
|
type: 'bar',
|
|
|
|
data: {
|
|
|
|
datasets: [
|
|
|
|
{data: [], stack: 'stack1'},
|
|
|
|
{data: [], stack: 'stack1'},
|
|
|
|
{data: [], stack: 'stack2'},
|
|
|
|
{data: [], stack: 'stack2'}
|
|
|
|
],
|
|
|
|
labels: []
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
scales: {
|
|
|
|
x: {
|
|
|
|
stacked: true
|
|
|
|
},
|
|
|
|
y: {
|
|
|
|
stacked: true
|
2017-01-01 15:36:01 +01:00
|
|
|
}
|
|
|
|
}
|
2020-06-18 23:35:52 +02:00
|
|
|
}
|
2017-01-01 15:36:01 +01:00
|
|
|
});
|
2020-06-18 23:35:52 +02:00
|
|
|
|
|
|
|
var meta = chart.getDatasetMeta(3);
|
|
|
|
expect(meta.controller._getStackCount()).toBe(2);
|
2017-01-01 15:36:01 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should correctly count the number of stacks when a group is specified for all and the scale is not stacked', function() {
|
2020-06-18 23:35:52 +02:00
|
|
|
var chart = window.acquireChart({
|
|
|
|
type: 'bar',
|
|
|
|
data: {
|
|
|
|
datasets: [
|
|
|
|
{data: [], stack: 'stack1'},
|
|
|
|
{data: [], stack: 'stack1'},
|
|
|
|
{data: [], stack: 'stack2'},
|
|
|
|
{data: [], stack: 'stack2'}
|
|
|
|
],
|
|
|
|
labels: []
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
scales: {
|
|
|
|
x: {
|
|
|
|
stacked: false
|
|
|
|
},
|
|
|
|
y: {
|
|
|
|
stacked: false
|
2017-01-01 15:36:01 +01:00
|
|
|
}
|
|
|
|
}
|
2020-06-18 23:35:52 +02:00
|
|
|
}
|
2017-01-01 15:36:01 +01:00
|
|
|
});
|
2020-06-18 23:35:52 +02:00
|
|
|
|
|
|
|
var meta = chart.getDatasetMeta(3);
|
|
|
|
expect(meta.controller._getStackCount()).toBe(4);
|
2017-01-01 15:36:01 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should correctly get the stack index accounting for datasets of other types and hidden datasets', function() {
|
2020-06-18 23:35:52 +02:00
|
|
|
var chart = window.acquireChart({
|
|
|
|
type: 'bar',
|
|
|
|
data: {
|
|
|
|
datasets: [
|
|
|
|
{data: []},
|
|
|
|
{data: [], hidden: true},
|
|
|
|
{data: [], type: 'line'},
|
|
|
|
{data: []}
|
|
|
|
],
|
|
|
|
labels: []
|
|
|
|
}
|
2017-01-01 15:36:01 +01:00
|
|
|
});
|
2020-06-18 23:35:52 +02:00
|
|
|
|
|
|
|
var meta = chart.getDatasetMeta(1);
|
|
|
|
expect(meta.controller._getStackIndex(0)).toBe(0);
|
|
|
|
expect(meta.controller._getStackIndex(3)).toBe(1);
|
2017-01-01 15:36:01 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should correctly get the stack index when a group is not specified', function() {
|
2020-06-18 23:35:52 +02:00
|
|
|
var chart = window.acquireChart({
|
|
|
|
type: 'bar',
|
|
|
|
data: {
|
|
|
|
datasets: [
|
|
|
|
{data: []},
|
|
|
|
{data: []},
|
|
|
|
{data: []},
|
|
|
|
{data: []}
|
|
|
|
],
|
|
|
|
labels: []
|
|
|
|
}
|
2017-01-01 15:36:01 +01:00
|
|
|
});
|
2020-06-18 23:35:52 +02:00
|
|
|
|
|
|
|
var meta = chart.getDatasetMeta(1);
|
|
|
|
expect(meta.controller._getStackIndex(0)).toBe(0);
|
|
|
|
expect(meta.controller._getStackIndex(1)).toBe(1);
|
|
|
|
expect(meta.controller._getStackIndex(2)).toBe(2);
|
|
|
|
expect(meta.controller._getStackIndex(3)).toBe(3);
|
2017-01-01 15:36:01 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should correctly get the stack index when a group is not specified and the scale is stacked', function() {
|
2020-06-18 23:35:52 +02:00
|
|
|
var chart = window.acquireChart({
|
|
|
|
type: 'bar',
|
|
|
|
data: {
|
|
|
|
datasets: [
|
|
|
|
{data: []},
|
|
|
|
{data: []},
|
|
|
|
{data: []},
|
|
|
|
{data: []}
|
|
|
|
],
|
|
|
|
labels: []
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
scales: {
|
|
|
|
x: {
|
|
|
|
stacked: true
|
|
|
|
},
|
|
|
|
y: {
|
|
|
|
stacked: true
|
2017-01-01 15:36:01 +01:00
|
|
|
}
|
|
|
|
}
|
2020-06-18 23:35:52 +02:00
|
|
|
}
|
2017-01-01 15:36:01 +01:00
|
|
|
});
|
2020-06-18 23:35:52 +02:00
|
|
|
|
|
|
|
var meta = chart.getDatasetMeta(1);
|
|
|
|
expect(meta.controller._getStackIndex(0)).toBe(0);
|
|
|
|
expect(meta.controller._getStackIndex(1)).toBe(0);
|
|
|
|
expect(meta.controller._getStackIndex(2)).toBe(0);
|
|
|
|
expect(meta.controller._getStackIndex(3)).toBe(0);
|
2017-01-01 15:36:01 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should correctly get the stack index when a group is not specified and the scale is not stacked', function() {
|
2020-06-18 23:35:52 +02:00
|
|
|
var chart = window.acquireChart({
|
|
|
|
type: 'bar',
|
|
|
|
data: {
|
|
|
|
datasets: [
|
|
|
|
{data: []},
|
|
|
|
{data: []},
|
|
|
|
{data: []},
|
|
|
|
{data: []}
|
|
|
|
],
|
|
|
|
labels: []
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
scales: {
|
|
|
|
x: {
|
|
|
|
stacked: false
|
|
|
|
},
|
|
|
|
y: {
|
|
|
|
stacked: false
|
2017-01-01 15:36:01 +01:00
|
|
|
}
|
|
|
|
}
|
2020-06-18 23:35:52 +02:00
|
|
|
}
|
2017-01-01 15:36:01 +01:00
|
|
|
});
|
2020-06-18 23:35:52 +02:00
|
|
|
|
|
|
|
var meta = chart.getDatasetMeta(1);
|
|
|
|
expect(meta.controller._getStackIndex(0)).toBe(0);
|
|
|
|
expect(meta.controller._getStackIndex(1)).toBe(1);
|
|
|
|
expect(meta.controller._getStackIndex(2)).toBe(2);
|
|
|
|
expect(meta.controller._getStackIndex(3)).toBe(3);
|
2017-01-01 15:36:01 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should correctly get the stack index when a group is specified for some', function() {
|
2020-06-18 23:35:52 +02:00
|
|
|
var chart = window.acquireChart({
|
|
|
|
type: 'bar',
|
|
|
|
data: {
|
|
|
|
datasets: [
|
|
|
|
{data: [], stack: 'stack1'},
|
|
|
|
{data: [], stack: 'stack1'},
|
|
|
|
{data: []},
|
|
|
|
{data: []}
|
|
|
|
],
|
|
|
|
labels: []
|
|
|
|
}
|
2017-01-01 15:36:01 +01:00
|
|
|
});
|
2020-06-18 23:35:52 +02:00
|
|
|
|
|
|
|
var meta = chart.getDatasetMeta(1);
|
|
|
|
expect(meta.controller._getStackIndex(0)).toBe(0);
|
|
|
|
expect(meta.controller._getStackIndex(1)).toBe(0);
|
|
|
|
expect(meta.controller._getStackIndex(2)).toBe(1);
|
|
|
|
expect(meta.controller._getStackIndex(3)).toBe(2);
|
2017-01-01 15:36:01 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should correctly get the stack index when a group is specified for some and the scale is stacked', function() {
|
2020-06-18 23:35:52 +02:00
|
|
|
var chart = window.acquireChart({
|
|
|
|
type: 'bar',
|
|
|
|
data: {
|
|
|
|
datasets: [
|
|
|
|
{data: [], stack: 'stack1'},
|
|
|
|
{data: [], stack: 'stack1'},
|
|
|
|
{data: []},
|
|
|
|
{data: []}
|
|
|
|
],
|
|
|
|
labels: []
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
scales: {
|
|
|
|
x: {
|
|
|
|
stacked: true
|
|
|
|
},
|
|
|
|
y: {
|
|
|
|
stacked: true
|
2017-01-01 15:36:01 +01:00
|
|
|
}
|
|
|
|
}
|
2020-06-18 23:35:52 +02:00
|
|
|
}
|
2017-01-01 15:36:01 +01:00
|
|
|
});
|
2020-06-18 23:35:52 +02:00
|
|
|
|
|
|
|
var meta = chart.getDatasetMeta(1);
|
|
|
|
expect(meta.controller._getStackIndex(0)).toBe(0);
|
|
|
|
expect(meta.controller._getStackIndex(1)).toBe(0);
|
|
|
|
expect(meta.controller._getStackIndex(2)).toBe(1);
|
|
|
|
expect(meta.controller._getStackIndex(3)).toBe(1);
|
2017-01-01 15:36:01 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should correctly get the stack index when a group is specified for some and the scale is not stacked', function() {
|
2020-06-18 23:35:52 +02:00
|
|
|
var chart = window.acquireChart({
|
|
|
|
type: 'bar',
|
|
|
|
data: {
|
|
|
|
datasets: [
|
|
|
|
{data: [], stack: 'stack1'},
|
|
|
|
{data: [], stack: 'stack1'},
|
|
|
|
{data: []},
|
|
|
|
{data: []}
|
|
|
|
],
|
|
|
|
labels: []
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
scales: {
|
|
|
|
x: {
|
|
|
|
stacked: false
|
|
|
|
},
|
|
|
|
y: {
|
|
|
|
stacked: false
|
2017-01-01 15:36:01 +01:00
|
|
|
}
|
|
|
|
}
|
2020-06-18 23:35:52 +02:00
|
|
|
}
|
2017-01-01 15:36:01 +01:00
|
|
|
});
|
2020-06-18 23:35:52 +02:00
|
|
|
|
|
|
|
var meta = chart.getDatasetMeta(1);
|
|
|
|
expect(meta.controller._getStackIndex(0)).toBe(0);
|
|
|
|
expect(meta.controller._getStackIndex(1)).toBe(1);
|
|
|
|
expect(meta.controller._getStackIndex(2)).toBe(2);
|
|
|
|
expect(meta.controller._getStackIndex(3)).toBe(3);
|
2017-01-01 15:36:01 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should correctly get the stack index when a group is specified for all', function() {
|
2020-06-18 23:35:52 +02:00
|
|
|
var chart = window.acquireChart({
|
|
|
|
type: 'bar',
|
|
|
|
data: {
|
|
|
|
datasets: [
|
|
|
|
{data: [], stack: 'stack1'},
|
|
|
|
{data: [], stack: 'stack1'},
|
|
|
|
{data: [], stack: 'stack2'},
|
|
|
|
{data: [], stack: 'stack2'}
|
|
|
|
],
|
|
|
|
labels: []
|
|
|
|
}
|
2017-01-01 15:36:01 +01:00
|
|
|
});
|
2020-06-18 23:35:52 +02:00
|
|
|
|
|
|
|
var meta = chart.getDatasetMeta(1);
|
|
|
|
expect(meta.controller._getStackIndex(0)).toBe(0);
|
|
|
|
expect(meta.controller._getStackIndex(1)).toBe(0);
|
|
|
|
expect(meta.controller._getStackIndex(2)).toBe(1);
|
|
|
|
expect(meta.controller._getStackIndex(3)).toBe(1);
|
2017-01-01 15:36:01 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should correctly get the stack index when a group is specified for all and the scale is stacked', function() {
|
2020-06-18 23:35:52 +02:00
|
|
|
var chart = window.acquireChart({
|
|
|
|
type: 'bar',
|
|
|
|
data: {
|
|
|
|
datasets: [
|
|
|
|
{data: [], stack: 'stack1'},
|
|
|
|
{data: [], stack: 'stack1'},
|
|
|
|
{data: [], stack: 'stack2'},
|
|
|
|
{data: [], stack: 'stack2'}
|
|
|
|
],
|
|
|
|
labels: []
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
scales: {
|
|
|
|
x: {
|
|
|
|
stacked: true
|
|
|
|
},
|
|
|
|
y: {
|
|
|
|
stacked: true
|
2017-01-01 15:36:01 +01:00
|
|
|
}
|
|
|
|
}
|
2020-06-18 23:35:52 +02:00
|
|
|
}
|
2017-01-01 15:36:01 +01:00
|
|
|
});
|
2020-06-18 23:35:52 +02:00
|
|
|
|
|
|
|
var meta = chart.getDatasetMeta(1);
|
|
|
|
expect(meta.controller._getStackIndex(0)).toBe(0);
|
|
|
|
expect(meta.controller._getStackIndex(1)).toBe(0);
|
|
|
|
expect(meta.controller._getStackIndex(2)).toBe(1);
|
|
|
|
expect(meta.controller._getStackIndex(3)).toBe(1);
|
2017-01-01 15:36:01 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should correctly get the stack index when a group is specified for all and the scale is not stacked', function() {
|
2020-06-18 23:35:52 +02:00
|
|
|
var chart = window.acquireChart({
|
|
|
|
type: 'bar',
|
|
|
|
data: {
|
|
|
|
datasets: [
|
|
|
|
{data: [], stack: 'stack1'},
|
|
|
|
{data: [], stack: 'stack1'},
|
|
|
|
{data: [], stack: 'stack2'},
|
|
|
|
{data: [], stack: 'stack2'}
|
|
|
|
],
|
|
|
|
labels: []
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
scales: {
|
|
|
|
x: {
|
|
|
|
stacked: false
|
|
|
|
},
|
|
|
|
y: {
|
|
|
|
stacked: false
|
2017-01-01 15:36:01 +01:00
|
|
|
}
|
|
|
|
}
|
2020-06-18 23:35:52 +02:00
|
|
|
}
|
2017-01-01 15:36:01 +01:00
|
|
|
});
|
2020-06-18 23:35:52 +02:00
|
|
|
|
|
|
|
var meta = chart.getDatasetMeta(1);
|
|
|
|
expect(meta.controller._getStackIndex(0)).toBe(0);
|
|
|
|
expect(meta.controller._getStackIndex(1)).toBe(1);
|
|
|
|
expect(meta.controller._getStackIndex(2)).toBe(2);
|
|
|
|
expect(meta.controller._getStackIndex(3)).toBe(3);
|
2016-04-25 19:59:32 +02:00
|
|
|
});
|
|
|
|
|
2020-10-20 14:18:56 +02:00
|
|
|
it('should create bar elements for each data item during initialization', function() {
|
2016-04-25 19:59:32 +02:00
|
|
|
var chart = window.acquireChart({
|
|
|
|
type: 'bar',
|
|
|
|
data: {
|
|
|
|
datasets: [
|
2016-10-16 23:34:59 +02:00
|
|
|
{data: []},
|
|
|
|
{data: [10, 15, 0, -4]}
|
2016-04-25 19:59:32 +02:00
|
|
|
],
|
|
|
|
labels: []
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var meta = chart.getDatasetMeta(1);
|
2020-10-20 14:18:56 +02:00
|
|
|
expect(meta.data.length).toBe(4); // 4 bars created
|
|
|
|
expect(meta.data[0] instanceof Chart.elements.BarElement).toBe(true);
|
|
|
|
expect(meta.data[1] instanceof Chart.elements.BarElement).toBe(true);
|
|
|
|
expect(meta.data[2] instanceof Chart.elements.BarElement).toBe(true);
|
|
|
|
expect(meta.data[3] instanceof Chart.elements.BarElement).toBe(true);
|
2016-04-25 19:59:32 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should update elements when modifying data', function() {
|
|
|
|
var chart = window.acquireChart({
|
|
|
|
type: 'bar',
|
|
|
|
data: {
|
|
|
|
datasets: [{
|
|
|
|
data: [1, 2],
|
|
|
|
label: 'dataset1'
|
|
|
|
}, {
|
|
|
|
data: [10, 15, 0, -4],
|
|
|
|
label: 'dataset2',
|
|
|
|
borderColor: 'blue'
|
|
|
|
}],
|
|
|
|
labels: ['label1', 'label2', 'label3', 'label4']
|
|
|
|
},
|
|
|
|
options: {
|
2017-08-25 00:16:08 +02:00
|
|
|
legend: false,
|
|
|
|
title: false,
|
2016-04-25 19:59:32 +02:00
|
|
|
elements: {
|
2020-10-20 14:18:56 +02:00
|
|
|
bar: {
|
2016-04-25 19:59:32 +02:00
|
|
|
backgroundColor: 'red',
|
|
|
|
borderSkipped: 'top',
|
|
|
|
borderColor: 'green',
|
|
|
|
borderWidth: 2,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
scales: {
|
2019-11-22 00:46:49 +01:00
|
|
|
x: {
|
2017-08-25 00:16:08 +02:00
|
|
|
type: 'category',
|
|
|
|
display: false
|
2019-11-22 00:46:49 +01:00
|
|
|
},
|
|
|
|
y: {
|
2017-08-25 00:16:08 +02:00
|
|
|
type: 'linear',
|
2020-01-05 21:50:24 +01:00
|
|
|
display: false,
|
|
|
|
beginAtZero: false
|
2019-11-22 00:46:49 +01:00
|
|
|
}
|
2016-04-25 19:59:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var meta = chart.getDatasetMeta(1);
|
|
|
|
expect(meta.data.length).toBe(4);
|
|
|
|
|
|
|
|
chart.data.datasets[1].data = [1, 2]; // remove 2 items
|
|
|
|
chart.data.datasets[1].borderWidth = 1;
|
|
|
|
chart.update();
|
|
|
|
|
|
|
|
expect(meta.data.length).toBe(2);
|
2019-12-11 00:57:21 +01:00
|
|
|
expect(meta._parsed.length).toBe(2);
|
2016-04-25 19:59:32 +02:00
|
|
|
|
2016-10-16 23:34:59 +02:00
|
|
|
[
|
2017-08-25 00:16:08 +02:00
|
|
|
{x: 89, y: 512},
|
|
|
|
{x: 217, y: 0}
|
2016-04-25 19:59:32 +02:00
|
|
|
].forEach(function(expected, i) {
|
2019-12-27 23:13:24 +01:00
|
|
|
expect(meta.data[i].x).toBeCloseToPixel(expected.x);
|
|
|
|
expect(meta.data[i].y).toBeCloseToPixel(expected.y);
|
2020-11-06 14:07:15 +01:00
|
|
|
expect(meta.data[i].base).toBeCloseToPixel(1024);
|
2019-12-27 23:13:24 +01:00
|
|
|
expect(meta.data[i].width).toBeCloseToPixel(46);
|
|
|
|
expect(meta.data[i].options).toEqual(jasmine.objectContaining({
|
2016-04-25 19:59:32 +02:00
|
|
|
backgroundColor: 'red',
|
|
|
|
borderSkipped: 'top',
|
|
|
|
borderColor: 'blue',
|
|
|
|
borderWidth: 1
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
chart.data.datasets[1].data = [1, 2, 3]; // add 1 items
|
|
|
|
chart.update();
|
|
|
|
|
|
|
|
expect(meta.data.length).toBe(3); // should add a new meta data item
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should get the correct bar points when datasets of different types exist', function() {
|
|
|
|
var chart = window.acquireChart({
|
|
|
|
type: 'bar',
|
|
|
|
data: {
|
|
|
|
datasets: [{
|
|
|
|
data: [1, 2],
|
|
|
|
label: 'dataset1'
|
|
|
|
}, {
|
|
|
|
type: 'line',
|
|
|
|
data: [4, 6],
|
|
|
|
label: 'dataset2'
|
|
|
|
}, {
|
|
|
|
data: [8, 10],
|
|
|
|
label: 'dataset3'
|
|
|
|
}],
|
|
|
|
labels: ['label1', 'label2']
|
|
|
|
},
|
|
|
|
options: {
|
2017-08-25 00:16:08 +02:00
|
|
|
legend: false,
|
|
|
|
title: false,
|
2016-04-25 19:59:32 +02:00
|
|
|
scales: {
|
2019-11-22 00:46:49 +01:00
|
|
|
x: {
|
2017-08-25 00:16:08 +02:00
|
|
|
type: 'category',
|
|
|
|
display: false
|
2019-11-22 00:46:49 +01:00
|
|
|
},
|
|
|
|
y: {
|
2017-08-25 00:16:08 +02:00
|
|
|
type: 'linear',
|
2020-01-05 21:50:24 +01:00
|
|
|
display: false,
|
|
|
|
beginAtZero: false
|
2019-11-22 00:46:49 +01:00
|
|
|
}
|
2016-04-25 19:59:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var meta = chart.getDatasetMeta(2);
|
|
|
|
expect(meta.data.length).toBe(2);
|
|
|
|
|
|
|
|
var bar1 = meta.data[0];
|
|
|
|
var bar2 = meta.data[1];
|
|
|
|
|
2019-12-27 23:13:24 +01:00
|
|
|
expect(bar1.x).toBeCloseToPixel(179);
|
|
|
|
expect(bar1.y).toBeCloseToPixel(114);
|
|
|
|
expect(bar2.x).toBeCloseToPixel(435);
|
|
|
|
expect(bar2.y).toBeCloseToPixel(0);
|
2016-04-25 19:59:32 +02:00
|
|
|
});
|
|
|
|
|
2020-01-08 23:27:17 +01:00
|
|
|
it('should get the bar points for hidden dataset', function() {
|
|
|
|
var chart = window.acquireChart({
|
|
|
|
type: 'bar',
|
|
|
|
data: {
|
|
|
|
datasets: [{
|
|
|
|
data: [1, 2],
|
|
|
|
label: 'dataset1',
|
|
|
|
hidden: true
|
|
|
|
}],
|
|
|
|
labels: ['label1', 'label2']
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
legend: false,
|
|
|
|
title: false,
|
|
|
|
scales: {
|
|
|
|
x: {
|
|
|
|
type: 'category',
|
|
|
|
display: false
|
|
|
|
},
|
|
|
|
y: {
|
|
|
|
type: 'linear',
|
|
|
|
min: 0,
|
|
|
|
max: 2,
|
|
|
|
display: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var meta = chart.getDatasetMeta(0);
|
|
|
|
expect(meta.data.length).toBe(2);
|
|
|
|
|
|
|
|
var bar1 = meta.data[0];
|
|
|
|
var bar2 = meta.data[1];
|
|
|
|
|
|
|
|
expect(bar1.x).toBeCloseToPixel(128);
|
|
|
|
expect(bar1.y).toBeCloseToPixel(256);
|
|
|
|
expect(bar2.x).toBeCloseToPixel(384);
|
|
|
|
expect(bar2.y).toBeCloseToPixel(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2016-04-25 19:59:32 +02:00
|
|
|
it('should update elements when the scales are stacked', function() {
|
|
|
|
var chart = window.acquireChart({
|
|
|
|
type: 'bar',
|
|
|
|
data: {
|
|
|
|
datasets: [{
|
|
|
|
data: [10, -10, 10, -10],
|
|
|
|
label: 'dataset1'
|
|
|
|
}, {
|
|
|
|
data: [10, 15, 0, -4],
|
|
|
|
label: 'dataset2'
|
|
|
|
}],
|
|
|
|
labels: ['label1', 'label2', 'label3', 'label4']
|
|
|
|
},
|
|
|
|
options: {
|
2017-08-25 00:16:08 +02:00
|
|
|
legend: false,
|
|
|
|
title: false,
|
2016-04-25 19:59:32 +02:00
|
|
|
scales: {
|
2019-11-22 00:46:49 +01:00
|
|
|
x: {
|
2017-08-25 00:16:08 +02:00
|
|
|
type: 'category',
|
|
|
|
display: false
|
2019-11-22 00:46:49 +01:00
|
|
|
},
|
|
|
|
y: {
|
2016-04-25 19:59:32 +02:00
|
|
|
type: 'linear',
|
2017-08-27 22:43:16 +02:00
|
|
|
display: false,
|
|
|
|
stacked: true
|
2019-11-22 00:46:49 +01:00
|
|
|
}
|
2016-04-25 19:59:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var meta0 = chart.getDatasetMeta(0);
|
|
|
|
|
2016-10-16 23:34:59 +02:00
|
|
|
[
|
2017-08-25 00:16:08 +02:00
|
|
|
{b: 293, w: 92 / 2, x: 38, y: 146},
|
|
|
|
{b: 293, w: 92 / 2, x: 166, y: 439},
|
|
|
|
{b: 293, w: 92 / 2, x: 295, y: 146},
|
|
|
|
{b: 293, w: 92 / 2, x: 422, y: 439}
|
2016-04-25 19:59:32 +02:00
|
|
|
].forEach(function(values, i) {
|
2019-12-27 23:13:24 +01:00
|
|
|
expect(meta0.data[i].base).toBeCloseToPixel(values.b);
|
|
|
|
expect(meta0.data[i].width).toBeCloseToPixel(values.w);
|
|
|
|
expect(meta0.data[i].x).toBeCloseToPixel(values.x);
|
|
|
|
expect(meta0.data[i].y).toBeCloseToPixel(values.y);
|
2016-07-07 00:22:42 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
var meta1 = chart.getDatasetMeta(1);
|
|
|
|
|
2016-10-16 23:34:59 +02:00
|
|
|
[
|
2017-08-25 00:16:08 +02:00
|
|
|
{b: 146, w: 92 / 2, x: 89, y: 0},
|
|
|
|
{b: 293, w: 92 / 2, x: 217, y: 73},
|
|
|
|
{b: 146, w: 92 / 2, x: 345, y: 146},
|
|
|
|
{b: 439, w: 92 / 2, x: 473, y: 497}
|
2016-07-07 00:22:42 +02:00
|
|
|
].forEach(function(values, i) {
|
2019-12-27 23:13:24 +01:00
|
|
|
expect(meta1.data[i].base).toBeCloseToPixel(values.b);
|
|
|
|
expect(meta1.data[i].width).toBeCloseToPixel(values.w);
|
|
|
|
expect(meta1.data[i].x).toBeCloseToPixel(values.x);
|
|
|
|
expect(meta1.data[i].y).toBeCloseToPixel(values.y);
|
2016-07-07 00:22:42 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-03-19 17:51:18 +01:00
|
|
|
it('should update elements when the scales are stacked and the y axis has a user defined minimum', function() {
|
2017-03-21 01:38:15 +01:00
|
|
|
var chart = window.acquireChart({
|
|
|
|
type: 'bar',
|
|
|
|
data: {
|
|
|
|
datasets: [{
|
|
|
|
data: [50, 20, 10, 100],
|
|
|
|
label: 'dataset1'
|
|
|
|
}, {
|
|
|
|
data: [50, 80, 90, 0],
|
|
|
|
label: 'dataset2'
|
|
|
|
}],
|
|
|
|
labels: ['label1', 'label2', 'label3', 'label4']
|
|
|
|
},
|
|
|
|
options: {
|
2017-08-25 00:16:08 +02:00
|
|
|
legend: false,
|
|
|
|
title: false,
|
2017-03-21 01:38:15 +01:00
|
|
|
scales: {
|
2019-11-22 00:46:49 +01:00
|
|
|
x: {
|
2017-08-25 00:16:08 +02:00
|
|
|
type: 'category',
|
|
|
|
display: false
|
2019-11-22 00:46:49 +01:00
|
|
|
},
|
|
|
|
y: {
|
2017-03-21 01:38:15 +01:00
|
|
|
type: 'linear',
|
2017-08-25 00:16:08 +02:00
|
|
|
display: false,
|
2017-08-27 22:43:16 +02:00
|
|
|
stacked: true,
|
2019-11-15 18:11:13 +01:00
|
|
|
min: 50,
|
|
|
|
max: 100
|
2019-11-22 00:46:49 +01:00
|
|
|
}
|
2017-03-21 01:38:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var meta0 = chart.getDatasetMeta(0);
|
|
|
|
|
|
|
|
[
|
2020-11-06 14:07:15 +01:00
|
|
|
{b: 1024, w: 92 / 2, x: 38, y: 512},
|
|
|
|
{b: 1024, w: 92 / 2, x: 166, y: 819},
|
|
|
|
{b: 1024, w: 92 / 2, x: 294, y: 922},
|
|
|
|
{b: 1024, w: 92 / 2, x: 422.5, y: 0}
|
2017-03-21 01:38:15 +01:00
|
|
|
].forEach(function(values, i) {
|
2019-12-27 23:13:24 +01:00
|
|
|
expect(meta0.data[i].base).toBeCloseToPixel(values.b);
|
|
|
|
expect(meta0.data[i].width).toBeCloseToPixel(values.w);
|
|
|
|
expect(meta0.data[i].x).toBeCloseToPixel(values.x);
|
|
|
|
expect(meta0.data[i].y).toBeCloseToPixel(values.y);
|
2017-03-21 01:38:15 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
var meta1 = chart.getDatasetMeta(1);
|
|
|
|
|
|
|
|
[
|
2017-08-25 00:16:08 +02:00
|
|
|
{b: 512, w: 92 / 2, x: 89, y: 0},
|
2020-11-06 14:07:15 +01:00
|
|
|
{b: 819.2, w: 92 / 2, x: 217, y: 0},
|
|
|
|
{b: 921.6, w: 92 / 2, x: 345, y: 0},
|
2017-08-25 00:16:08 +02:00
|
|
|
{b: 0, w: 92 / 2, x: 473.5, y: 0}
|
2017-03-21 01:38:15 +01:00
|
|
|
].forEach(function(values, i) {
|
2019-12-27 23:13:24 +01:00
|
|
|
expect(meta1.data[i].base).toBeCloseToPixel(values.b);
|
|
|
|
expect(meta1.data[i].width).toBeCloseToPixel(values.w);
|
|
|
|
expect(meta1.data[i].x).toBeCloseToPixel(values.x);
|
|
|
|
expect(meta1.data[i].y).toBeCloseToPixel(values.y);
|
2017-03-21 01:38:15 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-02-12 12:59:20 +01:00
|
|
|
it('should update elements when only the category scale is stacked', function() {
|
|
|
|
var chart = window.acquireChart({
|
|
|
|
type: 'bar',
|
|
|
|
data: {
|
|
|
|
datasets: [{
|
|
|
|
data: [20, -10, 10, -10],
|
|
|
|
label: 'dataset1'
|
|
|
|
}, {
|
|
|
|
data: [10, 15, 0, -14],
|
|
|
|
label: 'dataset2'
|
|
|
|
}],
|
|
|
|
labels: ['label1', 'label2', 'label3', 'label4']
|
|
|
|
},
|
|
|
|
options: {
|
2017-08-25 00:16:08 +02:00
|
|
|
legend: false,
|
|
|
|
title: false,
|
2017-02-12 12:59:20 +01:00
|
|
|
scales: {
|
2019-11-22 00:46:49 +01:00
|
|
|
x: {
|
2017-02-12 12:59:20 +01:00
|
|
|
type: 'category',
|
2017-08-27 22:43:16 +02:00
|
|
|
display: false,
|
|
|
|
stacked: true
|
2019-11-22 00:46:49 +01:00
|
|
|
},
|
|
|
|
y: {
|
2017-08-25 00:16:08 +02:00
|
|
|
type: 'linear',
|
|
|
|
display: false
|
2019-11-22 00:46:49 +01:00
|
|
|
}
|
2017-02-12 12:59:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var meta0 = chart.getDatasetMeta(0);
|
|
|
|
|
|
|
|
[
|
2017-08-25 00:16:08 +02:00
|
|
|
{b: 293, w: 92, x: 64, y: 0},
|
|
|
|
{b: 293, w: 92, x: 192, y: 439},
|
|
|
|
{b: 293, w: 92, x: 320, y: 146},
|
|
|
|
{b: 293, w: 92, x: 448, y: 439}
|
2017-02-12 12:59:20 +01:00
|
|
|
].forEach(function(values, i) {
|
2019-12-27 23:13:24 +01:00
|
|
|
expect(meta0.data[i].base).toBeCloseToPixel(values.b);
|
|
|
|
expect(meta0.data[i].width).toBeCloseToPixel(values.w);
|
|
|
|
expect(meta0.data[i].x).toBeCloseToPixel(values.x);
|
|
|
|
expect(meta0.data[i].y).toBeCloseToPixel(values.y);
|
2017-02-12 12:59:20 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
var meta1 = chart.getDatasetMeta(1);
|
|
|
|
|
|
|
|
[
|
2017-08-25 00:16:08 +02:00
|
|
|
{b: 293, w: 92, x: 64, y: 146},
|
|
|
|
{b: 293, w: 92, x: 192, y: 73},
|
|
|
|
{b: 293, w: 92, x: 320, y: 293},
|
|
|
|
{b: 293, w: 92, x: 448, y: 497}
|
2017-02-12 12:59:20 +01:00
|
|
|
].forEach(function(values, i) {
|
2019-12-27 23:13:24 +01:00
|
|
|
expect(meta1.data[i].base).toBeCloseToPixel(values.b);
|
|
|
|
expect(meta1.data[i].width).toBeCloseToPixel(values.w);
|
|
|
|
expect(meta1.data[i].x).toBeCloseToPixel(values.x);
|
|
|
|
expect(meta1.data[i].y).toBeCloseToPixel(values.y);
|
2017-02-12 12:59:20 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-07-07 00:22:42 +02:00
|
|
|
it('should update elements when the scales are stacked and data is strings', function() {
|
|
|
|
var chart = window.acquireChart({
|
|
|
|
type: 'bar',
|
|
|
|
data: {
|
|
|
|
datasets: [{
|
|
|
|
data: ['10', '-10', '10', '-10'],
|
|
|
|
label: 'dataset1'
|
|
|
|
}, {
|
|
|
|
data: ['10', '15', '0', '-4'],
|
|
|
|
label: 'dataset2'
|
|
|
|
}],
|
|
|
|
labels: ['label1', 'label2', 'label3', 'label4']
|
|
|
|
},
|
|
|
|
options: {
|
2017-08-25 00:16:08 +02:00
|
|
|
legend: false,
|
|
|
|
title: false,
|
2016-07-07 00:22:42 +02:00
|
|
|
scales: {
|
2019-11-22 00:46:49 +01:00
|
|
|
x: {
|
2017-08-25 00:16:08 +02:00
|
|
|
type: 'category',
|
|
|
|
display: false
|
2019-11-22 00:46:49 +01:00
|
|
|
},
|
|
|
|
y: {
|
2016-07-07 00:22:42 +02:00
|
|
|
type: 'linear',
|
2017-08-27 22:43:16 +02:00
|
|
|
display: false,
|
|
|
|
stacked: true
|
2019-11-22 00:46:49 +01:00
|
|
|
}
|
2016-07-07 00:22:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var meta0 = chart.getDatasetMeta(0);
|
|
|
|
|
2016-10-16 23:34:59 +02:00
|
|
|
[
|
2017-08-25 00:16:08 +02:00
|
|
|
{b: 293, w: 92 / 2, x: 38, y: 146},
|
|
|
|
{b: 293, w: 92 / 2, x: 166, y: 439},
|
|
|
|
{b: 293, w: 92 / 2, x: 295, y: 146},
|
|
|
|
{b: 293, w: 92 / 2, x: 422, y: 439}
|
2016-07-07 00:22:42 +02:00
|
|
|
].forEach(function(values, i) {
|
2019-12-27 23:13:24 +01:00
|
|
|
expect(meta0.data[i].base).toBeCloseToPixel(values.b);
|
|
|
|
expect(meta0.data[i].width).toBeCloseToPixel(values.w);
|
|
|
|
expect(meta0.data[i].x).toBeCloseToPixel(values.x);
|
|
|
|
expect(meta0.data[i].y).toBeCloseToPixel(values.y);
|
2016-04-25 19:59:32 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
var meta1 = chart.getDatasetMeta(1);
|
|
|
|
|
2016-10-16 23:34:59 +02:00
|
|
|
[
|
2017-08-25 00:16:08 +02:00
|
|
|
{b: 146, w: 92 / 2, x: 89, y: 0},
|
|
|
|
{b: 293, w: 92 / 2, x: 217, y: 73},
|
|
|
|
{b: 146, w: 92 / 2, x: 345, y: 146},
|
|
|
|
{b: 439, w: 92 / 2, x: 473, y: 497}
|
2016-04-25 19:59:32 +02:00
|
|
|
].forEach(function(values, i) {
|
2019-12-27 23:13:24 +01:00
|
|
|
expect(meta1.data[i].base).toBeCloseToPixel(values.b);
|
|
|
|
expect(meta1.data[i].width).toBeCloseToPixel(values.w);
|
|
|
|
expect(meta1.data[i].x).toBeCloseToPixel(values.x);
|
|
|
|
expect(meta1.data[i].y).toBeCloseToPixel(values.y);
|
2016-12-09 02:56:33 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-01-01 15:36:01 +01:00
|
|
|
it('should get the correct bar points for grouped stacked chart if the group name is same', function() {
|
|
|
|
var chart = window.acquireChart({
|
|
|
|
type: 'bar',
|
|
|
|
data: {
|
|
|
|
datasets: [{
|
|
|
|
data: [10, -10, 10, -10],
|
|
|
|
label: 'dataset1',
|
|
|
|
stack: 'stack1'
|
|
|
|
}, {
|
|
|
|
data: [10, 15, 0, -4],
|
|
|
|
label: 'dataset2',
|
|
|
|
stack: 'stack1'
|
|
|
|
}],
|
|
|
|
labels: ['label1', 'label2', 'label3', 'label4']
|
|
|
|
},
|
|
|
|
options: {
|
2017-08-25 00:16:08 +02:00
|
|
|
legend: false,
|
|
|
|
title: false,
|
2017-01-01 15:36:01 +01:00
|
|
|
scales: {
|
2019-11-22 00:46:49 +01:00
|
|
|
x: {
|
2017-08-25 00:16:08 +02:00
|
|
|
type: 'category',
|
|
|
|
display: false
|
2019-11-22 00:46:49 +01:00
|
|
|
},
|
|
|
|
y: {
|
2017-01-01 15:36:01 +01:00
|
|
|
type: 'linear',
|
2017-08-27 22:43:16 +02:00
|
|
|
display: false,
|
|
|
|
stacked: true
|
2019-11-22 00:46:49 +01:00
|
|
|
}
|
2017-01-01 15:36:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var meta0 = chart.getDatasetMeta(0);
|
|
|
|
|
|
|
|
[
|
2017-08-25 00:16:08 +02:00
|
|
|
{b: 293, w: 92, x: 64, y: 146},
|
|
|
|
{b: 293, w: 92, x: 192, y: 439},
|
|
|
|
{b: 293, w: 92, x: 320, y: 146},
|
|
|
|
{b: 293, w: 92, x: 448, y: 439}
|
2017-01-01 15:36:01 +01:00
|
|
|
].forEach(function(values, i) {
|
2019-12-27 23:13:24 +01:00
|
|
|
expect(meta0.data[i].base).toBeCloseToPixel(values.b);
|
|
|
|
expect(meta0.data[i].width).toBeCloseToPixel(values.w);
|
|
|
|
expect(meta0.data[i].x).toBeCloseToPixel(values.x);
|
|
|
|
expect(meta0.data[i].y).toBeCloseToPixel(values.y);
|
2017-01-01 15:36:01 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
var meta = chart.getDatasetMeta(1);
|
|
|
|
|
|
|
|
[
|
2017-08-25 00:16:08 +02:00
|
|
|
{b: 146, w: 92, x: 64, y: 0},
|
|
|
|
{b: 293, w: 92, x: 192, y: 73},
|
|
|
|
{b: 146, w: 92, x: 320, y: 146},
|
|
|
|
{b: 439, w: 92, x: 448, y: 497}
|
2017-01-01 15:36:01 +01:00
|
|
|
].forEach(function(values, i) {
|
2019-12-27 23:13:24 +01:00
|
|
|
expect(meta.data[i].base).toBeCloseToPixel(values.b);
|
|
|
|
expect(meta.data[i].width).toBeCloseToPixel(values.w);
|
|
|
|
expect(meta.data[i].x).toBeCloseToPixel(values.x);
|
|
|
|
expect(meta.data[i].y).toBeCloseToPixel(values.y);
|
2017-01-01 15:36:01 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should get the correct bar points for grouped stacked chart if the group name is different', function() {
|
|
|
|
var chart = window.acquireChart({
|
|
|
|
type: 'bar',
|
|
|
|
data: {
|
|
|
|
datasets: [{
|
|
|
|
data: [1, 2],
|
|
|
|
stack: 'stack1'
|
|
|
|
}, {
|
|
|
|
data: [1, 2],
|
|
|
|
stack: 'stack2'
|
|
|
|
}],
|
|
|
|
labels: ['label1', 'label2', 'label3', 'label4']
|
|
|
|
},
|
|
|
|
options: {
|
2017-08-25 00:16:08 +02:00
|
|
|
legend: false,
|
|
|
|
title: false,
|
2017-01-01 15:36:01 +01:00
|
|
|
scales: {
|
2019-11-22 00:46:49 +01:00
|
|
|
x: {
|
2017-08-25 00:16:08 +02:00
|
|
|
type: 'category',
|
|
|
|
display: false
|
2019-11-22 00:46:49 +01:00
|
|
|
},
|
|
|
|
y: {
|
2017-08-27 22:43:16 +02:00
|
|
|
type: 'linear',
|
2017-08-25 00:16:08 +02:00
|
|
|
display: false,
|
2017-08-27 22:43:16 +02:00
|
|
|
stacked: true,
|
2019-11-22 00:46:49 +01:00
|
|
|
}
|
2017-01-01 15:36:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var meta = chart.getDatasetMeta(1);
|
|
|
|
|
|
|
|
[
|
2017-08-25 00:16:08 +02:00
|
|
|
{x: 89, y: 256},
|
|
|
|
{x: 217, y: 0}
|
2017-01-01 15:36:01 +01:00
|
|
|
].forEach(function(values, i) {
|
2019-12-27 23:13:24 +01:00
|
|
|
expect(meta.data[i].base).toBeCloseToPixel(512);
|
|
|
|
expect(meta.data[i].width).toBeCloseToPixel(46);
|
|
|
|
expect(meta.data[i].x).toBeCloseToPixel(values.x);
|
|
|
|
expect(meta.data[i].y).toBeCloseToPixel(values.y);
|
2017-01-01 15:36:01 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should get the correct bar points for grouped stacked chart', function() {
|
|
|
|
var chart = window.acquireChart({
|
|
|
|
type: 'bar',
|
|
|
|
data: {
|
|
|
|
datasets: [{
|
|
|
|
data: [1, 2],
|
|
|
|
stack: 'stack1'
|
|
|
|
}, {
|
|
|
|
data: [0.5, 1],
|
|
|
|
stack: 'stack2'
|
|
|
|
}, {
|
|
|
|
data: [0.5, 1],
|
|
|
|
stack: 'stack2'
|
|
|
|
}],
|
|
|
|
labels: ['label1', 'label2', 'label3', 'label4']
|
|
|
|
},
|
|
|
|
options: {
|
2017-08-25 00:16:08 +02:00
|
|
|
legend: false,
|
|
|
|
title: false,
|
2017-01-01 15:36:01 +01:00
|
|
|
scales: {
|
2019-11-22 00:46:49 +01:00
|
|
|
x: {
|
2017-08-25 00:16:08 +02:00
|
|
|
type: 'category',
|
|
|
|
display: false
|
2019-11-22 00:46:49 +01:00
|
|
|
},
|
|
|
|
y: {
|
2017-08-27 22:43:16 +02:00
|
|
|
type: 'linear',
|
2017-08-25 00:16:08 +02:00
|
|
|
display: false,
|
2017-08-27 22:43:16 +02:00
|
|
|
stacked: true
|
2019-11-22 00:46:49 +01:00
|
|
|
}
|
2017-01-01 15:36:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var meta = chart.getDatasetMeta(2);
|
|
|
|
|
|
|
|
[
|
2017-08-25 00:16:08 +02:00
|
|
|
{b: 384, x: 89, y: 256},
|
|
|
|
{b: 256, x: 217, y: 0}
|
2017-01-01 15:36:01 +01:00
|
|
|
].forEach(function(values, i) {
|
2019-12-27 23:13:24 +01:00
|
|
|
expect(meta.data[i].base).toBeCloseToPixel(values.b);
|
|
|
|
expect(meta.data[i].width).toBeCloseToPixel(46);
|
|
|
|
expect(meta.data[i].x).toBeCloseToPixel(values.x);
|
|
|
|
expect(meta.data[i].y).toBeCloseToPixel(values.y);
|
2017-01-01 15:36:01 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-04-25 19:59:32 +02:00
|
|
|
it('should draw all bars', function() {
|
|
|
|
var chart = window.acquireChart({
|
|
|
|
type: 'bar',
|
|
|
|
data: {
|
|
|
|
datasets: [{
|
|
|
|
data: [],
|
|
|
|
}, {
|
|
|
|
data: [10, 15, 0, -4],
|
|
|
|
label: 'dataset2'
|
|
|
|
}],
|
|
|
|
labels: ['label1', 'label2', 'label3', 'label4']
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var meta = chart.getDatasetMeta(1);
|
|
|
|
|
|
|
|
spyOn(meta.data[0], 'draw');
|
|
|
|
spyOn(meta.data[1], 'draw');
|
|
|
|
spyOn(meta.data[2], 'draw');
|
|
|
|
spyOn(meta.data[3], 'draw');
|
|
|
|
|
|
|
|
chart.update();
|
|
|
|
|
|
|
|
expect(meta.data[0].draw.calls.count()).toBe(1);
|
|
|
|
expect(meta.data[1].draw.calls.count()).toBe(1);
|
|
|
|
expect(meta.data[2].draw.calls.count()).toBe(1);
|
|
|
|
expect(meta.data[3].draw.calls.count()).toBe(1);
|
|
|
|
});
|
|
|
|
|
2020-10-20 14:18:56 +02:00
|
|
|
it('should set hover styles on bars', function() {
|
2016-04-25 19:59:32 +02:00
|
|
|
var chart = window.acquireChart({
|
|
|
|
type: 'bar',
|
|
|
|
data: {
|
|
|
|
datasets: [{
|
|
|
|
data: [],
|
|
|
|
}, {
|
|
|
|
data: [10, 15, 0, -4],
|
|
|
|
label: 'dataset2'
|
|
|
|
}],
|
|
|
|
labels: ['label1', 'label2', 'label3', 'label4']
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
elements: {
|
2020-10-20 14:18:56 +02:00
|
|
|
bar: {
|
2016-04-25 19:59:32 +02:00
|
|
|
backgroundColor: 'rgb(255, 0, 0)',
|
|
|
|
borderColor: 'rgb(0, 0, 255)',
|
|
|
|
borderWidth: 2,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var meta = chart.getDatasetMeta(1);
|
|
|
|
var bar = meta.data[0];
|
|
|
|
|
2019-11-10 13:52:12 +01:00
|
|
|
meta.controller.setHoverStyle(bar, 1, 0);
|
2020-02-08 01:24:29 +01:00
|
|
|
expect(bar.options.backgroundColor).toBe('#E60000');
|
|
|
|
expect(bar.options.borderColor).toBe('#0000E6');
|
2019-12-27 23:13:24 +01:00
|
|
|
expect(bar.options.borderWidth).toBe(2);
|
2016-04-25 19:59:32 +02:00
|
|
|
|
|
|
|
// Set a dataset style
|
|
|
|
chart.data.datasets[1].hoverBackgroundColor = 'rgb(128, 128, 128)';
|
|
|
|
chart.data.datasets[1].hoverBorderColor = 'rgb(0, 0, 0)';
|
|
|
|
chart.data.datasets[1].hoverBorderWidth = 5;
|
2019-12-27 23:13:24 +01:00
|
|
|
chart.update();
|
2016-04-25 19:59:32 +02:00
|
|
|
|
2019-11-10 13:52:12 +01:00
|
|
|
meta.controller.setHoverStyle(bar, 1, 0);
|
2019-12-27 23:13:24 +01:00
|
|
|
expect(bar.options.backgroundColor).toBe('rgb(128, 128, 128)');
|
|
|
|
expect(bar.options.borderColor).toBe('rgb(0, 0, 0)');
|
|
|
|
expect(bar.options.borderWidth).toBe(5);
|
2016-04-25 19:59:32 +02:00
|
|
|
|
|
|
|
// Should work with array styles so that we can set per bar
|
|
|
|
chart.data.datasets[1].hoverBackgroundColor = ['rgb(255, 255, 255)', 'rgb(128, 128, 128)'];
|
|
|
|
chart.data.datasets[1].hoverBorderColor = ['rgb(9, 9, 9)', 'rgb(0, 0, 0)'];
|
|
|
|
chart.data.datasets[1].hoverBorderWidth = [2.5, 5];
|
2019-12-27 23:13:24 +01:00
|
|
|
chart.update();
|
2016-04-25 19:59:32 +02:00
|
|
|
|
2019-11-10 13:52:12 +01:00
|
|
|
meta.controller.setHoverStyle(bar, 1, 0);
|
2019-12-27 23:13:24 +01:00
|
|
|
expect(bar.options.backgroundColor).toBe('rgb(255, 255, 255)');
|
|
|
|
expect(bar.options.borderColor).toBe('rgb(9, 9, 9)');
|
|
|
|
expect(bar.options.borderWidth).toBe(2.5);
|
2016-04-25 19:59:32 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should remove a hover style from a bar', function() {
|
|
|
|
var chart = window.acquireChart({
|
|
|
|
type: 'bar',
|
|
|
|
data: {
|
|
|
|
datasets: [{
|
|
|
|
data: [],
|
|
|
|
}, {
|
|
|
|
data: [10, 15, 0, -4],
|
|
|
|
label: 'dataset2'
|
|
|
|
}],
|
|
|
|
labels: ['label1', 'label2', 'label3', 'label4']
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
elements: {
|
2020-11-01 13:38:37 +01:00
|
|
|
bar: {
|
2016-04-25 19:59:32 +02:00
|
|
|
backgroundColor: 'rgb(255, 0, 0)',
|
|
|
|
borderColor: 'rgb(0, 0, 255)',
|
|
|
|
borderWidth: 2,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var meta = chart.getDatasetMeta(1);
|
|
|
|
var bar = meta.data[0];
|
2018-06-26 08:56:53 +02:00
|
|
|
var helpers = window.Chart.helpers;
|
2016-04-25 19:59:32 +02:00
|
|
|
|
|
|
|
// Change default
|
2020-10-20 14:18:56 +02:00
|
|
|
chart.options.elements.bar.backgroundColor = 'rgb(128, 128, 128)';
|
|
|
|
chart.options.elements.bar.borderColor = 'rgb(15, 15, 15)';
|
|
|
|
chart.options.elements.bar.borderWidth = 3.14;
|
2016-04-25 19:59:32 +02:00
|
|
|
|
2018-06-26 08:56:53 +02:00
|
|
|
chart.update();
|
2019-12-27 23:13:24 +01:00
|
|
|
expect(bar.options.backgroundColor).toBe('rgb(128, 128, 128)');
|
|
|
|
expect(bar.options.borderColor).toBe('rgb(15, 15, 15)');
|
|
|
|
expect(bar.options.borderWidth).toBe(3.14);
|
2019-11-10 13:52:12 +01:00
|
|
|
meta.controller.setHoverStyle(bar, 1, 0);
|
2019-12-27 23:13:24 +01:00
|
|
|
expect(bar.options.backgroundColor).toBe(helpers.getHoverColor('rgb(128, 128, 128)'));
|
|
|
|
expect(bar.options.borderColor).toBe(helpers.getHoverColor('rgb(15, 15, 15)'));
|
|
|
|
expect(bar.options.borderWidth).toBe(3.14);
|
2016-04-25 19:59:32 +02:00
|
|
|
meta.controller.removeHoverStyle(bar);
|
2019-12-27 23:13:24 +01:00
|
|
|
expect(bar.options.backgroundColor).toBe('rgb(128, 128, 128)');
|
|
|
|
expect(bar.options.borderColor).toBe('rgb(15, 15, 15)');
|
|
|
|
expect(bar.options.borderWidth).toBe(3.14);
|
2016-04-25 19:59:32 +02:00
|
|
|
|
|
|
|
// Should work with array styles so that we can set per bar
|
|
|
|
chart.data.datasets[1].backgroundColor = ['rgb(255, 255, 255)', 'rgb(128, 128, 128)'];
|
|
|
|
chart.data.datasets[1].borderColor = ['rgb(9, 9, 9)', 'rgb(0, 0, 0)'];
|
|
|
|
chart.data.datasets[1].borderWidth = [2.5, 5];
|
|
|
|
|
2018-06-26 08:56:53 +02:00
|
|
|
chart.update();
|
2019-12-27 23:13:24 +01:00
|
|
|
expect(bar.options.backgroundColor).toBe('rgb(255, 255, 255)');
|
|
|
|
expect(bar.options.borderColor).toBe('rgb(9, 9, 9)');
|
|
|
|
expect(bar.options.borderWidth).toBe(2.5);
|
2019-11-10 13:52:12 +01:00
|
|
|
meta.controller.setHoverStyle(bar, 1, 0);
|
2019-12-27 23:13:24 +01:00
|
|
|
expect(bar.options.backgroundColor).toBe(helpers.getHoverColor('rgb(255, 255, 255)'));
|
|
|
|
expect(bar.options.borderColor).toBe(helpers.getHoverColor('rgb(9, 9, 9)'));
|
|
|
|
expect(bar.options.borderWidth).toBe(2.5);
|
2016-04-25 19:59:32 +02:00
|
|
|
meta.controller.removeHoverStyle(bar);
|
2019-12-27 23:13:24 +01:00
|
|
|
expect(bar.options.backgroundColor).toBe('rgb(255, 255, 255)');
|
|
|
|
expect(bar.options.borderColor).toBe('rgb(9, 9, 9)');
|
|
|
|
expect(bar.options.borderWidth).toBe(2.5);
|
2016-04-25 19:59:32 +02:00
|
|
|
});
|
2016-11-27 04:36:29 +01:00
|
|
|
|
|
|
|
describe('Bar width', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
// 2 datasets
|
|
|
|
this.data = {
|
|
|
|
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
|
|
|
|
datasets: [{
|
|
|
|
data: [10, 20, 30, 40, 50, 60, 70],
|
|
|
|
}, {
|
|
|
|
data: [10, 20, 30, 40, 50, 60, 70],
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function() {
|
|
|
|
var chart = window.acquireChart(this.config);
|
|
|
|
var meta = chart.getDatasetMeta(0);
|
|
|
|
var xScale = chart.scales[meta.xAxisID];
|
2020-10-30 23:34:32 +01:00
|
|
|
var options = Chart.defaults.controllers.bar.datasets;
|
2016-11-27 04:36:29 +01:00
|
|
|
|
2019-10-25 18:17:41 +02:00
|
|
|
var categoryPercentage = options.categoryPercentage;
|
|
|
|
var barPercentage = options.barPercentage;
|
2017-03-19 17:51:18 +01:00
|
|
|
var stacked = xScale.options.stacked;
|
2016-11-27 04:36:29 +01:00
|
|
|
|
|
|
|
var totalBarWidth = 0;
|
|
|
|
for (var i = 0; i < chart.data.datasets.length; i++) {
|
|
|
|
var bars = chart.getDatasetMeta(i).data;
|
2019-11-13 01:24:07 +01:00
|
|
|
for (var j = xScale.min; j <= xScale.max; j++) {
|
2019-12-27 23:13:24 +01:00
|
|
|
totalBarWidth += bars[j].width;
|
2016-11-27 04:36:29 +01:00
|
|
|
}
|
|
|
|
if (stacked) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var actualValue = totalBarWidth;
|
|
|
|
var expectedValue = xScale.width * categoryPercentage * barPercentage;
|
|
|
|
expect(actualValue).toBeCloseToPixel(expectedValue);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should correctly set bar width when min and max option is set.', function() {
|
|
|
|
this.config = {
|
|
|
|
type: 'bar',
|
|
|
|
data: this.data,
|
|
|
|
options: {
|
|
|
|
scales: {
|
2019-11-22 00:46:49 +01:00
|
|
|
x: {
|
2019-11-15 18:11:13 +01:00
|
|
|
min: 'March',
|
|
|
|
max: 'May',
|
2019-11-22 00:46:49 +01:00
|
|
|
}
|
2016-11-27 04:36:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should correctly set bar width when scale are stacked with min and max options.', function() {
|
|
|
|
this.config = {
|
|
|
|
type: 'bar',
|
|
|
|
data: this.data,
|
|
|
|
options: {
|
|
|
|
scales: {
|
2019-11-22 00:46:49 +01:00
|
|
|
x: {
|
2019-11-15 18:11:13 +01:00
|
|
|
min: 'March',
|
|
|
|
max: 'May',
|
2019-11-22 00:46:49 +01:00
|
|
|
},
|
|
|
|
y: {
|
2017-01-01 15:36:01 +01:00
|
|
|
stacked: true
|
2019-11-22 00:46:49 +01:00
|
|
|
}
|
2016-11-27 04:36:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-06-18 23:35:52 +02:00
|
|
|
describe('Bar height (horizontal type)', function() {
|
2016-11-27 04:36:29 +01:00
|
|
|
beforeEach(function() {
|
|
|
|
// 2 datasets
|
|
|
|
this.data = {
|
|
|
|
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
|
|
|
|
datasets: [{
|
|
|
|
data: [10, 20, 30, 40, 50, 60, 70],
|
|
|
|
}, {
|
|
|
|
data: [10, 20, 30, 40, 50, 60, 70],
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function() {
|
|
|
|
var chart = window.acquireChart(this.config);
|
|
|
|
var meta = chart.getDatasetMeta(0);
|
|
|
|
var yScale = chart.scales[meta.yAxisID];
|
|
|
|
|
2019-10-26 18:48:48 +02:00
|
|
|
var config = meta.controller._config;
|
|
|
|
var categoryPercentage = config.categoryPercentage;
|
|
|
|
var barPercentage = config.barPercentage;
|
2017-03-19 17:51:18 +01:00
|
|
|
var stacked = yScale.options.stacked;
|
2016-11-27 04:36:29 +01:00
|
|
|
|
|
|
|
var totalBarHeight = 0;
|
|
|
|
for (var i = 0; i < chart.data.datasets.length; i++) {
|
|
|
|
var bars = chart.getDatasetMeta(i).data;
|
2019-11-13 01:24:07 +01:00
|
|
|
for (var j = yScale.min; j <= yScale.max; j++) {
|
2019-12-27 23:13:24 +01:00
|
|
|
totalBarHeight += bars[j].height;
|
2016-11-27 04:36:29 +01:00
|
|
|
}
|
|
|
|
if (stacked) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var actualValue = totalBarHeight;
|
|
|
|
var expectedValue = yScale.height * categoryPercentage * barPercentage;
|
|
|
|
expect(actualValue).toBeCloseToPixel(expectedValue);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should correctly set bar height when min and max option is set.', function() {
|
|
|
|
this.config = {
|
2020-06-18 23:35:52 +02:00
|
|
|
type: 'bar',
|
2016-11-27 04:36:29 +01:00
|
|
|
data: this.data,
|
|
|
|
options: {
|
2020-06-18 23:35:52 +02:00
|
|
|
indexAxis: 'y',
|
2016-11-27 04:36:29 +01:00
|
|
|
scales: {
|
2019-11-22 00:46:49 +01:00
|
|
|
y: {
|
2019-11-15 18:11:13 +01:00
|
|
|
min: 'March',
|
|
|
|
max: 'May',
|
2019-11-22 00:46:49 +01:00
|
|
|
}
|
2016-11-27 04:36:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should correctly set bar height when scale are stacked with min and max options.', function() {
|
|
|
|
this.config = {
|
2020-06-18 23:35:52 +02:00
|
|
|
type: 'bar',
|
2016-11-27 04:36:29 +01:00
|
|
|
data: this.data,
|
|
|
|
options: {
|
2020-06-18 23:35:52 +02:00
|
|
|
indexAxis: 'y',
|
2016-11-27 04:36:29 +01:00
|
|
|
scales: {
|
2019-11-22 00:46:49 +01:00
|
|
|
x: {
|
2017-01-01 15:36:01 +01:00
|
|
|
stacked: true
|
2019-11-22 00:46:49 +01:00
|
|
|
},
|
|
|
|
y: {
|
2019-11-15 18:11:13 +01:00
|
|
|
min: 'March',
|
|
|
|
max: 'May',
|
2019-11-22 00:46:49 +01:00
|
|
|
}
|
2016-11-27 04:36:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
});
|
2017-08-14 10:09:33 +02:00
|
|
|
|
|
|
|
describe('Bar thickness with a category scale', function() {
|
|
|
|
[undefined, 20].forEach(function(barThickness) {
|
|
|
|
describe('When barThickness is ' + barThickness, function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
this.chart = window.acquireChart({
|
|
|
|
type: 'bar',
|
|
|
|
data: {
|
|
|
|
datasets: [{
|
|
|
|
data: [1, 2]
|
|
|
|
}, {
|
|
|
|
data: [1, 2]
|
|
|
|
}],
|
|
|
|
labels: ['label1', 'label2', 'label3']
|
|
|
|
},
|
|
|
|
options: {
|
2017-08-25 00:16:08 +02:00
|
|
|
legend: false,
|
|
|
|
title: false,
|
2020-01-14 01:39:30 +01:00
|
|
|
bar: {
|
|
|
|
datasets: {
|
2019-10-27 14:15:53 +01:00
|
|
|
barThickness: barThickness
|
|
|
|
}
|
|
|
|
},
|
2017-08-14 10:09:33 +02:00
|
|
|
scales: {
|
2019-11-22 00:46:49 +01:00
|
|
|
x: {
|
2017-08-14 10:09:33 +02:00
|
|
|
id: 'x',
|
|
|
|
type: 'category',
|
2019-11-22 00:46:49 +01:00
|
|
|
},
|
|
|
|
y: {
|
2017-08-25 00:16:08 +02:00
|
|
|
type: 'linear',
|
2019-11-22 00:46:49 +01:00
|
|
|
}
|
2017-08-14 10:09:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should correctly set bar width', function() {
|
|
|
|
var chart = this.chart;
|
|
|
|
var expected, i, ilen, meta;
|
|
|
|
|
|
|
|
if (barThickness) {
|
|
|
|
expected = barThickness;
|
|
|
|
} else {
|
|
|
|
var scale = chart.scales.x;
|
2020-10-30 23:34:32 +01:00
|
|
|
var options = Chart.defaults.controllers.bar.datasets;
|
2017-08-14 10:09:33 +02:00
|
|
|
var categoryPercentage = options.categoryPercentage;
|
|
|
|
var barPercentage = options.barPercentage;
|
|
|
|
var tickInterval = scale.getPixelForTick(1) - scale.getPixelForTick(0);
|
|
|
|
|
|
|
|
expected = tickInterval * categoryPercentage / 2 * barPercentage;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0, ilen = chart.data.datasets.length; i < ilen; ++i) {
|
|
|
|
meta = chart.getDatasetMeta(i);
|
2019-12-27 23:13:24 +01:00
|
|
|
expect(meta.data[0].width).toBeCloseToPixel(expected);
|
|
|
|
expect(meta.data[1].width).toBeCloseToPixel(expected);
|
2017-08-14 10:09:33 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should correctly set bar width if maxBarThickness is specified', function() {
|
2019-10-25 18:17:41 +02:00
|
|
|
var chart = this.chart;
|
|
|
|
var i, ilen, meta;
|
|
|
|
|
|
|
|
chart.data.datasets[0].maxBarThickness = 10;
|
|
|
|
chart.data.datasets[1].maxBarThickness = 10;
|
|
|
|
chart.update();
|
|
|
|
|
|
|
|
for (i = 0, ilen = chart.data.datasets.length; i < ilen; ++i) {
|
|
|
|
meta = chart.getDatasetMeta(i);
|
2019-12-27 23:13:24 +01:00
|
|
|
expect(meta.data[0].width).toBeCloseToPixel(10);
|
|
|
|
expect(meta.data[1].width).toBeCloseToPixel(10);
|
2019-10-25 18:17:41 +02:00
|
|
|
}
|
|
|
|
});
|
2017-08-14 10:09:33 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2019-10-25 18:17:41 +02:00
|
|
|
|
|
|
|
it('minBarLength settings should be used on Y axis on bar chart', function() {
|
|
|
|
var minBarLength = 4;
|
|
|
|
var chart = window.acquireChart({
|
|
|
|
type: 'bar',
|
|
|
|
data: {
|
|
|
|
datasets: [{
|
|
|
|
minBarLength: minBarLength,
|
|
|
|
data: [0.05, -0.05, 10, 15, 20, 25, 30, 35]
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var data = chart.getDatasetMeta(0).data;
|
|
|
|
|
2019-12-27 23:13:24 +01:00
|
|
|
expect(data[0].base - minBarLength).toEqual(data[0].y);
|
|
|
|
expect(data[1].base + minBarLength).toEqual(data[1].y);
|
2019-10-25 18:17:41 +02:00
|
|
|
});
|
|
|
|
|
2020-06-18 23:35:52 +02:00
|
|
|
it('minBarLength settings should be used on X axis on horizontal bar chart', function() {
|
2019-10-25 18:17:41 +02:00
|
|
|
var minBarLength = 4;
|
|
|
|
var chart = window.acquireChart({
|
2020-06-18 23:35:52 +02:00
|
|
|
type: 'bar',
|
2019-10-25 18:17:41 +02:00
|
|
|
data: {
|
|
|
|
datasets: [{
|
2020-06-18 23:35:52 +02:00
|
|
|
indexAxis: 'y',
|
2019-10-25 18:17:41 +02:00
|
|
|
minBarLength: minBarLength,
|
|
|
|
data: [0.05, -0.05, 10, 15, 20, 25, 30, 35]
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var data = chart.getDatasetMeta(0).data;
|
|
|
|
|
2019-12-27 23:13:24 +01:00
|
|
|
expect(data[0].base + minBarLength).toEqual(data[0].x);
|
|
|
|
expect(data[1].base - minBarLength).toEqual(data[1].x);
|
2019-10-25 18:17:41 +02:00
|
|
|
});
|
2020-06-09 23:15:05 +02:00
|
|
|
|
2020-10-12 16:22:55 +02:00
|
|
|
it('should respect the data visibility settings', function() {
|
|
|
|
var chart = window.acquireChart({
|
|
|
|
type: 'bar',
|
|
|
|
data: {
|
|
|
|
datasets: [{
|
|
|
|
data: [1, 2, 3, 4]
|
|
|
|
}],
|
|
|
|
labels: ['A', 'B', 'C', 'D']
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
legend: false,
|
|
|
|
title: false,
|
|
|
|
scales: {
|
|
|
|
x: {
|
|
|
|
type: 'category',
|
|
|
|
display: false
|
|
|
|
},
|
|
|
|
y: {
|
|
|
|
type: 'linear',
|
|
|
|
display: false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var data = chart.getDatasetMeta(0).data;
|
|
|
|
expect(data[0].base).toBeCloseToPixel(512);
|
|
|
|
expect(data[0].y).toBeCloseToPixel(384);
|
|
|
|
|
|
|
|
chart.toggleDataVisibility(0);
|
|
|
|
chart.update();
|
|
|
|
|
|
|
|
data = chart.getDatasetMeta(0).data;
|
|
|
|
expect(data[0].base).toBeCloseToPixel(512);
|
|
|
|
expect(data[0].y).toBeCloseToPixel(512);
|
|
|
|
});
|
|
|
|
|
2020-06-09 23:15:05 +02:00
|
|
|
describe('Float bar', function() {
|
|
|
|
it('Should return correct values from getMinMax', function() {
|
|
|
|
var chart = window.acquireChart({
|
|
|
|
type: 'bar',
|
|
|
|
data: {
|
|
|
|
labels: ['a'],
|
|
|
|
datasets: [{
|
|
|
|
data: [[10, -10]]
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(chart.scales.y.getMinMax()).toEqual({min: -10, max: 10});
|
|
|
|
});
|
|
|
|
});
|
2016-04-17 00:38:03 +02:00
|
|
|
});
|