victory-voronoi-container
Advanced tools
Comparing version 36.9.2-next.1 to 36.9.2-next.3
# victory-voronoi-container | ||
## 36.9.2-next.1 | ||
## 36.9.2-next.3 | ||
@@ -8,2 +8,3 @@ ### Patch Changes | ||
- 7da790934: Replace lodash keys with native code | ||
- 65d02419f: Refactor containers and portal to function components | ||
- 7efd582cc: Replace lodash array utils with native code | ||
@@ -14,2 +15,3 @@ - 6e34169a5: Replace lodash isFunction with native code | ||
- Updated dependencies [c13308624] | ||
- Updated dependencies [65d02419f] | ||
- Updated dependencies [7efd582cc] | ||
@@ -19,4 +21,4 @@ - Updated dependencies [9cdaf2c08] | ||
- Updated dependencies [6e34169a5] | ||
- victory-core@36.9.2-next.1 | ||
- victory-tooltip@36.9.2-next.1 | ||
- victory-core@36.9.2-next.3 | ||
- victory-tooltip@36.9.2-next.3 | ||
@@ -23,0 +25,0 @@ ## 36.9.1 |
import React from "react"; | ||
import { VictoryContainerProps, PaddingProps, VictoryEventHandler } from "victory-core"; | ||
import { VictoryContainer, VictoryContainerProps, PaddingProps } from "victory-core"; | ||
declare type ComponentClass<TProps> = { | ||
new (props: TProps): React.Component<TProps>; | ||
}; | ||
export interface VictoryVoronoiContainerProps extends VictoryContainerProps { | ||
@@ -7,3 +10,3 @@ activateData?: boolean; | ||
disable?: boolean; | ||
labels?: (point: any, index?: number, points?: any[]) => string; | ||
labels?: (point: any, index: number, points: any[]) => string; | ||
labelComponent?: React.ReactElement; | ||
@@ -17,72 +20,135 @@ mouseFollowTooltips?: boolean; | ||
voronoiPadding?: PaddingProps; | ||
horizontal?: boolean; | ||
} | ||
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; | ||
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; | ||
}; | ||
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; | ||
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; | ||
}; | ||
children: React.ReactElement<any, string | React.JSXElementConstructor<any>>[]; | ||
}; | ||
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; | ||
export declare const VictoryVoronoiContainer: { | ||
(initialProps: VictoryVoronoiContainerProps): JSX.Element; | ||
role: string; | ||
defaultEvents(initialProps: VictoryVoronoiContainerProps): ({ | ||
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) => ({ | ||
target: string; | ||
eventHandlers: { | ||
onMouseLeave: VictoryEventHandler; | ||
onTouchCancel: VictoryEventHandler; | ||
onMouseMove: VictoryEventHandler; | ||
onTouchMove: VictoryEventHandler; | ||
onMouseLeave: (evt: any, targetProps: any) => {}; | ||
onTouchCancel: (evt: any, targetProps: any) => {}; | ||
onMouseMove: (evt: any, targetProps: any) => {} | undefined; | ||
onTouchMove: (evt: any, targetProps: any) => {} | undefined; | ||
onMouseOver?: undefined; | ||
@@ -109,3 +175,4 @@ onMouseOut?: undefined; | ||
})[]; | ||
}; | ||
} & typeof VictoryContainer; | ||
export {}; | ||
//# sourceMappingURL=victory-voronoi-container.d.ts.map |
@@ -27,225 +27,255 @@ import _pick from "lodash/pick"; | ||
/* eslint-disable react/no-multi-comp */ | ||
import React from "react"; | ||
import { VictoryTooltip } from "victory-tooltip"; | ||
import { Helpers, VictoryContainer } from "victory-core"; | ||
import { VoronoiHelpers } from "./voronoi-helpers"; | ||
export var VICTORY_VORONOI_CONTAINER_DEFAULT_PROPS = { | ||
activateData: true, | ||
activateLabels: true, | ||
labelComponent: /*#__PURE__*/React.createElement(VictoryTooltip, null), | ||
voronoiPadding: 5 | ||
}; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var getPoint = function (point) { | ||
var whitelist = ["_x", "_x1", "_x0", "_y", "_y1", "_y0"]; | ||
return _pick(point, whitelist); | ||
}; | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
export var useVictoryVoronoiContainer = function (initialProps) { | ||
var props = _objectSpread(_objectSpread({}, VICTORY_VORONOI_CONTAINER_DEFAULT_PROPS), initialProps); | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } | ||
var children = props.children; | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
var getDimension = function () { | ||
var horizontal = props.horizontal, | ||
voronoiDimension = props.voronoiDimension; | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
if (!horizontal || !voronoiDimension) { | ||
return voronoiDimension; | ||
} | ||
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } | ||
return voronoiDimension === "x" ? "y" : "x"; | ||
}; | ||
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } | ||
var getLabelPosition = function (labelProps, points) { | ||
var mousePosition = props.mousePosition, | ||
mouseFollowTooltips = props.mouseFollowTooltips; | ||
var voronoiDimension = getDimension(); | ||
var point = getPoint(points[0]); | ||
var basePosition = Helpers.scalePoint(props, point); | ||
var center = mouseFollowTooltips ? mousePosition : undefined; | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
if (!voronoiDimension || points.length < 2) { | ||
return _objectSpread(_objectSpread({}, basePosition), {}, { | ||
center: _defaults({}, labelProps.center, center) | ||
}); | ||
} | ||
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } | ||
var x = voronoiDimension === "y" ? mousePosition.x : basePosition.x; | ||
var y = voronoiDimension === "x" ? mousePosition.y : basePosition.y; | ||
center = mouseFollowTooltips ? mousePosition : { | ||
x: x, | ||
y: y | ||
}; | ||
return { | ||
x: x, | ||
y: y, | ||
center: _defaults({}, labelProps.center, center) | ||
}; | ||
}; | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
var getStyle = function (points, type) { | ||
var labels = props.labels, | ||
labelComponent = props.labelComponent, | ||
theme = props.theme; | ||
var componentProps = labelComponent.props || {}; | ||
var themeStyles = theme && theme.voronoi && theme.voronoi.style ? theme.voronoi.style : {}; | ||
var componentStyleArray = type === "flyout" ? componentProps.flyoutStyle : componentProps.style; | ||
return points.reduce(function (memo, datum, index) { | ||
var labelProps = _defaults({}, componentProps, { | ||
datum: datum, | ||
active: true | ||
}); | ||
/* eslint-disable react/no-multi-comp */ | ||
import React from "react"; | ||
import { VictoryTooltip } from "victory-tooltip"; | ||
import { VictoryContainer, Helpers } from "victory-core"; | ||
import { VoronoiHelpers } from "./voronoi-helpers"; | ||
export function voronoiContainerMixin(Base) { | ||
var _class; | ||
var text = Helpers.isFunction(labels) ? labels(labelProps) : undefined; | ||
var textArray = text !== undefined ? "".concat(text).split("\n") : []; | ||
var baseStyle = datum.style && datum.style[type] || {}; | ||
var componentStyle = Array.isArray(componentStyleArray) ? componentStyleArray[index] : componentStyleArray; | ||
var style = Helpers.evaluateStyle(_defaults({}, componentStyle, baseStyle, themeStyles[type]), labelProps); | ||
var styleArray = textArray.length ? textArray.map(function () { | ||
return style; | ||
}) : [style]; | ||
return memo.concat(styleArray); | ||
}, []); | ||
}; | ||
// @ts-expect-error "TS2545: A mixin class must have a constructor with a single rest parameter of type 'any[]'." | ||
return _class = /*#__PURE__*/function (_Base) { | ||
_inherits(VictoryVoronoiContainer, _Base); | ||
var getDefaultLabelProps = function (points) { | ||
var voronoiDimension = props.voronoiDimension, | ||
horizontal = props.horizontal, | ||
mouseFollowTooltips = props.mouseFollowTooltips; | ||
var point = getPoint(points[0]); | ||
var multiPoint = voronoiDimension && points.length > 1; | ||
var y = point._y1 !== undefined ? point._y1 : point._y; | ||
var defaultHorizontalOrientation = y < 0 ? "left" : "right"; | ||
var defaultOrientation = y < 0 ? "bottom" : "top"; | ||
var labelOrientation = horizontal ? defaultHorizontalOrientation : defaultOrientation; | ||
var orientation = mouseFollowTooltips ? undefined : labelOrientation; | ||
return { | ||
orientation: orientation, | ||
pointerLength: multiPoint ? 0 : undefined, | ||
constrainToVisibleArea: multiPoint || mouseFollowTooltips ? true : undefined | ||
}; | ||
}; | ||
var _super = _createSuper(VictoryVoronoiContainer); | ||
var getLabelProps = function (points) { | ||
var labels = props.labels, | ||
scale = props.scale, | ||
labelComponent = props.labelComponent, | ||
theme = props.theme, | ||
width = props.width, | ||
height = props.height; | ||
var componentProps = labelComponent.props || {}; | ||
var text = points.reduce(function (memo, datum) { | ||
var labelProps = _defaults({}, componentProps, { | ||
datum: datum, | ||
active: true | ||
}); | ||
function VictoryVoronoiContainer() { | ||
_classCallCheck(this, VictoryVoronoiContainer); | ||
var t = Helpers.isFunction(labels) ? labels(labelProps) : null; | ||
return _super.apply(this, arguments); | ||
} | ||
if (t === null || t === undefined) { | ||
return memo; | ||
_createClass(VictoryVoronoiContainer, [{ | ||
key: "getDimension", | ||
value: function getDimension(props) { | ||
var horizontal = props.horizontal, | ||
voronoiDimension = props.voronoiDimension; | ||
if (!horizontal || !voronoiDimension) { | ||
return voronoiDimension; | ||
} | ||
return voronoiDimension === "x" ? "y" : "x"; | ||
} | ||
}, { | ||
key: "getPoint", | ||
value: function getPoint(point) { | ||
var whitelist = ["_x", "_x1", "_x0", "_y", "_y1", "_y0"]; | ||
return _pick(point, whitelist); | ||
} | ||
}, { | ||
key: "getLabelPosition", | ||
value: function getLabelPosition(props, labelProps, points) { | ||
var mousePosition = props.mousePosition, | ||
mouseFollowTooltips = props.mouseFollowTooltips; | ||
var voronoiDimension = this.getDimension(props); | ||
var point = this.getPoint(points[0]); | ||
var basePosition = Helpers.scalePoint(props, point); | ||
var center = mouseFollowTooltips ? mousePosition : undefined; | ||
return memo.concat("".concat(t).split("\n")); | ||
}, []); // remove properties from first point to make datum | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
if (!voronoiDimension || points.length < 2) { | ||
return _objectSpread(_objectSpread({}, basePosition), {}, { | ||
center: _defaults({}, labelProps.center, center) | ||
}); | ||
} | ||
var _points$ = points[0], | ||
childName = _points$.childName, | ||
eventKey = _points$.eventKey, | ||
style = _points$.style, | ||
continuous = _points$.continuous, | ||
datum = _objectWithoutProperties(_points$, _excluded); | ||
var x = voronoiDimension === "y" ? mousePosition.x : basePosition.x; | ||
var y = voronoiDimension === "x" ? mousePosition.y : basePosition.y; | ||
center = mouseFollowTooltips ? mousePosition : { | ||
x: x, | ||
y: y | ||
}; | ||
return { | ||
x: x, | ||
y: y, | ||
center: _defaults({}, labelProps.center, center) | ||
}; | ||
} | ||
}, { | ||
key: "getStyle", | ||
value: function getStyle(props, points, type) { | ||
var labels = props.labels, | ||
labelComponent = props.labelComponent, | ||
theme = props.theme; | ||
var componentProps = labelComponent.props || {}; | ||
var themeStyles = theme && theme.voronoi && theme.voronoi.style ? theme.voronoi.style : {}; | ||
var componentStyleArray = type === "flyout" ? componentProps.flyoutStyle : componentProps.style; | ||
return points.reduce(function (memo, datum, index) { | ||
var labelProps = _defaults({}, componentProps, { | ||
datum: datum, | ||
active: true | ||
}); | ||
var name = props.name === childName ? childName : "".concat(props.name, "-").concat(childName); | ||
var text = Helpers.isFunction(labels) ? labels(labelProps) : undefined; | ||
var textArray = text !== undefined ? "".concat(text).split("\n") : []; | ||
var baseStyle = datum.style && datum.style[type] || {}; | ||
var componentStyle = Array.isArray(componentStyleArray) ? componentStyleArray[index] : componentStyleArray; | ||
var style = Helpers.evaluateStyle(_defaults({}, componentStyle, baseStyle, themeStyles[type]), labelProps); | ||
var styleArray = textArray.length ? textArray.map(function () { | ||
return style; | ||
}) : [style]; | ||
return memo.concat(styleArray); | ||
}, []); | ||
} | ||
}, { | ||
key: "getDefaultLabelProps", | ||
value: function getDefaultLabelProps(props, points) { | ||
var voronoiDimension = props.voronoiDimension, | ||
horizontal = props.horizontal, | ||
mouseFollowTooltips = props.mouseFollowTooltips; | ||
var point = this.getPoint(points[0]); | ||
var multiPoint = voronoiDimension && points.length > 1; | ||
var y = point._y1 !== undefined ? point._y1 : point._y; | ||
var defaultHorizontalOrientation = y < 0 ? "left" : "right"; | ||
var defaultOrientation = y < 0 ? "bottom" : "top"; | ||
var labelOrientation = horizontal ? defaultHorizontalOrientation : defaultOrientation; | ||
var orientation = mouseFollowTooltips ? undefined : labelOrientation; | ||
return { | ||
orientation: orientation, | ||
pointerLength: multiPoint ? 0 : undefined, | ||
constrainToVisibleArea: multiPoint || mouseFollowTooltips ? true : undefined | ||
}; | ||
} | ||
}, { | ||
key: "getLabelProps", | ||
value: function getLabelProps(props, points) { | ||
var labels = props.labels, | ||
scale = props.scale, | ||
labelComponent = props.labelComponent, | ||
theme = props.theme, | ||
width = props.width, | ||
height = props.height; | ||
var componentProps = labelComponent.props || {}; | ||
var text = points.reduce(function (memo, datum) { | ||
var labelProps = _defaults({}, componentProps, { | ||
datum: datum, | ||
active: true | ||
}); | ||
var labelProps = _defaults({ | ||
key: "".concat(name, "-").concat(eventKey, "-voronoi-tooltip"), | ||
id: "".concat(name, "-").concat(eventKey, "-voronoi-tooltip"), | ||
active: true, | ||
renderInPortal: false, | ||
activePoints: points, | ||
datum: datum, | ||
scale: scale, | ||
theme: theme | ||
}, componentProps, { | ||
text: text, | ||
width: width, | ||
height: height, | ||
style: getStyle(points, "labels"), | ||
flyoutStyle: getStyle(points, "flyout")[0] | ||
}, getDefaultLabelProps(points)); | ||
var t = Helpers.isFunction(labels) ? labels(labelProps) : null; | ||
var labelPosition = getLabelPosition(labelProps, points); | ||
return _defaults({}, labelPosition, labelProps); | ||
}; | ||
if (t === null || t === undefined) { | ||
return memo; | ||
} | ||
var getTooltip = function () { | ||
var labels = props.labels, | ||
activePoints = props.activePoints, | ||
labelComponent = props.labelComponent; | ||
return memo.concat("".concat(t).split("\n")); | ||
}, []); // remove properties from first point to make datum | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
if (!labels) { | ||
return null; | ||
} | ||
var _points$ = points[0], | ||
childName = _points$.childName, | ||
eventKey = _points$.eventKey, | ||
style = _points$.style, | ||
continuous = _points$.continuous, | ||
datum = _objectWithoutProperties(_points$, _excluded); | ||
if (Array.isArray(activePoints) && activePoints.length) { | ||
var labelProps = getLabelProps(activePoints); | ||
var text = labelProps.text; | ||
var showLabel = Array.isArray(text) ? text.filter(Boolean).length : text; | ||
return showLabel ? /*#__PURE__*/React.cloneElement(labelComponent, labelProps) : null; | ||
} | ||
var name = props.name === childName ? childName : "".concat(props.name, "-").concat(childName); | ||
return null; | ||
}; | ||
var labelProps = _defaults({ | ||
key: "".concat(name, "-").concat(eventKey, "-voronoi-tooltip"), | ||
id: "".concat(name, "-").concat(eventKey, "-voronoi-tooltip"), | ||
active: true, | ||
renderInPortal: false, | ||
activePoints: points, | ||
datum: datum, | ||
scale: scale, | ||
theme: theme | ||
}, componentProps, { | ||
text: text, | ||
width: width, | ||
height: height, | ||
style: this.getStyle(props, points, "labels"), | ||
flyoutStyle: this.getStyle(props, points, "flyout")[0] | ||
}, this.getDefaultLabelProps(props, points)); | ||
return { | ||
props: props, | ||
children: [].concat(_toConsumableArray(React.Children.toArray(children)), [getTooltip()]) | ||
}; | ||
}; | ||
export var VictoryVoronoiContainer = function (initialProps) { | ||
var _useVictoryVoronoiCon = useVictoryVoronoiContainer(initialProps), | ||
props = _useVictoryVoronoiCon.props, | ||
children = _useVictoryVoronoiCon.children; | ||
var labelPosition = this.getLabelPosition(props, labelProps, points); | ||
return _defaults({}, labelPosition, labelProps); | ||
} | ||
}, { | ||
key: "getTooltip", | ||
value: function getTooltip(props) { | ||
var labels = props.labels, | ||
activePoints = props.activePoints, | ||
labelComponent = props.labelComponent; | ||
return /*#__PURE__*/React.createElement(VictoryContainer, props, children); | ||
}; | ||
VictoryVoronoiContainer.role = "container"; | ||
if (!labels) { | ||
return null; | ||
} | ||
VictoryVoronoiContainer.defaultEvents = function (initialProps) { | ||
var props = _objectSpread(_objectSpread({}, VICTORY_VORONOI_CONTAINER_DEFAULT_PROPS), initialProps); | ||
if (Array.isArray(activePoints) && activePoints.length) { | ||
var labelProps = this.getLabelProps(props, activePoints); | ||
var text = labelProps.text; | ||
var showLabel = Array.isArray(text) ? text.filter(Boolean).length : text; | ||
return showLabel ? /*#__PURE__*/React.cloneElement(labelComponent, labelProps) : null; | ||
} | ||
var createEventHandler = function (handler, disabled) { | ||
return (// eslint-disable-next-line max-params | ||
function (event, targetProps, eventKey, context) { | ||
return disabled || props.disable ? {} : handler(event, _objectSpread(_objectSpread({}, props), targetProps), eventKey, context); | ||
return null; | ||
} // Overrides method in VictoryContainer | ||
}, { | ||
key: "getChildren", | ||
value: function getChildren(props) { | ||
return [].concat(_toConsumableArray(React.Children.toArray(props.children)), [this.getTooltip(props)]); | ||
} | ||
); | ||
}; | ||
}]); | ||
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: function () { | ||
return null; | ||
}, | ||
onMouseOut: function () { | ||
return null; | ||
}, | ||
onMouseMove: function () { | ||
return null; | ||
return VictoryVoronoiContainer; | ||
}(Base), _class.displayName = "VictoryVoronoiContainer", _class.defaultProps = _objectSpread(_objectSpread({}, VictoryContainer.defaultProps), {}, { | ||
activateData: true, | ||
activateLabels: true, | ||
labelComponent: /*#__PURE__*/React.createElement(VictoryTooltip, null), | ||
voronoiPadding: 5 | ||
}), _class.defaultEvents = function (props) { | ||
return [{ | ||
target: "parent", | ||
eventHandlers: { | ||
onMouseLeave: function (evt, targetProps) { | ||
return props.disable ? {} : VoronoiHelpers.onMouseLeave(evt, targetProps); | ||
}, | ||
onTouchCancel: function (evt, targetProps) { | ||
return props.disable ? {} : VoronoiHelpers.onMouseLeave(evt, targetProps); | ||
}, | ||
onMouseMove: function (evt, targetProps) { | ||
return props.disable ? {} : VoronoiHelpers.onMouseMove(evt, targetProps); | ||
}, | ||
onTouchMove: function (evt, targetProps) { | ||
return props.disable ? {} : VoronoiHelpers.onMouseMove(evt, targetProps); | ||
} | ||
} | ||
} | ||
}]; | ||
}; | ||
}, { | ||
target: "data", | ||
eventHandlers: props.disable ? {} : { | ||
onMouseOver: function () { | ||
return null; | ||
}, | ||
onMouseOut: function () { | ||
return null; | ||
}, | ||
onMouseMove: function () { | ||
return null; | ||
} | ||
} | ||
}]; | ||
}, _class; | ||
} | ||
export var VictoryVoronoiContainer = voronoiContainerMixin(VictoryContainer); |
import React from "react"; | ||
import { VictoryContainerProps, PaddingProps, VictoryEventHandler } from "victory-core"; | ||
import { VictoryContainer, VictoryContainerProps, PaddingProps } from "victory-core"; | ||
declare type ComponentClass<TProps> = { | ||
new (props: TProps): React.Component<TProps>; | ||
}; | ||
export interface VictoryVoronoiContainerProps extends VictoryContainerProps { | ||
@@ -7,3 +10,3 @@ activateData?: boolean; | ||
disable?: boolean; | ||
labels?: (point: any, index?: number, points?: any[]) => string; | ||
labels?: (point: any, index: number, points: any[]) => string; | ||
labelComponent?: React.ReactElement; | ||
@@ -17,72 +20,135 @@ mouseFollowTooltips?: boolean; | ||
voronoiPadding?: PaddingProps; | ||
horizontal?: boolean; | ||
} | ||
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; | ||
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; | ||
}; | ||
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; | ||
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; | ||
}; | ||
children: React.ReactElement<any, string | React.JSXElementConstructor<any>>[]; | ||
}; | ||
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; | ||
export declare const VictoryVoronoiContainer: { | ||
(initialProps: VictoryVoronoiContainerProps): JSX.Element; | ||
role: string; | ||
defaultEvents(initialProps: VictoryVoronoiContainerProps): ({ | ||
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) => ({ | ||
target: string; | ||
eventHandlers: { | ||
onMouseLeave: VictoryEventHandler; | ||
onTouchCancel: VictoryEventHandler; | ||
onMouseMove: VictoryEventHandler; | ||
onTouchMove: VictoryEventHandler; | ||
onMouseLeave: (evt: any, targetProps: any) => {}; | ||
onTouchCancel: (evt: any, targetProps: any) => {}; | ||
onMouseMove: (evt: any, targetProps: any) => {} | undefined; | ||
onTouchMove: (evt: any, targetProps: any) => {} | undefined; | ||
onMouseOver?: undefined; | ||
@@ -109,3 +175,4 @@ onMouseOut?: undefined; | ||
})[]; | ||
}; | ||
} & typeof VictoryContainer; | ||
export {}; | ||
//# sourceMappingURL=victory-voronoi-container.d.ts.map |
@@ -6,3 +6,4 @@ "use strict"; | ||
}); | ||
exports.useVictoryVoronoiContainer = exports.VictoryVoronoiContainer = exports.VICTORY_VORONOI_CONTAINER_DEFAULT_PROPS = void 0; | ||
exports.VictoryVoronoiContainer = void 0; | ||
exports.voronoiContainerMixin = voronoiContainerMixin; | ||
@@ -47,226 +48,252 @@ var _pick2 = _interopRequireDefault(require("lodash/pick")); | ||
var VICTORY_VORONOI_CONTAINER_DEFAULT_PROPS = { | ||
activateData: true, | ||
activateLabels: true, | ||
labelComponent: /*#__PURE__*/_react.default.createElement(_victoryTooltip.VictoryTooltip, null), | ||
voronoiPadding: 5 | ||
}; | ||
exports.VICTORY_VORONOI_CONTAINER_DEFAULT_PROPS = VICTORY_VORONOI_CONTAINER_DEFAULT_PROPS; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var getPoint = function (point) { | ||
var whitelist = ["_x", "_x1", "_x0", "_y", "_y1", "_y0"]; | ||
return (0, _pick2.default)(point, whitelist); | ||
}; | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
var useVictoryVoronoiContainer = function (initialProps) { | ||
var props = _objectSpread(_objectSpread({}, VICTORY_VORONOI_CONTAINER_DEFAULT_PROPS), initialProps); | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } | ||
var children = props.children; | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
var getDimension = function () { | ||
var horizontal = props.horizontal, | ||
voronoiDimension = props.voronoiDimension; | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
if (!horizontal || !voronoiDimension) { | ||
return voronoiDimension; | ||
} | ||
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } | ||
return voronoiDimension === "x" ? "y" : "x"; | ||
}; | ||
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } | ||
var getLabelPosition = function (labelProps, points) { | ||
var mousePosition = props.mousePosition, | ||
mouseFollowTooltips = props.mouseFollowTooltips; | ||
var voronoiDimension = getDimension(); | ||
var point = getPoint(points[0]); | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
var basePosition = _victoryCore.Helpers.scalePoint(props, point); | ||
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } | ||
var center = mouseFollowTooltips ? mousePosition : undefined; | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
if (!voronoiDimension || points.length < 2) { | ||
return _objectSpread(_objectSpread({}, basePosition), {}, { | ||
center: (0, _defaults2.default)({}, labelProps.center, center) | ||
}); | ||
} | ||
function voronoiContainerMixin(Base) { | ||
var _class; | ||
var x = voronoiDimension === "y" ? mousePosition.x : basePosition.x; | ||
var y = voronoiDimension === "x" ? mousePosition.y : basePosition.y; | ||
center = mouseFollowTooltips ? mousePosition : { | ||
x: x, | ||
y: y | ||
}; | ||
return { | ||
x: x, | ||
y: y, | ||
center: (0, _defaults2.default)({}, labelProps.center, center) | ||
}; | ||
}; | ||
// @ts-expect-error "TS2545: A mixin class must have a constructor with a single rest parameter of type 'any[]'." | ||
return _class = /*#__PURE__*/function (_Base) { | ||
_inherits(VictoryVoronoiContainer, _Base); | ||
var getStyle = function (points, type) { | ||
var labels = props.labels, | ||
labelComponent = props.labelComponent, | ||
theme = props.theme; | ||
var componentProps = labelComponent.props || {}; | ||
var themeStyles = theme && theme.voronoi && theme.voronoi.style ? theme.voronoi.style : {}; | ||
var componentStyleArray = type === "flyout" ? componentProps.flyoutStyle : componentProps.style; | ||
return points.reduce(function (memo, datum, index) { | ||
var labelProps = (0, _defaults2.default)({}, componentProps, { | ||
datum: datum, | ||
active: true | ||
}); | ||
var text = _victoryCore.Helpers.isFunction(labels) ? labels(labelProps) : undefined; | ||
var textArray = text !== undefined ? "".concat(text).split("\n") : []; | ||
var baseStyle = datum.style && datum.style[type] || {}; | ||
var componentStyle = Array.isArray(componentStyleArray) ? componentStyleArray[index] : componentStyleArray; | ||
var _super = _createSuper(VictoryVoronoiContainer); | ||
var style = _victoryCore.Helpers.evaluateStyle((0, _defaults2.default)({}, componentStyle, baseStyle, themeStyles[type]), labelProps); | ||
function VictoryVoronoiContainer() { | ||
_classCallCheck(this, VictoryVoronoiContainer); | ||
var styleArray = textArray.length ? textArray.map(function () { | ||
return style; | ||
}) : [style]; | ||
return memo.concat(styleArray); | ||
}, []); | ||
}; | ||
return _super.apply(this, arguments); | ||
} | ||
var getDefaultLabelProps = function (points) { | ||
var voronoiDimension = props.voronoiDimension, | ||
horizontal = props.horizontal, | ||
mouseFollowTooltips = props.mouseFollowTooltips; | ||
var point = getPoint(points[0]); | ||
var multiPoint = voronoiDimension && points.length > 1; | ||
var y = point._y1 !== undefined ? point._y1 : point._y; | ||
var defaultHorizontalOrientation = y < 0 ? "left" : "right"; | ||
var defaultOrientation = y < 0 ? "bottom" : "top"; | ||
var labelOrientation = horizontal ? defaultHorizontalOrientation : defaultOrientation; | ||
var orientation = mouseFollowTooltips ? undefined : labelOrientation; | ||
return { | ||
orientation: orientation, | ||
pointerLength: multiPoint ? 0 : undefined, | ||
constrainToVisibleArea: multiPoint || mouseFollowTooltips ? true : undefined | ||
}; | ||
}; | ||
_createClass(VictoryVoronoiContainer, [{ | ||
key: "getDimension", | ||
value: function getDimension(props) { | ||
var horizontal = props.horizontal, | ||
voronoiDimension = props.voronoiDimension; | ||
var getLabelProps = function (points) { | ||
var labels = props.labels, | ||
scale = props.scale, | ||
labelComponent = props.labelComponent, | ||
theme = props.theme, | ||
width = props.width, | ||
height = props.height; | ||
var componentProps = labelComponent.props || {}; | ||
var text = points.reduce(function (memo, datum) { | ||
var labelProps = (0, _defaults2.default)({}, componentProps, { | ||
datum: datum, | ||
active: true | ||
}); | ||
var t = _victoryCore.Helpers.isFunction(labels) ? labels(labelProps) : null; | ||
if (!horizontal || !voronoiDimension) { | ||
return voronoiDimension; | ||
} | ||
if (t === null || t === undefined) { | ||
return memo; | ||
return voronoiDimension === "x" ? "y" : "x"; | ||
} | ||
}, { | ||
key: "getPoint", | ||
value: function getPoint(point) { | ||
var whitelist = ["_x", "_x1", "_x0", "_y", "_y1", "_y0"]; | ||
return (0, _pick2.default)(point, whitelist); | ||
} | ||
}, { | ||
key: "getLabelPosition", | ||
value: function getLabelPosition(props, labelProps, points) { | ||
var mousePosition = props.mousePosition, | ||
mouseFollowTooltips = props.mouseFollowTooltips; | ||
var voronoiDimension = this.getDimension(props); | ||
var point = this.getPoint(points[0]); | ||
return memo.concat("".concat(t).split("\n")); | ||
}, []); // remove properties from first point to make datum | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
var basePosition = _victoryCore.Helpers.scalePoint(props, point); | ||
var _points$ = points[0], | ||
childName = _points$.childName, | ||
eventKey = _points$.eventKey, | ||
style = _points$.style, | ||
continuous = _points$.continuous, | ||
datum = _objectWithoutProperties(_points$, _excluded); | ||
var center = mouseFollowTooltips ? mousePosition : undefined; | ||
var name = props.name === childName ? childName : "".concat(props.name, "-").concat(childName); | ||
var labelProps = (0, _defaults2.default)({ | ||
key: "".concat(name, "-").concat(eventKey, "-voronoi-tooltip"), | ||
id: "".concat(name, "-").concat(eventKey, "-voronoi-tooltip"), | ||
active: true, | ||
renderInPortal: false, | ||
activePoints: points, | ||
datum: datum, | ||
scale: scale, | ||
theme: theme | ||
}, componentProps, { | ||
text: text, | ||
width: width, | ||
height: height, | ||
style: getStyle(points, "labels"), | ||
flyoutStyle: getStyle(points, "flyout")[0] | ||
}, getDefaultLabelProps(points)); | ||
var labelPosition = getLabelPosition(labelProps, points); | ||
return (0, _defaults2.default)({}, labelPosition, labelProps); | ||
}; | ||
if (!voronoiDimension || points.length < 2) { | ||
return _objectSpread(_objectSpread({}, basePosition), {}, { | ||
center: (0, _defaults2.default)({}, labelProps.center, center) | ||
}); | ||
} | ||
var getTooltip = function () { | ||
var labels = props.labels, | ||
activePoints = props.activePoints, | ||
labelComponent = props.labelComponent; | ||
var x = voronoiDimension === "y" ? mousePosition.x : basePosition.x; | ||
var y = voronoiDimension === "x" ? mousePosition.y : basePosition.y; | ||
center = mouseFollowTooltips ? mousePosition : { | ||
x: x, | ||
y: y | ||
}; | ||
return { | ||
x: x, | ||
y: y, | ||
center: (0, _defaults2.default)({}, labelProps.center, center) | ||
}; | ||
} | ||
}, { | ||
key: "getStyle", | ||
value: function getStyle(props, points, type) { | ||
var labels = props.labels, | ||
labelComponent = props.labelComponent, | ||
theme = props.theme; | ||
var componentProps = labelComponent.props || {}; | ||
var themeStyles = theme && theme.voronoi && theme.voronoi.style ? theme.voronoi.style : {}; | ||
var componentStyleArray = type === "flyout" ? componentProps.flyoutStyle : componentProps.style; | ||
return points.reduce(function (memo, datum, index) { | ||
var labelProps = (0, _defaults2.default)({}, componentProps, { | ||
datum: datum, | ||
active: true | ||
}); | ||
var text = _victoryCore.Helpers.isFunction(labels) ? labels(labelProps) : undefined; | ||
var textArray = text !== undefined ? "".concat(text).split("\n") : []; | ||
var baseStyle = datum.style && datum.style[type] || {}; | ||
var componentStyle = Array.isArray(componentStyleArray) ? componentStyleArray[index] : componentStyleArray; | ||
if (!labels) { | ||
return null; | ||
} | ||
var style = _victoryCore.Helpers.evaluateStyle((0, _defaults2.default)({}, componentStyle, baseStyle, themeStyles[type]), labelProps); | ||
if (Array.isArray(activePoints) && activePoints.length) { | ||
var labelProps = getLabelProps(activePoints); | ||
var text = labelProps.text; | ||
var showLabel = Array.isArray(text) ? text.filter(Boolean).length : text; | ||
return showLabel ? /*#__PURE__*/_react.default.cloneElement(labelComponent, labelProps) : null; | ||
} | ||
var styleArray = textArray.length ? textArray.map(function () { | ||
return style; | ||
}) : [style]; | ||
return memo.concat(styleArray); | ||
}, []); | ||
} | ||
}, { | ||
key: "getDefaultLabelProps", | ||
value: function getDefaultLabelProps(props, points) { | ||
var voronoiDimension = props.voronoiDimension, | ||
horizontal = props.horizontal, | ||
mouseFollowTooltips = props.mouseFollowTooltips; | ||
var point = this.getPoint(points[0]); | ||
var multiPoint = voronoiDimension && points.length > 1; | ||
var y = point._y1 !== undefined ? point._y1 : point._y; | ||
var defaultHorizontalOrientation = y < 0 ? "left" : "right"; | ||
var defaultOrientation = y < 0 ? "bottom" : "top"; | ||
var labelOrientation = horizontal ? defaultHorizontalOrientation : defaultOrientation; | ||
var orientation = mouseFollowTooltips ? undefined : labelOrientation; | ||
return { | ||
orientation: orientation, | ||
pointerLength: multiPoint ? 0 : undefined, | ||
constrainToVisibleArea: multiPoint || mouseFollowTooltips ? true : undefined | ||
}; | ||
} | ||
}, { | ||
key: "getLabelProps", | ||
value: function getLabelProps(props, points) { | ||
var labels = props.labels, | ||
scale = props.scale, | ||
labelComponent = props.labelComponent, | ||
theme = props.theme, | ||
width = props.width, | ||
height = props.height; | ||
var componentProps = labelComponent.props || {}; | ||
var text = points.reduce(function (memo, datum) { | ||
var labelProps = (0, _defaults2.default)({}, componentProps, { | ||
datum: datum, | ||
active: true | ||
}); | ||
var t = _victoryCore.Helpers.isFunction(labels) ? labels(labelProps) : null; | ||
return null; | ||
}; | ||
if (t === null || t === undefined) { | ||
return memo; | ||
} | ||
return { | ||
props: props, | ||
children: [].concat(_toConsumableArray(_react.default.Children.toArray(children)), [getTooltip()]) | ||
}; | ||
}; | ||
return memo.concat("".concat(t).split("\n")); | ||
}, []); // remove properties from first point to make datum | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
exports.useVictoryVoronoiContainer = useVictoryVoronoiContainer; | ||
var _points$ = points[0], | ||
childName = _points$.childName, | ||
eventKey = _points$.eventKey, | ||
style = _points$.style, | ||
continuous = _points$.continuous, | ||
datum = _objectWithoutProperties(_points$, _excluded); | ||
var VictoryVoronoiContainer = function (initialProps) { | ||
var _useVictoryVoronoiCon = useVictoryVoronoiContainer(initialProps), | ||
props = _useVictoryVoronoiCon.props, | ||
children = _useVictoryVoronoiCon.children; | ||
var name = props.name === childName ? childName : "".concat(props.name, "-").concat(childName); | ||
var labelProps = (0, _defaults2.default)({ | ||
key: "".concat(name, "-").concat(eventKey, "-voronoi-tooltip"), | ||
id: "".concat(name, "-").concat(eventKey, "-voronoi-tooltip"), | ||
active: true, | ||
renderInPortal: false, | ||
activePoints: points, | ||
datum: datum, | ||
scale: scale, | ||
theme: theme | ||
}, componentProps, { | ||
text: text, | ||
width: width, | ||
height: height, | ||
style: this.getStyle(props, points, "labels"), | ||
flyoutStyle: this.getStyle(props, points, "flyout")[0] | ||
}, this.getDefaultLabelProps(props, points)); | ||
var labelPosition = this.getLabelPosition(props, labelProps, points); | ||
return (0, _defaults2.default)({}, labelPosition, labelProps); | ||
} | ||
}, { | ||
key: "getTooltip", | ||
value: function getTooltip(props) { | ||
var labels = props.labels, | ||
activePoints = props.activePoints, | ||
labelComponent = props.labelComponent; | ||
return /*#__PURE__*/_react.default.createElement(_victoryCore.VictoryContainer, props, children); | ||
}; | ||
if (!labels) { | ||
return null; | ||
} | ||
exports.VictoryVoronoiContainer = VictoryVoronoiContainer; | ||
VictoryVoronoiContainer.role = "container"; | ||
if (Array.isArray(activePoints) && activePoints.length) { | ||
var labelProps = this.getLabelProps(props, activePoints); | ||
var text = labelProps.text; | ||
var showLabel = Array.isArray(text) ? text.filter(Boolean).length : text; | ||
return showLabel ? /*#__PURE__*/_react.default.cloneElement(labelComponent, labelProps) : null; | ||
} | ||
VictoryVoronoiContainer.defaultEvents = function (initialProps) { | ||
var props = _objectSpread(_objectSpread({}, VICTORY_VORONOI_CONTAINER_DEFAULT_PROPS), initialProps); | ||
return null; | ||
} // Overrides method in VictoryContainer | ||
var createEventHandler = function (handler, disabled) { | ||
return (// eslint-disable-next-line max-params | ||
function (event, targetProps, eventKey, context) { | ||
return disabled || props.disable ? {} : handler(event, _objectSpread(_objectSpread({}, props), targetProps), eventKey, context); | ||
}, { | ||
key: "getChildren", | ||
value: function getChildren(props) { | ||
return [].concat(_toConsumableArray(_react.default.Children.toArray(props.children)), [this.getTooltip(props)]); | ||
} | ||
); | ||
}; | ||
}]); | ||
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: function () { | ||
return null; | ||
}, | ||
onMouseOut: function () { | ||
return null; | ||
}, | ||
onMouseMove: function () { | ||
return null; | ||
return VictoryVoronoiContainer; | ||
}(Base), _class.displayName = "VictoryVoronoiContainer", _class.defaultProps = _objectSpread(_objectSpread({}, _victoryCore.VictoryContainer.defaultProps), {}, { | ||
activateData: true, | ||
activateLabels: true, | ||
labelComponent: /*#__PURE__*/_react.default.createElement(_victoryTooltip.VictoryTooltip, null), | ||
voronoiPadding: 5 | ||
}), _class.defaultEvents = function (props) { | ||
return [{ | ||
target: "parent", | ||
eventHandlers: { | ||
onMouseLeave: function (evt, targetProps) { | ||
return props.disable ? {} : _voronoiHelpers.VoronoiHelpers.onMouseLeave(evt, targetProps); | ||
}, | ||
onTouchCancel: function (evt, targetProps) { | ||
return props.disable ? {} : _voronoiHelpers.VoronoiHelpers.onMouseLeave(evt, targetProps); | ||
}, | ||
onMouseMove: function (evt, targetProps) { | ||
return props.disable ? {} : _voronoiHelpers.VoronoiHelpers.onMouseMove(evt, targetProps); | ||
}, | ||
onTouchMove: function (evt, targetProps) { | ||
return props.disable ? {} : _voronoiHelpers.VoronoiHelpers.onMouseMove(evt, targetProps); | ||
} | ||
} | ||
} | ||
}]; | ||
}; | ||
}, { | ||
target: "data", | ||
eventHandlers: props.disable ? {} : { | ||
onMouseOver: function () { | ||
return null; | ||
}, | ||
onMouseOut: function () { | ||
return null; | ||
}, | ||
onMouseMove: function () { | ||
return null; | ||
} | ||
} | ||
}]; | ||
}, _class; | ||
} | ||
var VictoryVoronoiContainer = voronoiContainerMixin(_victoryCore.VictoryContainer); | ||
exports.VictoryVoronoiContainer = VictoryVoronoiContainer; |
{ | ||
"name": "victory-voronoi-container", | ||
"version": "36.9.2-next.1", | ||
"version": "36.9.2-next.3", | ||
"description": "Interactive Voronoi Mouseover Component for Victory", | ||
@@ -26,4 +26,4 @@ "keywords": [ | ||
"react-fast-compare": "^3.2.0", | ||
"victory-core": "^36.9.2-next.1", | ||
"victory-tooltip": "^36.9.2-next.1" | ||
"victory-core": "^36.9.2-next.3", | ||
"victory-tooltip": "^36.9.2-next.3" | ||
}, | ||
@@ -30,0 +30,0 @@ "peerDependencies": { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Uses eval
Supply chain riskPackage uses eval() which is a dangerous function. This prevents the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
0
7
996549
17030
4