if (this.options.stacked) {
helpers.each(this.data.datasets, function(dataset) {
- if (this.isHorizontal() ? dataset.xAxisID === this.id : dataset.yAxisID === this.id) {
+ if (helpers.isDatasetVisible(dataset) && (this.isHorizontal() ? dataset.xAxisID === this.id : dataset.yAxisID === this.id)) {
helpers.each(dataset.data, function(rawValue, index) {
var value = this.getRightValue(rawValue);
} else {
helpers.each(this.data.datasets, function(dataset) {
- if (this.isHorizontal() ? dataset.xAxisID === this.id : dataset.yAxisID === this.id) {
+ if (helpers.isDatasetVisible(dataset) && (this.isHorizontal() ? dataset.xAxisID === this.id : dataset.yAxisID === this.id)) {
helpers.each(dataset.data, function(rawValue, index) {
var value = this.getRightValue(rawValue);
if (this.options.stacked) {
helpers.each(this.data.datasets, function(dataset) {
- if (this.isHorizontal() ? dataset.xAxisID === this.id : dataset.yAxisID === this.id) {
+ if (helpers.isDatasetVisible(dataset) && (this.isHorizontal() ? dataset.xAxisID === this.id : dataset.yAxisID === this.id)) {
helpers.each(dataset.data, function(rawValue, index) {
var value = this.getRightValue(rawValue);
} else {
helpers.each(this.data.datasets, function(dataset) {
- if (this.isHorizontal() ? dataset.xAxisID === this.id : dataset.yAxisID === this.id) {
+ if (helpers.isDatasetVisible(dataset) && (this.isHorizontal() ? dataset.xAxisID === this.id : dataset.yAxisID === this.id)) {
helpers.each(dataset.data, function(rawValue, index) {
var value = this.getRightValue(rawValue);
this.max = null;
helpers.each(this.data.datasets, function(dataset) {
- helpers.each(dataset.data, function(value, index) {
- if (value === null) return;
-
- if (this.min === null) {
- this.min = value;
- } else if (value < this.min) {
- this.min = value;
- }
+ if (helpers.isDatasetVisible(dataset)) {
+ helpers.each(dataset.data, function(value, index) {
+ if (value === null) return;
+
+ if (this.min === null) {
+ this.min = value;
+ } else if (value < this.min) {
+ this.min = value;
+ }
- if (this.max === null) {
- this.max = value;
- } else if (value > this.max) {
- this.max = value;
- }
- }, this);
+ if (this.max === null) {
+ this.max = value;
+ } else if (value > this.max) {
+ this.max = value;
+ }
+ }, this);
+ }
}, this);
if (this.min === this.max) {
expect(scale.max).toBe(150);
});
+ it('Should correctly determine the max & min data values ignoring hidden datasets', function() {
+ var scaleID = 'myScale';
+
+ var mockData = {
+ datasets: [{
+ yAxisID: scaleID,
+ data: [10, 5, 0, -5, 78, -100]
+ }, {
+ yAxisID: 'second scale',
+ data: [-1000, 1000],
+ }, {
+ yAxisID: scaleID,
+ data: [150],
+ hidden: true
+ }]
+ };
+
+ var Constructor = Chart.scaleService.getScaleConstructor('linear');
+ var scale = new Constructor({
+ ctx: {},
+ options: Chart.scaleService.getScaleDefaults('linear'), // use default config for scale
+ data: mockData,
+ id: scaleID
+ });
+
+ expect(scale).not.toEqual(undefined); // must construct
+ expect(scale.min).toBe(undefined); // not yet set
+ expect(scale.max).toBe(undefined);
+
+ // Set arbitrary width and height for now
+ scale.width = 50;
+ scale.height = 400;
+
+ scale.buildTicks();
+ expect(scale.min).toBe(-100);
+ expect(scale.max).toBe(80);
+ });
+
it('Should correctly determine the max & min for scatter data', function() {
var scaleID = 'myScale';
expect(scale.max).toBe(200);
});
+ it('Should correctly determine the min and max data values when stacked mode is turned on and there are hidden datasets', function() {
+ var scaleID = 'myScale';
+
+ var mockData = {
+ datasets: [{
+ yAxisID: scaleID,
+ data: [10, 5, 0, -5, 78, -100]
+ }, {
+ yAxisID: 'second scale',
+ data: [-1000, 1000],
+ }, {
+ yAxisID: scaleID,
+ data: [150, 0, 0, -100, -10, 9]
+ }, {
+ yAxisID: scaleID,
+ data: [10, 20, 30, 40, 50, 60],
+ hidden: true
+ }]
+ };
+
+ var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('linear'));
+ config.stacked = true; // enable scale stacked mode
+
+ var Constructor = Chart.scaleService.getScaleConstructor('linear');
+ var scale = new Constructor({
+ ctx: {},
+ options: config,
+ data: mockData,
+ id: scaleID
+ });
+
+ // Set arbitrary width and height for now
+ scale.width = 50;
+ scale.height = 400;
+
+ scale.buildTicks();
+ expect(scale.min).toBe(-150);
+ expect(scale.max).toBe(200);
+ });
+
it('Should ensure that the scale has a max and min that are not equal', function() {
var scaleID = 'myScale';
expect(scale.max).toBe(10000);
});
+ 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
+ data: mockData,
+ id: scaleID
+ });
+
+ 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(10000);
+ });
+
it('Should correctly determine the max & min for scatter data', function() {
var scaleID = 'myScale';
expect(scale.max).toBe(1000);
});
+ 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]
+ }, {
+ yAxisID: 'second scale',
+ data: [-1000, 1000],
+ }, {
+ yAxisID: scaleID,
+ data: [150, 10, 10, 100, 10, 9]
+ }, {
+ yAxisID: scaleID,
+ data: [10000, 10000, 10000, 10000, 10000, 10000],
+ hidden: true
+ }]
+ };
+
+ 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,
+ data: mockData,
+ id: scaleID
+ });
+
+ scale.update(400, 400);
+ expect(scale.min).toBe(10);
+ expect(scale.max).toBe(1000);
+ });
+
it('Should ensure that the scale has a max and min that are not equal', function() {
var scaleID = 'myScale';
expect(scale.max).toBe(200);
});
+ 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, 0, -5, 78, -100]
+ }, {
+ yAxisID: scaleID,
+ data: [150]
+ }, {
+ yAxisID: scaleID,
+ data: [1000],
+ hidden: true
+ }],
+ labels: ['lablel1', 'label2', 'label3', 'label4', 'label5', 'label6']
+ };
+
+ var mockContext = window.createMockContext();
+ var Constructor = Chart.scaleService.getScaleConstructor('radialLinear');
+ var scale = new Constructor({
+ ctx: mockContext,
+ options: Chart.scaleService.getScaleDefaults('radialLinear'), // use default config for scale
+ data: mockData,
+ id: scaleID,
+ });
+
+ scale.update(200, 300);
+ expect(scale.min).toBe(-100);
+ expect(scale.max).toBe(200);
+ });
+
it('Should ensure that the scale has a max and min that are not equal', function() {
var scaleID = 'myScale';