@octanejs/visx 0.1.46 → 0.1.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -6
- package/src/chord/Ribbon.tsrx +1 -9
- package/src/hierarchy/hierarchies/Treemap.tsrx +1 -1
- package/src/internal/setNumberOrNumberAccessor.ts +11 -0
- package/src/shape/shapes/AreaClosed.tsrx +1 -1
- package/src/shape/shapes/BarStack.tsrx +1 -1
- package/src/shape/shapes/BarStackHorizontal.tsrx +1 -1
- package/src/shape/util/D3ShapeFactories.ts +1 -1
- package/src/xychart/components/series/private/AnimatedPath.tsrx.d.ts +5 -1
- package/src/hierarchy/utils/setNumOrNumAccessor.ts +0 -11
- package/src/shape/util/getOrCreateMeasurementElement.ts +0 -28
- package/src/shape/util/setNumberOrNumberAccessor.ts +0 -11
- package/src/xychart/utils/findNearestDatumXY.ts +0 -42
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octanejs/visx",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.47",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -104,9 +104,7 @@
|
|
|
104
104
|
"d3-array": "3.2.1",
|
|
105
105
|
"d3-chord": "^1.0.6",
|
|
106
106
|
"d3-cloud": "^1.2.9",
|
|
107
|
-
"d3-color": "3.1.0",
|
|
108
107
|
"d3-delaunay": "6.0.2",
|
|
109
|
-
"d3-format": "3.1.0",
|
|
110
108
|
"d3-geo": "3.1.0",
|
|
111
109
|
"d3-hierarchy": "^1.1.9",
|
|
112
110
|
"d3-interpolate": "3.0.1",
|
|
@@ -117,9 +115,7 @@
|
|
|
117
115
|
"d3-scale": "4.0.2",
|
|
118
116
|
"d3-shape": "3.2.0",
|
|
119
117
|
"d3-time": "3.1.0",
|
|
120
|
-
"d3-time-format": "4.1.0",
|
|
121
118
|
"d3-voronoi": "^1.1.4",
|
|
122
|
-
"internmap": "2.0.3",
|
|
123
119
|
"mitt": "^2.1.0",
|
|
124
120
|
"reduce-css-calc": "^1.3.0",
|
|
125
121
|
"svg-path-properties": "2.0.2",
|
|
@@ -149,7 +145,7 @@
|
|
|
149
145
|
"react-dom": "^19.2.7",
|
|
150
146
|
"typescript": "^5.9.3",
|
|
151
147
|
"vitest": "^4.1.10",
|
|
152
|
-
"octane": "0.2.
|
|
148
|
+
"octane": "0.2.3"
|
|
153
149
|
},
|
|
154
150
|
"scripts": {
|
|
155
151
|
"compile:check": "node scripts/check-tsrx-compile.mjs",
|
package/src/chord/Ribbon.tsrx
CHANGED
|
@@ -2,6 +2,7 @@ import type { Octane } from 'octane/jsx-runtime';
|
|
|
2
2
|
import cx from 'classnames';
|
|
3
3
|
import type { Chord, ChordSubgroup } from 'd3-chord';
|
|
4
4
|
import { ribbon as d3ribbon } from 'd3-chord';
|
|
5
|
+
import setNumberOrNumberAccessor from '../internal/setNumberOrNumberAccessor';
|
|
5
6
|
|
|
6
7
|
type NumAccessor = (d: ChordSubgroup) => number;
|
|
7
8
|
|
|
@@ -28,15 +29,6 @@ export type RibbonProps = {
|
|
|
28
29
|
className?: string;
|
|
29
30
|
};
|
|
30
31
|
|
|
31
|
-
/** This is a workaround for TypeScript not inferring the correct method overload */
|
|
32
|
-
function setNumberOrNumberAccessor(
|
|
33
|
-
func: (d: number | NumAccessor) => void,
|
|
34
|
-
value: number | NumAccessor,
|
|
35
|
-
) {
|
|
36
|
-
if (typeof value === 'number') func(value);
|
|
37
|
-
else func(value);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
32
|
export default function Ribbon({
|
|
41
33
|
chord,
|
|
42
34
|
source,
|
|
@@ -5,7 +5,7 @@ import { Group } from '@octanejs/visx/group';
|
|
|
5
5
|
import type { HierarchyRectangularNode, HierarchyNode } from 'd3-hierarchy';
|
|
6
6
|
import { treemap as d3treemap } from 'd3-hierarchy';
|
|
7
7
|
import HierarchyDefaultRectNode from '../HierarchyDefaultRectNode.tsrx';
|
|
8
|
-
import setNumberOrNumberAccessor from '
|
|
8
|
+
import setNumberOrNumberAccessor from '../../internal/setNumberOrNumberAccessor';
|
|
9
9
|
import type { TileMethod } from '../types';
|
|
10
10
|
|
|
11
11
|
export type NodeComponentProps<Datum> = { node: HierarchyRectangularNode<Datum> };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Work around TypeScript not narrowing the overloaded setter signatures used
|
|
3
|
+
* by several D3 packages.
|
|
4
|
+
*/
|
|
5
|
+
export default function setNumberOrNumberAccessor<NumAccessor>(
|
|
6
|
+
setter: (value: number | NumAccessor) => void,
|
|
7
|
+
value: number | NumAccessor,
|
|
8
|
+
) {
|
|
9
|
+
if (typeof value === 'number') setter(value);
|
|
10
|
+
else setter(value);
|
|
11
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import cx from 'classnames';
|
|
2
2
|
import type { PositionScale, AddSVGProps, BaseAreaProps } from '../types';
|
|
3
|
-
import setNumOrAccessor from '
|
|
3
|
+
import setNumOrAccessor from '../../internal/setNumberOrNumberAccessor';
|
|
4
4
|
import { area } from '../util/D3ShapeFactories';
|
|
5
5
|
|
|
6
6
|
export type AreaClosedProps<Datum> = BaseAreaProps<Datum> & {
|
|
@@ -13,7 +13,7 @@ import type {
|
|
|
13
13
|
} from '../types';
|
|
14
14
|
import { getFirstItem, getSecondItem } from '../util/accessors';
|
|
15
15
|
import getBandwidth from '../util/getBandwidth';
|
|
16
|
-
import setNumOrAccessor from '
|
|
16
|
+
import setNumOrAccessor from '../../internal/setNumberOrNumberAccessor';
|
|
17
17
|
import stackOrder from '../util/stackOrder';
|
|
18
18
|
import stackOffset from '../util/stackOffset';
|
|
19
19
|
import Bar from './Bar.tsrx';
|
|
@@ -6,7 +6,7 @@ import type { ScaleInput } from '@octanejs/visx/scale';
|
|
|
6
6
|
import type { AddSVGProps, PositionScale, BaseBarStackProps, StackKey, Accessor } from '../types';
|
|
7
7
|
import { getFirstItem, getSecondItem } from '../util/accessors';
|
|
8
8
|
import getBandwidth from '../util/getBandwidth';
|
|
9
|
-
import setNumOrAccessor from '
|
|
9
|
+
import setNumOrAccessor from '../../internal/setNumberOrNumberAccessor';
|
|
10
10
|
import stackOrder from '../util/stackOrder';
|
|
11
11
|
import stackOffset from '../util/stackOffset';
|
|
12
12
|
import Bar from './Bar.tsrx';
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
radialLine as d3RadialLine,
|
|
7
7
|
stack as d3Stack,
|
|
8
8
|
} from 'd3-shape';
|
|
9
|
-
import setNumberOrNumberAccessor from '
|
|
9
|
+
import setNumberOrNumberAccessor from '../../internal/setNumberOrNumberAccessor';
|
|
10
10
|
import type {
|
|
11
11
|
ArcPathConfig,
|
|
12
12
|
AreaPathConfig,
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
// Generated by scripts/generate-tsrx-types.mjs.
|
|
2
2
|
import type { Octane } from 'octane/jsx-runtime';
|
|
3
|
-
declare
|
|
3
|
+
declare function AnimatedPath({ d, stroke, fill, ...lineProps }: Omit<Octane.SVGProps<SVGPathElement>, 'ref'>): import("react").JSX.Element;
|
|
4
|
+
declare const _default: typeof AnimatedPath & {
|
|
5
|
+
readonly type: typeof AnimatedPath;
|
|
6
|
+
displayName?: string;
|
|
7
|
+
};
|
|
4
8
|
export default _default;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This is a workaround for TypeScript not inferring the correct
|
|
3
|
-
* method overload/signature for some d3 shape methods.
|
|
4
|
-
*/
|
|
5
|
-
export default function setNumberOrNumberAccessor<NumAccessor>(
|
|
6
|
-
func: (d: number | NumAccessor) => void,
|
|
7
|
-
value: number | NumAccessor,
|
|
8
|
-
) {
|
|
9
|
-
if (typeof value === 'number') func(value);
|
|
10
|
-
else func(value);
|
|
11
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
const SVG_NAMESPACE_URL = 'http://www.w3.org/2000/svg';
|
|
2
|
-
|
|
3
|
-
export default function getOrCreateMeasurementElement(elementId: string) {
|
|
4
|
-
let pathElement = document.getElementById(elementId) as SVGPathElement | null;
|
|
5
|
-
|
|
6
|
-
// create a single path element if not done already
|
|
7
|
-
if (!pathElement) {
|
|
8
|
-
const svg = document.createElementNS(SVG_NAMESPACE_URL, 'svg');
|
|
9
|
-
|
|
10
|
-
// not visible
|
|
11
|
-
svg.setAttribute('aria-hidden', 'true');
|
|
12
|
-
svg.style.opacity = '0';
|
|
13
|
-
svg.style.width = '0';
|
|
14
|
-
svg.style.height = '0';
|
|
15
|
-
// off screen
|
|
16
|
-
svg.style.position = 'absolute';
|
|
17
|
-
svg.style.top = '-100%';
|
|
18
|
-
svg.style.left = '-100%';
|
|
19
|
-
// no mouse events
|
|
20
|
-
svg.style.pointerEvents = 'none';
|
|
21
|
-
pathElement = document.createElementNS(SVG_NAMESPACE_URL, 'path');
|
|
22
|
-
pathElement.setAttribute('id', elementId);
|
|
23
|
-
svg.appendChild(pathElement);
|
|
24
|
-
document.body.appendChild(svg);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return pathElement;
|
|
28
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This is a workaround for TypeScript not inferring the correct
|
|
3
|
-
* method overload/signature for some d3 shape methods.
|
|
4
|
-
*/
|
|
5
|
-
export default function setNumberOrNumberAccessor<NumAccessor>(
|
|
6
|
-
func: (d: number | NumAccessor) => void,
|
|
7
|
-
value: number | NumAccessor,
|
|
8
|
-
) {
|
|
9
|
-
if (typeof value === 'number') func(value);
|
|
10
|
-
else func(value);
|
|
11
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { AxisScale } from '@octanejs/visx/axis';
|
|
2
|
-
import { voronoi } from '@octanejs/visx/voronoi';
|
|
3
|
-
import type { NearestDatumArgs, NearestDatumReturnType } from '../types';
|
|
4
|
-
|
|
5
|
-
/* finds the datum nearest to svgMouseX/Y using a voronoi */
|
|
6
|
-
export default function findNearestDatumXY<
|
|
7
|
-
XScale extends AxisScale,
|
|
8
|
-
YScale extends AxisScale,
|
|
9
|
-
Datum extends object,
|
|
10
|
-
>({
|
|
11
|
-
width,
|
|
12
|
-
height,
|
|
13
|
-
xScale,
|
|
14
|
-
yScale,
|
|
15
|
-
xAccessor,
|
|
16
|
-
yAccessor,
|
|
17
|
-
point,
|
|
18
|
-
data,
|
|
19
|
-
}: NearestDatumArgs<XScale, YScale, Datum>): NearestDatumReturnType<Datum> {
|
|
20
|
-
if (!point) return null;
|
|
21
|
-
|
|
22
|
-
const scaledX = (d: Datum) => Number(xScale(xAccessor(d)));
|
|
23
|
-
const scaledY = (d: Datum) => Number(yScale(yAccessor(d)));
|
|
24
|
-
|
|
25
|
-
// Create a voronoi for each datum's x,y coordinate
|
|
26
|
-
const voronoiInstance = voronoi({
|
|
27
|
-
x: scaledX,
|
|
28
|
-
y: scaledY,
|
|
29
|
-
width,
|
|
30
|
-
height,
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
const nearestDatum = voronoiInstance(data).find(point.x, point.y);
|
|
34
|
-
|
|
35
|
-
if (!nearestDatum) return null;
|
|
36
|
-
|
|
37
|
-
const { data: datum, index } = nearestDatum;
|
|
38
|
-
const distanceX = Math.abs(scaledX(datum) - point.x);
|
|
39
|
-
const distanceY = Math.abs(scaledY(datum) - point.y);
|
|
40
|
-
|
|
41
|
-
return { datum, index, distanceX, distanceY };
|
|
42
|
-
}
|