Skip to content

Commit

Permalink
feat(legends): add default text color + canvas support for text color
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphaël Benitte authored and Raphaël Benitte committed Jan 27, 2018
1 parent 8a985a4 commit 20a30ab
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/nivo-legends/src/canvas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const renderLegendToCanvas = (
itemsSpacing = LegendSvg.defaultProps.itemsSpacing,
symbolSize = LegendSvgItem.defaultProps.symbolSize,
symbolSpacing = LegendSvgItem.defaultProps.symbolSpacing,
textColor = LegendSvg.defaultProps.textColor,
// @todo add support for shapes
// symbolShape = LegendSvgItem.defaultProps.symbolShape,
}
Expand Down Expand Up @@ -99,7 +100,7 @@ export const renderLegendToCanvas = (

ctx.textAlign = textPropsMapping.align[labelAnchor]
ctx.textBaseline = textPropsMapping.baseline[labelAlignment]
ctx.fillStyle = '#000000'
ctx.fillStyle = textColor
ctx.fillText(d.label, itemX + labelX, itemY + labelY)
})

Expand Down
1 change: 1 addition & 0 deletions packages/nivo-legends/src/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,5 @@ export const LegendPropShape = {
symbolSize: PropTypes.number,
symbolSpacing: PropTypes.number,
symbolShape: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
textColor: PropTypes.string
}
2 changes: 1 addition & 1 deletion packages/nivo-legends/src/svg/BoxLegendSvg.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ BoxLegendSvg.propTypes = {
symbolSize: PropTypes.number,
symbolSpacing: PropTypes.number,
symbolShape: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
textColor: PropTypes.string.isRequired,
textColor: PropTypes.string,
}

BoxLegendSvg.defaultProps = {
Expand Down
1 change: 1 addition & 0 deletions packages/nivo-legends/src/svg/LegendSvg.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ LegendSvg.defaultProps = {
// items
itemDirection: DIRECTION_LEFT_TO_RIGHT,
itemsSpacing: 0,
textColor: 'black',
}

export default LegendSvg
1 change: 1 addition & 0 deletions packages/nivo-legends/tests/svg/LegendSvgItem.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const commonProps = {
height: 36,
label: 'testing',
fill: 'red',
textColor: 'black',
}

const directions = [
Expand Down

0 comments on commit 20a30ab

Please sign in to comment.