Skip to content

Commit

Permalink
feat(chord): 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 c7cf5ce commit f16f824
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 52 deletions.
22 changes: 8 additions & 14 deletions packages/chord/src/enhance.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,8 @@ import withPropsOnChange from 'recompose/withPropsOnChange'
import pure from 'recompose/pure'
import { arc as d3Arc } from 'd3-shape'
import { chord as d3Chord, ribbon as d3Ribbon } from 'd3-chord'
import {
getInheritedColorGenerator,
getLabelGenerator,
withMotion,
withTheme,
withDimensions,
} from '@nivo/core'
import { getOrdinalColorScale } from '@nivo/colors'
import { getLabelGenerator, withMotion, withTheme, withDimensions } from '@nivo/core'
import { getOrdinalColorScale, getInheritedColorGenerator } from '@nivo/colors'
import { ChordDefaultProps } from './props'

export default Component =>
Expand All @@ -37,8 +31,8 @@ export default Component =>
withPropsOnChange(['padAngle'], ({ padAngle }) => ({
chord: d3Chord().padAngle(padAngle),
})),
withPropsOnChange(['labelTextColor'], ({ labelTextColor }) => ({
getLabelTextColor: getInheritedColorGenerator(labelTextColor, 'labels.textColor'),
withPropsOnChange(['labelTextColor', 'theme'], ({ labelTextColor, theme }) => ({
getLabelTextColor: getInheritedColorGenerator(labelTextColor, theme),
})),
withPropsOnChange(['colors', 'keys'], ({ colors, keys }) => {
const getColor = getOrdinalColorScale(colors, 'key')
Expand Down Expand Up @@ -152,11 +146,11 @@ export default Component =>
return { ribbons, arcs }
}
),
withPropsOnChange(['arcBorderColor'], ({ arcBorderColor }) => ({
getArcBorderColor: getInheritedColorGenerator(arcBorderColor),
withPropsOnChange(['arcBorderColor', 'theme'], ({ arcBorderColor, theme }) => ({
getArcBorderColor: getInheritedColorGenerator(arcBorderColor, theme),
})),
withPropsOnChange(['ribbonBorderColor'], ({ ribbonBorderColor }) => ({
getRibbonBorderColor: getInheritedColorGenerator(ribbonBorderColor),
withPropsOnChange(['ribbonBorderColor', 'theme'], ({ ribbonBorderColor, theme }) => ({
getRibbonBorderColor: getInheritedColorGenerator(ribbonBorderColor, theme),
})),
pure
)(Component)
23 changes: 16 additions & 7 deletions packages/chord/src/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
import PropTypes from 'prop-types'
import { blendModePropType } from '@nivo/core'
import { ordinalColorsPropType } from '@nivo/colors'
import { ordinalColorsPropType, inheritedColorPropType } from '@nivo/colors'
import { LegendPropShape } from '@nivo/legends'

export const ChordPropTypes = {
Expand All @@ -21,12 +21,12 @@ export const ChordPropTypes = {

arcOpacity: PropTypes.number.isRequired,
arcBorderWidth: PropTypes.number.isRequired,
arcBorderColor: PropTypes.any.isRequired,
arcBorderColor: inheritedColorPropType.isRequired,
getArcBorderColor: PropTypes.func.isRequired,

ribbonOpacity: PropTypes.number.isRequired,
ribbonBorderWidth: PropTypes.number.isRequired,
ribbonBorderColor: PropTypes.any.isRequired,
ribbonBorderColor: inheritedColorPropType.isRequired,
ribbonBlendMode: blendModePropType.isRequired,
getRibbonBorderColor: PropTypes.func.isRequired,

Expand All @@ -35,7 +35,7 @@ export const ChordPropTypes = {
getLabel: PropTypes.func.isRequired, // computed
labelOffset: PropTypes.number.isRequired,
labelRotation: PropTypes.number.isRequired,
labelTextColor: PropTypes.oneOfType([PropTypes.string, PropTypes.func]).isRequired,
labelTextColor: inheritedColorPropType.isRequired,
getLabelTextColor: PropTypes.func.isRequired, // computed

colors: ordinalColorsPropType.isRequired,
Expand All @@ -59,18 +59,27 @@ export const ChordDefaultProps = {

arcOpacity: 1,
arcBorderWidth: 1,
arcBorderColor: 'inherit:darker(0.4)',
arcBorderColor: {
from: 'color',
modifiers: [['darker', 0.4]],
},

ribbonOpacity: 0.5,
ribbonBorderWidth: 1,
ribbonBorderColor: 'inherit:darker(0.4)',
ribbonBorderColor: {
from: 'color',
modifiers: [['darker', 0.4]],
},
ribbonBlendMode: 'normal',

enableLabel: true,
label: 'id',
labelOffset: 12,
labelRotation: 0,
labelTextColor: 'inherit:darker(1)',
labelTextColor: {
from: 'color',
modifiers: [['darker', 1]],
},

colors: { scheme: 'nivo' },

Expand Down
5 changes: 1 addition & 4 deletions website/src/data/components/chord/mapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@
* 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({
label: value => {
if (value === `d => \`\${d.id} [\${d.value}]\``) return d => `${d.id} [${d.value}]`
return value
},
labelTextColor: mapInheritedColor,
arcBorderColor: mapInheritedColor,
ribbonBorderColor: mapInheritedColor,
})
21 changes: 6 additions & 15 deletions website/src/data/components/chord/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,9 @@ const props = [
help: 'Arcs border color.',
required: false,
defaultValue: defaults.arcBorderColor,
type: 'string | Function',
controlType: 'color',
type: 'string | object | Function',
controlType: 'inheritedColor',
group: 'Style',
controlOptions: {
withCustomColor: true,
},
},
{
key: 'ribbonOpacity',
Expand Down Expand Up @@ -232,12 +229,9 @@ const props = [
help: 'Ribbons border color.',
required: false,
defaultValue: defaults.ribbonBorderColor,
type: 'string | Function',
controlType: 'color',
type: 'string | object | Function',
controlType: 'inheritedColor',
group: 'Style',
controlOptions: {
withCustomColor: true,
},
},
{
key: 'enableLabel',
Expand Down Expand Up @@ -304,14 +298,11 @@ const props = [
[see dedicated documentation](self:/guides/colors).
`,
help: 'Method to compute label text color.',
type: 'string | Function',
type: 'string | object | Function',
required: false,
defaultValue: defaults.labelTextColor,
controlType: 'color',
controlType: 'inheritedColor',
group: 'Labels',
controlOptions: {
withCustomColor: true,
},
},
{
key: 'isInteractive',
Expand Down
12 changes: 6 additions & 6 deletions website/src/pages/chord/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,24 @@ const initialProperties = {
arcOpacity: 1,
arcBorderWidth: 1,
arcBorderColor: {
type: 'inherit:darker',
gamma: 0.4,
from: 'color',
modifiers: [['darker', 0.4]],
},

ribbonOpacity: 0.5,
ribbonBorderWidth: 1,
ribbonBorderColor: {
type: 'inherit:darker',
gamma: 0.4,
from: 'color',
modifiers: [['darker', 0.4]],
},

enableLabel: true,
label: 'id',
labelOffset: 9,
labelRotation: -90,
labelTextColor: {
type: 'inherit:darker',
gamma: 1,
from: 'color',
modifiers: [['darker', 1]],
},

colors: { scheme: 'paired' },
Expand Down
12 changes: 6 additions & 6 deletions website/src/pages/chord/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,24 @@ const initialProperties = {
arcOpacity: 1,
arcBorderWidth: 1,
arcBorderColor: {
type: 'inherit:darker',
gamma: 0.4,
from: 'color',
modifiers: [['darker', 0.4]],
},

ribbonOpacity: 0.5,
ribbonBorderWidth: 1,
ribbonBorderColor: {
type: 'inherit:darker',
gamma: 0.4,
from: 'color',
modifiers: [['darker', 0.4]],
},

enableLabel: true,
label: 'id',
labelOffset: 12,
labelRotation: -90,
labelTextColor: {
type: 'inherit:darker',
gamma: 1,
from: 'color',
modifiers: [['darker', 1]],
},

colors: { scheme: 'nivo' },
Expand Down

0 comments on commit f16f824

Please sign in to comment.