Skip to content

Commit 00d4e57

Browse files
committed
fix types
1 parent 866bc2e commit 00d4e57

File tree

3 files changed

+35
-23
lines changed

3 files changed

+35
-23
lines changed

packages/victory-pie/src/curved-label.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
VictoryLabel,
1212
TSpan,
1313
Text,
14-
TextPath
14+
TextPath,
1515
} from "victory-core";
1616

1717
export interface CurvedLabelProps

packages/victory-pie/src/helper-methods.ts

+14-2
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ const getCurvedLabelProps = (text, dataProps, calculatedValues) => {
251251
theme,
252252
startOffset,
253253
} = dataProps;
254-
const { style, defaultRadius, defaultTransform } = calculatedValues;
254+
const { style, defaultRadius } = calculatedValues;
255255
const labelRadius = Helpers.evaluateProp(
256256
calculatedValues.labelRadius,
257257
Object.assign({ text }, dataProps),
@@ -284,7 +284,6 @@ const getCurvedLabelProps = (text, dataProps, calculatedValues) => {
284284
id: pathId,
285285
path,
286286
startOffset,
287-
transform: defaultTransform,
288287
};
289288

290289
if (!Helpers.isTooltip(curvedLabelComponent)) {
@@ -294,6 +293,13 @@ const getCurvedLabelProps = (text, dataProps, calculatedValues) => {
294293
return defaults({}, curvedLabelProps, Helpers.omit(tooltipTheme, ["style"]));
295294
};
296295

296+
const getCurvedLabelPathProps = (curvedLabelProps) => {
297+
return {
298+
id: curvedLabelProps.id,
299+
d: curvedLabelProps.path,
300+
};
301+
};
302+
297303
export const getXOffsetMultiplayerByAngle = (angle) =>
298304
Math.cos(angle - Helpers.degreesToRadians(90));
299305
export const getYOffsetMultiplayerByAngle = (angle) =>
@@ -416,6 +422,12 @@ export const getBaseProps = (initialProps, fallbackProps) => {
416422
Object.assign({}, props, dataProps),
417423
calculatedValues,
418424
);
425+
const curvedLabelProps = childProps[eventKey].curvedLabels;
426+
childProps[eventKey].curvedLabelPaths =
427+
getCurvedLabelPathProps(curvedLabelProps);
428+
childProps[eventKey].groupComponentProps = {
429+
transform: defaultTransform,
430+
};
419431
} else {
420432
childProps[eventKey].labels = getLabelProps(
421433
evaluatedText,

packages/victory-pie/src/victory-pie.tsx

+20-20
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ import {
3131
VictorySliceLabelPlacementType,
3232
VictorySliceLabelPositionType,
3333
} from "./slice";
34-
import { CurvedLabel, CurvedLabelProps } from "./curved-label";
34+
import { CurvedLabel } from "./curved-label";
3535

3636
export interface VictoryPieProps
3737
extends Omit<VictoryCommonProps, "polar">,
3838
VictoryDatableProps,
3939
VictoryLabelableProps,
4040
VictoryMultiLabelableProps {
41-
curvedLabelComponent?: React.ReactElement;
41+
curvedLabelComponent?: React.ReactElement;
4242
colorScale?: ColorScalePropType;
4343
cornerRadius?: SliceNumberOrCallback<SliceProps, "cornerRadius">;
4444
endAngle?: number;
@@ -161,7 +161,7 @@ class VictoryPieBase extends React.Component<VictoryPieProps> {
161161
"groupComponent",
162162
"containerComponent",
163163
"labelIndicatorComponent",
164-
"curvedLabelComponent"
164+
"curvedLabelComponent",
165165
];
166166

167167
// Overridden in victory-native
@@ -188,7 +188,6 @@ class VictoryPieBase extends React.Component<VictoryPieProps> {
188188
labelIndicator &&
189189
labelPosition === "centroid" &&
190190
labelPlacement !== "curved";
191-
let groupComponentTransform;
192191

193192
const children: React.ReactElement[] = [];
194193

@@ -217,31 +216,25 @@ class VictoryPieBase extends React.Component<VictoryPieProps> {
217216
// label arc. We need to pass this id to the href of textPath component which will
218217
// have label value(tspan) as child component.
219218
if (labelPlacement === "curved" && curvedLabelComponent) {
219+
// create labelPath
220+
const pathComponent: React.ReactElement = <Path />;
220221
const labelPathComponents = this.dataKeys.map((_dataKey, index) => {
221-
const curvedLabelProps: CurvedLabelProps = this.getComponentProps(
222-
curvedLabelComponent,
223-
"curvedLabels",
222+
const curvedLabelPathProps = this.getComponentProps(
223+
pathComponent,
224+
"curvedLabelPaths",
224225
index,
225226
);
226-
227-
// create labelPath
228-
const pathComponent: React.ReactElement = <Path />;
229-
return React.cloneElement(pathComponent, {
230-
d: curvedLabelProps.path,
231-
id: curvedLabelProps.id,
232-
key: index,
233-
});
227+
return React.cloneElement(pathComponent, curvedLabelPathProps);
234228
});
235229
children.push(...labelPathComponents);
236230

237231
const curvedLabelComponents = this.dataKeys
238232
.map((_dataKey, index) => {
239-
const curvedLabelProps: CurvedLabelProps = this.getComponentProps(
233+
const curvedLabelProps = this.getComponentProps(
240234
curvedLabelComponent,
241235
"curvedLabels",
242236
index,
243237
);
244-
groupComponentTransform = curvedLabelProps.transform;
245238
if (
246239
(curvedLabelProps as any).text !== undefined &&
247240
(curvedLabelProps as any).text !== null
@@ -299,9 +292,16 @@ class VictoryPieBase extends React.Component<VictoryPieProps> {
299292
children.push(...labelIndicatorComponents);
300293
}
301294
if (labelPlacement === "curved") {
302-
const groupCloneElement = React.cloneElement(groupComponent, {
303-
transform: groupComponentTransform,
304-
});
295+
const groupComponentProps = this.getComponentProps(
296+
groupComponent,
297+
"groupComponentProps",
298+
0,
299+
);
300+
301+
const groupCloneElement = React.cloneElement(
302+
groupComponent,
303+
groupComponentProps,
304+
);
305305
return this.renderContainer(groupCloneElement, children);
306306
}
307307
return this.renderContainer(groupComponent, children);

0 commit comments

Comments
 (0)