-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add option to toggle value labels on bar charts (#182)
- Loading branch information
1 parent
8133ab1
commit 6d8ec0e
Showing
16 changed files
with
1,071 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import React from 'react'; | ||
import { Group, Rect, Text } from 'react-konva'; | ||
import { BarGeometry } from '../../lib/series/rendering'; | ||
import { Rotation } from '../../lib/series/specs'; | ||
import { DisplayValueStyle } from '../../lib/themes/theme'; | ||
import { Dimensions } from '../../lib/utils/dimensions'; | ||
import { buildBarValueProps } from './utils/rendering_props_utils'; | ||
|
||
interface BarValuesProps { | ||
chartDimensions: Dimensions; | ||
chartRotation: Rotation; | ||
debug: boolean; | ||
bars: BarGeometry[]; | ||
displayValueStyle: DisplayValueStyle; | ||
} | ||
|
||
export class BarValues extends React.PureComponent<BarValuesProps> { | ||
render() { | ||
const { chartDimensions } = this.props; | ||
|
||
return ( | ||
<Group x={chartDimensions.left} y={chartDimensions.top}> | ||
{this.renderBarValues()} | ||
</Group> | ||
); | ||
} | ||
|
||
private renderBarValues = () => { | ||
const { bars, displayValueStyle, debug, chartRotation, chartDimensions } = this.props; | ||
return bars.map((bar, index) => { | ||
const { displayValue, x, y, height, width } = bar; | ||
if (!displayValue) { | ||
return; | ||
} | ||
|
||
const key = `bar-value-${index}`; | ||
const displayValueProps = buildBarValueProps({ | ||
x, | ||
y, | ||
barHeight: height, | ||
barWidth: width, | ||
displayValueStyle, | ||
displayValue, | ||
chartRotation, | ||
chartDimensions, | ||
}); | ||
|
||
const debugProps = { | ||
...displayValueProps, | ||
stroke: 'violet', | ||
strokeWidth: 1, | ||
fill: 'transparent', | ||
}; | ||
|
||
return ( | ||
<Group key={key}> | ||
{debug && <Rect {...debugProps} />} | ||
{displayValue && <Text {...displayValueProps} />} | ||
</Group> | ||
); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.