Skip to content

Commit

Permalink
Merge pull request #285 from reaviz/extend-theme
Browse files Browse the repository at this point in the history
Add ability to customise Label font size and offset
  • Loading branch information
amcdnl authored Oct 16, 2024
2 parents dcdc83c + 5192c01 commit 63e11f3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
2 changes: 2 additions & 0 deletions docs/Theme.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ export interface Theme {
label?: {
stroke?: ColorRepresentation;
color: ColorRepresentation;
fontSize?: number;
offset?: [number, number, number];
};
};
}
Expand Down
20 changes: 17 additions & 3 deletions src/symbols/Cluster.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,28 @@ export const Cluster: FC<ClusterProps> = ({
: theme.cluster?.inactiveOpacity
: theme.cluster?.opacity;

const labelPositionOffset = useMemo(() => {
const defaultPosition = [0, -offset, 2];
const themeOffset = theme.cluster?.label?.offset;
if (themeOffset) {
return [
defaultPosition[0] - themeOffset[0],
defaultPosition[1] - themeOffset[1],
defaultPosition[2] - themeOffset[2]
];
}

return defaultPosition;
}, [offset, theme.cluster?.label?.offset]);

const { circleOpacity, circlePosition, labelPosition } = useSpring({
from: {
circlePosition: [center.x, center.y, -1],
circleOpacity: 0,
labelPosition: [0, -offset, 2]
labelPosition: labelPositionOffset
},
to: {
labelPosition: [0, -offset, 2],
labelPosition: labelPositionOffset,
circlePosition: position ? [position.x, position.y, -1] : [0, 0, -1],
circleOpacity: opacity
},
Expand Down Expand Up @@ -200,7 +214,7 @@ export const Cluster: FC<ClusterProps> = ({
stroke={theme.cluster.label.stroke}
active={false}
color={theme.cluster?.label.color}
fontSize={12}
fontSize={theme.cluster?.label.fontSize ?? 12}
/>
</a.group>
)}
Expand Down
8 changes: 8 additions & 0 deletions src/themes/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ export interface Theme {
label?: {
stroke?: ColorRepresentation;
color: ColorRepresentation;
/**
* Size of the cluster label
*/
fontSize?: number;
/**
* Offset of the cluster label relative to the default
*/
offset?: [number, number, number];
};
};
}

0 comments on commit 63e11f3

Please sign in to comment.