Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ It is possible to wrap any component inside a `<G>` tag and add more vectors:
| numbersRadius | 17 | number | Distance from the border of the circle |
| fontSize | 18 | number | Font size of the numbers |
| lineSize | 12 | number | Large of the lines |
| specialMarkStep | 2 | number | Make every 2 mark special |

### Indicator
| Prop | Default | Type | Description
Expand Down
2 changes: 1 addition & 1 deletion examples/Thermostat.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const Thermostat = () => {
<Marks step={5}>
{(mark, i) => (
<G key={i}>
{mark.isEven && (
{mark.isSpecial && (
<Text
{...mark.textProps}
textAnchor="middle"
Expand Down
14 changes: 8 additions & 6 deletions src/Marks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const getMarkPosition = (angle: number, offset: number, radius: number) => {

interface Mark {
coordinates: { x1: number, y1: number, x2: number, y2: number }
isEven: boolean
isSpecial: boolean
textProps: { x: number, y: number, transform: string }
value: number
}
Expand All @@ -26,6 +26,7 @@ interface MarksProps {
numbersRadius?: number
fontSize?: number
lineSize?: number
specialMarkStep?: number
children?: (mark: Mark, index: number) => JSX.Element
}

Expand All @@ -37,6 +38,7 @@ export default function Marks({
numbersRadius = 17,
fontSize = 18,
lineSize = 12,
specialMarkStep = 2,
children,
}: MarksProps) {

Expand All @@ -55,16 +57,16 @@ export default function Marks({

return [...Array(stepsLength + 1)].map((val, index) => {
const actualAngle = gap * index
const isEven = index % 2 == 0
const size = isEven ? lineSize : lineSize - 5
const isSpecial = index % specialMarkStep == 0
const size = isSpecial ? lineSize : lineSize - 5

const { x: x1, y: y1 } = getMarkPosition(actualAngle, 0, radius)
const { x: x2, y: y2 } = getMarkPosition(actualAngle, - size, radius)
const { x, y } = getMarkPosition(actualAngle, - lineSize - numbersRadius, radius)

return {
coordinates: { x1, y1, x2, y2 },
isEven,
isSpecial,
textProps: { x, y, transform: `rotate(${360 - rotation}, ${x}, ${y})` },
value: Math.round((index * step) + min)
}
Expand All @@ -84,11 +86,11 @@ export default function Marks({
<line
{...mark.coordinates}
stroke={lineColor}
strokeWidth={mark.isEven ? 3 : 2}
strokeWidth={mark.isSpecial ? 3 : 2}
strokeOpacity={lineOpacity}
strokeLinecap={lineCap}
/>
{mark.isEven && (
{mark.isSpecial && (
<text
{...mark.textProps}
fill="white"
Expand Down