Skip to content

Commit

Permalink
feat(addon-charts): add index to hint context
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimirpotekhin committed Apr 1, 2022
1 parent 7c419db commit 6afcb90
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
Renderer2,
} from '@angular/core';
import {ANIMATION_FRAME} from '@ng-web-apis/common';
import {TuiLineChartHintContext} from '@taiga-ui/addon-charts';
import {
EMPTY_QUERY,
TuiContextWithImplicit,
Expand Down Expand Up @@ -73,7 +74,7 @@ export class TuiLineChartHintDirective {
getContext(
index: number,
_chart: TuiLineChartComponent,
): TuiContextWithImplicit<readonly TuiPoint[]> {
): TuiLineChartHintContext<readonly TuiPoint[]> {
return this.computeContext(index, this.charts);
}

Expand All @@ -96,9 +97,10 @@ export class TuiLineChartHintDirective {
private computeContext(
index: number,
charts: QueryList<TuiLineChartComponent>,
): TuiContextWithImplicit<readonly TuiPoint[]> {
): TuiLineChartHintContext<readonly TuiPoint[]> {
return {
$implicit: charts.map(chart => chart.value[index]),
index,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import {
NgZone,
Optional,
} from '@angular/core';
import {TuiLineChartHintContext} from '@taiga-ui/addon-charts/interfaces';
import {draw} from '@taiga-ui/addon-charts/utils';
import {
inRange,
TuiContextWithImplicit,
tuiDefaultProp,
TuiIdService,
tuiPure,
Expand Down Expand Up @@ -70,7 +70,7 @@ export class TuiLineChartComponent {

@Input()
@tuiDefaultProp()
hintContent: PolymorpheusContent<TuiContextWithImplicit<TuiPoint>> = '';
hintContent: PolymorpheusContent<TuiLineChartHintContext<TuiPoint>> = '';

@Input()
@tuiDefaultProp()
Expand Down Expand Up @@ -170,10 +170,14 @@ export class TuiLineChartComponent {
return `${this.autoIdString}_${index}`;
}

getContentContext($implicit: TuiPoint): TuiContextWithImplicit<readonly TuiPoint[]> {
getContentContext(
$implicit: TuiPoint,
index: number,
): TuiLineChartHintContext<readonly TuiPoint[]> {
return (
this.hintDirective?.getContext(this.value.indexOf($implicit), this) || {
$implicit: [],
index,
}
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@
polymorpheus-outlet
class="t-text"
[content]="hintDirective.hint"
[context]="getContentContext(point)"
[context]="getContentContext(point, index)"
></div>
<ng-template #single>
<div
polymorpheus-outlet
class="t-text"
[content]="hintContent"
[context]="{ $implicit: point }"
[context]="{ $implicit: point, index: index }"
></div>
</ng-template>
</ng-template>
Expand Down
1 change: 1 addition & 0 deletions projects/addon-charts/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './line-chart-hint-context';
export * from './ring-chart-context';
5 changes: 5 additions & 0 deletions projects/addon-charts/interfaces/line-chart-hint-context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {TuiContextWithImplicit} from '@taiga-ui/cdk';

export interface TuiLineChartHintContext<T> extends TuiContextWithImplicit<T> {
readonly index?: number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
[height]="200"
[value]="singleValue"
[dots]="true"
[hintContent]="hint"
[hintContent]="hintContent"
></tui-line-chart>
</tui-axes>

<ng-template #hintContent let-value let-index="index">
<div>Vertical: {{value[0]}}</div>
<div>Horizontal: {{value[1]}}</div>
<div>index: {{index}}</div>
</ng-template>

0 comments on commit 6afcb90

Please sign in to comment.