From 4107c31395053daa88953bd26229009c136e835d Mon Sep 17 00:00:00 2001 From: Ed Morales Date: Mon, 19 Nov 2018 17:03:04 -0800 Subject: [PATCH] perf(chart): make sure only to render chart when necessary (#37) * perf(chart): make sure only to render chart when necessary add a debounce and combine all options fed by subcomponents to render the chart only once.. before it was rerendered multiple times depending on changes on subcomponents * fix(): remove xAxis/yAxis from demo in tree/treemap * fix(): make demo fit screen better in treemap * fix(): change readme --- .../components/types/graph/graph.component.html | 6 ++---- .../components/types/sankey/sankey.component.html | 6 ++---- .../components/types/scatter/scatter.component.ts | 2 ++ src/app/components/types/tree/tree.component.html | 6 ++---- .../types/treemap/treemap.component.html | 6 ++---- src/platform/echarts/base/chart.component.ts | 14 ++++++++------ src/platform/echarts/graph/README.md | 2 +- src/platform/echarts/sankey/README.md | 2 +- src/platform/echarts/tree/README.md | 3 +-- src/platform/echarts/treemap/README.md | 3 +-- 10 files changed, 22 insertions(+), 28 deletions(-) diff --git a/src/app/components/types/graph/graph.component.html b/src/app/components/types/graph/graph.component.html index 403cb48ee5..c20fc2fd50 100644 --- a/src/app/components/types/graph/graph.component.html +++ b/src/app/components/types/graph/graph.component.html @@ -6,8 +6,7 @@ Demo - + @@ -73,8 +72,7 @@

HTML:

+ diff --git a/src/app/components/types/sankey/sankey.component.html b/src/app/components/types/sankey/sankey.component.html index 08bcee9094..4065dd8bc5 100644 --- a/src/app/components/types/sankey/sankey.component.html +++ b/src/app/components/types/sankey/sankey.component.html @@ -6,8 +6,7 @@ Demo - + HTML:

+ Demo - + @@ -319,8 +318,7 @@

HTML:

+ diff --git a/src/app/components/types/treemap/treemap.component.html b/src/app/components/types/treemap/treemap.component.html index a6a9997757..c464360d32 100644 --- a/src/app/components/types/treemap/treemap.component.html +++ b/src/app/components/types/treemap/treemap.component.html @@ -6,8 +6,7 @@ Demo - + @@ -160,8 +159,7 @@

HTML:

+ diff --git a/src/platform/echarts/base/chart.component.ts b/src/platform/echarts/base/chart.component.ts index a67dc204a9..5cd8d5d955 100644 --- a/src/platform/echarts/base/chart.component.ts +++ b/src/platform/echarts/base/chart.component.ts @@ -12,7 +12,7 @@ import { } from '@angular/core'; import { Subject, fromEvent, merge, timer } from 'rxjs'; -import { debounceTime, distinctUntilChanged, takeUntil } from 'rxjs/operators'; +import { debounceTime, distinctUntilChanged, takeUntil, tap } from 'rxjs/operators'; import * as echarts from 'echarts/lib/echarts'; @@ -95,9 +95,13 @@ export class TdChartComponent implements AfterViewInit, OnChanges, OnDestroy { this._changeDetectorRef.markForCheck(); } }); - this.render(); - this._optionsService.listen().subscribe((options: any) => { - assignDefined(this._options, options); + this._optionsService.listen().pipe( + tap((options: any) => { + assignDefined(this._options, options); + }), + debounceTime(0), + takeUntil(this._destroy), + ).subscribe(() => { this.render(); }); timer(500, 250).pipe( @@ -138,8 +142,6 @@ export class TdChartComponent implements AfterViewInit, OnChanges, OnDestroy { containLabel: true, borderColor: '#FCFCFC', }, - xAxis : [{}], // throws error if its empty - yAxis : [{}], // throws error if its empty }, this.config ? this.config : {}, this._options), true); this._changeDetectorRef.markForCheck(); } diff --git a/src/platform/echarts/graph/README.md b/src/platform/echarts/graph/README.md index 754235f59b..7486e95ec0 100644 --- a/src/platform/echarts/graph/README.md +++ b/src/platform/echarts/graph/README.md @@ -48,7 +48,7 @@ export class MyModule {} Basic Example: ```html - + + + +