@octanejs/recharts 0.1.61 → 0.1.63
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 +5 -5
- package/src/animation/AnimatedItems.tsrx +36 -31
- package/src/animation/CSSTransitionAnimate.tsrx +1 -2
- package/src/animation/JavascriptAnimate.tsrx +1 -2
- package/src/cartesian/Area.tsrx +414 -386
- package/src/cartesian/AreaRevealShape.tsrx +103 -84
- package/src/cartesian/Bar.tsrx +343 -317
- package/src/cartesian/BarStack.tsrx +33 -28
- package/src/cartesian/CartesianAxis.tsrx +168 -165
- package/src/cartesian/CartesianGrid.tsrx +256 -272
- package/src/cartesian/ErrorBar.tsrx +108 -104
- package/src/cartesian/Funnel.tsrx +405 -382
- package/src/cartesian/GraphicalItemClipPath.tsrx +4 -8
- package/src/cartesian/Line.tsrx +190 -177
- package/src/cartesian/LineDrawShape.tsrx +14 -15
- package/src/cartesian/ReferenceLine.tsrx +119 -105
- package/src/cartesian/Scatter.tsrx +416 -398
- package/src/cartesian/XAxis.tsrx +39 -32
- package/src/cartesian/YAxis.tsrx +47 -37
- package/src/cartesian/ZAxis.tsrx +76 -73
- package/src/chart/AreaChart.tsrx +15 -11
- package/src/chart/BarChart.tsrx +15 -11
- package/src/chart/CategoricalChart.tsrx +32 -26
- package/src/chart/ComposedChart.tsrx +15 -11
- package/src/chart/FunnelChart.tsrx +15 -11
- package/src/chart/LineChart.tsrx +15 -11
- package/src/chart/PieChart.tsrx +15 -11
- package/src/chart/PolarChart.tsrx +45 -48
- package/src/chart/RadarChart.tsrx +38 -32
- package/src/chart/RadialBarChart.tsrx +15 -11
- package/src/chart/RechartsWrapper.tsrx +214 -162
- package/src/chart/Sankey.tsrx +412 -378
- package/src/chart/ScatterChart.tsrx +15 -11
- package/src/chart/SunburstChart.tsrx +162 -155
- package/src/component/ActivePoints.tsrx +19 -13
- package/src/component/Cursor.tsrx +25 -18
- package/src/component/DefaultLegendContent.tsrx +131 -127
- package/src/component/DefaultTooltipContent.tsrx +46 -42
- package/src/component/Dots.tsrx +11 -5
- package/src/component/Label.tsrx +69 -55
- package/src/component/LabelList.tsrx +32 -27
- package/src/component/Legend.tsrx +120 -123
- package/src/component/ResponsiveContainer.tsrx +18 -11
- package/src/component/Text.tsrx +50 -43
- package/src/component/Tooltip.tsrx +234 -223
- package/src/component/TooltipBoundingBox.tsrx +34 -34
- package/src/container/ClipPathProvider.tsrx +1 -3
- package/src/container/Layer.tsrx +5 -1
- package/src/container/RootSurface.tsrx +31 -21
- package/src/container/Surface.tsrx +15 -13
- package/src/context/ErrorBarContext.tsrx +5 -5
- package/src/polar/Pie.tsrx +541 -487
- package/src/polar/PolarAngleAxis.tsrx +245 -227
- package/src/polar/PolarGrid.tsrx +139 -127
- package/src/polar/PolarRadiusAxis.tsrx +204 -185
- package/src/polar/Radar.tsrx +274 -264
- package/src/polar/RadialBar.tsrx +408 -361
- package/src/shape/Cross.tsrx +13 -7
- package/src/shape/Curve.tsrx +54 -44
- package/src/shape/Dot.tsrx +10 -8
- package/src/shape/Polygon.tsrx +38 -29
- package/src/shape/Rectangle.tsrx +73 -28
- package/src/shape/Sector.tsrx +30 -18
- package/src/shape/Symbols.tsrx +13 -11
- package/src/shape/Trapezoid.tsrx +16 -11
- package/src/state/RechartsStoreProvider.tsrx +5 -1
- package/src/synchronisation/useChartSynchronisation.tsrx +8 -7
- package/src/util/BarUtils.tsrx +43 -40
- package/src/util/FunnelUtils.tsrx +5 -5
- package/src/util/RadialBarUtils.tsrx +3 -4
- package/src/util/ScatterUtils.tsrx +13 -8
- package/src/zIndex/ZIndexLayer.tsrx +2 -2
- package/src/zIndex/ZIndexPortal.tsrx +2 -8
|
@@ -14,9 +14,7 @@ import { getTicks, type GetTicksInput } from './getTicks';
|
|
|
14
14
|
import { defaultCartesianAxisProps } from './CartesianAxis.tsrx';
|
|
15
15
|
import { useChartHeight, useChartWidth, useOffsetInternal } from '../context/chartLayoutContext';
|
|
16
16
|
import type { AxisId } from '../state/cartesianAxisSlice';
|
|
17
|
-
import {
|
|
18
|
-
selectAxisPropsNeededForCartesianGridTicksGenerator,
|
|
19
|
-
} from '../state/selectors/axisSelectors';
|
|
17
|
+
import { selectAxisPropsNeededForCartesianGridTicksGenerator } from '../state/selectors/axisSelectors';
|
|
20
18
|
import { useAppSelector } from '../state/hooks';
|
|
21
19
|
import { useIsPanorama } from '../context/PanoramaContext';
|
|
22
20
|
import { type RequiresDefaultProps, resolveDefaultProps } from '../util/resolveDefaultProps';
|
|
@@ -28,16 +26,15 @@ import { DefaultZIndexes } from '../zIndex/DefaultZIndexes';
|
|
|
28
26
|
/**
|
|
29
27
|
* The <CartesianGrid horizontal
|
|
30
28
|
*/
|
|
31
|
-
export type GridLineTypeFunctionProps =
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
};
|
|
29
|
+
export type GridLineTypeFunctionProps = Omit<LineItemProps, 'key'> & {
|
|
30
|
+
// React does not pass the key through when calling cloneElement - so it might be undefined when cloning
|
|
31
|
+
key: LineItemProps['key'] | undefined;
|
|
32
|
+
// offset is not present in LineItemProps, but it is read from context and then passed to the GridLineType function and element
|
|
33
|
+
offset: ChartOffsetInternal;
|
|
34
|
+
};
|
|
38
35
|
|
|
39
|
-
export type AxisPropsForCartesianGridTicksGeneration =
|
|
40
|
-
|
|
36
|
+
export type AxisPropsForCartesianGridTicksGeneration = AxisPropsNeededForTicksGenerator &
|
|
37
|
+
Omit<GetTicksInput, 'ticks' | 'viewBox'>;
|
|
41
38
|
|
|
42
39
|
type GridLineType =
|
|
43
40
|
| SVGProps<SVGLineElement>
|
|
@@ -45,163 +42,167 @@ type GridLineType =
|
|
|
45
42
|
| ((props: GridLineTypeFunctionProps) => OctaneElement<SVGElement>)
|
|
46
43
|
| boolean;
|
|
47
44
|
|
|
48
|
-
export type HorizontalCoordinatesGenerator =
|
|
49
|
-
|
|
45
|
+
export type HorizontalCoordinatesGenerator = (
|
|
46
|
+
props: {
|
|
50
47
|
yAxis: AxisPropsForCartesianGridTicksGeneration | undefined;
|
|
51
48
|
width: number;
|
|
52
49
|
height: number;
|
|
53
50
|
offset: ChartOffsetInternal;
|
|
54
|
-
},
|
|
51
|
+
},
|
|
52
|
+
syncWithTicks: boolean,
|
|
53
|
+
) => number[];
|
|
55
54
|
|
|
56
|
-
export type VerticalCoordinatesGenerator =
|
|
57
|
-
|
|
55
|
+
export type VerticalCoordinatesGenerator = (
|
|
56
|
+
props: {
|
|
58
57
|
xAxis: AxisPropsForCartesianGridTicksGeneration | undefined;
|
|
59
58
|
width: number;
|
|
60
59
|
height: number;
|
|
61
60
|
offset: ChartOffsetInternal;
|
|
62
|
-
},
|
|
61
|
+
},
|
|
62
|
+
syncWithTicks: boolean,
|
|
63
|
+
) => number[];
|
|
63
64
|
|
|
64
65
|
interface CartesianGridProps extends ZIndexable {
|
|
65
66
|
/**
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
* The width of grid. If undefined, covers the full width of the chart plot area.
|
|
68
|
+
*/
|
|
68
69
|
width?: number;
|
|
69
70
|
/**
|
|
70
|
-
|
|
71
|
-
|
|
71
|
+
* The height of grid. If undefined, covers the full height of the chart plot area.
|
|
72
|
+
*/
|
|
72
73
|
height?: number;
|
|
73
74
|
/**
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
* A function that generates the y-coordinates of all horizontal lines.
|
|
76
|
+
*
|
|
77
|
+
* @see {@link https://codesandbox.io/p/sandbox/cartesian-grid-with-coordinate-generators-my38cg?file=%2Fsrc%2FApp.tsx Cartesian grid with coordinate generators}
|
|
78
|
+
*/
|
|
78
79
|
horizontalCoordinatesGenerator?: HorizontalCoordinatesGenerator;
|
|
79
80
|
/**
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
* A function that generates the x-coordinates of all vertical lines.
|
|
82
|
+
*
|
|
83
|
+
* @see {@link https://codesandbox.io/p/sandbox/cartesian-grid-with-coordinate-generators-my38cg?file=%2Fsrc%2FApp.tsx Cartesian grid with coordinate generators}
|
|
84
|
+
*/
|
|
84
85
|
verticalCoordinatesGenerator?: VerticalCoordinatesGenerator;
|
|
85
86
|
/**
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
* The x-coordinate of grid.
|
|
88
|
+
* If left undefined, it will be computed from the chart's offset and margins.
|
|
89
|
+
*/
|
|
89
90
|
x?: number;
|
|
90
91
|
/**
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
* The y-coordinate of grid.
|
|
93
|
+
* If left undefined, it will be computed from the chart's offset and margins.
|
|
94
|
+
*/
|
|
94
95
|
y?: number;
|
|
95
96
|
/**
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
97
|
+
* If set false, no horizontal grid lines will be drawn.
|
|
98
|
+
*
|
|
99
|
+
* @defaultValue true
|
|
100
|
+
*/
|
|
100
101
|
horizontal?: GridLineType;
|
|
101
102
|
/**
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
103
|
+
* If set false, no vertical grid lines will be drawn.
|
|
104
|
+
*
|
|
105
|
+
* @defaultValue true
|
|
106
|
+
*/
|
|
106
107
|
vertical?: GridLineType;
|
|
107
108
|
/**
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
109
|
+
* Array of coordinates in pixels where to draw horizontal grid lines.
|
|
110
|
+
* Has priority over syncWithTicks and horizontalValues.
|
|
111
|
+
*
|
|
112
|
+
* @defaultValue []
|
|
113
|
+
*/
|
|
113
114
|
horizontalPoints?: number[];
|
|
114
115
|
/**
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
116
|
+
* Array of coordinates in pixels where to draw vertical grid lines.
|
|
117
|
+
* Has priority over syncWithTicks and verticalValues.
|
|
118
|
+
*
|
|
119
|
+
* @defaultValue []
|
|
120
|
+
*/
|
|
120
121
|
verticalPoints?: number[];
|
|
121
122
|
/**
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
123
|
+
* The background color used to fill the space between grid lines
|
|
124
|
+
*
|
|
125
|
+
* @defaultValue none
|
|
126
|
+
* @example <CartesianGrid fill="red" />
|
|
127
|
+
* @example <CartesianGrid fill="#ccc" />
|
|
128
|
+
*/
|
|
128
129
|
fill?: string;
|
|
129
130
|
/**
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
131
|
+
* The opacity of the background used to fill the space between grid lines
|
|
132
|
+
*
|
|
133
|
+
* @example <CartesianGrid fill="red" fillOpacity={0.6} />
|
|
134
|
+
*/
|
|
134
135
|
fillOpacity?: number | string;
|
|
135
136
|
/**
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
137
|
+
* Defines background color of stripes.
|
|
138
|
+
*
|
|
139
|
+
* The values from this array will be passed in as the `fill` property in a `rect` SVG element.
|
|
140
|
+
* For possible values see: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/fill#rect
|
|
141
|
+
*
|
|
142
|
+
* In case there are more stripes than colors, the colors will start from beginning.
|
|
143
|
+
* So for example: verticalFill['yellow', 'black'] produces a pattern of yellow|black|yellow|black
|
|
144
|
+
*
|
|
145
|
+
* If this is undefined, or an empty array, then there is no background fill.
|
|
146
|
+
* Note: Grid lines will be rendered above these background stripes.
|
|
147
|
+
*
|
|
148
|
+
* @defaultValue []
|
|
149
|
+
*/
|
|
149
150
|
verticalFill?: string[];
|
|
150
151
|
/**
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
152
|
+
* Defines background color of stripes.
|
|
153
|
+
*
|
|
154
|
+
* The values from this array will be passed in as the `fill` property in a `rect` SVG element.
|
|
155
|
+
* For possible values see: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/fill#rect
|
|
156
|
+
*
|
|
157
|
+
* In case there are more stripes than colors, the colors will start from beginning.
|
|
158
|
+
* So for example: horizontalFill['yellow', 'black'] produces a pattern of yellow|black|yellow|black
|
|
159
|
+
*
|
|
160
|
+
* If this is undefined, or an empty array, then there is no background fill.
|
|
161
|
+
* Note: Grid lines will be rendered above these background stripes.
|
|
162
|
+
*
|
|
163
|
+
* @defaultValue []
|
|
164
|
+
*/
|
|
164
165
|
horizontalFill?: string[];
|
|
165
166
|
/**
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
167
|
+
* If true, only the lines that correspond to the axes ticks values will be drawn.
|
|
168
|
+
* If false, extra lines could be added for each axis (at min and max coordinates), if there will not such ticks.
|
|
169
|
+
* horizontalPoints, verticalPoints, horizontalValues, verticalValues have priority over syncWithTicks.
|
|
170
|
+
*
|
|
171
|
+
* @defaultValue false
|
|
172
|
+
*/
|
|
172
173
|
syncWithTicks?: boolean;
|
|
173
174
|
/**
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
175
|
+
* Array of values, where horizontal lines will be drawn. Numbers or strings, in dependence on axis type.
|
|
176
|
+
* Has priority over syncWithTicks but not over horizontalPoints.
|
|
177
|
+
*/
|
|
177
178
|
horizontalValues?: number[] | string[];
|
|
178
179
|
/**
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
180
|
+
* Array of values, where vertical lines will be drawn. Numbers or strings, in dependence on axis type.
|
|
181
|
+
* Has priority over syncWithTicks but not over verticalPoints.
|
|
182
|
+
*/
|
|
182
183
|
verticalValues?: number[] | string[];
|
|
183
184
|
/**
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
185
|
+
* The pattern of dashes and gaps used to paint the lines of the grid
|
|
186
|
+
*
|
|
187
|
+
* @example <CartesianGrid strokeDasharray="3 3" />
|
|
188
|
+
* @example <CartesianGrid strokeDasharray={[5, 5, 1, 5]} />
|
|
189
|
+
* @example <CartesianGrid strokeDasharray="5 5 1 5" />
|
|
190
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dasharray stroke-dasharray on MDN}
|
|
191
|
+
*/
|
|
191
192
|
strokeDasharray?: string | number[];
|
|
192
193
|
/**
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
194
|
+
* The id of XAxis which is corresponding to the data. Required when there are multiple XAxes.
|
|
195
|
+
* @defaultValue 0
|
|
196
|
+
*/
|
|
196
197
|
xAxisId?: AxisId;
|
|
197
198
|
/**
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
199
|
+
* The id of YAxis which is corresponding to the data. Required when there are multiple YAxes.
|
|
200
|
+
* @defaultValue 0
|
|
201
|
+
*/
|
|
201
202
|
yAxisId?: AxisId;
|
|
202
203
|
/**
|
|
203
|
-
|
|
204
|
-
|
|
204
|
+
* @defaultValue -100
|
|
205
|
+
*/
|
|
205
206
|
zIndex?: number;
|
|
206
207
|
}
|
|
207
208
|
|
|
@@ -209,8 +210,8 @@ type AcceptedSvgProps = Omit<SVGProps<SVGLineElement>, 'offset'>;
|
|
|
209
210
|
|
|
210
211
|
export type Props = AcceptedSvgProps & CartesianGridProps;
|
|
211
212
|
|
|
212
|
-
type CartesianGridInternalProps =
|
|
213
|
-
|
|
213
|
+
type CartesianGridInternalProps = AcceptedSvgProps &
|
|
214
|
+
RequiresDefaultProps<CartesianGridProps, typeof defaultCartesianGridProps> & {
|
|
214
215
|
// x,y,width,height are not declared directly in default props but are resolved using offset, if undefined
|
|
215
216
|
x: number;
|
|
216
217
|
y: number;
|
|
@@ -229,31 +230,32 @@ const Background = (
|
|
|
229
230
|
|
|
230
231
|
const { fillOpacity, x, y, width, height, ry } = props;
|
|
231
232
|
|
|
232
|
-
return
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
233
|
+
return (
|
|
234
|
+
<rect
|
|
235
|
+
x={x}
|
|
236
|
+
y={y}
|
|
237
|
+
ry={ry}
|
|
238
|
+
width={width}
|
|
239
|
+
height={height}
|
|
240
|
+
stroke="none"
|
|
241
|
+
fill={fill}
|
|
242
|
+
fillOpacity={fillOpacity}
|
|
243
|
+
className="recharts-cartesian-grid-bg"
|
|
244
|
+
/>
|
|
245
|
+
);
|
|
243
246
|
};
|
|
244
247
|
|
|
245
|
-
type LineItemProps =
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
};
|
|
248
|
+
type LineItemProps = Props & {
|
|
249
|
+
offset: ChartOffsetInternal;
|
|
250
|
+
xAxis: undefined | AxisPropsForCartesianGridTicksGeneration;
|
|
251
|
+
yAxis: undefined | AxisPropsForCartesianGridTicksGeneration;
|
|
252
|
+
x1: number;
|
|
253
|
+
y1: number;
|
|
254
|
+
x2: number;
|
|
255
|
+
y2: number;
|
|
256
|
+
key: string;
|
|
257
|
+
index: number;
|
|
258
|
+
};
|
|
257
259
|
|
|
258
260
|
function LineItem({
|
|
259
261
|
option,
|
|
@@ -271,26 +273,19 @@ function LineItem({
|
|
|
271
273
|
} else {
|
|
272
274
|
const { x1, y1, x2, y2, key, ...others } = lineItemProps;
|
|
273
275
|
const { offset: __, ...restOfFilteredProps } = svgPropertiesNoEvents(others) ?? {};
|
|
274
|
-
lineItem =
|
|
275
|
-
{...restOfFilteredProps}
|
|
276
|
-
|
|
277
|
-
y1={y1}
|
|
278
|
-
x2={x2}
|
|
279
|
-
y2={y2}
|
|
280
|
-
fill="none"
|
|
281
|
-
key={key}
|
|
282
|
-
/>;
|
|
276
|
+
lineItem = (
|
|
277
|
+
<line {...restOfFilteredProps} x1={x1} y1={y1} x2={x2} y2={y2} fill="none" key={key} />
|
|
278
|
+
);
|
|
283
279
|
}
|
|
284
280
|
|
|
285
281
|
return lineItem;
|
|
286
282
|
}
|
|
287
283
|
|
|
288
|
-
type GridLinesProps =
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
};
|
|
284
|
+
type GridLinesProps = CartesianGridInternalProps & {
|
|
285
|
+
offset: GridLineTypeFunctionProps['offset'];
|
|
286
|
+
xAxis: GridLineTypeFunctionProps['xAxis'];
|
|
287
|
+
yAxis: GridLineTypeFunctionProps['yAxis'];
|
|
288
|
+
};
|
|
294
289
|
|
|
295
290
|
function HorizontalGridLines(props: GridLinesProps) {
|
|
296
291
|
const { x, width, horizontal = true, horizontalPoints } = props;
|
|
@@ -359,9 +354,9 @@ function HorizontalStripes(props: CartesianGridInternalProps) {
|
|
|
359
354
|
return null;
|
|
360
355
|
}
|
|
361
356
|
|
|
362
|
-
const roundedSortedHorizontalPoints = horizontalPoints
|
|
363
|
-
(
|
|
364
|
-
|
|
357
|
+
const roundedSortedHorizontalPoints = horizontalPoints
|
|
358
|
+
.map((e) => Math.round(e + y - y))
|
|
359
|
+
.sort((a, b) => a - b);
|
|
365
360
|
// Why is this condition `!==` instead of `<=` ?
|
|
366
361
|
if (y !== roundedSortedHorizontalPoints[0]) {
|
|
367
362
|
roundedSortedHorizontalPoints.unshift(y);
|
|
@@ -376,17 +371,19 @@ function HorizontalStripes(props: CartesianGridInternalProps) {
|
|
|
376
371
|
return null;
|
|
377
372
|
}
|
|
378
373
|
const colorIndex = i % horizontalFill.length;
|
|
379
|
-
return
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
374
|
+
return (
|
|
375
|
+
<rect
|
|
376
|
+
key={`react-${i}`}
|
|
377
|
+
y={entry}
|
|
378
|
+
x={x}
|
|
379
|
+
height={lineHeight}
|
|
380
|
+
width={width}
|
|
381
|
+
stroke="none"
|
|
382
|
+
fill={horizontalFill[colorIndex]}
|
|
383
|
+
fillOpacity={fillOpacity}
|
|
384
|
+
className="recharts-cartesian-grid-bg"
|
|
385
|
+
/>
|
|
386
|
+
);
|
|
390
387
|
});
|
|
391
388
|
|
|
392
389
|
return <g className="recharts-cartesian-gridstripes-horizontal">{items}</g>;
|
|
@@ -398,9 +395,9 @@ function VerticalStripes(props: CartesianGridInternalProps) {
|
|
|
398
395
|
return null;
|
|
399
396
|
}
|
|
400
397
|
|
|
401
|
-
const roundedSortedVerticalPoints = verticalPoints
|
|
402
|
-
(
|
|
403
|
-
|
|
398
|
+
const roundedSortedVerticalPoints = verticalPoints
|
|
399
|
+
.map((e) => Math.round(e + x - x))
|
|
400
|
+
.sort((a, b) => a - b);
|
|
404
401
|
|
|
405
402
|
if (x !== roundedSortedVerticalPoints[0]) {
|
|
406
403
|
roundedSortedVerticalPoints.unshift(x);
|
|
@@ -415,17 +412,19 @@ function VerticalStripes(props: CartesianGridInternalProps) {
|
|
|
415
412
|
return null;
|
|
416
413
|
}
|
|
417
414
|
const colorIndex = i % verticalFill.length;
|
|
418
|
-
return
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
415
|
+
return (
|
|
416
|
+
<rect
|
|
417
|
+
key={`react-${i}`}
|
|
418
|
+
x={entry}
|
|
419
|
+
y={y}
|
|
420
|
+
width={lineWidth}
|
|
421
|
+
height={height}
|
|
422
|
+
stroke="none"
|
|
423
|
+
fill={verticalFill[colorIndex]}
|
|
424
|
+
fillOpacity={fillOpacity}
|
|
425
|
+
className="recharts-cartesian-grid-bg"
|
|
426
|
+
/>
|
|
427
|
+
);
|
|
429
428
|
});
|
|
430
429
|
|
|
431
430
|
return <g className="recharts-cartesian-gridstripes-vertical">{items}</g>;
|
|
@@ -434,32 +433,34 @@ function VerticalStripes(props: CartesianGridInternalProps) {
|
|
|
434
433
|
const defaultVerticalCoordinatesGenerator: VerticalCoordinatesGenerator = (
|
|
435
434
|
{ xAxis, width, height, offset },
|
|
436
435
|
syncWithTicks,
|
|
437
|
-
) =>
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
436
|
+
) =>
|
|
437
|
+
getCoordinatesOfGrid(
|
|
438
|
+
getTicks({
|
|
439
|
+
...defaultCartesianAxisProps,
|
|
440
|
+
...xAxis,
|
|
441
|
+
ticks: getTicksOfAxis(xAxis, true),
|
|
442
|
+
viewBox: { x: 0, y: 0, width, height },
|
|
443
|
+
}),
|
|
444
|
+
offset.left,
|
|
445
|
+
offset.left + offset.width,
|
|
446
|
+
syncWithTicks,
|
|
447
|
+
);
|
|
448
448
|
|
|
449
449
|
const defaultHorizontalCoordinatesGenerator: HorizontalCoordinatesGenerator = (
|
|
450
450
|
{ yAxis, width, height, offset },
|
|
451
451
|
syncWithTicks,
|
|
452
|
-
) =>
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
452
|
+
) =>
|
|
453
|
+
getCoordinatesOfGrid(
|
|
454
|
+
getTicks({
|
|
455
|
+
...defaultCartesianAxisProps,
|
|
456
|
+
...yAxis,
|
|
457
|
+
ticks: getTicksOfAxis(yAxis, true),
|
|
458
|
+
viewBox: { x: 0, y: 0, width, height },
|
|
459
|
+
}),
|
|
460
|
+
offset.top,
|
|
461
|
+
offset.top + offset.height,
|
|
462
|
+
syncWithTicks,
|
|
463
|
+
);
|
|
463
464
|
|
|
464
465
|
export const defaultCartesianGridProps = {
|
|
465
466
|
horizontal: true,
|
|
@@ -497,34 +498,15 @@ export function CartesianGrid(props: Props) {
|
|
|
497
498
|
height: isNumber(props.height) ? props.height : offset.height,
|
|
498
499
|
};
|
|
499
500
|
|
|
500
|
-
const {
|
|
501
|
-
|
|
502
|
-
yAxisId,
|
|
503
|
-
x,
|
|
504
|
-
y,
|
|
505
|
-
width,
|
|
506
|
-
height,
|
|
507
|
-
syncWithTicks,
|
|
508
|
-
horizontalValues,
|
|
509
|
-
verticalValues,
|
|
510
|
-
} = propsIncludingDefaults;
|
|
501
|
+
const { xAxisId, yAxisId, x, y, width, height, syncWithTicks, horizontalValues, verticalValues } =
|
|
502
|
+
propsIncludingDefaults;
|
|
511
503
|
|
|
512
504
|
const isPanorama = useIsPanorama();
|
|
513
|
-
const xAxis: AxisPropsForCartesianGridTicksGeneration | undefined = useAppSelector(
|
|
514
|
-
(state
|
|
515
|
-
state,
|
|
516
|
-
'xAxis',
|
|
517
|
-
xAxisId,
|
|
518
|
-
isPanorama,
|
|
519
|
-
),
|
|
505
|
+
const xAxis: AxisPropsForCartesianGridTicksGeneration | undefined = useAppSelector((state) =>
|
|
506
|
+
selectAxisPropsNeededForCartesianGridTicksGenerator(state, 'xAxis', xAxisId, isPanorama),
|
|
520
507
|
);
|
|
521
|
-
const yAxis: AxisPropsForCartesianGridTicksGeneration | undefined = useAppSelector(
|
|
522
|
-
(state
|
|
523
|
-
state,
|
|
524
|
-
'yAxis',
|
|
525
|
-
yAxisId,
|
|
526
|
-
isPanorama,
|
|
527
|
-
),
|
|
508
|
+
const yAxis: AxisPropsForCartesianGridTicksGeneration | undefined = useAppSelector((state) =>
|
|
509
|
+
selectAxisPropsNeededForCartesianGridTicksGenerator(state, 'yAxis', yAxisId, isPanorama),
|
|
528
510
|
);
|
|
529
511
|
|
|
530
512
|
if (!isPositiveNumber(width) || !isPositiveNumber(height) || !isNumber(x) || !isNumber(y)) {
|
|
@@ -532,12 +514,12 @@ export function CartesianGrid(props: Props) {
|
|
|
532
514
|
}
|
|
533
515
|
|
|
534
516
|
/*
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
517
|
+
* verticalCoordinatesGenerator and horizontalCoordinatesGenerator are defined
|
|
518
|
+
* outside the propsIncludingDefaults because they were never part of the original props
|
|
519
|
+
* and they were never passed as a prop down to horizontal/vertical custom elements.
|
|
520
|
+
* If we add these two to propsIncludingDefaults then we are changing public API.
|
|
521
|
+
* Not a bad thing per se but also not necessary.
|
|
522
|
+
*/
|
|
541
523
|
const verticalCoordinatesGenerator =
|
|
542
524
|
propsIncludingDefaults.verticalCoordinatesGenerator || defaultVerticalCoordinatesGenerator;
|
|
543
525
|
const horizontalCoordinatesGenerator =
|
|
@@ -548,7 +530,7 @@ export function CartesianGrid(props: Props) {
|
|
|
548
530
|
// No horizontal points are specified
|
|
549
531
|
if (
|
|
550
532
|
(!horizontalPoints || !horizontalPoints.length) &&
|
|
551
|
-
|
|
533
|
+
typeof horizontalCoordinatesGenerator === 'function'
|
|
552
534
|
) {
|
|
553
535
|
const isHorizontalValues = horizontalValues && horizontalValues.length;
|
|
554
536
|
|
|
@@ -579,7 +561,7 @@ export function CartesianGrid(props: Props) {
|
|
|
579
561
|
// No vertical points are specified
|
|
580
562
|
if (
|
|
581
563
|
(!verticalPoints || !verticalPoints.length) &&
|
|
582
|
-
|
|
564
|
+
typeof verticalCoordinatesGenerator === 'function'
|
|
583
565
|
) {
|
|
584
566
|
const isVerticalValues = verticalValues && verticalValues.length;
|
|
585
567
|
const generatorResult = verticalCoordinatesGenerator(
|
|
@@ -605,38 +587,40 @@ export function CartesianGrid(props: Props) {
|
|
|
605
587
|
}
|
|
606
588
|
}
|
|
607
589
|
|
|
608
|
-
return
|
|
609
|
-
<
|
|
610
|
-
<
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
590
|
+
return (
|
|
591
|
+
<ZIndexLayer zIndex={propsIncludingDefaults.zIndex}>
|
|
592
|
+
<g className="recharts-cartesian-grid">
|
|
593
|
+
<Background
|
|
594
|
+
fill={propsIncludingDefaults.fill}
|
|
595
|
+
fillOpacity={propsIncludingDefaults.fillOpacity}
|
|
596
|
+
x={propsIncludingDefaults.x}
|
|
597
|
+
y={propsIncludingDefaults.y}
|
|
598
|
+
width={propsIncludingDefaults.width}
|
|
599
|
+
height={propsIncludingDefaults.height}
|
|
600
|
+
ry={propsIncludingDefaults.ry}
|
|
601
|
+
/>
|
|
602
|
+
|
|
603
|
+
<HorizontalStripes {...propsIncludingDefaults} horizontalPoints={horizontalPoints} />
|
|
604
|
+
<VerticalStripes {...propsIncludingDefaults} verticalPoints={verticalPoints} />
|
|
605
|
+
|
|
606
|
+
<HorizontalGridLines
|
|
607
|
+
{...propsIncludingDefaults}
|
|
608
|
+
offset={offset}
|
|
609
|
+
horizontalPoints={horizontalPoints}
|
|
610
|
+
xAxis={xAxis}
|
|
611
|
+
yAxis={yAxis}
|
|
612
|
+
/>
|
|
613
|
+
|
|
614
|
+
<VerticalGridLines
|
|
615
|
+
{...propsIncludingDefaults}
|
|
616
|
+
offset={offset}
|
|
617
|
+
verticalPoints={verticalPoints}
|
|
618
|
+
xAxis={xAxis}
|
|
619
|
+
yAxis={yAxis}
|
|
620
|
+
/>
|
|
621
|
+
</g>
|
|
622
|
+
</ZIndexLayer>
|
|
623
|
+
);
|
|
640
624
|
}
|
|
641
625
|
|
|
642
626
|
CartesianGrid.displayName = 'CartesianGrid';
|