victory-voronoi-container
Advanced tools
Comparing version 37.0.2 to 37.0.3-next.0
# victory-voronoi-container | ||
## 37.0.3-next.0 | ||
### Patch Changes | ||
- 65d02419f: Refactor containers and portal to function components | ||
- Updated dependencies [65d02419f] | ||
- victory-core@37.0.3-next.0 | ||
- victory-tooltip@37.0.3-next.0 | ||
## 37.0.2 | ||
@@ -4,0 +13,0 @@ |
export * from "./victory-voronoi-container"; | ||
export * from "./voronoi-helpers"; | ||
//# sourceMappingURL=index.d.ts.map |
import React from "react"; | ||
import { VictoryContainer, VictoryContainerProps, PaddingProps } from "victory-core"; | ||
declare type ComponentClass<TProps> = { | ||
new (props: TProps): React.Component<TProps>; | ||
}; | ||
import { VictoryContainerProps, PaddingProps, VictoryEventHandler } from "victory-core"; | ||
export interface VictoryVoronoiContainerProps extends VictoryContainerProps { | ||
@@ -10,3 +7,3 @@ activateData?: boolean; | ||
disable?: boolean; | ||
labels?: (point: any, index: number, points: any[]) => string; | ||
labels?: (point: any, index?: number, points?: any[]) => string; | ||
labelComponent?: React.ReactElement; | ||
@@ -20,135 +17,72 @@ mouseFollowTooltips?: boolean; | ||
voronoiPadding?: PaddingProps; | ||
horizontal?: boolean; | ||
} | ||
export declare function voronoiContainerMixin<TBase extends ComponentClass<TProps>, TProps extends VictoryVoronoiContainerProps>(Base: TBase): { | ||
new (props: TProps): { | ||
getDimension(props: any): any; | ||
getPoint(point: any): Pick<any, string>; | ||
getLabelPosition(props: any, labelProps: any, points: any): { | ||
center: any; | ||
x: any; | ||
x0: any; | ||
y: any; | ||
y0: any; | ||
} | { | ||
x: any; | ||
y: any; | ||
center: any; | ||
export declare const VICTORY_VORONOI_CONTAINER_DEFAULT_PROPS: { | ||
activateData: boolean; | ||
activateLabels: boolean; | ||
labelComponent: JSX.Element; | ||
voronoiPadding: number; | ||
}; | ||
export declare const useVictoryVoronoiContainer: (initialProps: VictoryVoronoiContainerProps) => { | ||
props: { | ||
mousePosition: { | ||
x: number; | ||
y: number; | ||
}; | ||
getStyle(props: any, points: any, type: any): any; | ||
getDefaultLabelProps(props: any, points: any): { | ||
orientation: string | undefined; | ||
pointerLength: number | undefined; | ||
constrainToVisibleArea: boolean | undefined; | ||
}; | ||
getLabelProps(props: any, points: any): any; | ||
getTooltip(props: any): React.DetailedReactHTMLElement<any, HTMLElement> | null; | ||
getChildren(props: VictoryVoronoiContainerProps): (string | number | React.ReactElement<any, string | React.JSXElementConstructor<any>> | React.ReactFragment | null)[]; | ||
context: unknown; | ||
setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<TProps>) => {} | Pick<{}, K> | null) | Pick<{}, K> | null, callback?: (() => void) | undefined): void; | ||
forceUpdate(callback?: (() => void) | undefined): void; | ||
render(): React.ReactNode; | ||
readonly props: Readonly<TProps>; | ||
state: Readonly<{}>; | ||
refs: { | ||
[key: string]: React.ReactInstance; | ||
}; | ||
componentDidMount?(): void; | ||
shouldComponentUpdate?(nextProps: Readonly<TProps>, nextState: Readonly<{}>, nextContext: any): boolean; | ||
componentWillUnmount?(): void; | ||
componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void; | ||
getSnapshotBeforeUpdate?(prevProps: Readonly<TProps>, prevState: Readonly<{}>): any; | ||
componentDidUpdate?(prevProps: Readonly<TProps>, prevState: Readonly<{}>, snapshot?: any): void; | ||
componentWillMount?(): void; | ||
UNSAFE_componentWillMount?(): void; | ||
componentWillReceiveProps?(nextProps: Readonly<TProps>, nextContext: any): void; | ||
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<TProps>, nextContext: any): void; | ||
componentWillUpdate?(nextProps: Readonly<TProps>, nextState: Readonly<{}>, nextContext: any): void; | ||
UNSAFE_componentWillUpdate?(nextProps: Readonly<TProps>, nextState: Readonly<{}>, nextContext: any): void; | ||
activePoints: any[]; | ||
activateData: boolean; | ||
activateLabels: boolean; | ||
disable?: boolean | undefined; | ||
labels?: ((point: any, index?: number, points?: any[]) => string) | undefined; | ||
labelComponent: JSX.Element; | ||
mouseFollowTooltips?: boolean | undefined; | ||
onActivated?: ((points: any[], props: VictoryVoronoiContainerProps) => void) | undefined; | ||
onDeactivated?: ((points: any[], props: VictoryVoronoiContainerProps) => void) | undefined; | ||
radius?: number | undefined; | ||
voronoiBlacklist?: (string | RegExp)[] | undefined; | ||
voronoiDimension?: "x" | "y" | undefined; | ||
voronoiPadding: PaddingProps; | ||
horizontal?: boolean | undefined; | ||
"aria-describedby"?: string | undefined; | ||
"aria-labelledby"?: string | undefined; | ||
children?: React.ReactElement<any, string | React.JSXElementConstructor<any>> | React.ReactElement<any, string | React.JSXElementConstructor<any>>[] | undefined; | ||
className?: string | undefined; | ||
containerId?: string | number | undefined; | ||
containerRef?: React.Ref<HTMLElement> | undefined; | ||
desc?: string | undefined; | ||
events?: React.DOMAttributes<any> | undefined; | ||
height?: number | undefined; | ||
name?: string | undefined; | ||
origin?: import("victory-core").OriginType | undefined; | ||
polar?: boolean | undefined; | ||
portalComponent?: React.ReactElement<any, string | React.JSXElementConstructor<any>> | undefined; | ||
portalZIndex?: number | undefined; | ||
preserveAspectRatio?: string | undefined; | ||
responsive?: boolean | undefined; | ||
role?: string | undefined; | ||
scale?: { | ||
x?: import("victory-core").D3Scale<any> | undefined; | ||
y?: import("victory-core").D3Scale<any> | undefined; | ||
} | undefined; | ||
style?: React.CSSProperties | undefined; | ||
tabIndex?: number | undefined; | ||
theme?: import("victory-core").VictoryThemeDefinition | undefined; | ||
title?: string | undefined; | ||
width?: number | undefined; | ||
ouiaId?: string | number | undefined; | ||
ouiaSafe?: boolean | undefined; | ||
ouiaType?: string | undefined; | ||
}; | ||
displayName: string; | ||
defaultProps: VictoryVoronoiContainerProps; | ||
defaultEvents(props: VictoryVoronoiContainerProps): ({ | ||
target: string; | ||
eventHandlers: { | ||
onMouseLeave: (evt: any, targetProps: any) => {}; | ||
onTouchCancel: (evt: any, targetProps: any) => {}; | ||
onMouseMove: (evt: any, targetProps: any) => {} | undefined; | ||
onTouchMove: (evt: any, targetProps: any) => {} | undefined; | ||
onMouseOver?: undefined; | ||
onMouseOut?: undefined; | ||
}; | ||
} | { | ||
target: string; | ||
eventHandlers: { | ||
onMouseLeave?: undefined; | ||
onTouchCancel?: undefined; | ||
onMouseMove?: undefined; | ||
onTouchMove?: undefined; | ||
onMouseOver?: undefined; | ||
onMouseOut?: undefined; | ||
} | { | ||
onMouseOver: () => null; | ||
onMouseOut: () => null; | ||
onMouseMove: () => null; | ||
onMouseLeave?: undefined; | ||
onTouchCancel?: undefined; | ||
onTouchMove?: undefined; | ||
}; | ||
})[]; | ||
} & TBase; | ||
children: React.ReactElement<any, string | React.JSXElementConstructor<any>>[]; | ||
}; | ||
export declare const VictoryVoronoiContainer: { | ||
new (props: VictoryVoronoiContainerProps): { | ||
getDimension(props: any): any; | ||
getPoint(point: any): Pick<any, string>; | ||
getLabelPosition(props: any, labelProps: any, points: any): { | ||
center: any; | ||
x: any; | ||
x0: any; | ||
y: any; | ||
y0: any; | ||
} | { | ||
x: any; | ||
y: any; | ||
center: any; | ||
}; | ||
getStyle(props: any, points: any, type: any): any; | ||
getDefaultLabelProps(props: any, points: any): { | ||
orientation: string | undefined; | ||
pointerLength: number | undefined; | ||
constrainToVisibleArea: boolean | undefined; | ||
}; | ||
getLabelProps(props: any, points: any): any; | ||
getTooltip(props: any): React.DetailedReactHTMLElement<any, HTMLElement> | null; | ||
getChildren(props: VictoryVoronoiContainerProps): (string | number | React.ReactElement<any, string | React.JSXElementConstructor<any>> | React.ReactFragment | null)[]; | ||
context: unknown; | ||
setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<VictoryVoronoiContainerProps>) => {} | Pick<{}, K> | null) | Pick<{}, K> | null, callback?: (() => void) | undefined): void; | ||
forceUpdate(callback?: (() => void) | undefined): void; | ||
render(): React.ReactNode; | ||
readonly props: Readonly<VictoryVoronoiContainerProps>; | ||
state: Readonly<{}>; | ||
refs: { | ||
[key: string]: React.ReactInstance; | ||
}; | ||
componentDidMount?(): void; | ||
shouldComponentUpdate?(nextProps: Readonly<VictoryVoronoiContainerProps>, nextState: Readonly<{}>, nextContext: any): boolean; | ||
componentWillUnmount?(): void; | ||
componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void; | ||
getSnapshotBeforeUpdate?(prevProps: Readonly<VictoryVoronoiContainerProps>, prevState: Readonly<{}>): any; | ||
componentDidUpdate?(prevProps: Readonly<VictoryVoronoiContainerProps>, prevState: Readonly<{}>, snapshot?: any): void; | ||
componentWillMount?(): void; | ||
UNSAFE_componentWillMount?(): void; | ||
componentWillReceiveProps?(nextProps: Readonly<VictoryVoronoiContainerProps>, nextContext: any): void; | ||
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<VictoryVoronoiContainerProps>, nextContext: any): void; | ||
componentWillUpdate?(nextProps: Readonly<VictoryVoronoiContainerProps>, nextState: Readonly<{}>, nextContext: any): void; | ||
UNSAFE_componentWillUpdate?(nextProps: Readonly<VictoryVoronoiContainerProps>, nextState: Readonly<{}>, nextContext: any): void; | ||
}; | ||
displayName: string; | ||
defaultProps: VictoryVoronoiContainerProps; | ||
defaultEvents(props: VictoryVoronoiContainerProps): ({ | ||
(initialProps: VictoryVoronoiContainerProps): JSX.Element; | ||
role: string; | ||
defaultEvents(initialProps: VictoryVoronoiContainerProps): ({ | ||
target: string; | ||
eventHandlers: { | ||
onMouseLeave: (evt: any, targetProps: any) => {}; | ||
onTouchCancel: (evt: any, targetProps: any) => {}; | ||
onMouseMove: (evt: any, targetProps: any) => {} | undefined; | ||
onTouchMove: (evt: any, targetProps: any) => {} | undefined; | ||
onMouseLeave: VictoryEventHandler; | ||
onTouchCancel: VictoryEventHandler; | ||
onMouseMove: VictoryEventHandler; | ||
onTouchMove: VictoryEventHandler; | ||
onMouseOver?: undefined; | ||
@@ -175,4 +109,3 @@ onMouseOut?: undefined; | ||
})[]; | ||
} & typeof VictoryContainer; | ||
export {}; | ||
}; | ||
//# sourceMappingURL=victory-voronoi-container.d.ts.map |
@@ -6,201 +6,211 @@ import _pick from "lodash/pick"; | ||
import { VictoryTooltip } from "victory-tooltip"; | ||
import { VictoryContainer, Helpers } from "victory-core"; | ||
import { Helpers, VictoryContainer } from "victory-core"; | ||
import { VoronoiHelpers } from "./voronoi-helpers"; | ||
export function voronoiContainerMixin(Base) { | ||
// @ts-expect-error "TS2545: A mixin class must have a constructor with a single rest parameter of type 'any[]'." | ||
return class VictoryVoronoiContainer extends Base { | ||
static displayName = "VictoryVoronoiContainer"; | ||
static defaultProps = { | ||
...VictoryContainer.defaultProps, | ||
activateData: true, | ||
activateLabels: true, | ||
labelComponent: /*#__PURE__*/React.createElement(VictoryTooltip, null), | ||
voronoiPadding: 5 | ||
}; | ||
static defaultEvents(props) { | ||
return [{ | ||
target: "parent", | ||
eventHandlers: { | ||
onMouseLeave: (evt, targetProps) => { | ||
return props.disable ? {} : VoronoiHelpers.onMouseLeave(evt, targetProps); | ||
}, | ||
onTouchCancel: (evt, targetProps) => { | ||
return props.disable ? {} : VoronoiHelpers.onMouseLeave(evt, targetProps); | ||
}, | ||
onMouseMove: (evt, targetProps) => { | ||
return props.disable ? {} : VoronoiHelpers.onMouseMove(evt, targetProps); | ||
}, | ||
onTouchMove: (evt, targetProps) => { | ||
return props.disable ? {} : VoronoiHelpers.onMouseMove(evt, targetProps); | ||
} | ||
} | ||
}, { | ||
target: "data", | ||
eventHandlers: props.disable ? {} : { | ||
onMouseOver: () => null, | ||
onMouseOut: () => null, | ||
onMouseMove: () => null | ||
} | ||
}]; | ||
export const VICTORY_VORONOI_CONTAINER_DEFAULT_PROPS = { | ||
activateData: true, | ||
activateLabels: true, | ||
labelComponent: /*#__PURE__*/React.createElement(VictoryTooltip, null), | ||
voronoiPadding: 5 | ||
}; | ||
const getPoint = point => { | ||
const whitelist = ["_x", "_x1", "_x0", "_y", "_y1", "_y0"]; | ||
return _pick(point, whitelist); | ||
}; | ||
export const useVictoryVoronoiContainer = initialProps => { | ||
const props = { | ||
...VICTORY_VORONOI_CONTAINER_DEFAULT_PROPS, | ||
...initialProps | ||
}; | ||
const { | ||
children | ||
} = props; | ||
const getDimension = () => { | ||
const { | ||
horizontal, | ||
voronoiDimension | ||
} = props; | ||
if (!horizontal || !voronoiDimension) { | ||
return voronoiDimension; | ||
} | ||
getDimension(props) { | ||
const { | ||
horizontal, | ||
voronoiDimension | ||
} = props; | ||
if (!horizontal || !voronoiDimension) { | ||
return voronoiDimension; | ||
} | ||
return voronoiDimension === "x" ? "y" : "x"; | ||
} | ||
getPoint(point) { | ||
const whitelist = ["_x", "_x1", "_x0", "_y", "_y1", "_y0"]; | ||
return _pick(point, whitelist); | ||
} | ||
getLabelPosition(props, labelProps, points) { | ||
const { | ||
mousePosition, | ||
mouseFollowTooltips | ||
} = props; | ||
const voronoiDimension = this.getDimension(props); | ||
const point = this.getPoint(points[0]); | ||
const basePosition = Helpers.scalePoint(props, point); | ||
let center = mouseFollowTooltips ? mousePosition : undefined; | ||
if (!voronoiDimension || points.length < 2) { | ||
return { | ||
...basePosition, | ||
center: _defaults({}, labelProps.center, center) | ||
}; | ||
} | ||
const x = voronoiDimension === "y" ? mousePosition.x : basePosition.x; | ||
const y = voronoiDimension === "x" ? mousePosition.y : basePosition.y; | ||
center = mouseFollowTooltips ? mousePosition : { | ||
x, | ||
y | ||
}; | ||
return voronoiDimension === "x" ? "y" : "x"; | ||
}; | ||
const getLabelPosition = (labelProps, points) => { | ||
const { | ||
mousePosition, | ||
mouseFollowTooltips | ||
} = props; | ||
const voronoiDimension = getDimension(); | ||
const point = getPoint(points[0]); | ||
const basePosition = Helpers.scalePoint(props, point); | ||
let center = mouseFollowTooltips ? mousePosition : undefined; | ||
if (!voronoiDimension || points.length < 2) { | ||
return { | ||
x, | ||
y, | ||
...basePosition, | ||
center: _defaults({}, labelProps.center, center) | ||
}; | ||
} | ||
getStyle(props, points, type) { | ||
const { | ||
labels, | ||
labelComponent, | ||
theme | ||
} = props; | ||
const componentProps = labelComponent.props || {}; | ||
const themeStyles = theme && theme.voronoi && theme.voronoi.style ? theme.voronoi.style : {}; | ||
const componentStyleArray = type === "flyout" ? componentProps.flyoutStyle : componentProps.style; | ||
return points.reduce((memo, datum, index) => { | ||
const labelProps = _defaults({}, componentProps, { | ||
datum, | ||
active: true | ||
}); | ||
const text = Helpers.isFunction(labels) ? labels(labelProps) : undefined; | ||
const textArray = text !== undefined ? `${text}`.split("\n") : []; | ||
const baseStyle = datum.style && datum.style[type] || {}; | ||
const componentStyle = Array.isArray(componentStyleArray) ? componentStyleArray[index] : componentStyleArray; | ||
const style = Helpers.evaluateStyle(_defaults({}, componentStyle, baseStyle, themeStyles[type]), labelProps); | ||
const styleArray = textArray.length ? textArray.map(() => style) : [style]; | ||
return memo.concat(styleArray); | ||
}, []); | ||
} | ||
getDefaultLabelProps(props, points) { | ||
const { | ||
voronoiDimension, | ||
horizontal, | ||
mouseFollowTooltips | ||
} = props; | ||
const point = this.getPoint(points[0]); | ||
const multiPoint = voronoiDimension && points.length > 1; | ||
const y = point._y1 !== undefined ? point._y1 : point._y; | ||
const defaultHorizontalOrientation = y < 0 ? "left" : "right"; | ||
const defaultOrientation = y < 0 ? "bottom" : "top"; | ||
const labelOrientation = horizontal ? defaultHorizontalOrientation : defaultOrientation; | ||
const orientation = mouseFollowTooltips ? undefined : labelOrientation; | ||
return { | ||
orientation, | ||
pointerLength: multiPoint ? 0 : undefined, | ||
constrainToVisibleArea: multiPoint || mouseFollowTooltips ? true : undefined | ||
}; | ||
} | ||
getLabelProps(props, points) { | ||
const { | ||
labels, | ||
scale, | ||
labelComponent, | ||
theme, | ||
width, | ||
height | ||
} = props; | ||
const componentProps = labelComponent.props || {}; | ||
const text = points.reduce((memo, datum) => { | ||
const labelProps = _defaults({}, componentProps, { | ||
datum, | ||
active: true | ||
}); | ||
const t = Helpers.isFunction(labels) ? labels(labelProps) : null; | ||
if (t === null || t === undefined) { | ||
return memo; | ||
} | ||
return memo.concat(`${t}`.split("\n")); | ||
}, []); | ||
// remove properties from first point to make datum | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const { | ||
childName, | ||
eventKey, | ||
style, | ||
continuous, | ||
...datum | ||
} = points[0]; | ||
const name = props.name === childName ? childName : `${props.name}-${childName}`; | ||
const labelProps = _defaults({ | ||
key: `${name}-${eventKey}-voronoi-tooltip`, | ||
id: `${name}-${eventKey}-voronoi-tooltip`, | ||
active: true, | ||
renderInPortal: false, | ||
activePoints: points, | ||
const x = voronoiDimension === "y" ? mousePosition.x : basePosition.x; | ||
const y = voronoiDimension === "x" ? mousePosition.y : basePosition.y; | ||
center = mouseFollowTooltips ? mousePosition : { | ||
x, | ||
y | ||
}; | ||
return { | ||
x, | ||
y, | ||
center: _defaults({}, labelProps.center, center) | ||
}; | ||
}; | ||
const getStyle = (points, type) => { | ||
const { | ||
labels, | ||
labelComponent, | ||
theme | ||
} = props; | ||
const componentProps = labelComponent.props || {}; | ||
const themeStyles = theme && theme.voronoi && theme.voronoi.style ? theme.voronoi.style : {}; | ||
const componentStyleArray = type === "flyout" ? componentProps.flyoutStyle : componentProps.style; | ||
return points.reduce((memo, datum, index) => { | ||
const labelProps = _defaults({}, componentProps, { | ||
datum, | ||
scale, | ||
theme | ||
}, componentProps, { | ||
text, | ||
width, | ||
height, | ||
style: this.getStyle(props, points, "labels"), | ||
flyoutStyle: this.getStyle(props, points, "flyout")[0] | ||
}, this.getDefaultLabelProps(props, points)); | ||
const labelPosition = this.getLabelPosition(props, labelProps, points); | ||
return _defaults({}, labelPosition, labelProps); | ||
} | ||
getTooltip(props) { | ||
const { | ||
labels, | ||
activePoints, | ||
labelComponent | ||
} = props; | ||
if (!labels) { | ||
return null; | ||
active: true | ||
}); | ||
const text = Helpers.isFunction(labels) ? labels(labelProps) : undefined; | ||
const textArray = text !== undefined ? `${text}`.split("\n") : []; | ||
const baseStyle = datum.style && datum.style[type] || {}; | ||
const componentStyle = Array.isArray(componentStyleArray) ? componentStyleArray[index] : componentStyleArray; | ||
const style = Helpers.evaluateStyle(_defaults({}, componentStyle, baseStyle, themeStyles[type]), labelProps); | ||
const styleArray = textArray.length ? textArray.map(() => style) : [style]; | ||
return memo.concat(styleArray); | ||
}, []); | ||
}; | ||
const getDefaultLabelProps = points => { | ||
const { | ||
voronoiDimension, | ||
horizontal, | ||
mouseFollowTooltips | ||
} = props; | ||
const point = getPoint(points[0]); | ||
const multiPoint = voronoiDimension && points.length > 1; | ||
const y = point._y1 !== undefined ? point._y1 : point._y; | ||
const defaultHorizontalOrientation = y < 0 ? "left" : "right"; | ||
const defaultOrientation = y < 0 ? "bottom" : "top"; | ||
const labelOrientation = horizontal ? defaultHorizontalOrientation : defaultOrientation; | ||
const orientation = mouseFollowTooltips ? undefined : labelOrientation; | ||
return { | ||
orientation, | ||
pointerLength: multiPoint ? 0 : undefined, | ||
constrainToVisibleArea: multiPoint || mouseFollowTooltips ? true : undefined | ||
}; | ||
}; | ||
const getLabelProps = points => { | ||
const { | ||
labels, | ||
scale, | ||
labelComponent, | ||
theme, | ||
width, | ||
height | ||
} = props; | ||
const componentProps = labelComponent.props || {}; | ||
const text = points.reduce((memo, datum) => { | ||
const labelProps = _defaults({}, componentProps, { | ||
datum, | ||
active: true | ||
}); | ||
const t = Helpers.isFunction(labels) ? labels(labelProps) : null; | ||
if (t === null || t === undefined) { | ||
return memo; | ||
} | ||
if (Array.isArray(activePoints) && activePoints.length) { | ||
const labelProps = this.getLabelProps(props, activePoints); | ||
const { | ||
text | ||
} = labelProps; | ||
const showLabel = Array.isArray(text) ? text.filter(Boolean).length : text; | ||
return showLabel ? /*#__PURE__*/React.cloneElement(labelComponent, labelProps) : null; | ||
} | ||
return memo.concat(`${t}`.split("\n")); | ||
}, []); | ||
// remove properties from first point to make datum | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const { | ||
childName, | ||
eventKey, | ||
style, | ||
continuous, | ||
...datum | ||
} = points[0]; | ||
const name = props.name === childName ? childName : `${props.name}-${childName}`; | ||
const labelProps = _defaults({ | ||
key: `${name}-${eventKey}-voronoi-tooltip`, | ||
id: `${name}-${eventKey}-voronoi-tooltip`, | ||
active: true, | ||
renderInPortal: false, | ||
activePoints: points, | ||
datum, | ||
scale, | ||
theme | ||
}, componentProps, { | ||
text, | ||
width, | ||
height, | ||
style: getStyle(points, "labels"), | ||
flyoutStyle: getStyle(points, "flyout")[0] | ||
}, getDefaultLabelProps(points)); | ||
const labelPosition = getLabelPosition(labelProps, points); | ||
return _defaults({}, labelPosition, labelProps); | ||
}; | ||
const getTooltip = () => { | ||
const { | ||
labels, | ||
activePoints, | ||
labelComponent | ||
} = props; | ||
if (!labels) { | ||
return null; | ||
} | ||
// Overrides method in VictoryContainer | ||
getChildren(props) { | ||
return [...React.Children.toArray(props.children), this.getTooltip(props)]; | ||
if (Array.isArray(activePoints) && activePoints.length) { | ||
const labelProps = getLabelProps(activePoints); | ||
const { | ||
text | ||
} = labelProps; | ||
const showLabel = Array.isArray(text) ? text.filter(Boolean).length : text; | ||
return showLabel ? /*#__PURE__*/React.cloneElement(labelComponent, labelProps) : null; | ||
} | ||
return null; | ||
}; | ||
} | ||
export const VictoryVoronoiContainer = voronoiContainerMixin(VictoryContainer); | ||
return { | ||
props, | ||
children: [...React.Children.toArray(children), getTooltip()] | ||
}; | ||
}; | ||
export const VictoryVoronoiContainer = initialProps => { | ||
const { | ||
props, | ||
children | ||
} = useVictoryVoronoiContainer(initialProps); | ||
return /*#__PURE__*/React.createElement(VictoryContainer, props, children); | ||
}; | ||
VictoryVoronoiContainer.role = "container"; | ||
VictoryVoronoiContainer.defaultEvents = initialProps => { | ||
const props = { | ||
...VICTORY_VORONOI_CONTAINER_DEFAULT_PROPS, | ||
...initialProps | ||
}; | ||
const createEventHandler = (handler, disabled) => | ||
// eslint-disable-next-line max-params | ||
(event, targetProps, eventKey, context) => disabled || props.disable ? {} : handler(event, { | ||
...props, | ||
...targetProps | ||
}, eventKey, context); | ||
return [{ | ||
target: "parent", | ||
eventHandlers: { | ||
onMouseLeave: createEventHandler(VoronoiHelpers.onMouseLeave), | ||
onTouchCancel: createEventHandler(VoronoiHelpers.onMouseLeave), | ||
onMouseMove: createEventHandler(VoronoiHelpers.onMouseMove), | ||
onTouchMove: createEventHandler(VoronoiHelpers.onMouseMove) | ||
} | ||
}, { | ||
target: "data", | ||
eventHandlers: props.disable ? {} : { | ||
onMouseOver: () => null, | ||
onMouseOut: () => null, | ||
onMouseMove: () => null | ||
} | ||
}]; | ||
}; |
@@ -0,0 +0,0 @@ /// <reference types="lodash" /> |
export * from "./victory-voronoi-container"; | ||
export * from "./voronoi-helpers"; | ||
//# sourceMappingURL=index.d.ts.map |
import React from "react"; | ||
import { VictoryContainer, VictoryContainerProps, PaddingProps } from "victory-core"; | ||
declare type ComponentClass<TProps> = { | ||
new (props: TProps): React.Component<TProps>; | ||
}; | ||
import { VictoryContainerProps, PaddingProps, VictoryEventHandler } from "victory-core"; | ||
export interface VictoryVoronoiContainerProps extends VictoryContainerProps { | ||
@@ -10,3 +7,3 @@ activateData?: boolean; | ||
disable?: boolean; | ||
labels?: (point: any, index: number, points: any[]) => string; | ||
labels?: (point: any, index?: number, points?: any[]) => string; | ||
labelComponent?: React.ReactElement; | ||
@@ -20,135 +17,72 @@ mouseFollowTooltips?: boolean; | ||
voronoiPadding?: PaddingProps; | ||
horizontal?: boolean; | ||
} | ||
export declare function voronoiContainerMixin<TBase extends ComponentClass<TProps>, TProps extends VictoryVoronoiContainerProps>(Base: TBase): { | ||
new (props: TProps): { | ||
getDimension(props: any): any; | ||
getPoint(point: any): Pick<any, string>; | ||
getLabelPosition(props: any, labelProps: any, points: any): { | ||
center: any; | ||
x: any; | ||
x0: any; | ||
y: any; | ||
y0: any; | ||
} | { | ||
x: any; | ||
y: any; | ||
center: any; | ||
export declare const VICTORY_VORONOI_CONTAINER_DEFAULT_PROPS: { | ||
activateData: boolean; | ||
activateLabels: boolean; | ||
labelComponent: JSX.Element; | ||
voronoiPadding: number; | ||
}; | ||
export declare const useVictoryVoronoiContainer: (initialProps: VictoryVoronoiContainerProps) => { | ||
props: { | ||
mousePosition: { | ||
x: number; | ||
y: number; | ||
}; | ||
getStyle(props: any, points: any, type: any): any; | ||
getDefaultLabelProps(props: any, points: any): { | ||
orientation: string | undefined; | ||
pointerLength: number | undefined; | ||
constrainToVisibleArea: boolean | undefined; | ||
}; | ||
getLabelProps(props: any, points: any): any; | ||
getTooltip(props: any): React.DetailedReactHTMLElement<any, HTMLElement> | null; | ||
getChildren(props: VictoryVoronoiContainerProps): (string | number | React.ReactElement<any, string | React.JSXElementConstructor<any>> | React.ReactFragment | null)[]; | ||
context: unknown; | ||
setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<TProps>) => {} | Pick<{}, K> | null) | Pick<{}, K> | null, callback?: (() => void) | undefined): void; | ||
forceUpdate(callback?: (() => void) | undefined): void; | ||
render(): React.ReactNode; | ||
readonly props: Readonly<TProps>; | ||
state: Readonly<{}>; | ||
refs: { | ||
[key: string]: React.ReactInstance; | ||
}; | ||
componentDidMount?(): void; | ||
shouldComponentUpdate?(nextProps: Readonly<TProps>, nextState: Readonly<{}>, nextContext: any): boolean; | ||
componentWillUnmount?(): void; | ||
componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void; | ||
getSnapshotBeforeUpdate?(prevProps: Readonly<TProps>, prevState: Readonly<{}>): any; | ||
componentDidUpdate?(prevProps: Readonly<TProps>, prevState: Readonly<{}>, snapshot?: any): void; | ||
componentWillMount?(): void; | ||
UNSAFE_componentWillMount?(): void; | ||
componentWillReceiveProps?(nextProps: Readonly<TProps>, nextContext: any): void; | ||
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<TProps>, nextContext: any): void; | ||
componentWillUpdate?(nextProps: Readonly<TProps>, nextState: Readonly<{}>, nextContext: any): void; | ||
UNSAFE_componentWillUpdate?(nextProps: Readonly<TProps>, nextState: Readonly<{}>, nextContext: any): void; | ||
activePoints: any[]; | ||
activateData: boolean; | ||
activateLabels: boolean; | ||
disable?: boolean | undefined; | ||
labels?: ((point: any, index?: number, points?: any[]) => string) | undefined; | ||
labelComponent: JSX.Element; | ||
mouseFollowTooltips?: boolean | undefined; | ||
onActivated?: ((points: any[], props: VictoryVoronoiContainerProps) => void) | undefined; | ||
onDeactivated?: ((points: any[], props: VictoryVoronoiContainerProps) => void) | undefined; | ||
radius?: number | undefined; | ||
voronoiBlacklist?: (string | RegExp)[] | undefined; | ||
voronoiDimension?: "x" | "y" | undefined; | ||
voronoiPadding: PaddingProps; | ||
horizontal?: boolean | undefined; | ||
"aria-describedby"?: string | undefined; | ||
"aria-labelledby"?: string | undefined; | ||
children?: React.ReactElement<any, string | React.JSXElementConstructor<any>> | React.ReactElement<any, string | React.JSXElementConstructor<any>>[] | undefined; | ||
className?: string | undefined; | ||
containerId?: string | number | undefined; | ||
containerRef?: React.Ref<HTMLElement> | undefined; | ||
desc?: string | undefined; | ||
events?: React.DOMAttributes<any> | undefined; | ||
height?: number | undefined; | ||
name?: string | undefined; | ||
origin?: import("victory-core").OriginType | undefined; | ||
polar?: boolean | undefined; | ||
portalComponent?: React.ReactElement<any, string | React.JSXElementConstructor<any>> | undefined; | ||
portalZIndex?: number | undefined; | ||
preserveAspectRatio?: string | undefined; | ||
responsive?: boolean | undefined; | ||
role?: string | undefined; | ||
scale?: { | ||
x?: import("victory-core").D3Scale<any> | undefined; | ||
y?: import("victory-core").D3Scale<any> | undefined; | ||
} | undefined; | ||
style?: React.CSSProperties | undefined; | ||
tabIndex?: number | undefined; | ||
theme?: import("victory-core").VictoryThemeDefinition | undefined; | ||
title?: string | undefined; | ||
width?: number | undefined; | ||
ouiaId?: string | number | undefined; | ||
ouiaSafe?: boolean | undefined; | ||
ouiaType?: string | undefined; | ||
}; | ||
displayName: string; | ||
defaultProps: VictoryVoronoiContainerProps; | ||
defaultEvents(props: VictoryVoronoiContainerProps): ({ | ||
target: string; | ||
eventHandlers: { | ||
onMouseLeave: (evt: any, targetProps: any) => {}; | ||
onTouchCancel: (evt: any, targetProps: any) => {}; | ||
onMouseMove: (evt: any, targetProps: any) => {} | undefined; | ||
onTouchMove: (evt: any, targetProps: any) => {} | undefined; | ||
onMouseOver?: undefined; | ||
onMouseOut?: undefined; | ||
}; | ||
} | { | ||
target: string; | ||
eventHandlers: { | ||
onMouseLeave?: undefined; | ||
onTouchCancel?: undefined; | ||
onMouseMove?: undefined; | ||
onTouchMove?: undefined; | ||
onMouseOver?: undefined; | ||
onMouseOut?: undefined; | ||
} | { | ||
onMouseOver: () => null; | ||
onMouseOut: () => null; | ||
onMouseMove: () => null; | ||
onMouseLeave?: undefined; | ||
onTouchCancel?: undefined; | ||
onTouchMove?: undefined; | ||
}; | ||
})[]; | ||
} & TBase; | ||
children: React.ReactElement<any, string | React.JSXElementConstructor<any>>[]; | ||
}; | ||
export declare const VictoryVoronoiContainer: { | ||
new (props: VictoryVoronoiContainerProps): { | ||
getDimension(props: any): any; | ||
getPoint(point: any): Pick<any, string>; | ||
getLabelPosition(props: any, labelProps: any, points: any): { | ||
center: any; | ||
x: any; | ||
x0: any; | ||
y: any; | ||
y0: any; | ||
} | { | ||
x: any; | ||
y: any; | ||
center: any; | ||
}; | ||
getStyle(props: any, points: any, type: any): any; | ||
getDefaultLabelProps(props: any, points: any): { | ||
orientation: string | undefined; | ||
pointerLength: number | undefined; | ||
constrainToVisibleArea: boolean | undefined; | ||
}; | ||
getLabelProps(props: any, points: any): any; | ||
getTooltip(props: any): React.DetailedReactHTMLElement<any, HTMLElement> | null; | ||
getChildren(props: VictoryVoronoiContainerProps): (string | number | React.ReactElement<any, string | React.JSXElementConstructor<any>> | React.ReactFragment | null)[]; | ||
context: unknown; | ||
setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<VictoryVoronoiContainerProps>) => {} | Pick<{}, K> | null) | Pick<{}, K> | null, callback?: (() => void) | undefined): void; | ||
forceUpdate(callback?: (() => void) | undefined): void; | ||
render(): React.ReactNode; | ||
readonly props: Readonly<VictoryVoronoiContainerProps>; | ||
state: Readonly<{}>; | ||
refs: { | ||
[key: string]: React.ReactInstance; | ||
}; | ||
componentDidMount?(): void; | ||
shouldComponentUpdate?(nextProps: Readonly<VictoryVoronoiContainerProps>, nextState: Readonly<{}>, nextContext: any): boolean; | ||
componentWillUnmount?(): void; | ||
componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void; | ||
getSnapshotBeforeUpdate?(prevProps: Readonly<VictoryVoronoiContainerProps>, prevState: Readonly<{}>): any; | ||
componentDidUpdate?(prevProps: Readonly<VictoryVoronoiContainerProps>, prevState: Readonly<{}>, snapshot?: any): void; | ||
componentWillMount?(): void; | ||
UNSAFE_componentWillMount?(): void; | ||
componentWillReceiveProps?(nextProps: Readonly<VictoryVoronoiContainerProps>, nextContext: any): void; | ||
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<VictoryVoronoiContainerProps>, nextContext: any): void; | ||
componentWillUpdate?(nextProps: Readonly<VictoryVoronoiContainerProps>, nextState: Readonly<{}>, nextContext: any): void; | ||
UNSAFE_componentWillUpdate?(nextProps: Readonly<VictoryVoronoiContainerProps>, nextState: Readonly<{}>, nextContext: any): void; | ||
}; | ||
displayName: string; | ||
defaultProps: VictoryVoronoiContainerProps; | ||
defaultEvents(props: VictoryVoronoiContainerProps): ({ | ||
(initialProps: VictoryVoronoiContainerProps): JSX.Element; | ||
role: string; | ||
defaultEvents(initialProps: VictoryVoronoiContainerProps): ({ | ||
target: string; | ||
eventHandlers: { | ||
onMouseLeave: (evt: any, targetProps: any) => {}; | ||
onTouchCancel: (evt: any, targetProps: any) => {}; | ||
onMouseMove: (evt: any, targetProps: any) => {} | undefined; | ||
onTouchMove: (evt: any, targetProps: any) => {} | undefined; | ||
onMouseLeave: VictoryEventHandler; | ||
onTouchCancel: VictoryEventHandler; | ||
onMouseMove: VictoryEventHandler; | ||
onTouchMove: VictoryEventHandler; | ||
onMouseOver?: undefined; | ||
@@ -175,4 +109,3 @@ onMouseOut?: undefined; | ||
})[]; | ||
} & typeof VictoryContainer; | ||
export {}; | ||
}; | ||
//# sourceMappingURL=victory-voronoi-container.d.ts.map |
@@ -6,4 +6,3 @@ "use strict"; | ||
}); | ||
exports.VictoryVoronoiContainer = void 0; | ||
exports.voronoiContainerMixin = voronoiContainerMixin; | ||
exports.useVictoryVoronoiContainer = exports.VictoryVoronoiContainer = exports.VICTORY_VORONOI_CONTAINER_DEFAULT_PROPS = void 0; | ||
var _pick2 = _interopRequireDefault(require("lodash/pick")); | ||
@@ -18,199 +17,211 @@ var _defaults2 = _interopRequireDefault(require("lodash/defaults")); | ||
function voronoiContainerMixin(Base) { | ||
// @ts-expect-error "TS2545: A mixin class must have a constructor with a single rest parameter of type 'any[]'." | ||
return class VictoryVoronoiContainer extends Base { | ||
static displayName = "VictoryVoronoiContainer"; | ||
static defaultProps = { | ||
..._victoryCore.VictoryContainer.defaultProps, | ||
activateData: true, | ||
activateLabels: true, | ||
labelComponent: /*#__PURE__*/_react.default.createElement(_victoryTooltip.VictoryTooltip, null), | ||
voronoiPadding: 5 | ||
}; | ||
static defaultEvents(props) { | ||
return [{ | ||
target: "parent", | ||
eventHandlers: { | ||
onMouseLeave: (evt, targetProps) => { | ||
return props.disable ? {} : _voronoiHelpers.VoronoiHelpers.onMouseLeave(evt, targetProps); | ||
}, | ||
onTouchCancel: (evt, targetProps) => { | ||
return props.disable ? {} : _voronoiHelpers.VoronoiHelpers.onMouseLeave(evt, targetProps); | ||
}, | ||
onMouseMove: (evt, targetProps) => { | ||
return props.disable ? {} : _voronoiHelpers.VoronoiHelpers.onMouseMove(evt, targetProps); | ||
}, | ||
onTouchMove: (evt, targetProps) => { | ||
return props.disable ? {} : _voronoiHelpers.VoronoiHelpers.onMouseMove(evt, targetProps); | ||
} | ||
} | ||
}, { | ||
target: "data", | ||
eventHandlers: props.disable ? {} : { | ||
onMouseOver: () => null, | ||
onMouseOut: () => null, | ||
onMouseMove: () => null | ||
} | ||
}]; | ||
const VICTORY_VORONOI_CONTAINER_DEFAULT_PROPS = exports.VICTORY_VORONOI_CONTAINER_DEFAULT_PROPS = { | ||
activateData: true, | ||
activateLabels: true, | ||
labelComponent: /*#__PURE__*/_react.default.createElement(_victoryTooltip.VictoryTooltip, null), | ||
voronoiPadding: 5 | ||
}; | ||
const getPoint = point => { | ||
const whitelist = ["_x", "_x1", "_x0", "_y", "_y1", "_y0"]; | ||
return (0, _pick2.default)(point, whitelist); | ||
}; | ||
const useVictoryVoronoiContainer = initialProps => { | ||
const props = { | ||
...VICTORY_VORONOI_CONTAINER_DEFAULT_PROPS, | ||
...initialProps | ||
}; | ||
const { | ||
children | ||
} = props; | ||
const getDimension = () => { | ||
const { | ||
horizontal, | ||
voronoiDimension | ||
} = props; | ||
if (!horizontal || !voronoiDimension) { | ||
return voronoiDimension; | ||
} | ||
getDimension(props) { | ||
const { | ||
horizontal, | ||
voronoiDimension | ||
} = props; | ||
if (!horizontal || !voronoiDimension) { | ||
return voronoiDimension; | ||
} | ||
return voronoiDimension === "x" ? "y" : "x"; | ||
} | ||
getPoint(point) { | ||
const whitelist = ["_x", "_x1", "_x0", "_y", "_y1", "_y0"]; | ||
return (0, _pick2.default)(point, whitelist); | ||
} | ||
getLabelPosition(props, labelProps, points) { | ||
const { | ||
mousePosition, | ||
mouseFollowTooltips | ||
} = props; | ||
const voronoiDimension = this.getDimension(props); | ||
const point = this.getPoint(points[0]); | ||
const basePosition = _victoryCore.Helpers.scalePoint(props, point); | ||
let center = mouseFollowTooltips ? mousePosition : undefined; | ||
if (!voronoiDimension || points.length < 2) { | ||
return { | ||
...basePosition, | ||
center: (0, _defaults2.default)({}, labelProps.center, center) | ||
}; | ||
} | ||
const x = voronoiDimension === "y" ? mousePosition.x : basePosition.x; | ||
const y = voronoiDimension === "x" ? mousePosition.y : basePosition.y; | ||
center = mouseFollowTooltips ? mousePosition : { | ||
x, | ||
y | ||
}; | ||
return voronoiDimension === "x" ? "y" : "x"; | ||
}; | ||
const getLabelPosition = (labelProps, points) => { | ||
const { | ||
mousePosition, | ||
mouseFollowTooltips | ||
} = props; | ||
const voronoiDimension = getDimension(); | ||
const point = getPoint(points[0]); | ||
const basePosition = _victoryCore.Helpers.scalePoint(props, point); | ||
let center = mouseFollowTooltips ? mousePosition : undefined; | ||
if (!voronoiDimension || points.length < 2) { | ||
return { | ||
x, | ||
y, | ||
...basePosition, | ||
center: (0, _defaults2.default)({}, labelProps.center, center) | ||
}; | ||
} | ||
getStyle(props, points, type) { | ||
const { | ||
labels, | ||
labelComponent, | ||
theme | ||
} = props; | ||
const componentProps = labelComponent.props || {}; | ||
const themeStyles = theme && theme.voronoi && theme.voronoi.style ? theme.voronoi.style : {}; | ||
const componentStyleArray = type === "flyout" ? componentProps.flyoutStyle : componentProps.style; | ||
return points.reduce((memo, datum, index) => { | ||
const labelProps = (0, _defaults2.default)({}, componentProps, { | ||
datum, | ||
active: true | ||
}); | ||
const text = _victoryCore.Helpers.isFunction(labels) ? labels(labelProps) : undefined; | ||
const textArray = text !== undefined ? `${text}`.split("\n") : []; | ||
const baseStyle = datum.style && datum.style[type] || {}; | ||
const componentStyle = Array.isArray(componentStyleArray) ? componentStyleArray[index] : componentStyleArray; | ||
const style = _victoryCore.Helpers.evaluateStyle((0, _defaults2.default)({}, componentStyle, baseStyle, themeStyles[type]), labelProps); | ||
const styleArray = textArray.length ? textArray.map(() => style) : [style]; | ||
return memo.concat(styleArray); | ||
}, []); | ||
} | ||
getDefaultLabelProps(props, points) { | ||
const { | ||
voronoiDimension, | ||
horizontal, | ||
mouseFollowTooltips | ||
} = props; | ||
const point = this.getPoint(points[0]); | ||
const multiPoint = voronoiDimension && points.length > 1; | ||
const y = point._y1 !== undefined ? point._y1 : point._y; | ||
const defaultHorizontalOrientation = y < 0 ? "left" : "right"; | ||
const defaultOrientation = y < 0 ? "bottom" : "top"; | ||
const labelOrientation = horizontal ? defaultHorizontalOrientation : defaultOrientation; | ||
const orientation = mouseFollowTooltips ? undefined : labelOrientation; | ||
return { | ||
orientation, | ||
pointerLength: multiPoint ? 0 : undefined, | ||
constrainToVisibleArea: multiPoint || mouseFollowTooltips ? true : undefined | ||
}; | ||
} | ||
getLabelProps(props, points) { | ||
const { | ||
labels, | ||
scale, | ||
labelComponent, | ||
theme, | ||
width, | ||
height | ||
} = props; | ||
const componentProps = labelComponent.props || {}; | ||
const text = points.reduce((memo, datum) => { | ||
const labelProps = (0, _defaults2.default)({}, componentProps, { | ||
datum, | ||
active: true | ||
}); | ||
const t = _victoryCore.Helpers.isFunction(labels) ? labels(labelProps) : null; | ||
if (t === null || t === undefined) { | ||
return memo; | ||
} | ||
return memo.concat(`${t}`.split("\n")); | ||
}, []); | ||
// remove properties from first point to make datum | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const { | ||
childName, | ||
eventKey, | ||
style, | ||
continuous, | ||
...datum | ||
} = points[0]; | ||
const name = props.name === childName ? childName : `${props.name}-${childName}`; | ||
const labelProps = (0, _defaults2.default)({ | ||
key: `${name}-${eventKey}-voronoi-tooltip`, | ||
id: `${name}-${eventKey}-voronoi-tooltip`, | ||
active: true, | ||
renderInPortal: false, | ||
activePoints: points, | ||
const x = voronoiDimension === "y" ? mousePosition.x : basePosition.x; | ||
const y = voronoiDimension === "x" ? mousePosition.y : basePosition.y; | ||
center = mouseFollowTooltips ? mousePosition : { | ||
x, | ||
y | ||
}; | ||
return { | ||
x, | ||
y, | ||
center: (0, _defaults2.default)({}, labelProps.center, center) | ||
}; | ||
}; | ||
const getStyle = (points, type) => { | ||
const { | ||
labels, | ||
labelComponent, | ||
theme | ||
} = props; | ||
const componentProps = labelComponent.props || {}; | ||
const themeStyles = theme && theme.voronoi && theme.voronoi.style ? theme.voronoi.style : {}; | ||
const componentStyleArray = type === "flyout" ? componentProps.flyoutStyle : componentProps.style; | ||
return points.reduce((memo, datum, index) => { | ||
const labelProps = (0, _defaults2.default)({}, componentProps, { | ||
datum, | ||
scale, | ||
theme | ||
}, componentProps, { | ||
text, | ||
width, | ||
height, | ||
style: this.getStyle(props, points, "labels"), | ||
flyoutStyle: this.getStyle(props, points, "flyout")[0] | ||
}, this.getDefaultLabelProps(props, points)); | ||
const labelPosition = this.getLabelPosition(props, labelProps, points); | ||
return (0, _defaults2.default)({}, labelPosition, labelProps); | ||
} | ||
getTooltip(props) { | ||
const { | ||
labels, | ||
activePoints, | ||
labelComponent | ||
} = props; | ||
if (!labels) { | ||
return null; | ||
active: true | ||
}); | ||
const text = _victoryCore.Helpers.isFunction(labels) ? labels(labelProps) : undefined; | ||
const textArray = text !== undefined ? `${text}`.split("\n") : []; | ||
const baseStyle = datum.style && datum.style[type] || {}; | ||
const componentStyle = Array.isArray(componentStyleArray) ? componentStyleArray[index] : componentStyleArray; | ||
const style = _victoryCore.Helpers.evaluateStyle((0, _defaults2.default)({}, componentStyle, baseStyle, themeStyles[type]), labelProps); | ||
const styleArray = textArray.length ? textArray.map(() => style) : [style]; | ||
return memo.concat(styleArray); | ||
}, []); | ||
}; | ||
const getDefaultLabelProps = points => { | ||
const { | ||
voronoiDimension, | ||
horizontal, | ||
mouseFollowTooltips | ||
} = props; | ||
const point = getPoint(points[0]); | ||
const multiPoint = voronoiDimension && points.length > 1; | ||
const y = point._y1 !== undefined ? point._y1 : point._y; | ||
const defaultHorizontalOrientation = y < 0 ? "left" : "right"; | ||
const defaultOrientation = y < 0 ? "bottom" : "top"; | ||
const labelOrientation = horizontal ? defaultHorizontalOrientation : defaultOrientation; | ||
const orientation = mouseFollowTooltips ? undefined : labelOrientation; | ||
return { | ||
orientation, | ||
pointerLength: multiPoint ? 0 : undefined, | ||
constrainToVisibleArea: multiPoint || mouseFollowTooltips ? true : undefined | ||
}; | ||
}; | ||
const getLabelProps = points => { | ||
const { | ||
labels, | ||
scale, | ||
labelComponent, | ||
theme, | ||
width, | ||
height | ||
} = props; | ||
const componentProps = labelComponent.props || {}; | ||
const text = points.reduce((memo, datum) => { | ||
const labelProps = (0, _defaults2.default)({}, componentProps, { | ||
datum, | ||
active: true | ||
}); | ||
const t = _victoryCore.Helpers.isFunction(labels) ? labels(labelProps) : null; | ||
if (t === null || t === undefined) { | ||
return memo; | ||
} | ||
if (Array.isArray(activePoints) && activePoints.length) { | ||
const labelProps = this.getLabelProps(props, activePoints); | ||
const { | ||
text | ||
} = labelProps; | ||
const showLabel = Array.isArray(text) ? text.filter(Boolean).length : text; | ||
return showLabel ? /*#__PURE__*/_react.default.cloneElement(labelComponent, labelProps) : null; | ||
} | ||
return memo.concat(`${t}`.split("\n")); | ||
}, []); | ||
// remove properties from first point to make datum | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const { | ||
childName, | ||
eventKey, | ||
style, | ||
continuous, | ||
...datum | ||
} = points[0]; | ||
const name = props.name === childName ? childName : `${props.name}-${childName}`; | ||
const labelProps = (0, _defaults2.default)({ | ||
key: `${name}-${eventKey}-voronoi-tooltip`, | ||
id: `${name}-${eventKey}-voronoi-tooltip`, | ||
active: true, | ||
renderInPortal: false, | ||
activePoints: points, | ||
datum, | ||
scale, | ||
theme | ||
}, componentProps, { | ||
text, | ||
width, | ||
height, | ||
style: getStyle(points, "labels"), | ||
flyoutStyle: getStyle(points, "flyout")[0] | ||
}, getDefaultLabelProps(points)); | ||
const labelPosition = getLabelPosition(labelProps, points); | ||
return (0, _defaults2.default)({}, labelPosition, labelProps); | ||
}; | ||
const getTooltip = () => { | ||
const { | ||
labels, | ||
activePoints, | ||
labelComponent | ||
} = props; | ||
if (!labels) { | ||
return null; | ||
} | ||
// Overrides method in VictoryContainer | ||
getChildren(props) { | ||
return [..._react.default.Children.toArray(props.children), this.getTooltip(props)]; | ||
if (Array.isArray(activePoints) && activePoints.length) { | ||
const labelProps = getLabelProps(activePoints); | ||
const { | ||
text | ||
} = labelProps; | ||
const showLabel = Array.isArray(text) ? text.filter(Boolean).length : text; | ||
return showLabel ? /*#__PURE__*/_react.default.cloneElement(labelComponent, labelProps) : null; | ||
} | ||
return null; | ||
}; | ||
} | ||
const VictoryVoronoiContainer = exports.VictoryVoronoiContainer = voronoiContainerMixin(_victoryCore.VictoryContainer); | ||
return { | ||
props, | ||
children: [..._react.default.Children.toArray(children), getTooltip()] | ||
}; | ||
}; | ||
exports.useVictoryVoronoiContainer = useVictoryVoronoiContainer; | ||
const VictoryVoronoiContainer = initialProps => { | ||
const { | ||
props, | ||
children | ||
} = useVictoryVoronoiContainer(initialProps); | ||
return /*#__PURE__*/_react.default.createElement(_victoryCore.VictoryContainer, props, children); | ||
}; | ||
exports.VictoryVoronoiContainer = VictoryVoronoiContainer; | ||
VictoryVoronoiContainer.role = "container"; | ||
VictoryVoronoiContainer.defaultEvents = initialProps => { | ||
const props = { | ||
...VICTORY_VORONOI_CONTAINER_DEFAULT_PROPS, | ||
...initialProps | ||
}; | ||
const createEventHandler = (handler, disabled) => | ||
// eslint-disable-next-line max-params | ||
(event, targetProps, eventKey, context) => disabled || props.disable ? {} : handler(event, { | ||
...props, | ||
...targetProps | ||
}, eventKey, context); | ||
return [{ | ||
target: "parent", | ||
eventHandlers: { | ||
onMouseLeave: createEventHandler(_voronoiHelpers.VoronoiHelpers.onMouseLeave), | ||
onTouchCancel: createEventHandler(_voronoiHelpers.VoronoiHelpers.onMouseLeave), | ||
onMouseMove: createEventHandler(_voronoiHelpers.VoronoiHelpers.onMouseMove), | ||
onTouchMove: createEventHandler(_voronoiHelpers.VoronoiHelpers.onMouseMove) | ||
} | ||
}, { | ||
target: "data", | ||
eventHandlers: props.disable ? {} : { | ||
onMouseOver: () => null, | ||
onMouseOut: () => null, | ||
onMouseMove: () => null | ||
} | ||
}]; | ||
}; |
@@ -0,0 +0,0 @@ /// <reference types="lodash" /> |
{ | ||
"name": "victory-voronoi-container", | ||
"version": "37.0.2", | ||
"version": "37.0.3-next.0", | ||
"description": "Interactive Voronoi Mouseover Component for Victory", | ||
@@ -26,4 +26,4 @@ "keywords": [ | ||
"react-fast-compare": "^3.2.0", | ||
"victory-core": "^37.0.2", | ||
"victory-tooltip": "^37.0.2" | ||
"victory-core": "^37.0.3-next.0", | ||
"victory-tooltip": "^37.0.3-next.0" | ||
}, | ||
@@ -33,5 +33,2 @@ "peerDependencies": { | ||
}, | ||
"publishConfig": { | ||
"provenance": true | ||
}, | ||
"wireit": { | ||
@@ -38,0 +35,0 @@ "### THESE WIREIT CONFIGS ARE GENERATED ####": {}, |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
864368
16073
2
+ Addedvictory-core@37.0.3-next.0(transitive)
+ Addedvictory-tooltip@37.0.3-next.0(transitive)
+ Addedvictory-vendor@37.0.3-next.0(transitive)
- Removedvictory-core@37.0.2(transitive)
- Removedvictory-tooltip@37.0.2(transitive)
- Removedvictory-vendor@37.0.2(transitive)
Updatedvictory-core@^37.0.3-next.0