Skip to content

Commit

Permalink
feat(line): add support for mix-blend-mode on areas
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphaël Benitte authored and Raphaël Benitte committed Oct 26, 2018
1 parent ff9399f commit c434148
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/line/index.d.ts
Expand Up @@ -67,6 +67,7 @@ declare module '@nivo/line' {

enableArea?: boolean
areaOpacity?: number
areaBlendMode?: string
areaBaselineValue?: number | string | Date

markers?: CartesianMarkerProps[]
Expand Down
2 changes: 2 additions & 0 deletions packages/line/src/Line.js
Expand Up @@ -56,6 +56,7 @@ const Line = ({
lineWidth,
enableArea,
areaOpacity,
areaBlendMode,

enableDots,
dotSymbol,
Expand Down Expand Up @@ -127,6 +128,7 @@ const Line = ({
<LineAreas
areaGenerator={areaGenerator}
areaOpacity={areaOpacity}
areaBlendMode={areaBlendMode}
lines={computedData.series}
{...motionProps}
/>
Expand Down
10 changes: 7 additions & 3 deletions packages/line/src/LineAreas.js
Expand Up @@ -9,12 +9,12 @@
import React from 'react'
import PropTypes from 'prop-types'
import pure from 'recompose/pure'
import { motionPropTypes } from '@nivo/core'
import { SmartMotion } from '@nivo/core'
import { motionPropTypes, SmartMotion, blendModePropType } from '@nivo/core'

const LineAreas = ({
areaGenerator,
areaOpacity,
areaBlendMode,
lines,
animate,
motionStiffness,
Expand All @@ -33,6 +33,9 @@ const LineAreas = ({
fill={areaColor}
fillOpacity={areaOpacity}
strokeWidth={0}
style={{
mixBlendMode: areaBlendMode,
}}
/>
))}
</g>
Expand Down Expand Up @@ -64,6 +67,7 @@ const LineAreas = ({
fill={areaColor}
fillOpacity={areaOpacity}
strokeWidth={0}
style={{ mixBlendMode: areaBlendMode }}
/>
)}
</SmartMotion>
Expand All @@ -74,7 +78,7 @@ const LineAreas = ({

LineAreas.propTypes = {
areaOpacity: PropTypes.number.isRequired,
// motion
areaBlendMode: blendModePropType.isRequired,
...motionPropTypes,
}

Expand Down
4 changes: 3 additions & 1 deletion packages/line/src/props.js
Expand Up @@ -7,7 +7,7 @@
* file that was distributed with this source code.
*/
import PropTypes from 'prop-types'
import { lineCurvePropType } from '@nivo/core'
import { lineCurvePropType, blendModePropType } from '@nivo/core'
import { axisPropType } from '@nivo/axes'
import { scalePropType } from '@nivo/scales'
import { LegendPropShape } from '@nivo/legends'
Expand Down Expand Up @@ -71,6 +71,7 @@ export const LinePropTypes = {
getColor: PropTypes.func.isRequired,
enableArea: PropTypes.bool.isRequired,
areaOpacity: PropTypes.number.isRequired,
areaBlendMode: blendModePropType.isRequired,
areaBaselineValue: PropTypes.oneOfType([
PropTypes.number,
PropTypes.string,
Expand Down Expand Up @@ -120,6 +121,7 @@ export const LineDefaultProps = {
enableArea: false,
areaBaselineValue: 0,
areaOpacity: 0.2,
areaBlendMode: 'normal',
lineWidth: 2,
defs: [],

Expand Down
3 changes: 2 additions & 1 deletion website/src/components/charts/line/defaultProps.js
Expand Up @@ -89,7 +89,8 @@ export default {
dotLabel: 'y',
dotLabelYOffset: -12,

enableArea: false,
enableArea: true,
areaBlendMode: 'normal',
areaBaselineValue: 0,
areaOpacity: 0.2,

Expand Down
45 changes: 45 additions & 0 deletions website/src/components/charts/line/props.js
Expand Up @@ -290,6 +290,51 @@ export default [
step: 0.05,
},
},
{
key: 'areaBlendMode',
scopes: '*',
description: (
<span>
Defines CSS <code>mix-blend-mode</code> property for areas, see{' '}
<a
href="https://developer.mozilla.org/fr/docs/Web/CSS/mix-blend-mode"
target="_blank"
rel="noopener noreferrer"
>
MDN documentation
</a>
.
</span>
),
type: '{string}',
required: false,
default: defaults.areaBlendMode,
controlType: 'choices',
controlGroup: 'Style',
controlOptions: {
choices: [
'normal',
'multiply',
'screen',
'overlay',
'darken',
'lighten',
'color-dodge',
'color-burn',
'hard-light',
'soft-light',
'difference',
'exclusion',
'hue',
'saturation',
'color',
'luminosity',
].map(key => ({
label: key,
value: key,
})),
},
},
...marginProperties,
{
key: 'enableDots',
Expand Down

0 comments on commit c434148

Please sign in to comment.