]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Fix helpers, layoutService and logarithmic tests
authorSimon Brunel <simonbrunel@users.noreply.github.com>
Tue, 26 Apr 2016 20:44:53 +0000 (22:44 +0200)
committerSimon Brunel <simonbrunel@users.noreply.github.com>
Tue, 26 Apr 2016 20:44:53 +0000 (22:44 +0200)
test/core.helpers.tests.js
test/core.layoutService.tests.js
test/scale.logarithmic.tests.js

index 9638a373a052aa1a9374cc4d1afa66ed87e1c761..1073928442fa6d7efb118e26efc652431ba63f5a 100644 (file)
@@ -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() {
index 4a0f6cdb9b59aecb5534597cd64aedbded2c0093..f8dccd6384b82d9111cf97fad54a51af0e81c2e6 100644 (file)
 // Tests of the scale service
 describe('Test the layout service', function() {
-       it('should fit a simple chart with 2 scales', function() {
-               var chartInstance = {
-                       boxes: [],
-               };
-
-               var xScaleID = 'xScale';
-               var yScaleID = 'yScale';
-               var mockData = {
-                       datasets: [{
-                               yAxisID: yScaleID,
-                               data: [10, 5, 0, 25, 78, -10]
-                       }],
-                       labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5']
-               };
-               var mockContext = window.createMockContext();
+       beforeEach(function() {
+               window.addDefaultMatchers(jasmine);
+       });
 
-               var xScaleConfig = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('category'));
-               var XConstructor = Chart.scaleService.getScaleConstructor('category');
-               var xScale = new XConstructor({
-                       ctx: mockContext,
-                       options: xScaleConfig,
-                       chart: {
-                               data: mockData
-                       },
-                       id: xScaleID
-               });
+       afterEach(function() {
+               window.releaseAllCharts();
+       });
 
-               var yScaleConfig = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('linear'));
-               var YConstructor = Chart.scaleService.getScaleConstructor('linear');
-               var yScale = new YConstructor({
-                       ctx: mockContext,
-                       options: yScaleConfig,
-                       chart: {
-                               data: mockData
+       it('should fit a simple chart with 2 scales', function() {
+               var chart = window.acquireChart({
+                       type: 'bar',
+                       data: {
+                               datasets: [
+                                       { data: [10, 5, 0, 25, 78, -10] }
+                               ],
+                               labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5', 'tick6']
                        },
-                       id: yScaleID
-               });
-
-               chartInstance.boxes.push(xScale);
-               chartInstance.boxes.push(yScale);
-
-               var canvasWidth = 250;
-               var canvasHeight = 150;
-               Chart.layoutService.update(chartInstance, canvasWidth, canvasHeight);
-
-               expect(chartInstance.chartArea).toEqual({
-                       left: 50,
-                       right: 250,
-                       top: 0,
-                       bottom: 83.6977778440511,
-               });
+                       options: {
+                               scales: {
+                                       xAxes: [{
+                                               id: 'xScale',
+                                               type: 'category'
+                                       }],
+                                       yAxes: [{
+                                               id: 'yScale',
+                                               type: 'linear'
+                                       }]
+                               }
+                       }
+               }, {
+                       height: '150px',
+                       width: '250px'
+               });
+
+               expect(chart.chartArea.bottom).toBeCloseToPixel(112);
+               expect(chart.chartArea.left).toBeCloseToPixel(41);
+               expect(chart.chartArea.right).toBeCloseToPixel(250);
+               expect(chart.chartArea.top).toBeCloseToPixel(32);
 
                // Is xScale at the right spot
-               expect(xScale.left).toBe(50);
-               expect(xScale.right).toBe(250);
-               expect(xScale.top).toBe(83.6977778440511);
-               expect(xScale.bottom).toBe(150);
-               expect(xScale.labelRotation).toBe(50);
+               expect(chart.scales.xScale.bottom).toBeCloseToPixel(150);
+               expect(chart.scales.xScale.left).toBeCloseToPixel(41);
+               expect(chart.scales.xScale.right).toBeCloseToPixel(250);
+               expect(chart.scales.xScale.top).toBeCloseToPixel(112);
+               expect(chart.scales.xScale.labelRotation).toBeCloseTo(25);
 
                // Is yScale at the right spot
-               expect(yScale.left).toBe(0);
-               expect(yScale.right).toBe(50);
-               expect(yScale.top).toBe(0);
-               expect(yScale.bottom).toBe(83.6977778440511);
+               expect(chart.scales.yScale.bottom).toBeCloseToPixel(112);
+               expect(chart.scales.yScale.left).toBeCloseToPixel(0);
+               expect(chart.scales.yScale.right).toBeCloseToPixel(41);
+               expect(chart.scales.yScale.top).toBeCloseToPixel(32);
+               expect(chart.scales.yScale.labelRotation).toBeCloseTo(0);
        });
 
        it('should fit scales that are in the top and right positions', function() {
-               var chartInstance = {
-                       boxes: [],
-               };
-
-               var xScaleID = 'xScale';
-               var yScaleID = 'yScale';
-               var mockData = {
-                       datasets: [{
-                               yAxisID: yScaleID,
-                               data: [10, 5, 0, 25, 78, -10]
-                       }],
-                       labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5']
-               };
-               var mockContext = window.createMockContext();
-
-               var xScaleConfig = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('category'));
-               xScaleConfig.position = 'top';
-               var XConstructor = Chart.scaleService.getScaleConstructor('category');
-               var xScale = new XConstructor({
-                       ctx: mockContext,
-                       options: xScaleConfig,
-                       chart: {
-                               data: mockData
-                       },
-                       id: xScaleID
-               });
-
-               var yScaleConfig = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('linear'));
-               yScaleConfig.position = 'right';
-               var YConstructor = Chart.scaleService.getScaleConstructor('linear');
-               var yScale = new YConstructor({
-                       ctx: mockContext,
-                       options: yScaleConfig,
-                       chart: {
-                               data: mockData
+               var chart = window.acquireChart({
+                       type: 'bar',
+                       data: {
+                               datasets: [
+                                       { data: [10, 5, 0, 25, 78, -10] }
+                               ],
+                               labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5', 'tick6']
                        },
-                       id: yScaleID
-               });
-
-               chartInstance.boxes.push(xScale);
-               chartInstance.boxes.push(yScale);
-
-               var canvasWidth = 250;
-               var canvasHeight = 150;
-               Chart.layoutService.update(chartInstance, canvasWidth, canvasHeight);
-
-               expect(chartInstance.chartArea).toEqual({
-                       left: 0,
-                       right: 200,
-                       top: 66.3022221559489,
-                       bottom: 150,
-               });
+                       options: {
+                               scales: {
+                                       xAxes: [{
+                                               id: 'xScale',
+                                               type: 'category',
+                                               position: 'top'
+                                       }],
+                                       yAxes: [{
+                                               id: 'yScale',
+                                               type: 'linear',
+                                               position: 'right'
+                                       }]
+                               }
+                       }
+               }, {
+                       height: '150px',
+                       width: '250px'
+               });
+
+               expect(chart.chartArea.bottom).toBeCloseToPixel(150);
+               expect(chart.chartArea.left).toBeCloseToPixel(0);
+               expect(chart.chartArea.right).toBeCloseToPixel(209);
+               expect(chart.chartArea.top).toBeCloseToPixel(71);
 
                // Is xScale at the right spot
-               expect(xScale.left).toBe(0);
-               expect(xScale.right).toBe(200);
-               expect(xScale.top).toBe(0);
-               expect(xScale.bottom).toBe(66.3022221559489);
-               expect(xScale.labelRotation).toBe(50);
+               expect(chart.scales.xScale.bottom).toBeCloseToPixel(71);
+               expect(chart.scales.xScale.left).toBeCloseToPixel(0);
+               expect(chart.scales.xScale.right).toBeCloseToPixel(209);
+               expect(chart.scales.xScale.top).toBeCloseToPixel(32);
+               expect(chart.scales.xScale.labelRotation).toBeCloseTo(25);
 
                // Is yScale at the right spot
-               expect(yScale.left).toBe(200);
-               expect(yScale.right).toBe(250);
-               expect(yScale.top).toBe(66.3022221559489);
-               expect(yScale.bottom).toBe(150);
+               expect(chart.scales.yScale.bottom).toBeCloseToPixel(150);
+               expect(chart.scales.yScale.left).toBeCloseToPixel(209);
+               expect(chart.scales.yScale.right).toBeCloseToPixel(250);
+               expect(chart.scales.yScale.top).toBeCloseToPixel(71);
+               expect(chart.scales.yScale.labelRotation).toBeCloseTo(0);
        });
 
-       it('should fit multiple axes in the same position', function() {
-               var chartInstance = {
-                       boxes: [],
-               };
-
-               var xScaleID = 'xScale';
-               var yScaleID1 = 'yScale1';
-               var yScaleID2 = 'yScale2';
-               var mockData = {
-                       datasets: [{
-                               yAxisID: yScaleID1,
-                               data: [10, 5, 0, 25, 78, -10]
-                       }, {
-                               yAxisID: yScaleID2,
-                               data: [-19, -20, 0, -99, -50, 0]
-                       }],
-                       labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5']
-               };
-               var mockContext = window.createMockContext();
+       it('should fit scales that overlap the chart area', function() {
+               var chart = window.acquireChart({
+                       type: 'radar',
+                       data: {
+                               datasets: [{
+                                       data: [10, 5, 0, 25, 78, -10]
+                               }, {
+                                       data: [-19, -20, 0, -99, -50, 0]
+                               }],
+                               labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5', 'tick6']
+                       }
+               });
+
+               expect(chart.chartArea.bottom).toBeCloseToPixel(512);
+               expect(chart.chartArea.left).toBeCloseToPixel(0);
+               expect(chart.chartArea.right).toBeCloseToPixel(512);
+               expect(chart.chartArea.top).toBeCloseToPixel(32);
+
+               expect(chart.scale.bottom).toBeCloseToPixel(512);
+               expect(chart.scale.left).toBeCloseToPixel(0);
+               expect(chart.scale.right).toBeCloseToPixel(512);
+               expect(chart.scale.top).toBeCloseToPixel(32);
+               expect(chart.scale.width).toBeCloseToPixel(512);
+               expect(chart.scale.height).toBeCloseToPixel(480)
+       });
 
-               var xScaleConfig = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('category'));
-               var XConstructor = Chart.scaleService.getScaleConstructor('category');
-               var xScale = new XConstructor({
-                       ctx: mockContext,
-                       options: xScaleConfig,
-                       chart: {
-                               data: mockData
+       it('should fit multiple axes in the same position', function() {
+               var chart = window.acquireChart({
+                       type: 'bar',
+                       data: {
+                               datasets: [{
+                                       yAxisID: 'yScale1',
+                                       data: [10, 5, 0, 25, 78, -10]
+                               }, {
+                                       yAxisID: 'yScale2',
+                                       data: [-19, -20, 0, -99, -50, 0]
+                               }],
+                               labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5', 'tick6']
                        },
-                       id: xScaleID
-               });
-
-               var yScaleConfig = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('linear'));
-               var YConstructor = Chart.scaleService.getScaleConstructor('linear');
-               var yScale1 = new YConstructor({
-                       ctx: mockContext,
-                       options: yScaleConfig,
-                       chart: {
-                               data: mockData
-                       },
-                       id: yScaleID1
-               });
-               var yScale2 = new YConstructor({
-                       ctx: mockContext,
-                       options: yScaleConfig,
-                       chart: {
-                               data: mockData
-                       },
-                       id: yScaleID2
-               });
-
-               chartInstance.boxes.push(xScale);
-               chartInstance.boxes.push(yScale1);
-               chartInstance.boxes.push(yScale2);
-
-               var canvasWidth = 250;
-               var canvasHeight = 150;
-               Chart.layoutService.update(chartInstance, canvasWidth, canvasHeight);
-
-               expect(chartInstance.chartArea).toEqual({
-                       left: 110,
-                       right: 250,
-                       top: 0,
-                       bottom: 83.6977778440511,
-               });
+                       options: {
+                               scales: {
+                                       xAxes: [{
+                                               id: 'xScale',
+                                               type: 'category'
+                                       }],
+                                       yAxes: [{
+                                               id: 'yScale1',
+                                               type: 'linear'
+                                       }, {
+                                               id: 'yScale2',
+                                               type: 'linear'
+                                       }]
+                               }
+                       }
+               }, {
+                       height: '150px',
+                       width: '250px'
+               });
+
+               expect(chart.chartArea.bottom).toBeCloseToPixel(102);
+               expect(chart.chartArea.left).toBeCloseToPixel(86);
+               expect(chart.chartArea.right).toBeCloseToPixel(250);
+               expect(chart.chartArea.top).toBeCloseToPixel(32);
 
                // Is xScale at the right spot
-               expect(xScale.left).toBe(110);
-               expect(xScale.right).toBe(250);
-               expect(xScale.top).toBe(83.6977778440511);
-               expect(xScale.bottom).toBe(150);
+               expect(chart.scales.xScale.bottom).toBeCloseToPixel(150);
+               expect(chart.scales.xScale.left).toBeCloseToPixel(86);
+               expect(chart.scales.xScale.right).toBeCloseToPixel(250);
+               expect(chart.scales.xScale.top).toBeCloseToPixel(103);
+               expect(chart.scales.xScale.labelRotation).toBeCloseTo(50);
 
                // Are yScales at the right spot
-               expect(yScale1.left).toBe(0);
-               expect(yScale1.right).toBe(50);
-               expect(yScale1.top).toBe(0);
-               expect(yScale1.bottom).toBe(83.6977778440511);
-
-               expect(yScale2.left).toBe(50);
-               expect(yScale2.right).toBe(110);
-               expect(yScale2.top).toBe(0);
-               expect(yScale2.bottom).toBe(83.6977778440511);
-       });
-
-       // This is an oddball case. What happens is, when the scales are fit the first time they must fit within the assigned size. In this case,
-       // the labels on the xScale need to rotate to fit. However, when the scales are fit again after the width of the left axis is determined,
-       // the labels do not need to rotate. Previously, the chart was too small because the chartArea did not expand to take up the space freed up
-       // due to the lack of label rotation
-       it('should fit scales that overlap the chart area', function() {
-               var chartInstance = {
-                       boxes: [],
-               };
-
-               var scaleID = 'scaleID';
-               var mockData = {
-                       datasets: [{
-                               yAxisID: scaleID,
-                               data: [10, 5, 0, 25, 78, -10]
-                       }, {
-                               yAxisID: scaleID,
-                               data: [-19, -20, 0, -99, -50, 0]
-                       }],
-                       labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5']
-               };
-               var mockContext = window.createMockContext();
-
-               var scaleConfig = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('radialLinear'));
-               var ScaleConstructor = Chart.scaleService.getScaleConstructor('radialLinear');
-               var scale = new ScaleConstructor({
-                       ctx: mockContext,
-                       options: scaleConfig,
-                       chart: {
-                               data: mockData
-                       },
-                       id: scaleID
-               });
-
-               chartInstance.boxes.push(scale);
-
-               var canvasWidth = 300;
-               var canvasHeight = 350;
-               Chart.layoutService.update(chartInstance, canvasWidth, canvasHeight);
-
-               expect(chartInstance.chartArea).toEqual({
-                       left: 0,
-                       right: 300,
-                       top: 0,
-                       bottom: 350,
-               });
-
-               expect(scale.left).toBe(0);
-               expect(scale.right).toBe(300);
-               expect(scale.top).toBe(0);
-               expect(scale.bottom).toBe(350);
-               expect(scale.width).toBe(300);
-               expect(scale.height).toBe(350)
+               expect(chart.scales.yScale1.bottom).toBeCloseToPixel(102);
+               expect(chart.scales.yScale1.left).toBeCloseToPixel(0);
+               expect(chart.scales.yScale1.right).toBeCloseToPixel(41);
+               expect(chart.scales.yScale1.top).toBeCloseToPixel(32);
+               expect(chart.scales.yScale1.labelRotation).toBeCloseTo(0);
+
+               expect(chart.scales.yScale2.bottom).toBeCloseToPixel(102);
+               expect(chart.scales.yScale2.left).toBeCloseToPixel(41);
+               expect(chart.scales.yScale2.right).toBeCloseToPixel(86);
+               expect(chart.scales.yScale2.top).toBeCloseToPixel(32);
+               expect(chart.scales.yScale2.labelRotation).toBeCloseTo(0);
        });
 
        it ('should fix a full width box correctly', function() {
-               var chartInstance = {
-                       boxes: [],
-               };
-
-               var xScaleID1= 'xScale1';
-               var xScaleID2 = 'xScale2';
-               var yScaleID = 'yScale2';
-
-               var mockData = {
-                       datasets: [{
-                               xAxisID: xScaleID1,
-                               data: [10, 5, 0, 25, 78, -10]
-                       }, {
-                               xAxisID: xScaleID2,
-                               data: [-19, -20, 0, -99, -50, 0]
-                       }],
-                       labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5']
-               };
-               var mockContext = window.createMockContext();
-
-               var xScaleConfig = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('category'));
-               var XConstructor = Chart.scaleService.getScaleConstructor('category');
-               var xScale1 = new XConstructor({
-                       ctx: mockContext,
-                       options: xScaleConfig,
-                       chart: {
-                               data: mockData
-                       },
-                       id: xScaleID1
-               });
-               var xScale2 = new XConstructor({
-                       ctx: mockContext,
-                       options: Chart.helpers.extend(Chart.helpers.clone(xScaleConfig), {
-                               position: 'top',
-                               fullWidth: true
-                       }),
-                       chart: {
-                               data: mockData,
+               var chart = window.acquireChart({
+                       type: 'bar',
+                       data: {
+                               datasets: [{
+                                       xAxisID: 'xScale1',
+                                       data: [10, 5, 0, 25, 78, -10]
+                               }, {
+                                       xAxisID: 'xScale2',
+                                       data: [-19, -20, 0, -99, -50, 0]
+                               }],
+                               labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5', 'tick6']
                        },
-                       id: xScaleID2
-               });
-
-               var yScaleConfig = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('linear'));
-               var YConstructor = Chart.scaleService.getScaleConstructor('linear');
-               var yScale = new YConstructor({
-                       ctx: mockContext,
-                       options: yScaleConfig,
-                       chart: {
-                               data: mockData
-                       },
-                       id: yScaleID
-               });
-
-               chartInstance.boxes.push(xScale1);
-               chartInstance.boxes.push(xScale2);
-               chartInstance.boxes.push(yScale);
-
-               var canvasWidth = 250;
-               var canvasHeight = 150;
-               Chart.layoutService.update(chartInstance, canvasWidth, canvasHeight);
-
-               expect(chartInstance.chartArea).toEqual({
-                       left: 60,
-                       right: 250,
-                       top: 54.495963211660246,
-                       bottom: 83.6977778440511
-               });
+                       options: {
+                               scales: {
+                                       xAxes: [{
+                                               id: 'xScale1',
+                                               type: 'category'
+                                       }, {
+                                               id: 'xScale2',
+                                               type: 'category',
+                                               position: 'top',
+                                               fullWidth: true
+                                       }],
+                                       yAxes: [{
+                                               id: 'yScale',
+                                               type: 'linear'
+                                       }]
+                               }
+                       }
+               });
+
+               expect(chart.chartArea.bottom).toBeCloseToPixel(484);
+               expect(chart.chartArea.left).toBeCloseToPixel(45);
+               expect(chart.chartArea.right).toBeCloseToPixel(512);
+               expect(chart.chartArea.top).toBeCloseToPixel(60);
 
                // Are xScales at the right spot
-               expect(xScale1.left).toBe(60);
-               expect(xScale1.right).toBe(250);
-               expect(xScale1.top).toBeCloseTo(83.69, 1e-3);
-               expect(xScale1.bottom).toBe(150);
+               expect(chart.scales.xScale1.bottom).toBeCloseToPixel(512);
+               expect(chart.scales.xScale1.left).toBeCloseToPixel(45);
+               expect(chart.scales.xScale1.right).toBeCloseToPixel(512);
+               expect(chart.scales.x1.top).toBeCloseToPixel(484);
 
-               expect(xScale2.left).toBe(0);
-               expect(xScale2.right).toBe(250);
-               expect(xScale2.top).toBe(0);
-               expect(xScale2.bottom).toBeCloseTo(54.49, 1e-3);
+               expect(chart.scales.xScale2.bottom).toBeCloseToPixel(28);
+               expect(chart.scales.xScale2.left).toBeCloseToPixel(0);
+               expect(chart.scales.xScale2.right).toBeCloseToPixel(512);
+               expect(chart.scales.xScale2.top).toBeCloseToPixel(0);
 
                // Is yScale at the right spot
-               expect(yScale.left).toBe(0);
-               expect(yScale.right).toBe(60);
-               expect(yScale.top).toBeCloseTo(54.49, 1e-3);
-               expect(yScale.bottom).toBeCloseTo(83.69, 1e-3);
+               expect(chart.scales.yScale.bottom).toBeCloseToPixel(484);
+               expect(chart.scales.yScale.left).toBeCloseToPixel(0);
+               expect(chart.scales.yScale.right).toBeCloseToPixel(45);
+               expect(chart.scales.yScale.top).toBeCloseToPixel(60);
        });
 });
index a75f174e15decafb191acae8ddc755e844c4c380..f87d411e958922bc253226ab9e9372a9c0c8ad23 100644 (file)
@@ -1,12 +1,20 @@
 describe('Logarithmic Scale tests', function() {
 
-       it('Should register the constructor with the scale service', function() {
+       beforeEach(function() {
+               window.addDefaultMatchers(jasmine);
+       });
+
+       afterEach(function() {
+               window.releaseAllCharts();
+       });
+
+       it('should register the constructor with the scale service', function() {
                var Constructor = Chart.scaleService.getScaleConstructor('logarithmic');
                expect(Constructor).not.toBe(undefined);
                expect(typeof Constructor).toBe('function');
        });
 
-       it('Should have the correct default config', function() {
+       it('should have the correct default config', function() {
                var defaultConfig = Chart.scaleService.getScaleDefaults('logarithmic');
                expect(defaultConfig).toEqual({
                        display: true,
@@ -43,588 +51,512 @@ describe('Logarithmic Scale tests', function() {
                expect(defaultConfig.ticks.callback).toEqual(jasmine.any(Function));
        });
 
-       it('Should correctly determine the max & min data values', function() {
-               var scaleID = 'myScale';
-
-               var mockData = {
-                       datasets: [{
-                               yAxisID: scaleID,
-                               data: [10, 5, 5000, 78, 450]
-                       }, {
-                               yAxisID: 'second scale',
-                               data: [1, 1000, 10, 100],
-                       }, {
-                               yAxisID: scaleID,
-                               data: [150]
-                       }]
-               };
-
-               var mockContext = window.createMockContext();
-               var Constructor = Chart.scaleService.getScaleConstructor('logarithmic');
-               var scale = new Constructor({
-                       ctx: mockContext,
-                       options: Chart.scaleService.getScaleDefaults('logarithmic'), // use default config for scale
-                       chart: {
-                               data: mockData,
+       it('should correctly determine the max & min data values', function() {
+               var chart = window.acquireChart({
+                       type: 'bar',
+                       data: {
+                               datasets: [{
+                                       yAxisID: 'yScale0',
+                                       data: [42, 1000, 64, 100],
+                               }, {
+                                       yAxisID: 'yScale1',
+                                       data: [10, 5, 5000, 78, 450]
+                               }, {
+                                       yAxisID: 'yScale1',
+                                       data: [150]
+                               }],
+                               labels: ['a', 'b', 'c', 'd', 'e']
                        },
-                       id: scaleID
+                       options: {
+                               scales: {
+                                       yAxes: [{
+                                               id: 'yScale0',
+                                               type: 'logarithmic'
+                                       }, {
+                                               id: 'yScale1',
+                                               type: 'logarithmic'
+                                       }]
+                               }
+                       }
                });
 
-               expect(scale).not.toEqual(undefined); // must construct
-               expect(scale.min).toBe(undefined); // not yet set
-               expect(scale.max).toBe(undefined);
+               expect(chart.scales.yScale0).not.toEqual(undefined); // must construct
+               expect(chart.scales.yScale0.min).toBe(10);
+               expect(chart.scales.yScale0.max).toBe(1000);
 
-               scale.update(400, 400);
-               expect(scale.min).toBe(1);
-               expect(scale.max).toBe(5000);
+               expect(chart.scales.yScale1).not.toEqual(undefined); // must construct
+               expect(chart.scales.yScale1.min).toBe(1);
+               expect(chart.scales.yScale1.max).toBe(5000);
        });
 
-       it('Should correctly determine the max & min of string data values', function() {
-               var scaleID = 'myScale';
-
-               var mockData = {
-                       datasets: [{
-                               yAxisID: scaleID,
-                               data: ['10', '5', '5000', '78', '450']
-                       }, {
-                               yAxisID: 'second scale',
-                               data: ['1', '1000', '10', '100'],
-                       }, {
-                               yAxisID: scaleID,
-                               data: ['150']
-                       }]
-               };
-
-               var mockContext = window.createMockContext();
-               var Constructor = Chart.scaleService.getScaleConstructor('logarithmic');
-               var scale = new Constructor({
-                       ctx: mockContext,
-                       options: Chart.scaleService.getScaleDefaults('logarithmic'), // use default config for scale
-                       chart: {
-                               data: mockData,
+       it('should correctly determine the max & min of string data values', function() {
+               var chart = window.acquireChart({
+                       type: 'line',
+                       data: {
+                               datasets: [{
+                                       yAxisID: 'yScale0',
+                                       data: ['42', '1000', '64', '100'],
+                               }, {
+                                       yAxisID: 'yScale1',
+                                       data: ['10', '5', '5000', '78', '450']
+                               }, {
+                                       yAxisID: 'yScale1',
+                                       data: ['150']
+                               }],
+                               labels: ['a', 'b', 'c', 'd', 'e']
                        },
-                       id: scaleID
+                       options: {
+                               scales: {
+                                       yAxes: [{
+                                               id: 'yScale0',
+                                               type: 'logarithmic'
+                                       }, {
+                                               id: 'yScale1',
+                                               type: 'logarithmic'
+                                       }]
+                               }
+                       }
                });
 
-               expect(scale).not.toEqual(undefined); // must construct
-               expect(scale.min).toBe(undefined); // not yet set
-               expect(scale.max).toBe(undefined);
+               expect(chart.scales.yScale0).not.toEqual(undefined); // must construct
+               expect(chart.scales.yScale0.min).toBe(10);
+               expect(chart.scales.yScale0.max).toBe(1000);
 
-               scale.update(400, 400);
-               expect(scale.min).toBe(1);
-               expect(scale.max).toBe(5000);
+               expect(chart.scales.yScale1).not.toEqual(undefined); // must construct
+               expect(chart.scales.yScale1.min).toBe(1);
+               expect(chart.scales.yScale1.max).toBe(5000);
        });
 
-       it('Should correctly determine the max & min data values when there are hidden datasets', function() {
-               var scaleID = 'myScale';
-
-               var mockData = {
-                       datasets: [{
-                               yAxisID: scaleID,
-                               data: [10, 5, 5000, 78, 450]
-                       }, {
-                               yAxisID: 'second scale',
-                               data: [1, 1000, 10, 100],
-                       }, {
-                               yAxisID: scaleID,
-                               data: [50000],
-                               hidden: true
-                       }]
-               };
-
-               var mockContext = window.createMockContext();
-               var Constructor = Chart.scaleService.getScaleConstructor('logarithmic');
-               var scale = new Constructor({
-                       ctx: mockContext,
-                       options: Chart.scaleService.getScaleDefaults('logarithmic'), // use default config for scale
-                       chart: {
-                               data: mockData
+       it('should correctly determine the max & min data values when there are hidden datasets', function() {
+               var chart = window.acquireChart({
+                       type: 'line',
+                       data: {
+                               datasets: [{
+                                       yAxisID: 'yScale1',
+                                       data: [10, 5, 5000, 78, 450]
+                               }, {
+                                       yAxisID: 'yScale0',
+                                       data: [42, 1000, 64, 100],
+                               }, {
+                                       yAxisID: 'yScale1',
+                                       data: [50000],
+                                       hidden: true
+                               }],
+                               labels: ['a', 'b', 'c', 'd', 'e']
                        },
-                       id: scaleID
+                       options: {
+                               scales: {
+                                       yAxes: [{
+                                               id: 'yScale0',
+                                               type: 'logarithmic'
+                                       }, {
+                                               id: 'yScale1',
+                                               type: 'logarithmic'
+                                       }]
+                               }
+                       }
                });
 
-               expect(scale).not.toEqual(undefined); // must construct
-               expect(scale.min).toBe(undefined); // not yet set
-               expect(scale.max).toBe(undefined);
-
-               scale.update(400, 400);
-               expect(scale.min).toBe(1);
-               expect(scale.max).toBe(5000);
+               expect(chart.scales.yScale1).not.toEqual(undefined); // must construct
+               expect(chart.scales.yScale1.min).toBe(1);
+               expect(chart.scales.yScale1.max).toBe(5000);
        });
 
-       it('Should correctly determine the max & min data values when there is NaN data', function() {
-               var scaleID = 'myScale';
-
-               var mockData = {
-                       datasets: [{
-                               yAxisID: scaleID,
-                               data: [undefined, 10, null, 5, 5000, NaN, 78, 450]
-                       }]
-               };
-
-               var mockContext = window.createMockContext();
-               var options = Chart.scaleService.getScaleDefaults('logarithmic');
-               var Constructor = Chart.scaleService.getScaleConstructor('logarithmic');
-               var scale = new Constructor({
-                       ctx: mockContext,
-                       options: options, // use default config for scale
-                       chart: {
-                               data: mockData
+       it('should correctly determine the max & min data values when there is NaN data', function() {
+               var chart = window.acquireChart({
+                       type: 'bar',
+                       data: {
+                               datasets: [{
+                                       data: [undefined, 10, null, 5, 5000, NaN, 78, 450]
+                               }, {
+                                       data: [undefined, 28, null, 1000, 500, NaN, 50, 42]
+                               }],
+                               labels: ['a', 'b', 'c', 'd', 'e', 'f' ,'g']
                        },
-                       id: scaleID
+                       options: {
+                               scales: {
+                                       yAxes: [{
+                                               id: 'yScale',
+                                               type: 'logarithmic'
+                                       }]
+                               }
+                       }
                });
 
-               expect(scale).not.toEqual(undefined); // must construct
-               expect(scale.min).toBe(undefined); // not yet set
-               expect(scale.max).toBe(undefined);
-
-               scale.update(400, 400);
-               expect(scale.min).toBe(1);
-               expect(scale.max).toBe(5000);
+               expect(chart.scales.yScale).not.toEqual(undefined); // must construct
+               expect(chart.scales.yScale.min).toBe(1);
+               expect(chart.scales.yScale.max).toBe(5000);
 
                // Turn on stacked mode since it uses it's own
-               options.stacked = true;
+               chart.options.scales.yAxes[0].stacked = true;
+               chart.update();
 
-               scale.update(400, 400);
-               expect(scale.min).toBe(1);
-               expect(scale.max).toBe(5000);
+               expect(chart.scales.yScale.min).toBe(10);
+               expect(chart.scales.yScale.max).toBe(6000);
        });
 
-
-       it('Should correctly determine the max & min for scatter data', function() {
-               var scaleID = 'myScale';
-
-               var mockData = {
-                       datasets: [{
-                               xAxisID: scaleID, // for the horizontal scale
-                               yAxisID: scaleID,
-                               data: [{
-                                       x: 10,
-                                       y: 100
-                               }, {
-                                       x: 2,
-                                       y: 6
-                               }, {
-                                       x: 65,
-                                       y: 121
-                               }, {
-                                       x: 99,
-                                       y: 7
+       it('should correctly determine the max & min for scatter data', function() {
+               var chart = window.acquireChart({
+                       type: 'line',
+                       data: {
+                               datasets: [{
+                                       data: [
+                                               { x: 10, y: 100 },
+                                               { x:  2, y:   6 },
+                                               { x: 65, y: 121 },
+                                               { x: 99, y:   7 }
+                                       ]
                                }]
-                       }]
-               };
-
-               var mockContext = window.createMockContext();
-               var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('logarithmic'));
-               var Constructor = Chart.scaleService.getScaleConstructor('logarithmic');
-               var verticalScale = new Constructor({
-                       ctx: mockContext,
-                       options: config,
-                       chart: {
-                               data: mockData
                        },
-                       id: scaleID
+                       options: {
+                               scales: {
+                                       xAxes: [{
+                                               id: 'xScale',
+                                               type: 'logarithmic',
+                                               position: 'bottom'
+                                       }],
+                                       yAxes: [{
+                                               id: 'yScale',
+                                               type: 'logarithmic'
+                                       }]
+                               }
+                       }
                });
 
-               verticalScale.update(400, 400);
-               expect(verticalScale.min).toBe(1);
-               expect(verticalScale.max).toBe(200);
-
-               var horizontalConfig = Chart.helpers.clone(config);
-               horizontalConfig.position = 'bottom';
-               var horizontalScale = new Constructor({
-                       ctx: mockContext,
-                       options: horizontalConfig,
-                       chart: {
-                               data: mockData
-                       },
-                       id: scaleID,
-               });
+               expect(chart.scales.xScale.min).toBe(1);
+               expect(chart.scales.xScale.max).toBe(100);
 
-               horizontalScale.update(400, 400);
-               expect(horizontalScale.min).toBe(1);
-               expect(horizontalScale.max).toBe(100);
+               expect(chart.scales.yScale.min).toBe(1);
+               expect(chart.scales.yScale.max).toBe(200);
        });
 
-       it('Should correctly determine the min and max data values when stacked mode is turned on', function() {
-               var scaleID = 'myScale';
-
-               var mockData = {
-                       datasets: [{
-                               yAxisID: scaleID,
-                               data: [10, 5, 1, 5, 78, 100],
-                               type: 'bar'
-                       }, {
-                               yAxisID: 'second scale',
-                               data: [-1000, 1000],
-                       }, {
-                               yAxisID: scaleID,
-                               data: [150, 10, 10, 100, 10, 9],
-                               type: 'bar'
-                       }, {
-                               yAxisID: scaleID,
-                               data: [100, 100, 100, 100, 100, 100],
-                               type: 'line'
-                       }]
-               };
-
-               var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('logarithmic'));
-               config.stacked = true; // enable scale stacked mode
-
-               var mockContext = window.createMockContext();
-               var Constructor = Chart.scaleService.getScaleConstructor('logarithmic');
-               var scale = new Constructor({
-                       ctx: mockContext,
-                       options: config,
-                       chart: {
-                               data: mockData
+       it('should correctly determine the min and max data values when stacked mode is turned on', function() {
+               var chart = window.acquireChart({
+                       type: 'bar',
+                       data: {
+                               datasets: [{
+                                       type: 'bar',
+                                       yAxisID: 'yScale0',
+                                       data: [10, 5, 1, 5, 78, 100]
+                               }, {
+                                       yAxisID: 'yScale1',
+                                       data: [-1000, 1000],
+                               }, {
+                                       type: 'bar',
+                                       yAxisID: 'yScale0',
+                                       data: [150, 10, 10, 100, 10, 9]
+                               }, {
+                                       type: 'line',
+                                       yAxisID: 'yScale0',
+                                       data: [100, 100, 100, 100, 100, 100]
+                               }],
+                               labels: ['a', 'b', 'c', 'd', 'e', 'f']
                        },
-                       id: scaleID
+                       options: {
+                               scales: {
+                                       yAxes: [{
+                                               id: 'yScale0',
+                                               type: 'logarithmic',
+                                               stacked: true
+                                       }, {
+                                               id: 'yScale1',
+                                               type: 'logarithmic'
+                                       }]
+                               }
+                       }
                });
 
-               scale.update(400, 400);
-               expect(scale.min).toBe(10);
-               expect(scale.max).toBe(200);
+               expect(chart.scales.yScale0.min).toBe(10);
+               expect(chart.scales.yScale0.max).toBe(200);
        });
 
-       it('Should correctly determine the min and max data values when stacked mode is turned on ignoring hidden datasets', function() {
-               var scaleID = 'myScale';
-
-               var mockData = {
-                       datasets: [{
-                               yAxisID: scaleID,
-                               data: [10, 5, 1, 5, 78, 100],
-                               type: 'bar'
-                       }, {
-                               yAxisID: 'second scale',
-                               data: [-1000, 1000],
-                               type: 'bar'
-                       }, {
-                               yAxisID: scaleID,
-                               data: [150, 10, 10, 100, 10, 9],
-                               type: 'bar'
-                       }, {
-                               yAxisID: scaleID,
-                               data: [10000, 10000, 10000, 10000, 10000, 10000],
-                               hidden: true,
-                               type: 'bar'
-                       }]
-               };
-
-               var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('logarithmic'));
-               config.stacked = true; // enable scale stacked mode
-
-               var mockContext = window.createMockContext();
-               var Constructor = Chart.scaleService.getScaleConstructor('logarithmic');
-               var scale = new Constructor({
-                       ctx: mockContext,
-                       options: config,
-                       chart: {
-                               data: mockData
+       it('should correctly determine the min and max data values when stacked mode is turned on ignoring hidden datasets', function() {
+               var chart = window.acquireChart({
+                       type: 'bar',
+                       data: {
+                               datasets: [{
+                                       yAxisID: 'yScale0',
+                                       data: [10, 5, 1, 5, 78, 100],
+                                       type: 'bar'
+                               }, {
+                                       yAxisID: 'yScale1',
+                                       data: [-1000, 1000],
+                                       type: 'bar'
+                               }, {
+                                       yAxisID: 'yScale0',
+                                       data: [150, 10, 10, 100, 10, 9],
+                                       type: 'bar'
+                               }, {
+                                       yAxisID: 'yScale0',
+                                       data: [10000, 10000, 10000, 10000, 10000, 10000],
+                                       hidden: true,
+                                       type: 'bar'
+                               }],
+                               labels: ['a', 'b', 'c', 'd', 'e', 'f']
                        },
-                       id: scaleID
+                       options: {
+                               scales: {
+                                       yAxes: [{
+                                               id: 'yScale0',
+                                               type: 'logarithmic',
+                                               stacked: true
+                                       }, {
+                                               id: 'yScale1',
+                                               type: 'logarithmic'
+                                       }]
+                               }
+                       }
                });
 
-               scale.update(400, 400);
-               expect(scale.min).toBe(10);
-               expect(scale.max).toBe(200);
+               expect(chart.scales.yScale0.min).toBe(10);
+               expect(chart.scales.yScale0.max).toBe(200);
        });
 
-       it('Should ensure that the scale has a max and min that are not equal', function() {
-               var scaleID = 'myScale';
-
-               var mockData = {
-                       datasets: []
-               };
-
-               var mockContext = window.createMockContext();
-               var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('logarithmic'));
-               var Constructor = Chart.scaleService.getScaleConstructor('logarithmic');
-               var scale = new Constructor({
-                       ctx: mockContext,
-                       options: config,
-                       chart: {
-                               data: mockData
+       it('should ensure that the scale has a max and min that are not equal', function() {
+               var chart = window.acquireChart({
+                       type: 'bar',
+                       data: {
+                               datasets: [{
+                                       data: []
+                               }],
+                               labels: []
                        },
-                       id: scaleID
+                       options: {
+                               scales: {
+                                       yAxes: [{
+                                               id: 'yScale',
+                                               type: 'logarithmic'
+                                       }]
+                               }
+                       }
                });
 
-               scale.update(400, 00);
-               expect(scale.min).toBe(1);
-               expect(scale.max).toBe(10);
+               expect(chart.scales.yScale.min).toBe(1);
+               expect(chart.scales.yScale.max).toBe(10);
 
-               mockData.datasets = [{
-                       yAxisID: scaleID,
-                       data: [0.15, 0.15]
-               }];
+               chart.data.datasets[0].data = [0.15, 0.15];
+               chart.update();
 
-               scale.update(400, 400);
-               expect(scale.min).toBe(0.01);
-               expect(scale.max).toBe(1);
+               expect(chart.scales.yScale.min).toBe(0.01);
+               expect(chart.scales.yScale.max).toBe(1);
        });
 
-
-       it('Should use the min and max options', function() {
-               var scaleID = 'myScale';
-
-               var mockData = {
-                       datasets: [{
-                               yAxisID: scaleID,
-                               data: [1, 1, 1, 2, 1, 0]
-                       }]
-               };
-
-               var mockContext = window.createMockContext();
-               var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('logarithmic'));
-
-               config.ticks.min = 10;
-               config.ticks.max = 1010;
-
-               var Constructor = Chart.scaleService.getScaleConstructor('logarithmic');
-               var scale = new Constructor({
-                       ctx: mockContext,
-                       options: config,
-                       chart: {
-                               data: mockData
+       it('should use the min and max options', function() {
+               var chart = window.acquireChart({
+                       type: 'bar',
+                       data: {
+                               datasets: [{
+                                       data: [1, 1, 1, 2, 1, 0]
+                               }],
+                               labels: []
                        },
-                       id: scaleID
+                       options: {
+                               scales: {
+                                       yAxes: [{
+                                               id: 'yScale',
+                                               type: 'logarithmic',
+                                               ticks: {
+                                                       min: 10,
+                                                       max: 1010,
+                                                       callback: function(value) {
+                                                               return value;
+                                                       }
+                                               }
+                                       }]
+                               }
+                       }
                });
 
-               scale.update(400, 00);
-               scale.buildTicks();
-               expect(scale.min).toBe(10);
-               expect(scale.max).toBe(1010);
-               expect(scale.ticks[0]).toBe(1010);
-               expect(scale.ticks[scale.ticks.length - 1]).toBe(10);
+               var yScale = chart.scales.yScale;
+               var tickCount = yScale.ticks.length;
+               expect(yScale.min).toBe(10);
+               expect(yScale.max).toBe(1010);
+               expect(yScale.ticks[0]).toBe(1010);
+               expect(yScale.ticks[tickCount - 1]).toBe(10);
        });
 
-       it('Should generate tick marks', function() {
-               var scaleID = 'myScale';
-
-               var mockData = {
-                       datasets: [{
-                               yAxisID: scaleID,
-                               data: [10, 5, 1, 25, 78]
-                       }, ]
-               };
-
-               var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('logarithmic'));
-               var Constructor = Chart.scaleService.getScaleConstructor('logarithmic');
-               var scale = new Constructor({
-                       ctx: {},
-                       options: config,
-                       chart: {
-                               data: mockData
+       it('should generate tick marks', function() {
+               var chart = window.acquireChart({
+                       type: 'bar',
+                       data: {
+                               datasets: [{
+                                       data: [10, 5, 1, 25, 78]
+                               }],
+                               labels: []
                        },
-                       id: scaleID
+                       options: {
+                               scales: {
+                                       yAxes: [{
+                                               id: 'yScale',
+                                               type: 'logarithmic',
+                                               ticks: {
+                                                       callback: function(value) {
+                                                               return value;
+                                                       }
+                                               }
+                                       }]
+                               }
+                       }
                });
 
-               // Set arbitrary width and height for now
-               scale.width = 50;
-               scale.height = 400;
-
-               scale.determineDataLimits();
-               scale.buildTicks();
-
                // Counts down because the lines are drawn top to bottom
-               expect(scale.ticks).toEqual([80, 70, 60, 50, 40, 30, 20, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]);
-               expect(scale.start).toBe(1);
-               expect(scale.end).toBe(80);
+               expect(chart.scales.yScale).toEqual(jasmine.objectContaining({
+                       ticks: [80, 70, 60, 50, 40, 30, 20, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],
+                       start: 1,
+                       end: 80
+               }));
        });
 
-       it('Should generate tick marks in the correct order in reversed mode', function() {
-               var scaleID = 'myScale';
-
-               var mockData = {
-                       datasets: [{
-                               yAxisID: scaleID,
-                               data: [10, 5, 1, 25, 78]
-                       }, ]
-               };
-
-               var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('logarithmic'));
-               config.ticks.reverse = true;
-
-               var Constructor = Chart.scaleService.getScaleConstructor('logarithmic');
-               var scale = new Constructor({
-                       ctx: {},
-                       options: config,
-                       chart: {
-                               data: mockData
+       it('should generate tick marks in the correct order in reversed mode', function() {
+               var chart = window.acquireChart({
+                       type: 'line',
+                       data: {
+                               datasets: [{
+                                       data: [10, 5, 1, 25, 78]
+                               }],
+                               labels: []
                        },
-                       id: scaleID
+                       options: {
+                               scales: {
+                                       yAxes: [{
+                                               id: 'yScale',
+                                               type: 'logarithmic',
+                                               ticks: {
+                                                       reverse: true,
+                                                       callback: function(value) {
+                                                               return value;
+                                                       }
+                                               }
+                                       }]
+                               }
+                       }
                });
 
-               // Set arbitrary width and height for now
-               scale.width = 50;
-               scale.height = 400;
-
-               scale.determineDataLimits();
-               scale.buildTicks();
-
                // Counts down because the lines are drawn top to bottom
-               expect(scale.ticks).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 60, 70, 80]);
-               expect(scale.start).toBe(80);
-               expect(scale.end).toBe(1);
+               expect(chart.scales.yScale).toEqual(jasmine.objectContaining({
+                       ticks: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 60, 70, 80],
+                       start: 80,
+                       end: 1
+               }));
        });
 
-       it('Should build labels using the default template', function() {
-               var scaleID = 'myScale';
-
-               var mockData = {
-                       datasets: [{
-                               yAxisID: scaleID,
-                               data: [10, 5, 1, 25, 78]
-                       }, ]
-               };
-
-               var mockContext = window.createMockContext();
-               var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('logarithmic'));
-               var Constructor = Chart.scaleService.getScaleConstructor('logarithmic');
-               var scale = new Constructor({
-                       ctx: mockContext,
-                       options: config,
-                       chart: {
-                               data: mockData
+       it('should build labels using the default template', function() {
+               var chart = window.acquireChart({
+                       type: 'line',
+                       data: {
+                               datasets: [{
+                                       data: [10, 5, 1, 25, 78]
+                               }],
+                               labels: []
                        },
-                       id: scaleID
+                       options: {
+                               scales: {
+                                       yAxes: [{
+                                               id: 'yScale',
+                                               type: 'logarithmic'
+                                       }]
+                               }
+                       }
                });
 
-               scale.update(400, 400);
-
-               expect(scale.ticks).toEqual(['8e+1', '', '', '5e+1', '', '', '2e+1', '1e+1', '', '', '', '', '5e+0', '', '', '2e+0', '1e+0']);
+               expect(chart.scales.yScale.ticks).toEqual(['8e+1', '', '', '5e+1', '', '', '2e+1', '1e+1', '', '', '', '', '5e+0', '', '', '2e+0', '1e+0']);
        });
 
-       it('Should build labels using the user supplied callback', function() {
-               var scaleID = 'myScale';
-
-               var mockData = {
-                       datasets: [{
-                               yAxisID: scaleID,
-                               data: [10, 5, 1, 25, 78]
-                       }, ]
-               };
-
-               var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('logarithmic'));
-               config.ticks.userCallback = function(value, index) {
-                       return index.toString();
-               };
-
-               var mockContext = window.createMockContext();
-               var Constructor = Chart.scaleService.getScaleConstructor('logarithmic');
-               var scale = new Constructor({
-                       ctx: mockContext,
-                       options: config,
-                       chart: {
-                               data: mockData
+       it('should build labels using the user supplied callback', function() {
+               var chart = window.acquireChart({
+                       type: 'bar',
+                       data: {
+                               datasets: [{
+                                       data: [10, 5, 1, 25, 78]
+                               }],
+                               labels: []
                        },
-                       id: scaleID
+                       options: {
+                               scales: {
+                                       yAxes: [{
+                                               id: 'yScale',
+                                               type: 'logarithmic',
+                                               ticks: {
+                                                       callback: function(value, index) {
+                                                               return index.toString();
+                                                       }
+                                               }
+                                       }]
+                               }
+                       }
                });
 
-               scale.update(400, 400);
-
                // Just the index
-               expect(scale.ticks).toEqual(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16']);
+               expect(chart.scales.yScale.ticks).toEqual(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16']);
        });
 
-       it('Should correctly get the correct label for a data item', function() {
-               var scaleID = 'myScale';
-
-               var mockData = {
-                       datasets: [{
-                               yAxisID: scaleID,
-                               data: [10, 5, 5000, 78, 450]
-                       }, {
-                               yAxisID: 'second scale',
-                               data: [1, 1000, 10, 100],
-                       }, {
-                               yAxisID: scaleID,
-                               data: [150]
-                       }]
-               };
-
-               var mockContext = window.createMockContext();
-               var Constructor = Chart.scaleService.getScaleConstructor('logarithmic');
-               var scale = new Constructor({
-                       ctx: mockContext,
-                       options: Chart.scaleService.getScaleDefaults('logarithmic'), // use default config for scale
-                       chart: {
-                               data: mockData,
+       it('should correctly get the correct label for a data item', function() {
+               var chart = window.acquireChart({
+                       type: 'bar',
+                       data: {
+                               datasets: [{
+                                       yAxisID: 'yScale0',
+                                       data: [10, 5, 5000, 78, 450]
+                               }, {
+                                       yAxisID: 'yScale1',
+                                       data: [1, 1000, 10, 100],
+                               }, {
+                                       yAxisID: 'yScale0',
+                                       data: [150]
+                               }],
+                               labels: []
                        },
-                       id: scaleID
+                       options: {
+                               scales: {
+                                       yAxes: [{
+                                               id: 'yScale0',
+                                               type: 'logarithmic'
+                                       }, {
+                                               id: 'yScale1',
+                                               type: 'logarithmic'
+                                       }]
+                               }
+                       }
                });
 
-               scale.update(400, 400);
-
-               expect(scale.getLabelForIndex(0, 2)).toBe(150);
+               expect(chart.scales.yScale1.getLabelForIndex(0, 2)).toBe(150);
        });
 
-       it('Should get the correct pixel value for a point', function() {
-               var scaleID = 'myScale';
-
-               var mockData = {
-                       datasets: [{
-                               xAxisID: scaleID, // for the horizontal scale
-                               yAxisID: scaleID,
-                               data: [10, 5, 1, 25, 78]
-                       }]
-               };
-
-               var mockContext = window.createMockContext();
-               var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('logarithmic'));
-               var Constructor = Chart.scaleService.getScaleConstructor('logarithmic');
-               var verticalScale = new Constructor({
-                       ctx: mockContext,
-                       options: config,
-                       chart: {
-                               data: mockData
-                       },
-                       id: scaleID
-               });
-
-               verticalScale.update(50, 100);
-
-               // Fake out positioning of the scale service
-               verticalScale.left = 0;
-               verticalScale.top = 0;
-               verticalScale.right = 50;
-               verticalScale.bottom = 110;
-               verticalScale.paddingTop = 5;
-               verticalScale.paddingBottom = 5;
-               verticalScale.width = 50;
-               verticalScale.height = 110;
-
-               expect(verticalScale.getPixelForValue(80, 0, 0)).toBe(5); // top + paddingTop
-               expect(verticalScale.getPixelForValue(1, 0, 0)).toBe(105); // bottom - paddingBottom
-               expect(verticalScale.getPixelForValue(10, 0, 0)).toBeCloseTo(52.4, 1e-4); // halfway
-               expect(verticalScale.getPixelForValue(0, 0, 0)).toBe(5); // 0 is invalid. force it on top
-
-               var horizontalConfig = Chart.helpers.clone(config);
-               horizontalConfig.position = 'bottom';
-               var horizontalScale = new Constructor({
-                       ctx: mockContext,
-                       options: horizontalConfig,
-                       chart: {
-                               data: mockData
+       it('should get the correct pixel value for a point', function() {
+               var chart = window.acquireChart({
+                       type: 'bar',
+                       data: {
+                               datasets: [{
+                                       xAxisID: 'xScale', // for the horizontal scale
+                                       yAxisID: 'yScale',
+                                       data: [10, 5, 1, 25, 78]
+                               }],
+                               labels: []
                        },
-                       id: scaleID,
+                       options: {
+                               scales: {
+                                       yAxes: [{
+                                               id: 'xScale',
+                                               type: 'logarithmic',
+                                               position: 'bottom'
+                                       }, {
+                                               id: 'yScale',
+                                               type: 'logarithmic'
+                                       }]
+                               }
+                       }
                });
 
-               horizontalScale.update(100, 50);
-
-               // Fake out positioning of the scale service
-               horizontalScale.left = 0;
-               horizontalScale.top = 0;
-               horizontalScale.right = 110;
-               horizontalScale.bottom = 50;
-               horizontalScale.paddingLeft = 5;
-               horizontalScale.paddingRight = 5;
-               horizontalScale.width = 110;
-               horizontalScale.height = 50;
-
-               expect(horizontalScale.getPixelForValue(80, 0, 0)).toBe(105); // right - paddingRight
-               expect(horizontalScale.getPixelForValue(1, 0, 0)).toBe(5); // left + paddingLeft
-               expect(horizontalScale.getPixelForValue(10, 0, 0)).toBeCloseTo(57.5, 1e-4); // halfway
-               expect(horizontalScale.getPixelForValue(0, 0, 0)).toBe(5); // 0 is invalid, put it on the left.
+               var xScale = chart.scales.xScale;
+               expect(xScale.getPixelForValue(80, 0, 0)).toBeCloseToPixel(495);  // right - paddingRight
+               expect(xScale.getPixelForValue( 1, 0, 0)).toBeCloseToPixel(48);   // left + paddingLeft
+               expect(xScale.getPixelForValue(10, 0, 0)).toBeCloseToPixel(283);  // halfway
+               expect(xScale.getPixelForValue( 0, 0, 0)).toBeCloseToPixel(48);   // 0 is invalid, put it on the left.
+
+               var yScale = chart.scales.yScale;
+               expect(yScale.getPixelForValue(80, 0, 0)).toBeCloseToPixel(32);   // top + paddingTop
+               expect(yScale.getPixelForValue( 1, 0, 0)).toBeCloseToPixel(456);  // bottom - paddingBottom
+               expect(yScale.getPixelForValue(10, 0, 0)).toBeCloseToPixel(234);  // halfway
+               expect(yScale.getPixelForValue( 0, 0, 0)).toBeCloseToPixel(32);   // 0 is invalid. force it on top
        });
 });