@octanejs/recharts 0.1.16 → 0.1.18
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 +4 -4
- package/src/animation/CSSTransitionAnimate.tsrx +142 -0
- package/src/cartesian/Area.tsrx +1096 -0
- package/src/cartesian/Area.tsrx.d.ts +340 -0
- package/src/cartesian/AreaRevealShape.tsrx +202 -0
- package/src/cartesian/CartesianGrid.tsrx +643 -0
- package/src/cartesian/CartesianGrid.tsrx.d.ts +219 -0
- package/src/cartesian/ErrorBar.tsrx +322 -0
- package/src/cartesian/ErrorBar.tsrx.d.ts +131 -0
- package/src/cartesian/Funnel.tsrx +833 -0
- package/src/cartesian/Funnel.tsrx.d.ts +274 -0
- package/src/cartesian/ReferenceLine.tsrx +452 -0
- package/src/cartesian/ReferenceLine.tsrx.d.ts +178 -0
- package/src/cartesian/Scatter.tsrx +1076 -0
- package/src/cartesian/Scatter.tsrx.d.ts +351 -0
- package/src/cartesian/ZAxis.tsrx +148 -0
- package/src/cartesian/ZAxis.tsrx.d.ts +102 -0
- package/src/chart/AreaChart.tsrx +22 -0
- package/src/chart/AreaChart.tsrx.d.ts +12 -0
- package/src/chart/ComposedChart.tsrx +22 -0
- package/src/chart/ComposedChart.tsrx.d.ts +12 -0
- package/src/chart/FunnelChart.tsrx +22 -0
- package/src/chart/FunnelChart.tsrx.d.ts +12 -0
- package/src/chart/PieChart.tsrx +31 -0
- package/src/chart/PieChart.tsrx.d.ts +31 -0
- package/src/chart/PolarChart.tsrx +121 -0
- package/src/chart/RadarChart.tsrx +53 -0
- package/src/chart/RadarChart.tsrx.d.ts +31 -0
- package/src/chart/RadialBarChart.tsrx +31 -0
- package/src/chart/RadialBarChart.tsrx.d.ts +31 -0
- package/src/chart/Sankey.tsrx +1542 -0
- package/src/chart/Sankey.tsrx.d.ts +253 -0
- package/src/chart/ScatterChart.tsrx +22 -0
- package/src/chart/ScatterChart.tsrx.d.ts +12 -0
- package/src/chart/SunburstChart.tsrx +495 -0
- package/src/chart/SunburstChart.tsrx.d.ts +146 -0
- package/src/chart/types.ts +19 -0
- package/src/component/Cursor.tsrx +157 -0
- package/src/component/DefaultLegendContent.tsrx +288 -0
- package/src/component/DefaultLegendContent.tsrx.d.ts +125 -0
- package/src/component/DefaultTooltipContent.tsrx +215 -0
- package/src/component/DefaultTooltipContent.tsrx.d.ts +87 -0
- package/src/component/Legend.tsrx +302 -0
- package/src/component/Legend.tsrx.d.ts +88 -0
- package/src/component/ResponsiveContainer.ts +1 -22
- package/src/component/ResponsiveContainer.tsrx +171 -0
- package/src/component/ResponsiveContainer.tsrx.d.ts +81 -0
- package/src/component/Tooltip.tsrx +425 -0
- package/src/component/Tooltip.tsrx.d.ts +246 -0
- package/src/component/TooltipBoundingBox.tsrx +135 -0
- package/src/context/CellsContext.ts +12 -0
- package/src/context/legendPayloadContext.tsrx +11 -0
- package/src/context/useTooltipAxis.ts +20 -0
- package/src/index.d.ts +236 -0
- package/src/index.ts +67 -0
- package/src/polar/Pie.tsrx +1224 -0
- package/src/polar/Pie.tsrx.d.ts +436 -0
- package/src/polar/PolarAngleAxis.tsrx +554 -0
- package/src/polar/PolarAngleAxis.tsrx.d.ts +215 -0
- package/src/polar/PolarGrid.tsrx +317 -0
- package/src/polar/PolarGrid.tsrx.d.ts +117 -0
- package/src/polar/PolarRadiusAxis.tsrx +463 -0
- package/src/polar/PolarRadiusAxis.tsrx.d.ts +209 -0
- package/src/polar/Radar.tsrx +696 -0
- package/src/polar/Radar.tsrx.d.ts +215 -0
- package/src/polar/RadialBar.tsrx +887 -0
- package/src/polar/RadialBar.tsrx.d.ts +340 -0
- package/src/state/ReportPolarOptions.tsrx +11 -0
- package/src/state/selectors/areaSelectors.ts +257 -0
- package/src/state/selectors/funnelSelectors.ts +86 -0
- package/src/state/selectors/pieSelectors.ts +134 -0
- package/src/state/selectors/polarGridSelectors.ts +43 -0
- package/src/state/selectors/polarScaleSelectors.ts +159 -0
- package/src/state/selectors/polarSelectors.ts +198 -0
- package/src/state/selectors/radarSelectors.ts +228 -0
- package/src/state/selectors/radialBarSelectors.ts +511 -0
- package/src/state/selectors/scatterSelectors.ts +168 -0
- package/src/util/FunnelUtils.tsrx +19 -0
- package/src/util/RadialBarUtils.tsrx +29 -0
- package/src/util/ScatterUtils.tsrx +34 -0
- package/src/util/cursor/getCursorPoints.ts +45 -0
- package/src/util/cursor/getCursorRectangle.ts +28 -0
- package/src/util/cursor/getRadialCursorPoints.ts +31 -0
- package/src/util/payload/getUniqPayload.ts +28 -0
- package/src/util/scale/CartesianScaleHelper.ts +71 -0
- package/src/util/tooltip/translate.ts +168 -0
- package/src/util/types.ts +3 -0
- package/src/util/useElementOffset.ts +147 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import * as React from 'octane';
|
|
2
|
+
import { FunctionComponent, SVGProps } from 'octane';
|
|
3
|
+
import {
|
|
4
|
+
AxisDomain,
|
|
5
|
+
AxisDomainTypeInput,
|
|
6
|
+
BaseTickContentProps,
|
|
7
|
+
PresentationAttributesAdaptChildEvent,
|
|
8
|
+
RenderableAxisProps,
|
|
9
|
+
ScaleType,
|
|
10
|
+
TickItem,
|
|
11
|
+
TickProp,
|
|
12
|
+
} from '../util/types';
|
|
13
|
+
import { NiceTicksAlgorithm } from '../state/cartesianAxisSlice';
|
|
14
|
+
import { defaultPolarAngleAxisProps } from './defaultPolarAngleAxisProps';
|
|
15
|
+
import { RequiresDefaultProps } from '../util/resolveDefaultProps';
|
|
16
|
+
import { ZIndexable } from '../zIndex/ZIndexLayer';
|
|
17
|
+
import { CustomScaleDefinition } from '../util/scale/CustomScaleDefinition';
|
|
18
|
+
export interface PolarAngleAxisProps<DataPointType = any, DataValueType = any>
|
|
19
|
+
extends
|
|
20
|
+
Omit<
|
|
21
|
+
RenderableAxisProps<DataPointType, DataValueType>,
|
|
22
|
+
'axisLine' | 'tickCount' | 'domain' | 'scale' | 'tick'
|
|
23
|
+
>,
|
|
24
|
+
ZIndexable {
|
|
25
|
+
/**
|
|
26
|
+
* Controls axis line element. These are be passed as props to SVG `<line>` element representing the axis line.
|
|
27
|
+
* If `true` then the axis line is drawn using props of the PolarAngleAxis component.
|
|
28
|
+
* If `false` then the axis line is not drawn.
|
|
29
|
+
*
|
|
30
|
+
* Also see `axisLineType` prop to change the shape of the axis line.
|
|
31
|
+
*
|
|
32
|
+
* @defaultValue true
|
|
33
|
+
*
|
|
34
|
+
* @example <PolarAngleAxis axisLine={{ stroke: 'red', strokeWidth: 2 }} />
|
|
35
|
+
* @example <PolarAngleAxis axisLine={false} />
|
|
36
|
+
* @example <PolarAngleAxis stroke='red' strokeWidth={2} strokeDasharray={4} />
|
|
37
|
+
*/
|
|
38
|
+
axisLine?: boolean | SVGProps<SVGLineElement>;
|
|
39
|
+
/**
|
|
40
|
+
* @defaultValue false
|
|
41
|
+
*/
|
|
42
|
+
allowDecimals?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Allow the axis has duplicated categories or not when the type of axis is "category".
|
|
45
|
+
* @defaultValue true
|
|
46
|
+
*/
|
|
47
|
+
allowDuplicatedCategory?: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* @defaultValue 0
|
|
50
|
+
*/
|
|
51
|
+
angleAxisId?: string | number;
|
|
52
|
+
/**
|
|
53
|
+
* The type of axis line.
|
|
54
|
+
* @defaultValue polygon
|
|
55
|
+
*/
|
|
56
|
+
axisLineType?: 'polygon' | 'circle';
|
|
57
|
+
/**
|
|
58
|
+
* The x-coordinate of center.
|
|
59
|
+
* When used inside a chart context, this prop is calculated based on the chart's dimensions,
|
|
60
|
+
* and this prop is ignored.
|
|
61
|
+
*
|
|
62
|
+
* This is only used when rendered outside a chart context.
|
|
63
|
+
*/
|
|
64
|
+
cx?: number;
|
|
65
|
+
/**
|
|
66
|
+
* The y-coordinate of center.
|
|
67
|
+
* When used inside a chart context, this prop is calculated based on the chart's dimensions,
|
|
68
|
+
* and this prop is ignored.
|
|
69
|
+
*
|
|
70
|
+
* This is only used when rendered outside a chart context.
|
|
71
|
+
*/
|
|
72
|
+
cy?: number;
|
|
73
|
+
/**
|
|
74
|
+
* The orientation of axis text.
|
|
75
|
+
* @defaultValue 'outer'
|
|
76
|
+
*/
|
|
77
|
+
orientation?: 'inner' | 'outer';
|
|
78
|
+
/**
|
|
79
|
+
* Specify the domain of axis when the axis is a number axis.
|
|
80
|
+
*
|
|
81
|
+
* If undefined, then the domain is calculated based on the data and dataKeys.
|
|
82
|
+
*
|
|
83
|
+
* The length of domain should be 2, and we will validate the values in domain.
|
|
84
|
+
*
|
|
85
|
+
* Each element in the array can be a number, 'auto', 'dataMin', 'dataMax', a string like 'dataMin - 20', 'dataMax + 100',
|
|
86
|
+
* or a function that accepts a single argument and returns a number.
|
|
87
|
+
*
|
|
88
|
+
* If any element of domain is set to be 'auto', comprehensible scale ticks will be calculated, and the final domain of axis is generated by the ticks.
|
|
89
|
+
* If a function, receives '[dataMin, dataMax]', and must return a computed domain as '[min, max]'.
|
|
90
|
+
*
|
|
91
|
+
* @example <PolarAngleAxis type="number" domain={['dataMin', 'dataMax']} />
|
|
92
|
+
* @example <PolarAngleAxis type="number" domain={[0, 'dataMax']} />
|
|
93
|
+
* @example <PolarAngleAxis type="number" domain={['auto', 'auto']} />
|
|
94
|
+
* @example <PolarAngleAxis type="number" domain={[0, 'dataMax + 1000']} />
|
|
95
|
+
* @example <PolarAngleAxis type="number" domain={['dataMin - 100', 'dataMax + 100']} />
|
|
96
|
+
* @example <PolarAngleAxis type="number" domain={[dataMin => (0 - Math.abs(dataMin)), dataMax => (dataMax * 2)]} />
|
|
97
|
+
* @example <PolarAngleAxis type="number" domain={([dataMin, dataMax]) => { const absMax = Math.max(Math.abs(dataMin), Math.abs(dataMax)); return [-absMax, absMax]; }} />
|
|
98
|
+
* @example <PolarAngleAxis type="number" domain={[0, 100]} allowDataOverflow />
|
|
99
|
+
*/
|
|
100
|
+
domain?: AxisDomain;
|
|
101
|
+
/**
|
|
102
|
+
* Scale function determines how data values are mapped to visual values.
|
|
103
|
+
* In other words, decided the mapping between data domain and coordinate range.
|
|
104
|
+
*
|
|
105
|
+
* If undefined, or 'auto', the scale function is created internally according to the type of axis and data.
|
|
106
|
+
*
|
|
107
|
+
* You can define a custom scale, either as a string shortcut to a d3 scale, or as a complete scale definition object.
|
|
108
|
+
*
|
|
109
|
+
* @defaultValue auto
|
|
110
|
+
* @example <PolarAngleAxis scale="log" />
|
|
111
|
+
* @example
|
|
112
|
+
* import { scaleLog } from 'd3-scale';
|
|
113
|
+
* const scale = scaleLog().base(Math.E);
|
|
114
|
+
* <PolarAngleAxis scale={scale} />
|
|
115
|
+
*/
|
|
116
|
+
scale?:
|
|
117
|
+
| ScaleType
|
|
118
|
+
| CustomScaleDefinition
|
|
119
|
+
| CustomScaleDefinition<string>
|
|
120
|
+
| CustomScaleDefinition<number>
|
|
121
|
+
| CustomScaleDefinition<Date>;
|
|
122
|
+
/**
|
|
123
|
+
* The outer radius of circle grid.
|
|
124
|
+
* If set a percentage, the final value is obtained by multiplying the percentage of maxRadius which is calculated by the width, height, cx, cy.
|
|
125
|
+
*/
|
|
126
|
+
radius?: number | string;
|
|
127
|
+
/**
|
|
128
|
+
* Defines how the individual label text is rendered.
|
|
129
|
+
* This controls the settings for individual ticks; on a typical axis, there are multiple ticks, depending on your data.
|
|
130
|
+
*
|
|
131
|
+
* If you want to customize the overall axis label, use the `label` prop instead.
|
|
132
|
+
*
|
|
133
|
+
* Options:
|
|
134
|
+
* - `false`: Do not render any tick labels.
|
|
135
|
+
* - `true`: Render tick labels with default settings.
|
|
136
|
+
* - `object`: An object of props to be merged into the internally calculated tick props.
|
|
137
|
+
* - `ReactElement`: A custom React element to be used as the tick label.
|
|
138
|
+
* - `function`: A function that returns a React element for custom rendering of tick labels.
|
|
139
|
+
*
|
|
140
|
+
* @defaultValue true
|
|
141
|
+
*/
|
|
142
|
+
tick?: TickProp<BaseTickContentProps>;
|
|
143
|
+
/**
|
|
144
|
+
* The count of axis ticks. Not used if 'type' is 'category'.
|
|
145
|
+
*/
|
|
146
|
+
tickCount?: number;
|
|
147
|
+
/**
|
|
148
|
+
* Controls how Recharts calculates "nice" tick values for this axis.
|
|
149
|
+
* Options: `'none'`, `'auto'`, `'adaptive'`, `'snap125'`.
|
|
150
|
+
* See {@link NiceTicksAlgorithm} for a full description of each option.
|
|
151
|
+
*
|
|
152
|
+
* @defaultValue 'auto'
|
|
153
|
+
*/
|
|
154
|
+
niceTicks?: NiceTicksAlgorithm;
|
|
155
|
+
/**
|
|
156
|
+
* The formatter function of ticks.
|
|
157
|
+
*/
|
|
158
|
+
tickFormatter?: (value: any, index: number) => string;
|
|
159
|
+
/**
|
|
160
|
+
* The length of tick line.
|
|
161
|
+
* @defaultValue 8
|
|
162
|
+
*/
|
|
163
|
+
tickSize?: number;
|
|
164
|
+
/**
|
|
165
|
+
* The array of every tick's value and angle.
|
|
166
|
+
*/
|
|
167
|
+
ticks?: ReadonlyArray<TickItem>;
|
|
168
|
+
/**
|
|
169
|
+
* The type of axis.
|
|
170
|
+
*
|
|
171
|
+
* `category`: Treats data as distinct values.
|
|
172
|
+
* Each value is in the same distance from its neighbors, regardless of their actual numeric difference.
|
|
173
|
+
*
|
|
174
|
+
* `number`: Treats data as continuous range.
|
|
175
|
+
* Values that are numerically closer are placed closer together on the axis.
|
|
176
|
+
*
|
|
177
|
+
* `auto`: the type is inferred based on the chart layout.
|
|
178
|
+
*
|
|
179
|
+
* @defaultValue auto
|
|
180
|
+
*/
|
|
181
|
+
type?: AxisDomainTypeInput;
|
|
182
|
+
/**
|
|
183
|
+
* Z-Index of this component and its children. The higher the value,
|
|
184
|
+
* the more on top it will be rendered.
|
|
185
|
+
* Components with higher zIndex will appear in front of components with lower zIndex.
|
|
186
|
+
* If undefined or 0, the content is rendered in the default layer without portals.
|
|
187
|
+
*
|
|
188
|
+
* @since 3.4
|
|
189
|
+
* @defaultValue 500
|
|
190
|
+
* @see {@link https://recharts.github.io/en-US/guide/zIndex/ Z-Index and layers guide}
|
|
191
|
+
*/
|
|
192
|
+
zIndex?: number;
|
|
193
|
+
}
|
|
194
|
+
type AxisSvgProps = Omit<
|
|
195
|
+
PresentationAttributesAdaptChildEvent<TickItem, SVGTextElement>,
|
|
196
|
+
'scale' | 'type' | 'dangerouslySetInnerHTML'
|
|
197
|
+
>;
|
|
198
|
+
export type Props<DataPointType = any, DataValueType = any> = AxisSvgProps &
|
|
199
|
+
PolarAngleAxisProps<DataPointType, DataValueType>;
|
|
200
|
+
type PropsWithDefaults<DataPointType = any, DataValueType = any> = RequiresDefaultProps<
|
|
201
|
+
Props<DataPointType, DataValueType>,
|
|
202
|
+
typeof defaultPolarAngleAxisProps
|
|
203
|
+
>;
|
|
204
|
+
export declare const PolarAngleAxisWrapper: FunctionComponent<PropsWithDefaults>;
|
|
205
|
+
/**
|
|
206
|
+
* @provides PolarLabelContext
|
|
207
|
+
* @consumes PolarViewBoxContext
|
|
208
|
+
*/
|
|
209
|
+
export declare function PolarAngleAxis<DataPointType = any, DataValueType = any>(
|
|
210
|
+
outsideProps: Props<DataPointType, DataValueType>,
|
|
211
|
+
): React.ReactNode;
|
|
212
|
+
export declare namespace PolarAngleAxis {
|
|
213
|
+
var displayName: string;
|
|
214
|
+
}
|
|
215
|
+
export {};
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import { clsx } from 'clsx';
|
|
2
|
+
import * as React from 'octane';
|
|
3
|
+
import { SVGProps } from 'octane';
|
|
4
|
+
import { polarToCartesian } from '../util/PolarUtils';
|
|
5
|
+
import { AxisId } from '../state/cartesianAxisSlice';
|
|
6
|
+
import { useAppSelector } from '../state/hooks';
|
|
7
|
+
import { selectPolarGridAngles, selectPolarGridRadii } from '../state/selectors/polarGridSelectors';
|
|
8
|
+
import { selectPolarViewBox } from '../state/selectors/polarAxisSelectors';
|
|
9
|
+
import { PolarViewBoxRequired } from '../util/types';
|
|
10
|
+
import { svgPropertiesNoEvents } from '../util/svgPropertiesNoEvents';
|
|
11
|
+
import { ZIndexable, ZIndexLayer } from '../zIndex/ZIndexLayer';
|
|
12
|
+
import { DefaultZIndexes } from '../zIndex/DefaultZIndexes';
|
|
13
|
+
import { resolveDefaultProps } from '../util/resolveDefaultProps';
|
|
14
|
+
|
|
15
|
+
interface PolarGridProps extends ZIndexable {
|
|
16
|
+
/**
|
|
17
|
+
* The x-coordinate of center.
|
|
18
|
+
* When used inside a chart context, this prop is calculated based on the chart's dimensions,
|
|
19
|
+
* and this prop is ignored.
|
|
20
|
+
*
|
|
21
|
+
* This is only used when rendered outside a chart context.
|
|
22
|
+
*/
|
|
23
|
+
cx?: number;
|
|
24
|
+
/**
|
|
25
|
+
* The y-coordinate of center.
|
|
26
|
+
* When used inside a chart context, this prop is calculated based on the chart's dimensions,
|
|
27
|
+
* and this prop is ignored.
|
|
28
|
+
*
|
|
29
|
+
* This is only used when rendered outside a chart context.
|
|
30
|
+
*/
|
|
31
|
+
cy?: number;
|
|
32
|
+
/**
|
|
33
|
+
* The radius of the inner polar grid.
|
|
34
|
+
* When used inside a chart context, this prop is calculated based on the chart's dimensions,
|
|
35
|
+
* and this prop is ignored.
|
|
36
|
+
*
|
|
37
|
+
* This is only used when rendered outside a chart context.
|
|
38
|
+
*/
|
|
39
|
+
innerRadius?: number;
|
|
40
|
+
/**
|
|
41
|
+
* The radius of the outer polar grid.
|
|
42
|
+
* When used inside a chart context, this prop is calculated based on the chart's dimensions,
|
|
43
|
+
* and this prop is ignored.
|
|
44
|
+
*
|
|
45
|
+
* This is only used when rendered outside a chart context.
|
|
46
|
+
*/
|
|
47
|
+
outerRadius?: number;
|
|
48
|
+
/**
|
|
49
|
+
* The array of every line grid's angle.
|
|
50
|
+
*/
|
|
51
|
+
polarAngles?: ReadonlyArray<number>;
|
|
52
|
+
/**
|
|
53
|
+
* The array of every circle grid's radius.
|
|
54
|
+
*/
|
|
55
|
+
polarRadius?: ReadonlyArray<number>;
|
|
56
|
+
/**
|
|
57
|
+
* The type of polar grids.
|
|
58
|
+
* @defaultValue polygon
|
|
59
|
+
*/
|
|
60
|
+
gridType?: 'polygon' | 'circle';
|
|
61
|
+
/**
|
|
62
|
+
* @defaultValue true
|
|
63
|
+
*/
|
|
64
|
+
radialLines?: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* @defaultValue 0
|
|
67
|
+
*/
|
|
68
|
+
angleAxisId?: AxisId;
|
|
69
|
+
/**
|
|
70
|
+
* @defaultValue 0
|
|
71
|
+
*/
|
|
72
|
+
radiusAxisId?: AxisId;
|
|
73
|
+
/**
|
|
74
|
+
* Z-Index of this component and its children. The higher the value,
|
|
75
|
+
* the more on top it will be rendered.
|
|
76
|
+
* Components with higher zIndex will appear in front of components with lower zIndex.
|
|
77
|
+
* If undefined or 0, the content is rendered in the default layer without portals.
|
|
78
|
+
*
|
|
79
|
+
* @since 3.4
|
|
80
|
+
* @defaultValue -100
|
|
81
|
+
* @see {@link https://recharts.github.io/en-US/guide/zIndex/ Z-Index and layers guide}
|
|
82
|
+
*/
|
|
83
|
+
zIndex?: number;
|
|
84
|
+
/**
|
|
85
|
+
* The stroke color. If "none", no line will be drawn.
|
|
86
|
+
* @defaultValue #ccc
|
|
87
|
+
*/
|
|
88
|
+
stroke?: string;
|
|
89
|
+
/**
|
|
90
|
+
* The width of the stroke.
|
|
91
|
+
* @defaultValue 1
|
|
92
|
+
*/
|
|
93
|
+
strokeWidth?: number | string;
|
|
94
|
+
/**
|
|
95
|
+
* The pattern of dashes and gaps used to paint the lines of the grid.
|
|
96
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dasharray stroke-dasharray on MDN}
|
|
97
|
+
*/
|
|
98
|
+
strokeDasharray?: string | number;
|
|
99
|
+
/**
|
|
100
|
+
* The background color used to fill the space between grid lines.
|
|
101
|
+
* @defaultValue none
|
|
102
|
+
*/
|
|
103
|
+
fill?: string;
|
|
104
|
+
/**
|
|
105
|
+
* The opacity of the background used to fill the space between grid lines.
|
|
106
|
+
*/
|
|
107
|
+
fillOpacity?: number | string;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export type Props = SVGProps<SVGLineElement> & PolarGridProps;
|
|
111
|
+
|
|
112
|
+
type PropsWithDefaults =
|
|
113
|
+
Props & {
|
|
114
|
+
cx: number;
|
|
115
|
+
cy: number;
|
|
116
|
+
innerRadius: number;
|
|
117
|
+
outerRadius: number;
|
|
118
|
+
polarAngles: ReadonlyArray<number>;
|
|
119
|
+
polarRadius: ReadonlyArray<number>;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
type ConcentricProps =
|
|
123
|
+
PropsWithDefaults & {
|
|
124
|
+
// The radius of circle
|
|
125
|
+
radius: number;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const getPolygonPath = (
|
|
129
|
+
radius: number,
|
|
130
|
+
cx: number,
|
|
131
|
+
cy: number,
|
|
132
|
+
polarAngles: ReadonlyArray<number>,
|
|
133
|
+
) => {
|
|
134
|
+
let path = '';
|
|
135
|
+
|
|
136
|
+
polarAngles.forEach((angle: number, i: number) => {
|
|
137
|
+
const point = polarToCartesian(cx, cy, radius, angle);
|
|
138
|
+
|
|
139
|
+
if (i) {
|
|
140
|
+
path += `L ${point.x},${point.y}`;
|
|
141
|
+
} else {
|
|
142
|
+
path += `M ${point.x},${point.y}`;
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
path += 'Z';
|
|
146
|
+
|
|
147
|
+
return path;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
// Draw axis of radial line
|
|
151
|
+
const PolarAngles: React.FC<PropsWithDefaults> = (props: PropsWithDefaults) => {
|
|
152
|
+
const { cx, cy, innerRadius, outerRadius, polarAngles, radialLines } = props;
|
|
153
|
+
|
|
154
|
+
if (!polarAngles || !polarAngles.length || !radialLines) {
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
const polarAnglesProps = {
|
|
158
|
+
...svgPropertiesNoEvents(props),
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
return <g className="recharts-polar-grid-angle">{polarAngles.map((entry) => {
|
|
162
|
+
const start = polarToCartesian(cx, cy, innerRadius, entry);
|
|
163
|
+
const end = polarToCartesian(cx, cy, outerRadius, entry);
|
|
164
|
+
|
|
165
|
+
return <line
|
|
166
|
+
key={`line-${entry}`}
|
|
167
|
+
{...polarAnglesProps}
|
|
168
|
+
x1={start.x}
|
|
169
|
+
y1={start.y}
|
|
170
|
+
x2={end.x}
|
|
171
|
+
y2={end.y}
|
|
172
|
+
/>;
|
|
173
|
+
})}</g>;
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
// Draw concentric circles
|
|
177
|
+
const ConcentricCircle: React.FC<ConcentricProps> = (props) => {
|
|
178
|
+
const { cx, cy, radius } = props;
|
|
179
|
+
const concentricCircleProps = {
|
|
180
|
+
...svgPropertiesNoEvents(props),
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
return (
|
|
184
|
+
// @ts-expect-error wrong SVG element type
|
|
185
|
+
<circle
|
|
186
|
+
{...concentricCircleProps}
|
|
187
|
+
className={clsx('recharts-polar-grid-concentric-circle', props.className)}
|
|
188
|
+
cx={cx}
|
|
189
|
+
cy={cy}
|
|
190
|
+
r={radius}
|
|
191
|
+
/>
|
|
192
|
+
);
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
// Draw concentric polygons
|
|
196
|
+
const ConcentricPolygon: React.FC<ConcentricProps> = (props: ConcentricProps) => {
|
|
197
|
+
const { radius } = props;
|
|
198
|
+
const concentricPolygonProps = {
|
|
199
|
+
...svgPropertiesNoEvents(props),
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
return <path
|
|
203
|
+
{...concentricPolygonProps}
|
|
204
|
+
className={clsx('recharts-polar-grid-concentric-polygon', props.className)}
|
|
205
|
+
d={getPolygonPath(radius, props.cx, props.cy, props.polarAngles)}
|
|
206
|
+
/>;
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
// Draw concentric axis
|
|
210
|
+
const ConcentricGridPath = (props: PropsWithDefaults) => {
|
|
211
|
+
const { polarRadius, gridType } = props;
|
|
212
|
+
|
|
213
|
+
if (!polarRadius || !polarRadius.length) {
|
|
214
|
+
return null;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const maxPolarRadius: number = Math.max(...polarRadius);
|
|
218
|
+
const renderBackground = props.fill && props.fill !== 'none';
|
|
219
|
+
|
|
220
|
+
return <g className="recharts-polar-grid-concentric">
|
|
221
|
+
{/* Render background as separate first child to do not cover strokes of smaller figures */}
|
|
222
|
+
{renderBackground && gridType === 'circle' &&
|
|
223
|
+
<ConcentricCircle {...props} radius={maxPolarRadius} />}
|
|
224
|
+
{renderBackground && gridType !== 'circle' &&
|
|
225
|
+
<ConcentricPolygon {...props} radius={maxPolarRadius} />}
|
|
226
|
+
|
|
227
|
+
{polarRadius.map((entry: number, i: number) => {
|
|
228
|
+
const key = i;
|
|
229
|
+
|
|
230
|
+
if (gridType === 'circle') {
|
|
231
|
+
return <ConcentricCircle key={key} {...props} fill="none" radius={entry} />;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return <ConcentricPolygon key={key} {...props} fill="none" radius={entry} />;
|
|
235
|
+
})}
|
|
236
|
+
</g>;
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
export const defaultPolarGridProps = {
|
|
240
|
+
angleAxisId: 0,
|
|
241
|
+
radiusAxisId: 0,
|
|
242
|
+
gridType: 'polygon',
|
|
243
|
+
radialLines: true,
|
|
244
|
+
zIndex: DefaultZIndexes.grid,
|
|
245
|
+
stroke: '#ccc',
|
|
246
|
+
strokeWidth: 1,
|
|
247
|
+
fill: 'none',
|
|
248
|
+
} as const satisfies Partial<Props>;
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* @consumes PolarViewBoxContext
|
|
252
|
+
*/
|
|
253
|
+
export const PolarGrid = (outsideProps: Props) => {
|
|
254
|
+
const {
|
|
255
|
+
gridType,
|
|
256
|
+
radialLines,
|
|
257
|
+
angleAxisId,
|
|
258
|
+
radiusAxisId,
|
|
259
|
+
cx: cxFromOutside,
|
|
260
|
+
cy: cyFromOutside,
|
|
261
|
+
innerRadius: innerRadiusFromOutside,
|
|
262
|
+
outerRadius: outerRadiusFromOutside,
|
|
263
|
+
polarAngles: polarAnglesInput,
|
|
264
|
+
polarRadius: polarRadiusInput,
|
|
265
|
+
zIndex,
|
|
266
|
+
...inputs
|
|
267
|
+
} = resolveDefaultProps(outsideProps, defaultPolarGridProps);
|
|
268
|
+
const polarViewBox: PolarViewBoxRequired | undefined = useAppSelector(selectPolarViewBox);
|
|
269
|
+
|
|
270
|
+
const polarAnglesFromRedux = useAppSelector((state) => selectPolarGridAngles(state, angleAxisId));
|
|
271
|
+
const polarRadiiFromRedux = useAppSelector((state) => selectPolarGridRadii(state, radiusAxisId));
|
|
272
|
+
|
|
273
|
+
const polarAngles = Array.isArray(polarAnglesInput) ? polarAnglesInput : polarAnglesFromRedux;
|
|
274
|
+
const polarRadius = Array.isArray(polarRadiusInput) ? polarRadiusInput : polarRadiiFromRedux;
|
|
275
|
+
|
|
276
|
+
if (polarAngles == null || polarRadius == null) {
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
const props: PropsWithDefaults = {
|
|
281
|
+
cx: polarViewBox?.cx ?? cxFromOutside ?? 0,
|
|
282
|
+
cy: polarViewBox?.cy ?? cyFromOutside ?? 0,
|
|
283
|
+
innerRadius: polarViewBox?.innerRadius ?? innerRadiusFromOutside ?? 0,
|
|
284
|
+
outerRadius: polarViewBox?.outerRadius ?? outerRadiusFromOutside ?? 0,
|
|
285
|
+
polarAngles,
|
|
286
|
+
polarRadius,
|
|
287
|
+
zIndex,
|
|
288
|
+
...inputs,
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
const { outerRadius } = props;
|
|
292
|
+
|
|
293
|
+
if (outerRadius <= 0) {
|
|
294
|
+
return null;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
return <ZIndexLayer zIndex={props.zIndex}>
|
|
298
|
+
<g className="recharts-polar-grid">
|
|
299
|
+
<ConcentricGridPath
|
|
300
|
+
gridType={gridType}
|
|
301
|
+
radialLines={radialLines}
|
|
302
|
+
{...props}
|
|
303
|
+
polarAngles={polarAngles}
|
|
304
|
+
polarRadius={polarRadius}
|
|
305
|
+
/>
|
|
306
|
+
<PolarAngles
|
|
307
|
+
gridType={gridType}
|
|
308
|
+
radialLines={radialLines}
|
|
309
|
+
{...props}
|
|
310
|
+
polarAngles={polarAngles}
|
|
311
|
+
polarRadius={polarRadius}
|
|
312
|
+
/>
|
|
313
|
+
</g>
|
|
314
|
+
</ZIndexLayer>;
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
PolarGrid.displayName = 'PolarGrid';
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import * as React from 'octane';
|
|
2
|
+
import { SVGProps } from 'octane';
|
|
3
|
+
import { AxisId } from '../state/cartesianAxisSlice';
|
|
4
|
+
import { ZIndexable } from '../zIndex/ZIndexLayer';
|
|
5
|
+
interface PolarGridProps extends ZIndexable {
|
|
6
|
+
/**
|
|
7
|
+
* The x-coordinate of center.
|
|
8
|
+
* When used inside a chart context, this prop is calculated based on the chart's dimensions,
|
|
9
|
+
* and this prop is ignored.
|
|
10
|
+
*
|
|
11
|
+
* This is only used when rendered outside a chart context.
|
|
12
|
+
*/
|
|
13
|
+
cx?: number;
|
|
14
|
+
/**
|
|
15
|
+
* The y-coordinate of center.
|
|
16
|
+
* When used inside a chart context, this prop is calculated based on the chart's dimensions,
|
|
17
|
+
* and this prop is ignored.
|
|
18
|
+
*
|
|
19
|
+
* This is only used when rendered outside a chart context.
|
|
20
|
+
*/
|
|
21
|
+
cy?: number;
|
|
22
|
+
/**
|
|
23
|
+
* The radius of the inner polar grid.
|
|
24
|
+
* When used inside a chart context, this prop is calculated based on the chart's dimensions,
|
|
25
|
+
* and this prop is ignored.
|
|
26
|
+
*
|
|
27
|
+
* This is only used when rendered outside a chart context.
|
|
28
|
+
*/
|
|
29
|
+
innerRadius?: number;
|
|
30
|
+
/**
|
|
31
|
+
* The radius of the outer polar grid.
|
|
32
|
+
* When used inside a chart context, this prop is calculated based on the chart's dimensions,
|
|
33
|
+
* and this prop is ignored.
|
|
34
|
+
*
|
|
35
|
+
* This is only used when rendered outside a chart context.
|
|
36
|
+
*/
|
|
37
|
+
outerRadius?: number;
|
|
38
|
+
/**
|
|
39
|
+
* The array of every line grid's angle.
|
|
40
|
+
*/
|
|
41
|
+
polarAngles?: ReadonlyArray<number>;
|
|
42
|
+
/**
|
|
43
|
+
* The array of every circle grid's radius.
|
|
44
|
+
*/
|
|
45
|
+
polarRadius?: ReadonlyArray<number>;
|
|
46
|
+
/**
|
|
47
|
+
* The type of polar grids.
|
|
48
|
+
* @defaultValue polygon
|
|
49
|
+
*/
|
|
50
|
+
gridType?: 'polygon' | 'circle';
|
|
51
|
+
/**
|
|
52
|
+
* @defaultValue true
|
|
53
|
+
*/
|
|
54
|
+
radialLines?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* @defaultValue 0
|
|
57
|
+
*/
|
|
58
|
+
angleAxisId?: AxisId;
|
|
59
|
+
/**
|
|
60
|
+
* @defaultValue 0
|
|
61
|
+
*/
|
|
62
|
+
radiusAxisId?: AxisId;
|
|
63
|
+
/**
|
|
64
|
+
* Z-Index of this component and its children. The higher the value,
|
|
65
|
+
* the more on top it will be rendered.
|
|
66
|
+
* Components with higher zIndex will appear in front of components with lower zIndex.
|
|
67
|
+
* If undefined or 0, the content is rendered in the default layer without portals.
|
|
68
|
+
*
|
|
69
|
+
* @since 3.4
|
|
70
|
+
* @defaultValue -100
|
|
71
|
+
* @see {@link https://recharts.github.io/en-US/guide/zIndex/ Z-Index and layers guide}
|
|
72
|
+
*/
|
|
73
|
+
zIndex?: number;
|
|
74
|
+
/**
|
|
75
|
+
* The stroke color. If "none", no line will be drawn.
|
|
76
|
+
* @defaultValue #ccc
|
|
77
|
+
*/
|
|
78
|
+
stroke?: string;
|
|
79
|
+
/**
|
|
80
|
+
* The width of the stroke.
|
|
81
|
+
* @defaultValue 1
|
|
82
|
+
*/
|
|
83
|
+
strokeWidth?: number | string;
|
|
84
|
+
/**
|
|
85
|
+
* The pattern of dashes and gaps used to paint the lines of the grid.
|
|
86
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dasharray stroke-dasharray on MDN}
|
|
87
|
+
*/
|
|
88
|
+
strokeDasharray?: string | number;
|
|
89
|
+
/**
|
|
90
|
+
* The background color used to fill the space between grid lines.
|
|
91
|
+
* @defaultValue none
|
|
92
|
+
*/
|
|
93
|
+
fill?: string;
|
|
94
|
+
/**
|
|
95
|
+
* The opacity of the background used to fill the space between grid lines.
|
|
96
|
+
*/
|
|
97
|
+
fillOpacity?: number | string;
|
|
98
|
+
}
|
|
99
|
+
export type Props = SVGProps<SVGLineElement> & PolarGridProps;
|
|
100
|
+
export declare const defaultPolarGridProps: {
|
|
101
|
+
readonly angleAxisId: 0;
|
|
102
|
+
readonly radiusAxisId: 0;
|
|
103
|
+
readonly gridType: 'polygon';
|
|
104
|
+
readonly radialLines: true;
|
|
105
|
+
readonly zIndex: -100;
|
|
106
|
+
readonly stroke: '#ccc';
|
|
107
|
+
readonly strokeWidth: 1;
|
|
108
|
+
readonly fill: 'none';
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* @consumes PolarViewBoxContext
|
|
112
|
+
*/
|
|
113
|
+
export declare const PolarGrid: {
|
|
114
|
+
(outsideProps: Props): React.JSX.Element | null;
|
|
115
|
+
displayName: string;
|
|
116
|
+
};
|
|
117
|
+
export {};
|