Skip to content

Commit

Permalink
feat(sunburst): use @nivo/colors for inherited colors
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphaël Benitte authored and Raphaël Benitte committed Apr 17, 2019
1 parent 4686b2b commit 9cb6b2a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 19 deletions.
20 changes: 9 additions & 11 deletions packages/sunburst/src/Sunburst.js
Expand Up @@ -17,15 +17,13 @@ import withProps from 'recompose/withProps'
import pure from 'recompose/pure'
import { partition as Partition, hierarchy } from 'd3-hierarchy'
import { arc } from 'd3-shape'
import { withTheme, withDimensions, getAccessorFor, Container, SvgWrapper } from '@nivo/core'
import {
getOrdinalColorScale,
ordinalColorsPropType,
inheritedColorPropType,
getInheritedColorGenerator,
withTheme,
withDimensions,
getAccessorFor,
Container,
SvgWrapper,
} from '@nivo/core'
import { getOrdinalColorScale, ordinalColorsPropType } from '@nivo/colors'
} from '@nivo/colors'
import SunburstArc from './SunburstArc'

const getAncestor = node => {
Expand Down Expand Up @@ -99,7 +97,7 @@ Sunburst.propTypes = {
borderWidth: PropTypes.number.isRequired,
borderColor: PropTypes.string.isRequired,

childColor: PropTypes.oneOfType([PropTypes.string, PropTypes.func]).isRequired,
childColor: inheritedColorPropType.isRequired,

isInteractive: PropTypes.bool,
}
Expand All @@ -114,7 +112,7 @@ export const SunburstDefaultProps = {
borderWidth: 1,
borderColor: 'white',

childColor: 'inherit',
childColor: { from: 'color' },

isInteractive: true,
}
Expand Down Expand Up @@ -150,8 +148,8 @@ const enhance = compose(
withPropsOnChange(['data', 'getValue'], ({ data, getValue }) => ({
data: hierarchy(data).sum(getValue),
})),
withPropsOnChange(['childColor'], ({ childColor }) => ({
getChildColor: getInheritedColorGenerator(childColor),
withPropsOnChange(['childColor', 'theme'], ({ childColor, theme }) => ({
getChildColor: getInheritedColorGenerator(childColor, theme),
})),
withPropsOnChange(
['data', 'partition', 'getIdentity', 'getChildColor'],
Expand Down
6 changes: 2 additions & 4 deletions website/src/data/components/sunburst/mapper.js
Expand Up @@ -6,8 +6,6 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import { settingsMapper, mapInheritedColor } from '../../../lib/settings'
import { settingsMapper } from '../../../lib/settings'

export default settingsMapper({
childColor: mapInheritedColor,
})
export default settingsMapper({})
4 changes: 2 additions & 2 deletions website/src/data/components/sunburst/props.js
Expand Up @@ -104,10 +104,10 @@ const props = [
{
key: 'childColor',
help: 'Defines how to compute child nodes color.',
type: 'string | Function',
type: 'string | object | Function',
required: false,
defaultValue: defaults.childColor,
controlType: 'color',
controlType: 'inheritedColor',
group: 'Base',
},
{
Expand Down
2 changes: 1 addition & 1 deletion website/src/pages/sunburst/api.js
Expand Up @@ -49,7 +49,7 @@ const SunburstApi = () => {
borderColor: 'white',

childColor: {
type: 'inherit',
from: 'color',
},
}}
/>
Expand Down
2 changes: 1 addition & 1 deletion website/src/pages/sunburst/index.js
Expand Up @@ -32,7 +32,7 @@ const initialProperties = {

colors: { scheme: 'nivo' },
childColor: {
type: 'inherit',
from: 'color',
},

animate: true,
Expand Down

0 comments on commit 9cb6b2a

Please sign in to comment.