From 110c1afbaa8e495cdaa308ac1d95c6e8f3ebc4df Mon Sep 17 00:00:00 2001 From: "v.terekhov" Date: Tue, 21 Jun 2022 14:09:52 +0400 Subject: [PATCH 1/6] feat: remove line element from scatter controller default config --- src/controllers/controller.scatter.js | 183 +++++++++++++++++++++++++- src/core/core.controller.js | 4 +- 2 files changed, 183 insertions(+), 4 deletions(-) diff --git a/src/controllers/controller.scatter.js b/src/controllers/controller.scatter.js index 1d1ccb73e5a..28efbd84ad1 100644 --- a/src/controllers/controller.scatter.js +++ b/src/controllers/controller.scatter.js @@ -1,7 +1,133 @@ -import LineController from './controller.line'; +import DatasetController from '../core/core.datasetController'; +import {isNullOrUndef} from '../helpers'; +import {_limitValue, isNumber} from '../helpers/helpers.math'; +import {_lookupByKey} from '../helpers/helpers.collection'; -export default class ScatterController extends LineController { +export default class ScatterController extends DatasetController { + initialize() { + super.initialize(); + const {dataset} = this._cachedMeta || null; + const {showLine} = this.options || false; + + if (showLine && dataset === null) { + const config = { + datasetElementType: 'line', + dataElementType: 'point', + showLine: true, + fill: false, + }; + this.chart.buildOrUpdateControllers(config); + } + } + + update(mode) { + const meta = this._cachedMeta; + const {data: points = []} = meta; + // @ts-ignore + const animationsDisabled = this.chart._animationsDisabled; + let {start, count} = getStartAndCountOfVisiblePoints(meta, points, animationsDisabled); + + this._drawStart = start; + this._drawCount = count; + + if (scaleRangesChanged(meta)) { + start = 0; + count = points.length; + } + + if (this.options.showLine) { + + const {dataset: line, _dataset} = meta; + + // Update Line + line._chart = this.chart; + line._datasetIndex = this.index; + line._decimated = !!_dataset._decimated; + line.points = points; + + const options = this.resolveDatasetElementOptions(mode); + options.segment = this.options.segment; + this.updateElement(line, undefined, { + animated: !animationsDisabled, + options + }, mode); + } else { + this.options.borderWidth = 0; + } + + // Update Points + this.updateElements(points, start, count, mode); + } + + updateElements(points, start, count, mode) { + const reset = mode === 'reset'; + const {iScale, vScale, _stacked, _dataset} = this._cachedMeta; + const firstOpts = this.resolveDataElementOptions(start, mode); + const sharedOptions = this.getSharedOptions(firstOpts); + const includeOptions = this.includeOptions(mode, sharedOptions); + const iAxis = iScale.axis; + const vAxis = vScale.axis; + const {spanGaps, segment} = this.options; + const maxGapLength = isNumber(spanGaps) ? spanGaps : Number.POSITIVE_INFINITY; + const directUpdate = this.chart._animationsDisabled || reset || mode === 'none'; + let prevParsed = start > 0 && this.getParsed(start - 1); + + for (let i = start; i < start + count; ++i) { + const point = points[i]; + const parsed = this.getParsed(i); + const properties = directUpdate ? point : {}; + const nullData = isNullOrUndef(parsed[vAxis]); + const iPixel = properties[iAxis] = iScale.getPixelForValue(parsed[iAxis], i); + const vPixel = properties[vAxis] = reset || nullData ? vScale.getBasePixel() : vScale.getPixelForValue(_stacked ? this.applyStack(vScale, parsed, _stacked) : parsed[vAxis], i); + + properties.skip = isNaN(iPixel) || isNaN(vPixel) || nullData; + properties.stop = i > 0 && (Math.abs(parsed[iAxis] - prevParsed[iAxis])) > maxGapLength; + if (segment) { + properties.parsed = parsed; + properties.raw = _dataset.data[i]; + } + + if (includeOptions) { + properties.options = sharedOptions || this.resolveDataElementOptions(i, point.active ? 'active' : mode); + } + + if (!directUpdate) { + this.updateElement(point, i, properties, mode); + } + + prevParsed = parsed; + } + + this.updateSharedOptions(sharedOptions, mode, firstOpts); + } + + /** + * @protected + */ + getMaxOverflow() { + const meta = this._cachedMeta; + const data = meta.data || []; + + if (!this.options.showLine) { + let max = 0; + for (let i = data.length - 1; i >= 0; --i) { + max = Math.max(max, data[i].size(this.resolveDataElementOptions(i)) / 2); + } + return max > 0 && max; + } + + const dataset = meta.dataset; + const border = dataset.options && dataset.options.borderWidth || 0; + + if (!data.length) { + return border; + } + + const firstPoint = data[0].size(this.resolveDataElementOptions(0)); + const lastPoint = data[data.length - 1].size(this.resolveDataElementOptions(data.length - 1)); + return Math.max(border, firstPoint, lastPoint) / 2; + } } ScatterController.id = 'scatter'; @@ -10,6 +136,8 @@ ScatterController.id = 'scatter'; * @type {any} */ ScatterController.defaults = { + datasetElementType: false, + dataElementType: 'point', showLine: false, fill: false }; @@ -45,3 +173,54 @@ ScatterController.overrides = { } } }; + +function getStartAndCountOfVisiblePoints(meta, points, animationsDisabled) { + const pointCount = points.length; + + let start = 0; + let count = pointCount; + + if (meta._sorted) { + const {iScale, _parsed} = meta; + const axis = iScale.axis; + const {min, max, minDefined, maxDefined} = iScale.getUserBounds(); + + if (minDefined) { + start = _limitValue(Math.min( + _lookupByKey(_parsed, iScale.axis, min).lo, + animationsDisabled ? pointCount : _lookupByKey(points, axis, iScale.getPixelForValue(min)).lo), + 0, pointCount - 1); + } + if (maxDefined) { + count = _limitValue(Math.max( + _lookupByKey(_parsed, iScale.axis, max).hi + 1, + animationsDisabled ? 0 : _lookupByKey(points, axis, iScale.getPixelForValue(max)).hi + 1), + start, pointCount) - start; + } else { + count = pointCount - start; + } + } + + return {start, count}; +} + +function scaleRangesChanged(meta) { + const {xScale, yScale, _scaleRanges} = meta; + const newRanges = { + xmin: xScale.min, + xmax: xScale.max, + ymin: yScale.min, + ymax: yScale.max + }; + if (!_scaleRanges) { + meta._scaleRanges = newRanges; + return true; + } + const changed = _scaleRanges.xmin !== xScale.min + || _scaleRanges.xmax !== xScale.max + || _scaleRanges.ymin !== yScale.min + || _scaleRanges.ymax !== yScale.max; + + Object.assign(_scaleRanges, newRanges); + return changed; +} diff --git a/src/core/core.controller.js b/src/core/core.controller.js index 907f4d198ec..98d8d31945c 100644 --- a/src/core/core.controller.js +++ b/src/core/core.controller.js @@ -392,7 +392,7 @@ class Chart { }); } - buildOrUpdateControllers() { + buildOrUpdateControllers(config) { const newControllers = []; const datasets = this.data.datasets; let i, ilen; @@ -420,7 +420,7 @@ class Chart { meta.controller.linkScales(); } else { const ControllerClass = registry.getController(type); - const {datasetElementType, dataElementType} = defaults.datasets[type]; + const {datasetElementType, dataElementType} = config || defaults.datasets[type]; Object.assign(ControllerClass.prototype, { dataElementType: registry.getElement(dataElementType), datasetElementType: datasetElementType && registry.getElement(datasetElementType) From f637d4ee2b410863a3382b03649d74d6c9411e8e Mon Sep 17 00:00:00 2001 From: "v.terekhov" Date: Wed, 29 Jun 2022 14:52:54 +0400 Subject: [PATCH 2/6] feat: move common controllers methods to helpers and add types --- src/controllers/controller.line.js | 55 +------------------- src/controllers/controller.scatter.js | 74 +++------------------------ src/core/core.controller.js | 4 +- src/helpers/helpers.extras.js | 65 +++++++++++++++++++++++ types/helpers/helpers.extras.d.ts | 16 ++++++ 5 files changed, 93 insertions(+), 121 deletions(-) diff --git a/src/controllers/controller.line.js b/src/controllers/controller.line.js index b28997aad07..756675c65e0 100644 --- a/src/controllers/controller.line.js +++ b/src/controllers/controller.line.js @@ -1,7 +1,7 @@ import DatasetController from '../core/core.datasetController'; import {isNullOrUndef} from '../helpers'; -import {_limitValue, isNumber} from '../helpers/helpers.math'; -import {_lookupByKey} from '../helpers/helpers.collection'; +import {isNumber} from '../helpers/helpers.math'; +import {getStartAndCountOfVisiblePoints, scaleRangesChanged} from '../helpers/helpers.extras'; export default class LineController extends DatasetController { @@ -133,54 +133,3 @@ LineController.overrides = { }, } }; - -function getStartAndCountOfVisiblePoints(meta, points, animationsDisabled) { - const pointCount = points.length; - - let start = 0; - let count = pointCount; - - if (meta._sorted) { - const {iScale, _parsed} = meta; - const axis = iScale.axis; - const {min, max, minDefined, maxDefined} = iScale.getUserBounds(); - - if (minDefined) { - start = _limitValue(Math.min( - _lookupByKey(_parsed, iScale.axis, min).lo, - animationsDisabled ? pointCount : _lookupByKey(points, axis, iScale.getPixelForValue(min)).lo), - 0, pointCount - 1); - } - if (maxDefined) { - count = _limitValue(Math.max( - _lookupByKey(_parsed, iScale.axis, max, true).hi + 1, - animationsDisabled ? 0 : _lookupByKey(points, axis, iScale.getPixelForValue(max), true).hi + 1), - start, pointCount) - start; - } else { - count = pointCount - start; - } - } - - return {start, count}; -} - -function scaleRangesChanged(meta) { - const {xScale, yScale, _scaleRanges} = meta; - const newRanges = { - xmin: xScale.min, - xmax: xScale.max, - ymin: yScale.min, - ymax: yScale.max - }; - if (!_scaleRanges) { - meta._scaleRanges = newRanges; - return true; - } - const changed = _scaleRanges.xmin !== xScale.min - || _scaleRanges.xmax !== xScale.max - || _scaleRanges.ymin !== yScale.min - || _scaleRanges.ymax !== yScale.max; - - Object.assign(_scaleRanges, newRanges); - return changed; -} diff --git a/src/controllers/controller.scatter.js b/src/controllers/controller.scatter.js index 28efbd84ad1..965e58a88bf 100644 --- a/src/controllers/controller.scatter.js +++ b/src/controllers/controller.scatter.js @@ -1,24 +1,17 @@ import DatasetController from '../core/core.datasetController'; import {isNullOrUndef} from '../helpers'; -import {_limitValue, isNumber} from '../helpers/helpers.math'; -import {_lookupByKey} from '../helpers/helpers.collection'; +import {isNumber} from '../helpers/helpers.math'; +import {getStartAndCountOfVisiblePoints, scaleRangesChanged} from '../helpers/helpers.extras'; +import registry from '../core/core.registry'; export default class ScatterController extends DatasetController { initialize() { - super.initialize(); - - const {dataset} = this._cachedMeta || null; - const {showLine} = this.options || false; - - if (showLine && dataset === null) { - const config = { - datasetElementType: 'line', - dataElementType: 'point', - showLine: true, - fill: false, - }; - this.chart.buildOrUpdateControllers(config); + const {showLine} = this.getDataset(); + if (!this.datasetElementType && showLine) { + this.datasetElementType = registry.getElement('line'); } + + super.initialize(); } update(mode) { @@ -173,54 +166,3 @@ ScatterController.overrides = { } } }; - -function getStartAndCountOfVisiblePoints(meta, points, animationsDisabled) { - const pointCount = points.length; - - let start = 0; - let count = pointCount; - - if (meta._sorted) { - const {iScale, _parsed} = meta; - const axis = iScale.axis; - const {min, max, minDefined, maxDefined} = iScale.getUserBounds(); - - if (minDefined) { - start = _limitValue(Math.min( - _lookupByKey(_parsed, iScale.axis, min).lo, - animationsDisabled ? pointCount : _lookupByKey(points, axis, iScale.getPixelForValue(min)).lo), - 0, pointCount - 1); - } - if (maxDefined) { - count = _limitValue(Math.max( - _lookupByKey(_parsed, iScale.axis, max).hi + 1, - animationsDisabled ? 0 : _lookupByKey(points, axis, iScale.getPixelForValue(max)).hi + 1), - start, pointCount) - start; - } else { - count = pointCount - start; - } - } - - return {start, count}; -} - -function scaleRangesChanged(meta) { - const {xScale, yScale, _scaleRanges} = meta; - const newRanges = { - xmin: xScale.min, - xmax: xScale.max, - ymin: yScale.min, - ymax: yScale.max - }; - if (!_scaleRanges) { - meta._scaleRanges = newRanges; - return true; - } - const changed = _scaleRanges.xmin !== xScale.min - || _scaleRanges.xmax !== xScale.max - || _scaleRanges.ymin !== yScale.min - || _scaleRanges.ymax !== yScale.max; - - Object.assign(_scaleRanges, newRanges); - return changed; -} diff --git a/src/core/core.controller.js b/src/core/core.controller.js index 98d8d31945c..907f4d198ec 100644 --- a/src/core/core.controller.js +++ b/src/core/core.controller.js @@ -392,7 +392,7 @@ class Chart { }); } - buildOrUpdateControllers(config) { + buildOrUpdateControllers() { const newControllers = []; const datasets = this.data.datasets; let i, ilen; @@ -420,7 +420,7 @@ class Chart { meta.controller.linkScales(); } else { const ControllerClass = registry.getController(type); - const {datasetElementType, dataElementType} = config || defaults.datasets[type]; + const {datasetElementType, dataElementType} = defaults.datasets[type]; Object.assign(ControllerClass.prototype, { dataElementType: registry.getElement(dataElementType), datasetElementType: datasetElementType && registry.getElement(datasetElementType) diff --git a/src/helpers/helpers.extras.js b/src/helpers/helpers.extras.js index 2b73328f9ac..6f065d7c955 100644 --- a/src/helpers/helpers.extras.js +++ b/src/helpers/helpers.extras.js @@ -1,3 +1,5 @@ +import {_limitValue} from './helpers.math'; +import {_lookupByKey} from './helpers.collection'; export function fontString(pixelSize, fontStyle, fontFamily) { return fontStyle + ' ' + pixelSize + 'px ' + fontFamily; @@ -87,3 +89,66 @@ export const _textX = (align, left, right, rtl) => { const check = rtl ? 'left' : 'right'; return align === check ? right : align === 'center' ? (left + right) / 2 : left; }; + +/** + * Return start and count of visible points. + * @param {object} meta - dataset meta. + * @param {array} points - array of point elements. + * @param {boolean} animationsDisabled - if true animation is disabled. + * @returns {{start: number; count: number}} + */ +export function getStartAndCountOfVisiblePoints(meta, points, animationsDisabled) { + const pointCount = points.length; + + let start = 0; + let count = pointCount; + + if (meta._sorted) { + const {iScale, _parsed} = meta; + const axis = iScale.axis; + const {min, max, minDefined, maxDefined} = iScale.getUserBounds(); + + if (minDefined) { + start = _limitValue(Math.min( + _lookupByKey(_parsed, iScale.axis, min).lo, + animationsDisabled ? pointCount : _lookupByKey(points, axis, iScale.getPixelForValue(min)).lo), + 0, pointCount - 1); + } + if (maxDefined) { + count = _limitValue(Math.max( + _lookupByKey(_parsed, iScale.axis, max).hi + 1, + animationsDisabled ? 0 : _lookupByKey(points, axis, iScale.getPixelForValue(max)).hi + 1), + start, pointCount) - start; + } else { + count = pointCount - start; + } + } + + return {start, count}; +} + +/** + * Checks if the scale ranges have changed. + * @param {object} meta - dataset meta. + * @returns {boolean} + */ +export function scaleRangesChanged(meta) { + const {xScale, yScale, _scaleRanges} = meta; + const newRanges = { + xmin: xScale.min, + xmax: xScale.max, + ymin: yScale.min, + ymax: yScale.max + }; + if (!_scaleRanges) { + meta._scaleRanges = newRanges; + return true; + } + const changed = _scaleRanges.xmin !== xScale.min + || _scaleRanges.xmax !== xScale.max + || _scaleRanges.ymin !== yScale.min + || _scaleRanges.ymax !== yScale.max; + + Object.assign(_scaleRanges, newRanges); + return changed; +} diff --git a/types/helpers/helpers.extras.d.ts b/types/helpers/helpers.extras.d.ts index cb445c32793..820d3489c54 100644 --- a/types/helpers/helpers.extras.d.ts +++ b/types/helpers/helpers.extras.d.ts @@ -21,3 +21,19 @@ export function throttled(fn: (...args: unknown[]) => void, thisArg: unknown, up * @returns {function} */ export function debounce(fn: () => void, delay: number): () => number; + +/** + * Return start and count of visible points. + * @param {object} meta - dataset meta. + * @param {array} points - array of point elements. + * @param {boolean} animationsDisabled - if true animation is disabled. + * @returns {{start: number; count: number}} + */ +export function getStartAndCountOfVisiblePoints(meta?: unknown, points?: unknown[], animationsDisabled?: boolean): {start: number; count: number}; + +/** + * Checks if the scale ranges have changed. + * @param {object} meta - dataset meta. + * @returns {boolean} + */ +export function scaleRangesChanged(meta?: unknown): boolean; From d3844de83188bde8181dc6c0c580b1990afde072 Mon Sep 17 00:00:00 2001 From: "v.terekhov" Date: Wed, 29 Jun 2022 23:23:05 +0400 Subject: [PATCH 3/6] feat: mark methods for scatter and line conntrollers as private --- src/controllers/controller.line.js | 6 +++--- src/controllers/controller.scatter.js | 6 +++--- src/helpers/helpers.extras.js | 6 ++++-- types/helpers/helpers.extras.d.ts | 16 ---------------- 4 files changed, 10 insertions(+), 24 deletions(-) diff --git a/src/controllers/controller.line.js b/src/controllers/controller.line.js index 756675c65e0..3ddd09896e0 100644 --- a/src/controllers/controller.line.js +++ b/src/controllers/controller.line.js @@ -1,7 +1,7 @@ import DatasetController from '../core/core.datasetController'; import {isNullOrUndef} from '../helpers'; import {isNumber} from '../helpers/helpers.math'; -import {getStartAndCountOfVisiblePoints, scaleRangesChanged} from '../helpers/helpers.extras'; +import {_getStartAndCountOfVisiblePoints, _scaleRangesChanged} from '../helpers/helpers.extras'; export default class LineController extends DatasetController { @@ -16,12 +16,12 @@ export default class LineController extends DatasetController { const {dataset: line, data: points = [], _dataset} = meta; // @ts-ignore const animationsDisabled = this.chart._animationsDisabled; - let {start, count} = getStartAndCountOfVisiblePoints(meta, points, animationsDisabled); + let {start, count} = _getStartAndCountOfVisiblePoints(meta, points, animationsDisabled); this._drawStart = start; this._drawCount = count; - if (scaleRangesChanged(meta)) { + if (_scaleRangesChanged(meta)) { start = 0; count = points.length; } diff --git a/src/controllers/controller.scatter.js b/src/controllers/controller.scatter.js index 965e58a88bf..ac8e861291c 100644 --- a/src/controllers/controller.scatter.js +++ b/src/controllers/controller.scatter.js @@ -1,7 +1,7 @@ import DatasetController from '../core/core.datasetController'; import {isNullOrUndef} from '../helpers'; import {isNumber} from '../helpers/helpers.math'; -import {getStartAndCountOfVisiblePoints, scaleRangesChanged} from '../helpers/helpers.extras'; +import {_getStartAndCountOfVisiblePoints, _scaleRangesChanged} from '../helpers/helpers.extras'; import registry from '../core/core.registry'; export default class ScatterController extends DatasetController { @@ -19,12 +19,12 @@ export default class ScatterController extends DatasetController { const {data: points = []} = meta; // @ts-ignore const animationsDisabled = this.chart._animationsDisabled; - let {start, count} = getStartAndCountOfVisiblePoints(meta, points, animationsDisabled); + let {start, count} = _getStartAndCountOfVisiblePoints(meta, points, animationsDisabled); this._drawStart = start; this._drawCount = count; - if (scaleRangesChanged(meta)) { + if (_scaleRangesChanged(meta)) { start = 0; count = points.length; } diff --git a/src/helpers/helpers.extras.js b/src/helpers/helpers.extras.js index 6f065d7c955..686affb2787 100644 --- a/src/helpers/helpers.extras.js +++ b/src/helpers/helpers.extras.js @@ -96,8 +96,9 @@ export const _textX = (align, left, right, rtl) => { * @param {array} points - array of point elements. * @param {boolean} animationsDisabled - if true animation is disabled. * @returns {{start: number; count: number}} + * @private */ -export function getStartAndCountOfVisiblePoints(meta, points, animationsDisabled) { +export function _getStartAndCountOfVisiblePoints(meta, points, animationsDisabled) { const pointCount = points.length; let start = 0; @@ -131,8 +132,9 @@ export function getStartAndCountOfVisiblePoints(meta, points, animationsDisabled * Checks if the scale ranges have changed. * @param {object} meta - dataset meta. * @returns {boolean} + * @private */ -export function scaleRangesChanged(meta) { +export function _scaleRangesChanged(meta) { const {xScale, yScale, _scaleRanges} = meta; const newRanges = { xmin: xScale.min, diff --git a/types/helpers/helpers.extras.d.ts b/types/helpers/helpers.extras.d.ts index 820d3489c54..cb445c32793 100644 --- a/types/helpers/helpers.extras.d.ts +++ b/types/helpers/helpers.extras.d.ts @@ -21,19 +21,3 @@ export function throttled(fn: (...args: unknown[]) => void, thisArg: unknown, up * @returns {function} */ export function debounce(fn: () => void, delay: number): () => number; - -/** - * Return start and count of visible points. - * @param {object} meta - dataset meta. - * @param {array} points - array of point elements. - * @param {boolean} animationsDisabled - if true animation is disabled. - * @returns {{start: number; count: number}} - */ -export function getStartAndCountOfVisiblePoints(meta?: unknown, points?: unknown[], animationsDisabled?: boolean): {start: number; count: number}; - -/** - * Checks if the scale ranges have changed. - * @param {object} meta - dataset meta. - * @returns {boolean} - */ -export function scaleRangesChanged(meta?: unknown): boolean; From 97f2ffd9997a60007b4c9f54a2029328010e3929 Mon Sep 17 00:00:00 2001 From: "v.terekhov" Date: Tue, 12 Jul 2022 17:14:34 +0400 Subject: [PATCH 4/6] fix: fix error when showline is true at root options and add tests --- src/controllers/controller.scatter.js | 19 ++--- test/specs/controller.scatter.tests.js | 103 +++++++++++++++++++++++++ 2 files changed, 113 insertions(+), 9 deletions(-) diff --git a/src/controllers/controller.scatter.js b/src/controllers/controller.scatter.js index ac8e861291c..3943f815eb7 100644 --- a/src/controllers/controller.scatter.js +++ b/src/controllers/controller.scatter.js @@ -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; @@ -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; diff --git a/test/specs/controller.scatter.tests.js b/test/specs/controller.scatter.tests.js index 3f0b17594d5..1e89849a40f 100644 --- a/test/specs/controller.scatter.tests.js +++ b/test/specs/controller.scatter.tests.js @@ -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); + }); }); From 121563552a25f6c924e1296357d3d76474a89e0c Mon Sep 17 00:00:00 2001 From: "v.terekhov" Date: Fri, 29 Jul 2022 13:04:55 +0400 Subject: [PATCH 5/6] feat: remove else inside scatter controller update --- src/controllers/controller.scatter.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/controllers/controller.scatter.js b/src/controllers/controller.scatter.js index 3943f815eb7..ee229120bc0 100644 --- a/src/controllers/controller.scatter.js +++ b/src/controllers/controller.scatter.js @@ -36,8 +36,6 @@ export default class ScatterController extends DatasetController { animated: !animationsDisabled, options }, mode); - } else { - this.options.borderWidth = 0; } // Update Points From 9418f9727fa3f00b5fc2ed840641468a08117e6d Mon Sep 17 00:00:00 2001 From: "v.terekhov" Date: Mon, 1 Aug 2022 13:32:13 +0400 Subject: [PATCH 6/6] fix: update getStartAndCountOFVisiblePoints helper code --- src/helpers/helpers.extras.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/helpers/helpers.extras.js b/src/helpers/helpers.extras.js index 686affb2787..8bab58ae182 100644 --- a/src/helpers/helpers.extras.js +++ b/src/helpers/helpers.extras.js @@ -117,8 +117,8 @@ export function _getStartAndCountOfVisiblePoints(meta, points, animationsDisable } if (maxDefined) { count = _limitValue(Math.max( - _lookupByKey(_parsed, iScale.axis, max).hi + 1, - animationsDisabled ? 0 : _lookupByKey(points, axis, iScale.getPixelForValue(max)).hi + 1), + _lookupByKey(_parsed, iScale.axis, max, true).hi + 1, + animationsDisabled ? 0 : _lookupByKey(points, axis, iScale.getPixelForValue(max), true).hi + 1), start, pointCount) - start; } else { count = pointCount - start;