palerdot / react-d3-speedometer

React Speedometer component using d3.js ⚛️
https://palerdot.in/react-d3-speedometer/
MIT License
230 stars 57 forks source link

Wrapped customSegmentLabels texts #139

Open ThomasGil92 opened 2 years ago

ThomasGil92 commented 2 years ago

Is there a way to wrap texts in array for "long" strings?image

I found "custom-react-d3-speedometer" but not compatible with react 17

Thanks for your great module by the way

palerdot commented 2 years ago

Is there a way to wrap texts in array for "long" strings?

I don't see a reliable way to achieve this as the segment size can be very small and it could be very difficult to even display small length text.

You can try customSegmentLabels and control the position of the label (INSIDE/OUTSIDE). Something like

<ReactSpeedometer
        width={400}
        height={400}
        paddingHorizontal={50}
        value={777}
        currentValueText="Happiness Level"
        customSegmentLabels={[
          {
            text: "Very Bad",
            position: "INSIDE",
            color: "#555"
          },
          {
            text: "Bad",
            position: "INSIDE",
            color: "#555"
          },
          {
            text: "Ok",
            position: "INSIDE",
            color: "#555",
            fontSize: "19px"
          },
          {
            text: "Good",
            position: "INSIDE",
            color: "#555"
          },
          {
            text: "Very Good and a long text",
            position: "OUTSIDE",
            color: "#555"
          }
        ]}
      />

Codesandbox reference: https://codesandbox.io/s/busy-hamilton-u9kmyc?file=/src/App.js

Live example - https://palerdot.in/react-d3-speedometer/?path=/story/reactspeedometer--custom-segment-labels

Also, I'm open to some better solution/PR for this issue.