mirror of
https://github.com/chartjs/Chart.js.git
synced 2025-12-08 20:36:08 +00:00
Fix helpers, layoutService and logarithmic tests
This commit is contained in:
parent
e0353dac98
commit
a93b3f45ac
@ -6,7 +6,7 @@ describe('Core helper tests', function() {
|
||||
helpers = window.Chart.helpers;
|
||||
});
|
||||
|
||||
it('Should iterate over an array and pass the extra data to that function', function() {
|
||||
it('should iterate over an array and pass the extra data to that function', function() {
|
||||
var testData = [0, 9, "abc"];
|
||||
var scope = {}; // fake out the scope and ensure that 'this' is the correct thing
|
||||
|
||||
@ -33,7 +33,7 @@ describe('Core helper tests', function() {
|
||||
expect(iterated.slice().reverse()).toEqual(testData);
|
||||
});
|
||||
|
||||
it('Should iterate over properties in an object', function() {
|
||||
it('should iterate over properties in an object', function() {
|
||||
var testData = {
|
||||
myProp1: 'abc',
|
||||
myProp2: 276,
|
||||
@ -59,7 +59,7 @@ describe('Core helper tests', function() {
|
||||
}).not.toThrow();
|
||||
});
|
||||
|
||||
it('Should clone an object', function() {
|
||||
it('should clone an object', function() {
|
||||
var testData = {
|
||||
myProp1: 'abc',
|
||||
myProp2: ['a', 'b'],
|
||||
@ -98,7 +98,7 @@ describe('Core helper tests', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Should merge a normal config without scales', function() {
|
||||
it('should merge a normal config without scales', function() {
|
||||
var baseConfig = {
|
||||
valueProp: 5,
|
||||
arrayProp: [1, 2, 3, 4, 5, 6],
|
||||
@ -161,7 +161,7 @@ describe('Core helper tests', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Should merge scale configs', function() {
|
||||
it('should merge scale configs', function() {
|
||||
var baseConfig = {
|
||||
scales: {
|
||||
prop1: {
|
||||
@ -303,7 +303,7 @@ describe('Core helper tests', function() {
|
||||
expect(helpers.findPreviousWhere(data, callback, 0)).toBe(undefined);
|
||||
});
|
||||
|
||||
it('Should get the correct sign', function() {
|
||||
it('should get the correct sign', function() {
|
||||
expect(helpers.sign(0)).toBe(0);
|
||||
expect(helpers.sign(10)).toBe(1);
|
||||
expect(helpers.sign(-5)).toBe(-1);
|
||||
@ -322,11 +322,12 @@ describe('Core helper tests', function() {
|
||||
expect(helpers.almostEquals(1e30, 1e30 + Number.EPSILON, 2 * Number.EPSILON)).toBe(true);
|
||||
});
|
||||
|
||||
it('Should generate ids', function() {
|
||||
expect(helpers.uid()).toBe('chart-0');
|
||||
expect(helpers.uid()).toBe('chart-1');
|
||||
expect(helpers.uid()).toBe('chart-2');
|
||||
expect(helpers.uid()).toBe('chart-3');
|
||||
it('should generate integer ids', function() {
|
||||
var uid = helpers.uid();
|
||||
expect(uid).toEqual(jasmine.any(Number));
|
||||
expect(helpers.uid()).toBe(uid + 1);
|
||||
expect(helpers.uid()).toBe(uid + 2);
|
||||
expect(helpers.uid()).toBe(uid + 3);
|
||||
});
|
||||
|
||||
it('should detect a number', function() {
|
||||
|
||||
@ -1,360 +1,244 @@
|
||||
// Tests of the scale service
|
||||
describe('Test the layout service', function() {
|
||||
beforeEach(function() {
|
||||
window.addDefaultMatchers(jasmine);
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
window.releaseAllCharts();
|
||||
});
|
||||
|
||||
it('should fit a simple chart with 2 scales', function() {
|
||||
var chartInstance = {
|
||||
boxes: [],
|
||||
};
|
||||
|
||||
var xScaleID = 'xScale';
|
||||
var yScaleID = 'yScale';
|
||||
var mockData = {
|
||||
datasets: [{
|
||||
yAxisID: yScaleID,
|
||||
data: [10, 5, 0, 25, 78, -10]
|
||||
}],
|
||||
labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5']
|
||||
};
|
||||
var mockContext = window.createMockContext();
|
||||
|
||||
var xScaleConfig = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('category'));
|
||||
var XConstructor = Chart.scaleService.getScaleConstructor('category');
|
||||
var xScale = new XConstructor({
|
||||
ctx: mockContext,
|
||||
options: xScaleConfig,
|
||||
chart: {
|
||||
data: mockData
|
||||
var chart = window.acquireChart({
|
||||
type: 'bar',
|
||||
data: {
|
||||
datasets: [
|
||||
{ data: [10, 5, 0, 25, 78, -10] }
|
||||
],
|
||||
labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5', 'tick6']
|
||||
},
|
||||
id: xScaleID
|
||||
options: {
|
||||
scales: {
|
||||
xAxes: [{
|
||||
id: 'xScale',
|
||||
type: 'category'
|
||||
}],
|
||||
yAxes: [{
|
||||
id: 'yScale',
|
||||
type: 'linear'
|
||||
}]
|
||||
}
|
||||
}
|
||||
}, {
|
||||
height: '150px',
|
||||
width: '250px'
|
||||
});
|
||||
|
||||
var yScaleConfig = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('linear'));
|
||||
var YConstructor = Chart.scaleService.getScaleConstructor('linear');
|
||||
var yScale = new YConstructor({
|
||||
ctx: mockContext,
|
||||
options: yScaleConfig,
|
||||
chart: {
|
||||
data: mockData
|
||||
},
|
||||
id: yScaleID
|
||||
});
|
||||
|
||||
chartInstance.boxes.push(xScale);
|
||||
chartInstance.boxes.push(yScale);
|
||||
|
||||
var canvasWidth = 250;
|
||||
var canvasHeight = 150;
|
||||
Chart.layoutService.update(chartInstance, canvasWidth, canvasHeight);
|
||||
|
||||
expect(chartInstance.chartArea).toEqual({
|
||||
left: 50,
|
||||
right: 250,
|
||||
top: 0,
|
||||
bottom: 83.6977778440511,
|
||||
});
|
||||
expect(chart.chartArea.bottom).toBeCloseToPixel(112);
|
||||
expect(chart.chartArea.left).toBeCloseToPixel(41);
|
||||
expect(chart.chartArea.right).toBeCloseToPixel(250);
|
||||
expect(chart.chartArea.top).toBeCloseToPixel(32);
|
||||
|
||||
// Is xScale at the right spot
|
||||
expect(xScale.left).toBe(50);
|
||||
expect(xScale.right).toBe(250);
|
||||
expect(xScale.top).toBe(83.6977778440511);
|
||||
expect(xScale.bottom).toBe(150);
|
||||
expect(xScale.labelRotation).toBe(50);
|
||||
expect(chart.scales.xScale.bottom).toBeCloseToPixel(150);
|
||||
expect(chart.scales.xScale.left).toBeCloseToPixel(41);
|
||||
expect(chart.scales.xScale.right).toBeCloseToPixel(250);
|
||||
expect(chart.scales.xScale.top).toBeCloseToPixel(112);
|
||||
expect(chart.scales.xScale.labelRotation).toBeCloseTo(25);
|
||||
|
||||
// Is yScale at the right spot
|
||||
expect(yScale.left).toBe(0);
|
||||
expect(yScale.right).toBe(50);
|
||||
expect(yScale.top).toBe(0);
|
||||
expect(yScale.bottom).toBe(83.6977778440511);
|
||||
expect(chart.scales.yScale.bottom).toBeCloseToPixel(112);
|
||||
expect(chart.scales.yScale.left).toBeCloseToPixel(0);
|
||||
expect(chart.scales.yScale.right).toBeCloseToPixel(41);
|
||||
expect(chart.scales.yScale.top).toBeCloseToPixel(32);
|
||||
expect(chart.scales.yScale.labelRotation).toBeCloseTo(0);
|
||||
});
|
||||
|
||||
it('should fit scales that are in the top and right positions', function() {
|
||||
var chartInstance = {
|
||||
boxes: [],
|
||||
};
|
||||
|
||||
var xScaleID = 'xScale';
|
||||
var yScaleID = 'yScale';
|
||||
var mockData = {
|
||||
datasets: [{
|
||||
yAxisID: yScaleID,
|
||||
data: [10, 5, 0, 25, 78, -10]
|
||||
}],
|
||||
labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5']
|
||||
};
|
||||
var mockContext = window.createMockContext();
|
||||
|
||||
var xScaleConfig = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('category'));
|
||||
xScaleConfig.position = 'top';
|
||||
var XConstructor = Chart.scaleService.getScaleConstructor('category');
|
||||
var xScale = new XConstructor({
|
||||
ctx: mockContext,
|
||||
options: xScaleConfig,
|
||||
chart: {
|
||||
data: mockData
|
||||
var chart = window.acquireChart({
|
||||
type: 'bar',
|
||||
data: {
|
||||
datasets: [
|
||||
{ data: [10, 5, 0, 25, 78, -10] }
|
||||
],
|
||||
labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5', 'tick6']
|
||||
},
|
||||
id: xScaleID
|
||||
options: {
|
||||
scales: {
|
||||
xAxes: [{
|
||||
id: 'xScale',
|
||||
type: 'category',
|
||||
position: 'top'
|
||||
}],
|
||||
yAxes: [{
|
||||
id: 'yScale',
|
||||
type: 'linear',
|
||||
position: 'right'
|
||||
}]
|
||||
}
|
||||
}
|
||||
}, {
|
||||
height: '150px',
|
||||
width: '250px'
|
||||
});
|
||||
|
||||
var yScaleConfig = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('linear'));
|
||||
yScaleConfig.position = 'right';
|
||||
var YConstructor = Chart.scaleService.getScaleConstructor('linear');
|
||||
var yScale = new YConstructor({
|
||||
ctx: mockContext,
|
||||
options: yScaleConfig,
|
||||
chart: {
|
||||
data: mockData
|
||||
},
|
||||
id: yScaleID
|
||||
});
|
||||
|
||||
chartInstance.boxes.push(xScale);
|
||||
chartInstance.boxes.push(yScale);
|
||||
|
||||
var canvasWidth = 250;
|
||||
var canvasHeight = 150;
|
||||
Chart.layoutService.update(chartInstance, canvasWidth, canvasHeight);
|
||||
|
||||
expect(chartInstance.chartArea).toEqual({
|
||||
left: 0,
|
||||
right: 200,
|
||||
top: 66.3022221559489,
|
||||
bottom: 150,
|
||||
});
|
||||
expect(chart.chartArea.bottom).toBeCloseToPixel(150);
|
||||
expect(chart.chartArea.left).toBeCloseToPixel(0);
|
||||
expect(chart.chartArea.right).toBeCloseToPixel(209);
|
||||
expect(chart.chartArea.top).toBeCloseToPixel(71);
|
||||
|
||||
// Is xScale at the right spot
|
||||
expect(xScale.left).toBe(0);
|
||||
expect(xScale.right).toBe(200);
|
||||
expect(xScale.top).toBe(0);
|
||||
expect(xScale.bottom).toBe(66.3022221559489);
|
||||
expect(xScale.labelRotation).toBe(50);
|
||||
expect(chart.scales.xScale.bottom).toBeCloseToPixel(71);
|
||||
expect(chart.scales.xScale.left).toBeCloseToPixel(0);
|
||||
expect(chart.scales.xScale.right).toBeCloseToPixel(209);
|
||||
expect(chart.scales.xScale.top).toBeCloseToPixel(32);
|
||||
expect(chart.scales.xScale.labelRotation).toBeCloseTo(25);
|
||||
|
||||
// Is yScale at the right spot
|
||||
expect(yScale.left).toBe(200);
|
||||
expect(yScale.right).toBe(250);
|
||||
expect(yScale.top).toBe(66.3022221559489);
|
||||
expect(yScale.bottom).toBe(150);
|
||||
expect(chart.scales.yScale.bottom).toBeCloseToPixel(150);
|
||||
expect(chart.scales.yScale.left).toBeCloseToPixel(209);
|
||||
expect(chart.scales.yScale.right).toBeCloseToPixel(250);
|
||||
expect(chart.scales.yScale.top).toBeCloseToPixel(71);
|
||||
expect(chart.scales.yScale.labelRotation).toBeCloseTo(0);
|
||||
});
|
||||
|
||||
it('should fit scales that overlap the chart area', function() {
|
||||
var chart = window.acquireChart({
|
||||
type: 'radar',
|
||||
data: {
|
||||
datasets: [{
|
||||
data: [10, 5, 0, 25, 78, -10]
|
||||
}, {
|
||||
data: [-19, -20, 0, -99, -50, 0]
|
||||
}],
|
||||
labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5', 'tick6']
|
||||
}
|
||||
});
|
||||
|
||||
expect(chart.chartArea.bottom).toBeCloseToPixel(512);
|
||||
expect(chart.chartArea.left).toBeCloseToPixel(0);
|
||||
expect(chart.chartArea.right).toBeCloseToPixel(512);
|
||||
expect(chart.chartArea.top).toBeCloseToPixel(32);
|
||||
|
||||
expect(chart.scale.bottom).toBeCloseToPixel(512);
|
||||
expect(chart.scale.left).toBeCloseToPixel(0);
|
||||
expect(chart.scale.right).toBeCloseToPixel(512);
|
||||
expect(chart.scale.top).toBeCloseToPixel(32);
|
||||
expect(chart.scale.width).toBeCloseToPixel(512);
|
||||
expect(chart.scale.height).toBeCloseToPixel(480)
|
||||
});
|
||||
|
||||
it('should fit multiple axes in the same position', function() {
|
||||
var chartInstance = {
|
||||
boxes: [],
|
||||
};
|
||||
|
||||
var xScaleID = 'xScale';
|
||||
var yScaleID1 = 'yScale1';
|
||||
var yScaleID2 = 'yScale2';
|
||||
var mockData = {
|
||||
datasets: [{
|
||||
yAxisID: yScaleID1,
|
||||
data: [10, 5, 0, 25, 78, -10]
|
||||
}, {
|
||||
yAxisID: yScaleID2,
|
||||
data: [-19, -20, 0, -99, -50, 0]
|
||||
}],
|
||||
labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5']
|
||||
};
|
||||
var mockContext = window.createMockContext();
|
||||
|
||||
var xScaleConfig = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('category'));
|
||||
var XConstructor = Chart.scaleService.getScaleConstructor('category');
|
||||
var xScale = new XConstructor({
|
||||
ctx: mockContext,
|
||||
options: xScaleConfig,
|
||||
chart: {
|
||||
data: mockData
|
||||
var chart = window.acquireChart({
|
||||
type: 'bar',
|
||||
data: {
|
||||
datasets: [{
|
||||
yAxisID: 'yScale1',
|
||||
data: [10, 5, 0, 25, 78, -10]
|
||||
}, {
|
||||
yAxisID: 'yScale2',
|
||||
data: [-19, -20, 0, -99, -50, 0]
|
||||
}],
|
||||
labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5', 'tick6']
|
||||
},
|
||||
id: xScaleID
|
||||
options: {
|
||||
scales: {
|
||||
xAxes: [{
|
||||
id: 'xScale',
|
||||
type: 'category'
|
||||
}],
|
||||
yAxes: [{
|
||||
id: 'yScale1',
|
||||
type: 'linear'
|
||||
}, {
|
||||
id: 'yScale2',
|
||||
type: 'linear'
|
||||
}]
|
||||
}
|
||||
}
|
||||
}, {
|
||||
height: '150px',
|
||||
width: '250px'
|
||||
});
|
||||
|
||||
var yScaleConfig = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('linear'));
|
||||
var YConstructor = Chart.scaleService.getScaleConstructor('linear');
|
||||
var yScale1 = new YConstructor({
|
||||
ctx: mockContext,
|
||||
options: yScaleConfig,
|
||||
chart: {
|
||||
data: mockData
|
||||
},
|
||||
id: yScaleID1
|
||||
});
|
||||
var yScale2 = new YConstructor({
|
||||
ctx: mockContext,
|
||||
options: yScaleConfig,
|
||||
chart: {
|
||||
data: mockData
|
||||
},
|
||||
id: yScaleID2
|
||||
});
|
||||
|
||||
chartInstance.boxes.push(xScale);
|
||||
chartInstance.boxes.push(yScale1);
|
||||
chartInstance.boxes.push(yScale2);
|
||||
|
||||
var canvasWidth = 250;
|
||||
var canvasHeight = 150;
|
||||
Chart.layoutService.update(chartInstance, canvasWidth, canvasHeight);
|
||||
|
||||
expect(chartInstance.chartArea).toEqual({
|
||||
left: 110,
|
||||
right: 250,
|
||||
top: 0,
|
||||
bottom: 83.6977778440511,
|
||||
});
|
||||
expect(chart.chartArea.bottom).toBeCloseToPixel(102);
|
||||
expect(chart.chartArea.left).toBeCloseToPixel(86);
|
||||
expect(chart.chartArea.right).toBeCloseToPixel(250);
|
||||
expect(chart.chartArea.top).toBeCloseToPixel(32);
|
||||
|
||||
// Is xScale at the right spot
|
||||
expect(xScale.left).toBe(110);
|
||||
expect(xScale.right).toBe(250);
|
||||
expect(xScale.top).toBe(83.6977778440511);
|
||||
expect(xScale.bottom).toBe(150);
|
||||
expect(chart.scales.xScale.bottom).toBeCloseToPixel(150);
|
||||
expect(chart.scales.xScale.left).toBeCloseToPixel(86);
|
||||
expect(chart.scales.xScale.right).toBeCloseToPixel(250);
|
||||
expect(chart.scales.xScale.top).toBeCloseToPixel(103);
|
||||
expect(chart.scales.xScale.labelRotation).toBeCloseTo(50);
|
||||
|
||||
// Are yScales at the right spot
|
||||
expect(yScale1.left).toBe(0);
|
||||
expect(yScale1.right).toBe(50);
|
||||
expect(yScale1.top).toBe(0);
|
||||
expect(yScale1.bottom).toBe(83.6977778440511);
|
||||
expect(chart.scales.yScale1.bottom).toBeCloseToPixel(102);
|
||||
expect(chart.scales.yScale1.left).toBeCloseToPixel(0);
|
||||
expect(chart.scales.yScale1.right).toBeCloseToPixel(41);
|
||||
expect(chart.scales.yScale1.top).toBeCloseToPixel(32);
|
||||
expect(chart.scales.yScale1.labelRotation).toBeCloseTo(0);
|
||||
|
||||
expect(yScale2.left).toBe(50);
|
||||
expect(yScale2.right).toBe(110);
|
||||
expect(yScale2.top).toBe(0);
|
||||
expect(yScale2.bottom).toBe(83.6977778440511);
|
||||
});
|
||||
|
||||
// This is an oddball case. What happens is, when the scales are fit the first time they must fit within the assigned size. In this case,
|
||||
// the labels on the xScale need to rotate to fit. However, when the scales are fit again after the width of the left axis is determined,
|
||||
// the labels do not need to rotate. Previously, the chart was too small because the chartArea did not expand to take up the space freed up
|
||||
// due to the lack of label rotation
|
||||
it('should fit scales that overlap the chart area', function() {
|
||||
var chartInstance = {
|
||||
boxes: [],
|
||||
};
|
||||
|
||||
var scaleID = 'scaleID';
|
||||
var mockData = {
|
||||
datasets: [{
|
||||
yAxisID: scaleID,
|
||||
data: [10, 5, 0, 25, 78, -10]
|
||||
}, {
|
||||
yAxisID: scaleID,
|
||||
data: [-19, -20, 0, -99, -50, 0]
|
||||
}],
|
||||
labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5']
|
||||
};
|
||||
var mockContext = window.createMockContext();
|
||||
|
||||
var scaleConfig = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('radialLinear'));
|
||||
var ScaleConstructor = Chart.scaleService.getScaleConstructor('radialLinear');
|
||||
var scale = new ScaleConstructor({
|
||||
ctx: mockContext,
|
||||
options: scaleConfig,
|
||||
chart: {
|
||||
data: mockData
|
||||
},
|
||||
id: scaleID
|
||||
});
|
||||
|
||||
chartInstance.boxes.push(scale);
|
||||
|
||||
var canvasWidth = 300;
|
||||
var canvasHeight = 350;
|
||||
Chart.layoutService.update(chartInstance, canvasWidth, canvasHeight);
|
||||
|
||||
expect(chartInstance.chartArea).toEqual({
|
||||
left: 0,
|
||||
right: 300,
|
||||
top: 0,
|
||||
bottom: 350,
|
||||
});
|
||||
|
||||
expect(scale.left).toBe(0);
|
||||
expect(scale.right).toBe(300);
|
||||
expect(scale.top).toBe(0);
|
||||
expect(scale.bottom).toBe(350);
|
||||
expect(scale.width).toBe(300);
|
||||
expect(scale.height).toBe(350)
|
||||
expect(chart.scales.yScale2.bottom).toBeCloseToPixel(102);
|
||||
expect(chart.scales.yScale2.left).toBeCloseToPixel(41);
|
||||
expect(chart.scales.yScale2.right).toBeCloseToPixel(86);
|
||||
expect(chart.scales.yScale2.top).toBeCloseToPixel(32);
|
||||
expect(chart.scales.yScale2.labelRotation).toBeCloseTo(0);
|
||||
});
|
||||
|
||||
it ('should fix a full width box correctly', function() {
|
||||
var chartInstance = {
|
||||
boxes: [],
|
||||
};
|
||||
|
||||
var xScaleID1= 'xScale1';
|
||||
var xScaleID2 = 'xScale2';
|
||||
var yScaleID = 'yScale2';
|
||||
|
||||
var mockData = {
|
||||
datasets: [{
|
||||
xAxisID: xScaleID1,
|
||||
data: [10, 5, 0, 25, 78, -10]
|
||||
}, {
|
||||
xAxisID: xScaleID2,
|
||||
data: [-19, -20, 0, -99, -50, 0]
|
||||
}],
|
||||
labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5']
|
||||
};
|
||||
var mockContext = window.createMockContext();
|
||||
|
||||
var xScaleConfig = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('category'));
|
||||
var XConstructor = Chart.scaleService.getScaleConstructor('category');
|
||||
var xScale1 = new XConstructor({
|
||||
ctx: mockContext,
|
||||
options: xScaleConfig,
|
||||
chart: {
|
||||
data: mockData
|
||||
var chart = window.acquireChart({
|
||||
type: 'bar',
|
||||
data: {
|
||||
datasets: [{
|
||||
xAxisID: 'xScale1',
|
||||
data: [10, 5, 0, 25, 78, -10]
|
||||
}, {
|
||||
xAxisID: 'xScale2',
|
||||
data: [-19, -20, 0, -99, -50, 0]
|
||||
}],
|
||||
labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5', 'tick6']
|
||||
},
|
||||
id: xScaleID1
|
||||
});
|
||||
var xScale2 = new XConstructor({
|
||||
ctx: mockContext,
|
||||
options: Chart.helpers.extend(Chart.helpers.clone(xScaleConfig), {
|
||||
position: 'top',
|
||||
fullWidth: true
|
||||
}),
|
||||
chart: {
|
||||
data: mockData,
|
||||
},
|
||||
id: xScaleID2
|
||||
options: {
|
||||
scales: {
|
||||
xAxes: [{
|
||||
id: 'xScale1',
|
||||
type: 'category'
|
||||
}, {
|
||||
id: 'xScale2',
|
||||
type: 'category',
|
||||
position: 'top',
|
||||
fullWidth: true
|
||||
}],
|
||||
yAxes: [{
|
||||
id: 'yScale',
|
||||
type: 'linear'
|
||||
}]
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var yScaleConfig = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('linear'));
|
||||
var YConstructor = Chart.scaleService.getScaleConstructor('linear');
|
||||
var yScale = new YConstructor({
|
||||
ctx: mockContext,
|
||||
options: yScaleConfig,
|
||||
chart: {
|
||||
data: mockData
|
||||
},
|
||||
id: yScaleID
|
||||
});
|
||||
|
||||
chartInstance.boxes.push(xScale1);
|
||||
chartInstance.boxes.push(xScale2);
|
||||
chartInstance.boxes.push(yScale);
|
||||
|
||||
var canvasWidth = 250;
|
||||
var canvasHeight = 150;
|
||||
Chart.layoutService.update(chartInstance, canvasWidth, canvasHeight);
|
||||
|
||||
expect(chartInstance.chartArea).toEqual({
|
||||
left: 60,
|
||||
right: 250,
|
||||
top: 54.495963211660246,
|
||||
bottom: 83.6977778440511
|
||||
});
|
||||
expect(chart.chartArea.bottom).toBeCloseToPixel(484);
|
||||
expect(chart.chartArea.left).toBeCloseToPixel(45);
|
||||
expect(chart.chartArea.right).toBeCloseToPixel(512);
|
||||
expect(chart.chartArea.top).toBeCloseToPixel(60);
|
||||
|
||||
// Are xScales at the right spot
|
||||
expect(xScale1.left).toBe(60);
|
||||
expect(xScale1.right).toBe(250);
|
||||
expect(xScale1.top).toBeCloseTo(83.69, 1e-3);
|
||||
expect(xScale1.bottom).toBe(150);
|
||||
expect(chart.scales.xScale1.bottom).toBeCloseToPixel(512);
|
||||
expect(chart.scales.xScale1.left).toBeCloseToPixel(45);
|
||||
expect(chart.scales.xScale1.right).toBeCloseToPixel(512);
|
||||
expect(chart.scales.x1.top).toBeCloseToPixel(484);
|
||||
|
||||
expect(xScale2.left).toBe(0);
|
||||
expect(xScale2.right).toBe(250);
|
||||
expect(xScale2.top).toBe(0);
|
||||
expect(xScale2.bottom).toBeCloseTo(54.49, 1e-3);
|
||||
expect(chart.scales.xScale2.bottom).toBeCloseToPixel(28);
|
||||
expect(chart.scales.xScale2.left).toBeCloseToPixel(0);
|
||||
expect(chart.scales.xScale2.right).toBeCloseToPixel(512);
|
||||
expect(chart.scales.xScale2.top).toBeCloseToPixel(0);
|
||||
|
||||
// Is yScale at the right spot
|
||||
expect(yScale.left).toBe(0);
|
||||
expect(yScale.right).toBe(60);
|
||||
expect(yScale.top).toBeCloseTo(54.49, 1e-3);
|
||||
expect(yScale.bottom).toBeCloseTo(83.69, 1e-3);
|
||||
expect(chart.scales.yScale.bottom).toBeCloseToPixel(484);
|
||||
expect(chart.scales.yScale.left).toBeCloseToPixel(0);
|
||||
expect(chart.scales.yScale.right).toBeCloseToPixel(45);
|
||||
expect(chart.scales.yScale.top).toBeCloseToPixel(60);
|
||||
});
|
||||
});
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user