This is an automated email from the ASF dual-hosted git repository. shenyi pushed a commit to branch enhance-missing-components-log in repository https://gitbox.apache.org/repos/asf/echarts.git
commit da7d797cdd1a9568aa8d2becff0afb7ca04e6be4 Author: pissang <[email protected]> AuthorDate: Wed Mar 31 13:29:01 2021 +0800 fix(marker): only use maker component when exists on series --- .../{installMarkLine.ts => checkMarkerInSeries.ts} | 29 ++++++++++++++-------- src/component/marker/installMarkArea.ts | 7 ++++-- src/component/marker/installMarkLine.ts | 7 ++++-- src/component/marker/installMarkPoint.ts | 7 ++++-- 4 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/component/marker/installMarkLine.ts b/src/component/marker/checkMarkerInSeries.ts similarity index 56% copy from src/component/marker/installMarkLine.ts copy to src/component/marker/checkMarkerInSeries.ts index 2946b71..5f87a4c 100644 --- a/src/component/marker/installMarkLine.ts +++ b/src/component/marker/checkMarkerInSeries.ts @@ -16,16 +16,25 @@ * specific language governing permissions and limitations * under the License. */ -import { EChartsExtensionInstallRegisters } from '../../extension'; -import MarkLineModel from './MarkLineModel'; -import MarkLineView from './MarkLineView'; -export function install(registers: EChartsExtensionInstallRegisters) { - registers.registerComponentModel(MarkLineModel); - registers.registerComponentView(MarkLineView); +import { isArray } from 'zrender/src/core/util'; +import { SeriesOption } from '../../util/types'; - registers.registerPreprocessor(function (opt) { - // Make sure markLine component is enabled - opt.markLine = opt.markLine || {}; - }); +type MarkerTypes = 'markPoint' | 'markLine' | 'markArea'; + +type SeriesWithMarkerOption = SeriesOption & Partial<Record<MarkerTypes, unknown>>; + +export default function checkMarkerInSeries( + seriesOpts: SeriesOption | SeriesOption[], markerType: MarkerTypes +): boolean { + if (!seriesOpts) { + return false; + } + const seriesOptArr = isArray(seriesOpts) ? seriesOpts : [seriesOpts]; + for (let idx = 0; idx < seriesOptArr.length; idx++) { + if (seriesOptArr[idx] && (seriesOptArr[idx] as SeriesWithMarkerOption)[markerType]) { + return true; + } + } + return false; } \ No newline at end of file diff --git a/src/component/marker/installMarkArea.ts b/src/component/marker/installMarkArea.ts index a34b07d..1d41f58 100644 --- a/src/component/marker/installMarkArea.ts +++ b/src/component/marker/installMarkArea.ts @@ -18,6 +18,7 @@ */ import { EChartsExtensionInstallRegisters } from '../../extension'; +import checkMarkerInSeries from './checkMarkerInSeries'; import MarkAreaModel from './MarkAreaModel'; import MarkAreaView from './MarkAreaView'; @@ -26,7 +27,9 @@ export function install(registers: EChartsExtensionInstallRegisters) { registers.registerComponentView(MarkAreaView); registers.registerPreprocessor(function (opt) { - // Make sure markArea component is enabled - opt.markArea = opt.markArea || {}; + if (checkMarkerInSeries(opt.series, 'markArea')) { + // Make sure markLine component is enabled + opt.markLine = opt.markLine || {}; + } }); } \ No newline at end of file diff --git a/src/component/marker/installMarkLine.ts b/src/component/marker/installMarkLine.ts index 2946b71..b8542ab 100644 --- a/src/component/marker/installMarkLine.ts +++ b/src/component/marker/installMarkLine.ts @@ -17,6 +17,7 @@ * under the License. */ import { EChartsExtensionInstallRegisters } from '../../extension'; +import checkMarkerInSeries from './checkMarkerInSeries'; import MarkLineModel from './MarkLineModel'; import MarkLineView from './MarkLineView'; @@ -25,7 +26,9 @@ export function install(registers: EChartsExtensionInstallRegisters) { registers.registerComponentView(MarkLineView); registers.registerPreprocessor(function (opt) { - // Make sure markLine component is enabled - opt.markLine = opt.markLine || {}; + if (checkMarkerInSeries(opt.series, 'markLine')) { + // Make sure markLine component is enabled + opt.markLine = opt.markLine || {}; + } }); } \ No newline at end of file diff --git a/src/component/marker/installMarkPoint.ts b/src/component/marker/installMarkPoint.ts index 7526ddd..3d7cbf3 100644 --- a/src/component/marker/installMarkPoint.ts +++ b/src/component/marker/installMarkPoint.ts @@ -17,6 +17,7 @@ * under the License. */ import { EChartsExtensionInstallRegisters } from '../../extension'; +import checkMarkerInSeries from './checkMarkerInSeries'; import MarkPointModel from './MarkPointModel'; import MarkPointView from './MarkPointView'; @@ -25,7 +26,9 @@ export function install(registers: EChartsExtensionInstallRegisters) { registers.registerComponentView(MarkPointView); registers.registerPreprocessor(function (opt) { - // Make sure markPoint component is enabled - opt.markPoint = opt.markPoint || {}; + if (checkMarkerInSeries(opt.series, 'markPoint')) { + // Make sure markLine component is enabled + opt.markLine = opt.markLine || {}; + } }); } \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
