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(tooltip): improve positioning with popperjs #651

Merged
merged 52 commits into from
May 28, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
5ee6ad0
fix: tooltip container scroll issue
nickofthyme Apr 23, 2020
8a18b7a
Merge branch 'master' into fix/tooltip-scroll
nickofthyme Apr 23, 2020
072b09f
fix: type error in dist
nickofthyme Apr 23, 2020
0140bd2
fix: possibly fix the scrollbar in all charts
markov00 Apr 24, 2020
f574e6d
refactor: improve tooltip postioning logic
nickofthyme Apr 27, 2020
5e09582
cleanup: remove highlight type, update popper
nickofthyme Apr 28, 2020
83ef7e4
Merge branch 'master' into feat/popper-poc
nickofthyme Apr 29, 2020
f91b9cf
refactor: tooltip portal to functional component
nickofthyme Apr 29, 2020
b379f99
refactor: decouple tooltip and portal logic
nickofthyme Apr 29, 2020
547dab4
refactor: move portal into seperate folder and cleanup types
nickofthyme Apr 29, 2020
e0fecf1
feat: expand tooltip placement options
nickofthyme Apr 29, 2020
24892d1
refactor: combine real anchor and invisble anchor ref into single prop
nickofthyme Apr 29, 2020
618148e
refactor: move annotations, pull out rect and line tooltip render com…
nickofthyme Apr 29, 2020
e07649a
refactor: line and rect annotations to use Portal
nickofthyme Apr 30, 2020
3b30486
fix: line tooltip annotation position
nickofthyme Apr 30, 2020
87a57b4
fix: final cleanup of code before ready for review
nickofthyme Apr 30, 2020
4184fcb
fix: use full version of popper until library is using babel for tree…
nickofthyme Apr 30, 2020
df7675f
fix: cleanup debug styles in portal
nickofthyme Apr 30, 2020
c3b31dc
Merge branch 'master' into feat/popper-poc
nickofthyme Apr 30, 2020
73f8495
feat: add fallback knobs
nickofthyme Apr 30, 2020
a0b7cd4
fix: settings error
nickofthyme Apr 30, 2020
e64700a
fix: tooltip render on partition charts
nickofthyme Apr 30, 2020
842b11b
fix: variable naming
nickofthyme Apr 30, 2020
afc7227
test: update annotations utils to use non-projected cursor
nickofthyme Apr 30, 2020
5227c93
ci: enforce no .only in tests on ci
nickofthyme Apr 30, 2020
9d2deb5
test: update vrt
nickofthyme Apr 30, 2020
a43f7d8
test: update vrt screenshots based on changes
nickofthyme Apr 30, 2020
6261e6c
fix: multiple charts issue and scrolling issues
nickofthyme May 4, 2020
ccfe32e
fix: prevent popper updates when tooltip is not visible
nickofthyme May 4, 2020
dc5a01e
Merge branch 'master' into feat/popper-poc
nickofthyme May 4, 2020
8094278
fix: scss and typings build issues
nickofthyme May 4, 2020
7467d2a
test: update vrt to better test tooltip placement and rotations
nickofthyme May 5, 2020
884aacb
Merge branch 'master' into feat/popper-poc
nickofthyme May 5, 2020
d76de27
Merge branch 'master' into feat/popper-poc
nickofthyme May 5, 2020
eeb574f
test: fix missed vrt update
nickofthyme May 5, 2020
a6f5ded
Merge branch 'master' into feat/popper-poc
monfera May 19, 2020
26954a8
test: revert changes to vrt, add to seperate pr
nickofthyme May 26, 2020
a38ada2
refactor: rename portal to tooltip portal
nickofthyme May 26, 2020
e7256b6
refactor: cleanup hook logic
nickofthyme May 26, 2020
95def5f
Merge branch 'master' into feat/popper-poc
nickofthyme May 26, 2020
ddc44cb
fix: remove forced non-null
nickofthyme May 26, 2020
9d43a4b
fix: remove cruft from highlight tooltip type
nickofthyme May 26, 2020
c517407
test: remove all stale screenshots
nickofthyme May 26, 2020
37bd0b8
test: add back missing screenshots
nickofthyme May 26, 2020
0b365c6
docs: update api docs
nickofthyme May 26, 2020
7060feb
test: update screenshots
nickofthyme May 26, 2020
7efd73f
fix: variable naming in playground
nickofthyme May 27, 2020
1c3b868
Merge branch 'master' into feat/popper-poc
monfera May 27, 2020
9c534e7
fix: broken knobs, add rotation based defaults for popper placement
nickofthyme May 27, 2020
2484f23
docs: fix api-extractor warnings for tooltips
markov00 May 28, 2020
492b426
docs: fix api-extractor warnings for placements
markov00 May 28, 2020
514d8ac
Merge branch 'master' into feat/popper-poc
nickofthyme May 28, 2020
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
43 changes: 16 additions & 27 deletions api/charts.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,9 @@ export const CurveType: Readonly<{
// @public (undocumented)
export type CurveType = $Values<typeof CurveType>;

// @public
export type CustomTooltip = ComponentType<TooltipInfo>;

// Warning: (ae-missing-release-tag) "DARK_THEME" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
Expand Down Expand Up @@ -494,14 +497,10 @@ export const DEFAULT_MISSING_COLOR = "red";
// @public (undocumented)
export const DEFAULT_SETTINGS_SPEC: SettingsSpec;

// Warning: (ae-missing-release-tag) "DEFAULT_TOOLTIP_SNAP" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
// @public
export const DEFAULT_TOOLTIP_SNAP = true;

// Warning: (ae-missing-release-tag) "DEFAULT_TOOLTIP_TYPE" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
// @public
export const DEFAULT_TOOLTIP_TYPE: "vertical";

// Warning: (ae-missing-release-tag) "DefaultSettingsProps" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
Expand Down Expand Up @@ -1322,7 +1321,6 @@ export interface SettingsSpec extends Spec {
showLegend: boolean;
showLegendExtra: boolean;
theme?: PartialTheme | PartialTheme[];
// (undocumented)
tooltip: TooltipSettings;
// Warning: (ae-forgotten-export) The symbol "Domain" needs to be exported by the entry point index.d.ts
//
Expand Down Expand Up @@ -1455,33 +1453,28 @@ export type TickStyle = StrokeStyle & Visible;
// @public (undocumented)
export function timeFormatter(format: string): TickFormatter;

// Warning: (ae-missing-release-tag) "TooltipProps" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
// @public
export interface TooltipInfo {
header: TooltipValue | null;
values: TooltipValue[];
}

// @public
export interface TooltipProps {
boundary?: HTMLElement | 'chart';
// Warning: (ae-forgotten-export) The symbol "CustomTooltip" needs to be exported by the entry point index.d.ts
customTooltip?: CustomTooltip;
fallbackPlacements?: Placement[];
// (undocumented)
headerFormatter?: TooltipValueFormatter;
placement?: Placement;
// (undocumented)
snap?: boolean;
// (undocumented)
type?: TooltipType;
// (undocumented)
// @alpha
unit?: string;
}

// Warning: (ae-missing-release-tag) "TooltipSettings" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public
export type TooltipSettings = TooltipType | TooltipProps;

// Warning: (ae-missing-release-tag) "TooltipType" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
// Warning: (ae-missing-release-tag) "TooltipType" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public
export const TooltipType: Readonly<{
VerticalCursor: "vertical";
Expand All @@ -1490,12 +1483,10 @@ export const TooltipType: Readonly<{
None: "none";
}>;

// @public (undocumented)
// @public
export type TooltipType = $Values<typeof TooltipType>;

// Warning: (ae-missing-release-tag) "TooltipValue" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
// @public
export interface TooltipValue {
color: Color;
isHighlighted: boolean;
Expand All @@ -1507,9 +1498,7 @@ export interface TooltipValue {
valueAccessor?: Accessor;
}

// Warning: (ae-missing-release-tag) "TooltipValueFormatter" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
// @public
export type TooltipValueFormatter = (data: TooltipValue) => JSX.Element | string;

// @public
Expand Down
16 changes: 16 additions & 0 deletions src/components/tooltip/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,27 @@ import { ComponentType } from 'react';

import { TooltipValue } from '../../specs';

/**
* The set of info used to render the a tooltip.
* @public
*/
export interface TooltipInfo {
/**
* The TooltipValue for the header. On XYAxis chart the x value
*/
header: TooltipValue | null;
/**
* The array of {@link TooltipValue}s to show on the tooltip.
* On XYAxis chart correspond to the set of y values for each series
*/
values: TooltipValue[];
}

/**
* The react component used to render a custom tooltip
* with the {@link TooltipInfo} props
* @public
*/
export type CustomTooltip = ComponentType<TooltipInfo>;

/** @internal */
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export { Layer as PartitionLayer } from './chart_types/partition_chart/specs/ind
export { Goal } from './chart_types/goal_chart/specs/index';
export { AccessorFn, IndexedAccessorFn, UnaryAccessorFn } from './utils/accessor';
export { SpecTypes } from './specs/settings';
export { CustomTooltip, TooltipInfo } from './components/tooltip/types';

// scales
export { ScaleType } from './scales';
Expand Down
50 changes: 49 additions & 1 deletion src/specs/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ export interface PointerOutEvent extends BasePointerEvent {

export type PointerEvent = PointerOverEvent | PointerOutEvent;

/** The type of tooltip to use */
/**
* This enums provides the available tooltip types
* @public
*/
export const TooltipType = Object.freeze({
/** Vertical cursor parallel to x axis */
VerticalCursor: 'vertical' as 'vertical',
Expand All @@ -111,6 +114,10 @@ export const TooltipType = Object.freeze({
None: 'none' as 'none',
});

/**
* The TooltipType
* @public
*/
export type TooltipType = $Values<typeof TooltipType>;

export const BrushAxis = Object.freeze({
Expand All @@ -121,6 +128,10 @@ export const BrushAxis = Object.freeze({

export type BrushAxis = $Values<typeof BrushAxis>;

/**
* This interface describe the properties of single value shown in the tooltip
* @public
*/
export interface TooltipValue {
/**
* The label of the tooltip value
Expand Down Expand Up @@ -156,11 +167,28 @@ export interface TooltipValue {
valueAccessor?: Accessor;
}

/**
* A value formatter of a {@link (TooltipValue:type) | TooltipValue}
* @public
*/
export type TooltipValueFormatter = (data: TooltipValue) => JSX.Element | string;

/**
* The advanced configuration for the tooltip
* @public
*/
export interface TooltipProps {
/**
* The {@link (TooltipType:type) | TooltipType} of the tooltip
*/
type?: TooltipType;
/**
* Whenever the tooltip needs to snap to the x/band position or not
*/
snap?: boolean;
/**
* A {@link TooltipValueFormatter} to format the header value
*/
headerFormatter?: TooltipValueFormatter;
/**
* Preferred placement of tooltip relative to anchor.
Expand All @@ -183,6 +211,11 @@ export interface TooltipProps {
* @defaultValue parent scroll container
*/
boundary?: HTMLElement | 'chart';
/**
* Unit for event (i.e. `time`, `feet`, `count`, etc.).
* Not currently used/implemented
* @alpha
*/
unit?: string;
Comment on lines +214 to 219
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👍

/**
* Render custom tooltip given header and values
Expand All @@ -192,6 +225,7 @@ export interface TooltipProps {

/**
* Either a TooltipType or an object with configuration of type, snap, and/or headerFormatter
* @public
*/
export type TooltipSettings = TooltipType | TooltipProps;

Expand Down Expand Up @@ -246,6 +280,9 @@ export interface SettingsSpec extends Spec {
rotation: Rotation;
animateData: boolean;
showLegend: boolean;
/**
* The tooltip configuration forr the chart {@link TooltipSettings}
*/
tooltip: TooltipSettings;
debug: boolean;
legendPosition: Position;
Expand Down Expand Up @@ -314,7 +351,18 @@ export type DefaultSettingsProps =
| 'brushAxis'
| 'minBrushDelta';

/**
* Default value for the tooltip type
* @defaultValue `vertical` {@link (TooltipType:type) | TooltipType.VerticalCursor}
* @public
*/
export const DEFAULT_TOOLTIP_TYPE = TooltipType.VerticalCursor;

/**
* Default value for the tooltip snap
* @defaultValue `true`
* @public
*/
export const DEFAULT_TOOLTIP_SNAP = true;

export const SpecTypes = Object.freeze({
Expand Down