]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Update bar controller tests 1877/head
authorEvert Timberg <evert.timberg@gmail.com>
Sat, 9 Jan 2016 14:58:14 +0000 (09:58 -0500)
committerEvert Timberg <evert.timberg@gmail.com>
Sat, 9 Jan 2016 14:58:14 +0000 (09:58 -0500)
test/controller.bar.tests.js

index 97d39f71e0f430fb77d25cdbbfbfc7fcbf0fdbc6..76634e941bd8eb0fd5ecc6d9189a5723a8d39380 100644 (file)
@@ -275,6 +275,109 @@ describe('Bar controller tests', function() {
                expect(chart.data.datasets[1].metaData.length).toBe(3); // should add a new meta data item
        });
 
+       it ('should get the correct bar points when datasets of different types exist', function() {
+               var data = {
+                       datasets: [{
+                               data: [1, 2],
+                               label: 'dataset1',
+                               xAxisID: 'firstXScaleID',
+                               yAxisID: 'firstYScaleID',
+                               bar: true,
+                       }, {
+                               data: [10, 15],
+                               label: 'dataset2',
+                               xAxisID: 'firstXScaleID',
+                               yAxisID: 'firstYScaleID',
+                       }, {
+                               data: [30, 25],
+                               label: 'dataset3',
+                               xAxisID: 'firstXScaleID',
+                               yAxisID: 'firstYScaleID',
+                               bar: true
+                       }],
+                       labels: ['label1', 'label2']
+               };
+               var mockContext = window.createMockContext();
+
+               var VerticalScaleConstructor = Chart.scaleService.getScaleConstructor('linear');
+               var verticalScaleConfig = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('linear'));
+               verticalScaleConfig = Chart.helpers.scaleMerge(verticalScaleConfig, Chart.defaults.bar.scales.yAxes[0]);
+               var yScale = new VerticalScaleConstructor({
+                       ctx: mockContext,
+                       options: verticalScaleConfig,
+                       chart: {
+                               data: data
+                       },
+                       id: 'firstYScaleID'
+               });
+
+               // Update ticks & set physical dimensions
+               var verticalSize = yScale.update(50, 200);
+               yScale.top = 0;
+               yScale.left = 0;
+               yScale.right = verticalSize.width;
+               yScale.bottom = verticalSize.height;
+
+               var HorizontalScaleConstructor = Chart.scaleService.getScaleConstructor('category');
+               var horizontalScaleConfig = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('category'));
+               horizontalScaleConfig = Chart.helpers.scaleMerge(horizontalScaleConfig, Chart.defaults.bar.scales.xAxes[0]);
+               var xScale = new HorizontalScaleConstructor({
+                       ctx: mockContext,
+                       options: horizontalScaleConfig,
+                       chart: {
+                               data: data
+                       },
+                       id: 'firstXScaleID'
+               });
+
+               // Update ticks & set physical dimensions
+               var horizontalSize = xScale.update(200, 50);
+               xScale.left = yScale.right;
+               xScale.top = yScale.bottom;
+               xScale.right = horizontalSize.width + xScale.left;
+               xScale.bottom = horizontalSize.height + xScale.top;
+
+               var chart = {
+                       data: data,
+                       config: {
+                               type: 'bar'
+                       },
+                       options: {
+                               elements: {
+                                       rectangle: {
+                                               backgroundColor: 'rgb(255, 0, 0)',
+                                               borderColor: 'rgb(0, 0, 255)',
+                                               borderWidth: 2,
+                                       }
+                               },
+                               scales: {
+                                       xAxes: [{
+                                               id: 'firstXScaleID'
+                                       }],
+                                       yAxes: [{
+                                               id: 'firstYScaleID'
+                                       }]
+                               }
+                       },
+                       scales: {
+                               firstXScaleID: xScale,
+                               firstYScaleID: yScale,
+                       }
+               };
+
+               var controller = new Chart.controllers.bar(chart, 2);
+               controller.buildOrUpdateElements();
+               controller.update();
+
+               var bar1 = chart.data.datasets[2].metaData[0];
+               var bar2 = chart.data.datasets[2].metaData[1];
+
+               expect(bar1._model.x).toBe(119.9);
+               expect(bar1._model.y).toBe(6);
+               expect(bar2._model.x).toBe(186.9);
+               expect(bar2._model.y).toBe(37);
+       });
+
        it ('should draw all bars', function() {
                var data = {
                        datasets: [{}, {