Skip to content

Commit

Permalink
Force tooltips on the DonutChart to a constant width (#1618)
Browse files Browse the repository at this point in the history
By default the `@patternfly/react-charts` chart tooltips use
the same text width estimation as is used in the Victory charts [1].
This estimation works ok for ASCII characters, but underestimate
sizes for other non-Latin character code pages.

Instead of creating another text size estimation function that can
handle non-Latin characters (e.g. see [2]), just pick a constant
width that should accommodate the expected text widths of most
languages we support.

[1] - https://github.com/FormidableLabs/victory/blob/main/packages/victory-core/src/victory-util/textsize.ts
[2] - https://stackoverflow.com/questions/118241/calculate-text-width-with-javascript
  • Loading branch information
sjd78 committed Jul 22, 2022
1 parent 3903152 commit e297a79
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import React from 'react'
import PropTypes from 'prop-types'
import { ChartDonut, ChartLabel } from '@patternfly/react-charts'
import {
ChartDonut,
ChartLabel,
ChartTooltip,
} from '@patternfly/react-charts'

import style from '../style.css'

Expand All @@ -20,6 +24,7 @@ const DonutChart = ({ data, title, subTitle, id }) => {
title={title}
style={{ labels: { fontSize: 12 } }}
titleComponent={<ChartLabel style={[{ fontSize: 30 }, { fontSize: 20, fill: '#bbb' }]} />}
labelComponent={<ChartTooltip flyoutWidth={180} />}
/>
</div>
)
Expand Down

0 comments on commit e297a79

Please sign in to comment.