diff --git a/projects/addon-charts/components/bar-chart/bar-chart.component.ts b/projects/addon-charts/components/bar-chart/bar-chart.component.ts index 97e12722a708..fdf6feae4ada 100644 --- a/projects/addon-charts/components/bar-chart/bar-chart.component.ts +++ b/projects/addon-charts/components/bar-chart/bar-chart.component.ts @@ -1,5 +1,13 @@ -import {ChangeDetectionStrategy, Component, Inject, Input} from '@angular/core'; import { + ChangeDetectionStrategy, + Component, + Inject, + Input, + QueryList, + ViewChildren, +} from '@angular/core'; +import { + EMPTY_QUERY, sum, TuiContextWithImplicit, tuiDefaultProp, @@ -7,8 +15,9 @@ import { TuiMapper, tuiPure, } from '@taiga-ui/cdk'; -import {TuiHintMode, TuiSizeL, TuiSizeS} from '@taiga-ui/core'; +import {TuiDriver, TuiSizeL, TuiSizeS} from '@taiga-ui/core'; import {PolymorpheusContent} from '@tinkoff/ng-polymorpheus'; +import {Observable} from 'rxjs'; function valueAssertion(value: ReadonlyArray): boolean { const valid = value.every(array => array.length === value[0].length); @@ -27,6 +36,9 @@ const VALUE_ERROR = `All arrays must be of the same length`; export class TuiBarChartComponent { private readonly autoIdString: string; + @ViewChildren(TuiDriver) + readonly drivers: QueryList> = EMPTY_QUERY; + @Input() @tuiDefaultProp(valueAssertion, VALUE_ERROR) value: ReadonlyArray = []; @@ -49,7 +61,7 @@ export class TuiBarChartComponent { @Input() @tuiDefaultProp() - hintMode: TuiHintMode | null = null; + hintAppearance = ``; constructor(@Inject(TuiIdService) idService: TuiIdService) { this.autoIdString = idService.generate(); @@ -67,13 +79,6 @@ export class TuiBarChartComponent { return this.max || this.getMax(this.value, this.collapsed); } - @tuiPure - getContentContext(index: number): TuiContextWithImplicit { - return { - $implicit: index, - }; - } - readonly percentMapper: TuiMapper = ( set, collapsed: boolean, diff --git a/projects/addon-charts/components/bar-chart/bar-chart.style.less b/projects/addon-charts/components/bar-chart/bar-chart.style.less index 3cb3f6e68b0d..d555f67a13e1 100644 --- a/projects/addon-charts/components/bar-chart/bar-chart.style.less +++ b/projects/addon-charts/components/bar-chart/bar-chart.style.less @@ -15,9 +15,13 @@ justify-content: center; height: 100%; - &_hoverable._hint_hovered { - background-color: rgba(0, 0, 0, 0.05); + &_hoverable { cursor: pointer; + + &:hover, + &.t-wrapper_hovered { + background-color: rgba(0, 0, 0, 0.05); + } } } @@ -40,7 +44,3 @@ box-shadow: 0 0 0 2px var(--tui-focus); } } - -.t-text { - white-space: pre-wrap; -} diff --git a/projects/addon-charts/components/bar-chart/bar-chart.template.html b/projects/addon-charts/components/bar-chart/bar-chart.template.html index 4af286298cd1..f54d24060cf2 100644 --- a/projects/addon-charts/components/bar-chart/bar-chart.template.html +++ b/projects/addon-charts/components/bar-chart/bar-chart.template.html @@ -3,10 +3,11 @@ tuiHintDirection="top-left" class="t-wrapper" [class.t-wrapper_hoverable]="hasHint" + [class.t-wrapper_hovered]="drivers.get(index) | async" [tuiHintHost]="hintHost" [tuiHintId]="getHintId(index)" [tuiHint]="getHint(hint)" - [tuiHintMode]="hintMode" + [tuiHintAppearance]="hintAppearance" >
-
+ + + {{ text }} +
diff --git a/projects/addon-charts/components/line-chart/line-chart-hint.directive.ts b/projects/addon-charts/components/line-chart/line-chart-hint.directive.ts index e52f8c94e390..ffdd0a09b9c7 100644 --- a/projects/addon-charts/components/line-chart/line-chart-hint.directive.ts +++ b/projects/addon-charts/components/line-chart/line-chart-hint.directive.ts @@ -1,4 +1,5 @@ import { + AfterContentInit, ContentChildren, Directive, ElementRef, @@ -9,35 +10,28 @@ import { QueryList, Renderer2, } from '@angular/core'; -import {ANIMATION_FRAME} from '@ng-web-apis/common'; import {TuiLineChartHintContext} from '@taiga-ui/addon-charts/interfaces'; import { EMPTY_QUERY, TuiContextWithImplicit, tuiDefaultProp, TuiDestroyService, + TuiHoveredService, tuiPure, tuiZonefree, } from '@taiga-ui/cdk'; -import {HINT_HOVERED_CLASS, TuiPoint} from '@taiga-ui/core'; +import {TuiPoint} from '@taiga-ui/core'; import {PolymorpheusContent} from '@tinkoff/ng-polymorpheus'; -import {Observable} from 'rxjs'; -import { - distinctUntilChanged, - filter, - map, - startWith, - takeUntil, - throttleTime, -} from 'rxjs/operators'; +import {combineLatest, Observable} from 'rxjs'; +import {distinctUntilChanged, filter, map, startWith, takeUntil} from 'rxjs/operators'; import {TuiLineChartComponent} from './line-chart.component'; @Directive({ selector: `[tuiLineChartHint]`, - providers: [TuiDestroyService], + providers: [TuiDestroyService, TuiHoveredService], }) -export class TuiLineChartHintDirective { +export class TuiLineChartHintDirective implements AfterContentInit { @ContentChildren(forwardRef(() => TuiLineChartComponent)) private readonly charts: QueryList = EMPTY_QUERY; @@ -50,20 +44,18 @@ export class TuiLineChartHintDirective { constructor( @Inject(Renderer2) private readonly renderer: Renderer2, - @Inject(TuiDestroyService) destroy$: TuiDestroyService, - @Inject(ElementRef) {nativeElement}: ElementRef, - @Inject(NgZone) ngZone: NgZone, - @Inject(ANIMATION_FRAME) animationFrame$: Observable, - ) { - animationFrame$ + @Inject(TuiDestroyService) private readonly destroy$: TuiDestroyService, + @Inject(NgZone) private readonly ngZone: NgZone, + @Inject(TuiHoveredService) private readonly hovered$: Observable, + ) {} + + ngAfterContentInit(): void { + combineLatest([tuiLineChartDrivers(this.charts), this.hovered$]) .pipe( - throttleTime(200), - map(() => !!nativeElement.querySelector(`.${HINT_HOVERED_CLASS}`)), - startWith(false), - distinctUntilChanged(), - filter(v => !v), - tuiZonefree(ngZone), - takeUntil(destroy$), + map(([drivers, hovered]) => !drivers && !hovered), + filter(Boolean), + tuiZonefree(this.ngZone), + takeUntil(this.destroy$), ) .subscribe(() => { this.charts.forEach(chart => chart.onHovered(NaN)); @@ -104,3 +96,16 @@ export class TuiLineChartHintDirective { }; } } + +export function tuiLineChartDrivers( + charts: QueryList<{drivers: QueryList>}>, +): Observable { + return combineLatest( + charts + .map(({drivers}) => drivers.map(driver => driver.pipe(startWith(false)))) + .reduce((acc, drivers) => acc.concat(drivers), []), + ).pipe( + map(values => values.some(Boolean)), + distinctUntilChanged(), + ); +} diff --git a/projects/addon-charts/components/line-chart/line-chart.component.ts b/projects/addon-charts/components/line-chart/line-chart.component.ts index 16ea1f8f4a02..02ed152daf67 100644 --- a/projects/addon-charts/components/line-chart/line-chart.component.ts +++ b/projects/addon-charts/components/line-chart/line-chart.component.ts @@ -7,10 +7,13 @@ import { Input, NgZone, Optional, + QueryList, + ViewChildren, } from '@angular/core'; import {TuiLineChartHintContext} from '@taiga-ui/addon-charts/interfaces'; import {tuiDraw} from '@taiga-ui/addon-charts/utils'; import { + EMPTY_QUERY, tuiDefaultProp, TuiIdService, tuiInRange, @@ -18,7 +21,7 @@ import { TuiStringHandler, tuiZoneOptimized, } from '@taiga-ui/cdk'; -import {TuiPoint} from '@taiga-ui/core'; +import {TuiDriver, TuiPoint} from '@taiga-ui/core'; import {PolymorpheusContent} from '@tinkoff/ng-polymorpheus'; import {Observable, Subject} from 'rxjs'; import {distinctUntilChanged} from 'rxjs/operators'; @@ -36,6 +39,9 @@ export class TuiLineChartComponent { private readonly autoIdString: string; + @ViewChildren(TuiDriver) + readonly drivers: QueryList> = EMPTY_QUERY; + @Input(`value`) @tuiDefaultProp() set valueSetter(value: readonly TuiPoint[]) { diff --git a/projects/addon-charts/components/line-chart/line-chart.style.less b/projects/addon-charts/components/line-chart/line-chart.style.less index e50dbb414923..50513de0beb1 100644 --- a/projects/addon-charts/components/line-chart/line-chart.style.less +++ b/projects/addon-charts/components/line-chart/line-chart.style.less @@ -44,7 +44,7 @@ &:focus, .t-column_hovered &, .t-column:hover &, - .t-column._hint_hovered & { + .t-column_hint_hovered & { opacity: 1; } } @@ -69,18 +69,14 @@ :host[style^='z-index: 0'] .t-column_hovered &, :host:not([style]) .t-column:hover &, - :host:not([style]) .t-column._hint_hovered &, + :host:not([style]) .t-column_hint_hovered &, :host[style^='z-index: 0'] .t-column_hovered + &, :host:not([style]) .t-column:hover + &, - :host:not([style]) .t-column._hint_hovered + & { + :host:not([style]) .t-column_hint_hovered + & { opacity: 1; } } -.t-text { - white-space: pre-wrap; -} - .t-hint { .shadow(); position: absolute; diff --git a/projects/addon-charts/components/line-chart/line-chart.template.html b/projects/addon-charts/components/line-chart/line-chart.template.html index 1e0560e9e640..8860e35dba78 100644 --- a/projects/addon-charts/components/line-chart/line-chart.template.html +++ b/projects/addon-charts/components/line-chart/line-chart.template.html @@ -53,9 +53,10 @@
+ -
+ > + {{ text }} +
-
+ > + {{ text }} +
diff --git a/projects/addon-charts/components/line-days-chart/line-days-chart-hint.directive.ts b/projects/addon-charts/components/line-days-chart/line-days-chart-hint.directive.ts index b9fcaeda7364..01b3b99342e2 100644 --- a/projects/addon-charts/components/line-days-chart/line-days-chart-hint.directive.ts +++ b/projects/addon-charts/components/line-days-chart/line-days-chart-hint.directive.ts @@ -1,42 +1,37 @@ import { + AfterContentInit, ContentChildren, Directive, - ElementRef, forwardRef, Inject, Input, NgZone, QueryList, } from '@angular/core'; -import {ANIMATION_FRAME} from '@ng-web-apis/common'; +import {tuiLineChartDrivers} from '@taiga-ui/addon-charts/components/line-chart'; import { EMPTY_QUERY, TuiContextWithImplicit, TuiDay, tuiDefaultProp, TuiDestroyService, + TuiHoveredService, tuiPure, tuiZonefree, } from '@taiga-ui/cdk'; -import {HINT_HOVERED_CLASS, TuiPoint} from '@taiga-ui/core'; +import {TuiPoint} from '@taiga-ui/core'; import {PolymorpheusContent} from '@tinkoff/ng-polymorpheus'; -import {Observable} from 'rxjs'; -import { - distinctUntilChanged, - filter, - map, - startWith, - takeUntil, - throttleTime, -} from 'rxjs/operators'; +import {combineLatest, Observable} from 'rxjs'; +import {filter, map, takeUntil} from 'rxjs/operators'; import {TuiLineDaysChartComponent} from './line-days-chart.component'; +// TODO: Consider extending TuiLineChartHintDirective @Directive({ selector: `[tuiLineChartHint]`, - providers: [TuiDestroyService], + providers: [TuiDestroyService, TuiHoveredService], }) -export class TuiLineDaysChartHintDirective { +export class TuiLineDaysChartHintDirective implements AfterContentInit { @ContentChildren(forwardRef(() => TuiLineDaysChartComponent)) private readonly charts: QueryList = EMPTY_QUERY; @@ -45,23 +40,21 @@ export class TuiLineDaysChartHintDirective { hint: PolymorpheusContent> = ``; constructor( - @Inject(TuiDestroyService) destroy$: TuiDestroyService, - @Inject(ElementRef) {nativeElement}: ElementRef, - @Inject(NgZone) ngZone: NgZone, - @Inject(ANIMATION_FRAME) animationFrame$: Observable, - ) { - animationFrame$ + @Inject(TuiDestroyService) private readonly destroy$: TuiDestroyService, + @Inject(NgZone) private readonly ngZone: NgZone, + @Inject(TuiHoveredService) private readonly hovered$: Observable, + ) {} + + ngAfterContentInit(): void { + combineLatest([tuiLineChartDrivers(this.charts), this.hovered$]) .pipe( - throttleTime(200), - map(() => !!nativeElement.querySelector(`.${HINT_HOVERED_CLASS}`)), - startWith(false), - distinctUntilChanged(), - tuiZonefree(ngZone), - filter(v => !v), - takeUntil(destroy$), + map(([drivers, hovered]) => !drivers && !hovered), + filter(Boolean), + tuiZonefree(this.ngZone), + takeUntil(this.destroy$), ) .subscribe(() => { - this.charts.forEach(chart => chart.onHovered(null)); + this.charts.forEach(chart => chart.onHovered(NaN)); }); } diff --git a/projects/addon-charts/components/line-days-chart/line-days-chart.component.ts b/projects/addon-charts/components/line-days-chart/line-days-chart.component.ts index 095245897c43..0dfc55710faf 100644 --- a/projects/addon-charts/components/line-days-chart/line-days-chart.component.ts +++ b/projects/addon-charts/components/line-days-chart/line-days-chart.component.ts @@ -20,12 +20,14 @@ import { TuiContextWithImplicit, TuiDay, tuiDefaultProp, + tuiIsNumber, TuiMonth, tuiPure, TuiStringHandler, } from '@taiga-ui/cdk'; -import {TuiPoint} from '@taiga-ui/core'; +import {TuiDriver, TuiPoint} from '@taiga-ui/core'; import {PolymorpheusContent} from '@tinkoff/ng-polymorpheus'; +import {Observable} from 'rxjs'; import {TuiLineDaysChartHintDirective} from './line-days-chart-hint.directive'; @@ -47,6 +49,9 @@ export class TuiLineDaysChartComponent { @ViewChildren(TuiLineChartComponent) private readonly charts: QueryList = EMPTY_QUERY; + @ViewChildren(TuiDriver) + readonly drivers: QueryList> = EMPTY_QUERY; + @Input(`value`) @tuiDefaultProp() set valueSetter(value: ReadonlyArray<[TuiDay, number]>) { @@ -143,8 +148,8 @@ export class TuiLineDaysChartComponent { return index - offset; } - onHovered(day: TuiDay | null): void { - if (!day) { + onHovered(day: TuiDay | number): void { + if (tuiIsNumber(day)) { this.charts.forEach(chart => chart.onHovered(NaN)); return; diff --git a/projects/addon-charts/components/pie-chart/pie-chart.component.ts b/projects/addon-charts/components/pie-chart/pie-chart.component.ts index 160cdf5788e8..ca28a4301288 100644 --- a/projects/addon-charts/components/pie-chart/pie-chart.component.ts +++ b/projects/addon-charts/components/pie-chart/pie-chart.component.ts @@ -16,7 +16,7 @@ import { tuiPure, tuiSum, } from '@taiga-ui/cdk'; -import {TuiSizeXL, TuiSizeXS} from '@taiga-ui/core'; +import {tuiHintOptionsProvider, TuiSizeXL, TuiSizeXS} from '@taiga-ui/core'; import {PolymorpheusContent} from '@tinkoff/ng-polymorpheus'; const RADII = { @@ -39,6 +39,7 @@ const TRANSFORM = { templateUrl: `./pie-chart.template.html`, styleUrls: [`./pie-chart.style.less`], changeDetection: ChangeDetectionStrategy.OnPush, + providers: [tuiHintOptionsProvider({showDelay: 0, hideDelay: 0})], }) export class TuiPieChartComponent { private readonly autoIdString: string; diff --git a/projects/addon-charts/components/pie-chart/pie-chart.module.ts b/projects/addon-charts/components/pie-chart/pie-chart.module.ts index 35c8bd72daad..7e993e107837 100644 --- a/projects/addon-charts/components/pie-chart/pie-chart.module.ts +++ b/projects/addon-charts/components/pie-chart/pie-chart.module.ts @@ -1,7 +1,7 @@ import {CommonModule} from '@angular/common'; import {NgModule} from '@angular/core'; import {TuiHoveredModule, TuiRepeatTimesModule} from '@taiga-ui/cdk'; -import {TuiPointerHintModule} from '@taiga-ui/core'; +import {TuiHintModule} from '@taiga-ui/core'; import {PolymorpheusModule} from '@tinkoff/ng-polymorpheus'; import {TuiPieChartComponent} from './pie-chart.component'; @@ -13,7 +13,7 @@ import {TuiPieChartDirective} from './pie-chart.directive'; TuiRepeatTimesModule, TuiHoveredModule, PolymorpheusModule, - TuiPointerHintModule, + TuiHintModule, ], declarations: [TuiPieChartComponent, TuiPieChartDirective], exports: [TuiPieChartComponent], diff --git a/projects/addon-charts/components/pie-chart/pie-chart.style.less b/projects/addon-charts/components/pie-chart/pie-chart.style.less index fbbab72754e7..99fb91861ebf 100644 --- a/projects/addon-charts/components/pie-chart/pie-chart.style.less +++ b/projects/addon-charts/components/pie-chart/pie-chart.style.less @@ -54,7 +54,3 @@ .t-placeholder { fill: var(--tui-base-03); } - -.t-text { - white-space: pre-wrap; -} diff --git a/projects/addon-charts/components/pie-chart/pie-chart.template.html b/projects/addon-charts/components/pie-chart/pie-chart.template.html index 28a616ce1ddc..2979a7010161 100644 --- a/projects/addon-charts/components/pie-chart/pie-chart.template.html +++ b/projects/addon-charts/components/pie-chart/pie-chart.template.html @@ -33,14 +33,15 @@ *tuiRepeatTimes="let index of segments.length" fill="currentColor" automation-id="tui-pie-chart__segment" - tuiHintMode="onDark" + tuiHintPointer + tuiHintAppearance="onDark" tuiHintDirection="top-right" d="" class="t-segment" [attr.transform]="getTransform(index)" [style.color]="getColor(index)" [tuiPieChart]="segments[index]" - [tuiPointerHint]="getHint(hint)" + [tuiHint]="getHint(hint)" (tuiHoveredChange)="onHovered($event, index)" > @@ -56,9 +57,8 @@ #template let-index > -
+ + + {{ text }} +
diff --git a/projects/addon-preview/components/preview/preview.module.ts b/projects/addon-preview/components/preview/preview.module.ts index 45b53419b6c5..dd11b13527f8 100644 --- a/projects/addon-preview/components/preview/preview.module.ts +++ b/projects/addon-preview/components/preview/preview.module.ts @@ -8,7 +8,6 @@ import { TuiButtonModule, TuiHintModule, TuiLoaderModule, - TuiManualHintModule, TuiSvgModule, } from '@taiga-ui/core'; import {TuiSliderModule} from '@taiga-ui/kit'; @@ -31,7 +30,6 @@ import {TuiPreviewZoomComponent} from './zoom/preview-zoom.component'; TuiSliderModule, TuiHintModule, TuiDragModule, - TuiManualHintModule, TuiResizeModule, TuiSvgModule, TuiLoaderModule, diff --git a/projects/addon-preview/components/preview/preview.template.html b/projects/addon-preview/components/preview/preview.template.html index 108712d15140..4f230d82498e 100644 --- a/projects/addon-preview/components/preview/preview.template.html +++ b/projects/addon-preview/components/preview/preview.template.html @@ -38,7 +38,7 @@ icon="tuiIconRotate" tuiHintId="Rotate" tuiHintDirection="top-right" - tuiHintMode="onDark" + tuiHintAppearance="onDark" class="t-rotate-button" [tuiHint]="texts.rotate" (click)="rotate()" diff --git a/projects/addon-preview/components/preview/zoom/preview-zoom.template.html b/projects/addon-preview/components/preview/zoom/preview-zoom.template.html index cefaf4a96ecf..b7ccb23da3bf 100644 --- a/projects/addon-preview/components/preview/zoom/preview-zoom.template.html +++ b/projects/addon-preview/components/preview/zoom/preview-zoom.template.html @@ -11,10 +11,10 @@ >