Skip to content

Commit

Permalink
fix: fix error when showline is true at root options and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thabarbados committed Jul 12, 2022
1 parent 9d97f58 commit 7117bcb
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/controllers/controller.scatter.js
Expand Up @@ -5,15 +5,6 @@ import {_getStartAndCountOfVisiblePoints, _scaleRangesChanged} from '../helpers/
import registry from '../core/core.registry';

export default class ScatterController extends DatasetController {
initialize() {
const {showLine} = this.getDataset();
if (!this.datasetElementType && showLine) {
this.datasetElementType = registry.getElement('line');
}

super.initialize();
}

update(mode) {
const meta = this._cachedMeta;
const {data: points = []} = meta;
Expand Down Expand Up @@ -53,6 +44,16 @@ export default class ScatterController extends DatasetController {
this.updateElements(points, start, count, mode);
}

addElements() {
const {showLine} = this.options;

if (!this.datasetElementType && showLine) {
this.datasetElementType = registry.getElement('line');
}

super.addElements();
}

updateElements(points, start, count, mode) {
const reset = mode === 'reset';
const {iScale, vScale, _stacked, _dataset} = this._cachedMeta;
Expand Down
103 changes: 103 additions & 0 deletions test/specs/controller.scatter.tests.js
Expand Up @@ -61,4 +61,107 @@ describe('Chart.controllers.scatter', function() {
await jasmine.triggerMouseEvent(chart, 'mousemove', point);
expect(chart.tooltip.body.length).toEqual(1);
});

it('should not create line element by default', function() {
var chart = window.acquireChart({
type: 'scatter',
data: {
datasets: [{
data: [{
x: 10,
y: 15
},
{
x: 12,
y: 10
}],
label: 'dataset1'
},
{
data: [{
x: 20,
y: 10
},
{
x: 4,
y: 8
}],
label: 'dataset2'
}]
},
});

var meta = chart.getDatasetMeta(0);
expect(meta.dataset instanceof Chart.elements.LineElement).toBe(false);
});

it('should create line element if showline is true at datasets options', function() {
var chart = window.acquireChart({
type: 'scatter',
data: {
datasets: [{
showLine: true,
data: [{
x: 10,
y: 15
},
{
x: 12,
y: 10
}],
label: 'dataset1'
},
{
data: [{
x: 20,
y: 10
},
{
x: 4,
y: 8
}],
label: 'dataset2'
}]
},
});

var meta = chart.getDatasetMeta(0);
expect(meta.dataset instanceof Chart.elements.LineElement).toBe(true);
});

it('should create line element if showline is true at root options', function() {
var chart = window.acquireChart({
type: 'scatter',
data: {
datasets: [{
data: [{
x: 10,
y: 15
},
{
x: 12,
y: 10
}],
label: 'dataset1'
},
{
data: [{
x: 20,
y: 10
},
{
x: 4,
y: 8
}],
label: 'dataset2'
}]
},
options: {
showLine: true
}
});

var meta = chart.getDatasetMeta(0);
expect(meta.dataset instanceof Chart.elements.LineElement).toBe(true);
});
});

0 comments on commit 7117bcb

Please sign in to comment.