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
7 changes: 7 additions & 0 deletions src/core/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ export const DEFAULT_PROPS = {
// custom segment labels
customSegmentLabels: [],


// show custom segment labels only on hover
showSegmentLabelsOnlyOnHover: false,

// color strings
needleColor: 'steelblue',
startColor: '#FF471A',
Expand Down Expand Up @@ -117,6 +121,9 @@ export const getConfig = ({ PROPS, parentWidth, parentHeight }) => {
// custom segment labels
customSegmentLabels: PROPS.customSegmentLabels,

// show custom segment labels only on hover
showSegmentLabelsOnlyOnHover: PROPS.showSegmentLabelsOnlyOnHover,

// max segment labels
maxSegmentLabels: calculateSegmentLabelCount({
maxSegmentLabelCount: PROPS.maxSegmentLabels,
Expand Down
21 changes: 20 additions & 1 deletion src/core/render/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,26 @@ function _renderCustomSegmentLabels({

const position = outerRadius - (outerRadius - innerRadius) / 2

let lg = svg.append('g').attr('class', 'label').attr('transform', centerTx)
let lg;
if (config.showSegmentLabelsOnlyOnHover) {
lg = svg.append('g')
.attr('class', 'label custom-segment-labels')
.attr('transform', centerTx)
.style('opacity', 0) // Start with labels hidden

// Add hover events to the parent SVG
svg
.on('mouseenter', () => {
lg.style('opacity', 1)
.style('transition', 'opacity 0.2s ease-in-out')
})
.on('mouseleave', () => {
lg.style('opacity', 0)
.style('transition', 'opacity 0.2s ease-in-out')
})
} else {
lg = svg.append('g').attr('class', 'label').attr('transform', centerTx)
}

lg.selectAll('text')
.data(customSegmentLabels)
Expand Down
2 changes: 2 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ declare module 'react-d3-speedometer' {

customSegmentLabels?: CustomSegmentLabel[]

showSegmentLabelsOnlyOnHover?: boolean

labelFontSize?: string
valueTextFontSize?: string
valueTextFontWeight?: string
Expand Down