From 92ec9e1256b7d3ca9c808a9cedb2f98c36f4314f Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Wed, 7 Jun 2023 13:53:31 +0200 Subject: [PATCH] MOBILE-4273 core: Lazy-load ChartJS --- src/core/components/chart/chart.lazy.ts | 15 +++++++++++++++ src/core/components/chart/chart.ts | 4 +++- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/core/components/chart/chart.lazy.ts diff --git a/src/core/components/chart/chart.lazy.ts b/src/core/components/chart/chart.lazy.ts new file mode 100644 index 000000000..08fd31f04 --- /dev/null +++ b/src/core/components/chart/chart.lazy.ts @@ -0,0 +1,15 @@ +// (C) Copyright 2015 Moodle Pty Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +export { Chart } from 'chart.js'; diff --git a/src/core/components/chart/chart.ts b/src/core/components/chart/chart.ts index 8f181e239..8643f8285 100644 --- a/src/core/components/chart/chart.ts +++ b/src/core/components/chart/chart.ts @@ -16,7 +16,7 @@ import { Component, Input, OnDestroy, OnInit, ElementRef, OnChanges, ViewChild, import { CoreFilter } from '@features/filter/services/filter'; import { CoreFilterHelper } from '@features/filter/services/filter-helper'; import { CoreUtils } from '@services/utils/utils'; -import { Chart, ChartLegendLabelItem, ChartLegendOptions } from 'chart.js'; +import { ChartLegendLabelItem, ChartLegendOptions } from 'chart.js'; /** * This component shows a chart using chart.js. @@ -99,6 +99,8 @@ export class CoreChartComponent implements OnDestroy, OnInit, OnChanges { return; } + const { Chart } = await import('./chart.lazy'); + this.chart = new Chart(context, { type: this.type, data: {