Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: hold traces tooltip on hover #2387

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import { CartesianLegend } from '../legend/cartesian-legend';
import { ScaleBounds } from '../scale/cartesian-scale';
import { CartesianScaleBuilder } from '../scale/cartesian-scale-builder';
import { tap } from 'rxjs/operators';

export class DefaultCartesianChart<TData> implements CartesianChart<TData> {
public static DATA_SERIES_CLASS: string = 'data-series';
Expand Down Expand Up @@ -75,6 +76,7 @@

private activeSeriesSubscription?: Subscription;
private activeSeries: Series<TData>[] = [];
// private lastDataPoint?: TData;

public constructor(
protected readonly hostElement: Element,
Expand Down Expand Up @@ -608,16 +610,22 @@
}

private onMouseLeave(): void {
if (this.tooltip) {
this.tooltip.hide();
}

this.eventListeners.forEach(listener => {
if (listener.event === ChartEvent.MouseLeave) {
listener.onEvent();
}
});

this.hideCrosshair();
this.tooltip?.hovered$
.pipe(
tap(onHoverTooltip => {

Check warning on line 615 in projects/observability/src/shared/components/cartesian/d3/chart/cartesian-chart.ts

View check run for this annotation

Codecov / codecov/patch

projects/observability/src/shared/components/cartesian/d3/chart/cartesian-chart.ts#L615

Added line #L615 was not covered by tests
if (!onHoverTooltip) {
this.tooltip?.hide();

this.eventListeners.forEach(listener => {

Check warning on line 619 in projects/observability/src/shared/components/cartesian/d3/chart/cartesian-chart.ts

View check run for this annotation

Codecov / codecov/patch

projects/observability/src/shared/components/cartesian/d3/chart/cartesian-chart.ts#L619

Added line #L619 was not covered by tests
if (listener.event === ChartEvent.MouseLeave) {
listener.onEvent();

Check warning on line 621 in projects/observability/src/shared/components/cartesian/d3/chart/cartesian-chart.ts

View check run for this annotation

Codecov / codecov/patch

projects/observability/src/shared/components/cartesian/d3/chart/cartesian-chart.ts#L621

Added line #L621 was not covered by tests
}
});

this.hideCrosshair();

Check warning on line 625 in projects/observability/src/shared/components/cartesian/d3/chart/cartesian-chart.ts

View check run for this annotation

Codecov / codecov/patch

projects/observability/src/shared/components/cartesian/d3/chart/cartesian-chart.ts#L625

Added line #L625 was not covered by tests
}
})
)
.subscribe();
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { PopoverPositionType, PopoverRef } from '@hypertrace/components';
import { Observer } from 'rxjs';
import { Observable, Observer } from 'rxjs';
import { MouseLocationData } from '../mouse-tracking/mouse-tracking';

export class ChartTooltipPopover<TData, TContext> implements ChartTooltipRef<TData, TContext> {
private boundElement?: Element;
public readonly hovered$: Observable<boolean>;

public constructor(
private readonly popoverRef: PopoverRef,
private readonly dataObserver: Observer<MouseLocationData<TData, TContext>[]>
) {}
) {
this.hovered$ = popoverRef.hovered$;
}

public showWithData(element: Element, data: MouseLocationData<TData, TContext>[]): void {
this.updatePositionStrategyIfNeeded(element);
Expand All @@ -30,8 +33,8 @@ export class ChartTooltipPopover<TData, TContext> implements ChartTooltipRef<TDa
this.popoverRef.updatePositionStrategy({
type: PopoverPositionType.FollowMouse,
boundingElement: element,
offsetX: 20,
offsetY: 30
offsetX: 0,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would be the impact of this change at other places?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will be changing the way that we display the tooltip keeping it visible when the user has the cursor on the tooltip but will not break the functionality.

offsetY: 0
});
this.boundElement = element;
}
Expand All @@ -42,4 +45,5 @@ export interface ChartTooltipRef<TData, TContext = unknown> {
showWithData(relativeTo: Element, data: MouseLocationData<TData, TContext>[]): void;
hide(): void;
destroy(): void;
hovered$: Observable<boolean>;
}
Loading