Skip to content

Commit

Permalink
perf(chart): make sure only to render chart when necessary (Teradata#37)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
emoralesb05 authored Nov 20, 2018
1 parent e0d72db commit 4107c31
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 28 deletions.
6 changes: 2 additions & 4 deletions src/app/components/types/graph/graph.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
<mat-tab-group mat-stretch-tabs dynamicHeight>
<mat-tab>
<ng-template matTabLabel>Demo</ng-template>
<td-chart [style.height.px]="500"
[config]="{ xAxis: { show: false }, yAxis: { show: false } }">
<td-chart [style.height.px]="500">
<td-chart-tooltip [trigger]="'item'">
<ng-template let-params let-i="index" let-ticket="ticket" tdTooltipFormatter>
<ng-container *ngIf="params">
Expand Down Expand Up @@ -73,8 +72,7 @@
<p>HTML: </p>
<td-highlight lang="html">
<![CDATA[
<td-chart [style.height.px]="500"
[config]="{ xAxis: { show: false }, yAxis: { show: false } }">
<td-chart [style.height.px]="500">
<td-chart-tooltip [trigger]="'item'">
<ng-template let-params let-i="index" let-ticket="ticket" tdTooltipFormatter>
<ng-container *ngIf="params">
Expand Down
6 changes: 2 additions & 4 deletions src/app/components/types/sankey/sankey.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
<mat-tab-group mat-stretch-tabs dynamicHeight>
<mat-tab>
<ng-template matTabLabel>Demo</ng-template>
<td-chart [style.height.px]="300"
[config]="{ xAxis: { show: false }, yAxis: { show: false }, grid: { borderColor: 'transparent' } }">
<td-chart [style.height.px]="300">
<td-chart-series td-sankey
[focusNodeAdjacency]="'allEdges'"
[right]="40"
Expand Down Expand Up @@ -74,8 +73,7 @@
<p>HTML: </p>
<td-highlight lang="html">
<![CDATA[
<td-chart [style.height.px]="300"
[config]="{ xAxis: { show: false }, yAxis: { show: false }, grid: { borderColor: 'transparent' } }">
<td-chart [style.height.px]="300">
<td-chart-series td-sankey
[focusNodeAdjacency]="'allEdges'"
[right]="40"
Expand Down
2 changes: 2 additions & 0 deletions src/app/components/types/scatter/scatter.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export class TypesScatterComponent {
right: 10,
data: ['1990', '2015'],
},
xAxis: [{show: true}],
yAxis: [{show: true}],
series: [
{
name: '1990',
Expand Down
6 changes: 2 additions & 4 deletions src/app/components/types/tree/tree.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
<mat-tab-group mat-stretch-tabs dynamicHeight>
<mat-tab>
<ng-template matTabLabel>Demo</ng-template>
<td-chart [style.height.px]="800"
[config]="{ xAxis: { show: false }, yAxis: { show: false }, grid: { borderColor: 'transparent' } }">
<td-chart [style.height.px]="800">
<td-chart-tooltip [trigger]="'item'">
<ng-template let-params let-ticket="ticket" tdTooltipFormatter>
<ng-container *ngIf="params">
Expand Down Expand Up @@ -319,8 +318,7 @@
<p>HTML: </p>
<td-highlight lang="html">
<![CDATA[
<td-chart [style.height.px]="800"
[config]="{ xAxis: { show: false }, yAxis: { show: false }, grid: { borderColor: 'transparent' } }">
<td-chart [style.height.px]="800">
<td-chart-tooltip [trigger]="'item'">
<ng-template let-params let-ticket="ticket" tdTooltipFormatter>
<ng-container *ngIf="params">
Expand Down
6 changes: 2 additions & 4 deletions src/app/components/types/treemap/treemap.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
<mat-tab-group mat-stretch-tabs dynamicHeight>
<mat-tab>
<ng-template matTabLabel>Demo</ng-template>
<td-chart [style.height.px]="800"
[config]="{ xAxis: { show: false }, yAxis: { show: false }, grid: { borderColor: 'transparent' } }">
<td-chart [style.height.px]="600">
<td-chart-tooltip [trigger]="'item'">
<ng-template let-params let-ticket="ticket" tdTooltipFormatter>
<ng-container *ngIf="params">
Expand Down Expand Up @@ -160,8 +159,7 @@
<p>HTML: </p>
<td-highlight lang="html">
<![CDATA[
<td-chart [style.height.px]="800"
[config]="{ xAxis: { show: false }, yAxis: { show: false }, grid: { borderColor: 'transparent' } }">
<td-chart [style.height.px]="600">
<td-chart-tooltip [trigger]="'item'">
<ng-template let-params let-ticket="ticket" tdTooltipFormatter>
<ng-container *ngIf="params">
Expand Down
14 changes: 8 additions & 6 deletions src/platform/echarts/base/chart.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/platform/echarts/graph/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class MyModule {}
Basic Example:

```html
<td-chart [config]="{ xAxis: { show: false }, yAxis: { show: false } }">
<td-chart>
<td-chart-series td-graph
[data]="[{ x: -739.36383, y: -404.26147, id: 'jquery', name: 'jquery',
symbolSize: 40.7252817, itemStyle: { normal: { color: '#4f19c7' } } },
Expand Down
2 changes: 1 addition & 1 deletion src/platform/echarts/sankey/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class MyModule {}
Basic Example:

```html
<td-chart [config]="{ xAxis: { show: false }, yAxis: { show: false }, grid: { borderColor: 'transparent' } }">
<td-chart>
<td-chart-series td-sankey
[focusNodeAdjacency]="'allEdges'"
[right]="40"
Expand Down
3 changes: 1 addition & 2 deletions src/platform/echarts/tree/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ export class MyModule {}
Basic Example:

```html
<td-chart [style.height.px]="800"
[config]="{ xAxis: { show: false }, yAxis: { show: false }, grid: { borderColor: 'transparent' } }">
<td-chart>
<td-chart-series td-tree
[leaves]="{ label: { position: 'right' } }"
[label]="{ position: 'left' }"
Expand Down
3 changes: 1 addition & 2 deletions src/platform/echarts/treemap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ export class MyModule {}
Basic Example:

```html
<td-chart [style.height.px]="800"
[config]="{ xAxis: { show: false }, yAxis: { show: false }, grid: { borderColor: 'transparent' } }">
<td-chart>
<td-chart-series td-treemap
[top]="'10%'"
[left]="'10%'"
Expand Down

0 comments on commit 4107c31

Please sign in to comment.