Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(line): add gradient support to line areas #844

Merged
merged 4 commits into from May 17, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/line/src/Areas.js
Expand Up @@ -19,11 +19,11 @@ const Areas = ({ areaGenerator, areaOpacity, areaBlendMode, lines }) => {
{lines
.slice(0)
.reverse()
.map(({ id, data, color: areaColor }) => (
.map(({ id, data, color: areaColor, fill }) => (
<path
key={id}
d={areaGenerator(data.map(d => d.position))}
fill={areaColor}
fill={fill ? fill : areaColor}
fillOpacity={areaOpacity}
strokeWidth={0}
style={{
Expand All @@ -40,7 +40,7 @@ const Areas = ({ areaGenerator, areaOpacity, areaBlendMode, lines }) => {
{lines
.slice(0)
.reverse()
.map(({ id, data, color: areaColor }) => (
.map(({ id, data, color: areaColor, fill }) => (
<SmartMotion
key={id}
style={spring => ({
Expand All @@ -52,7 +52,7 @@ const Areas = ({ areaGenerator, areaOpacity, areaBlendMode, lines }) => {
<path
key={id}
d={style.d}
fill={areaColor}
fill={fill ? fill : areaColor}
fillOpacity={areaOpacity}
strokeWidth={0}
style={{ mixBlendMode: areaBlendMode }}
Expand Down
16 changes: 14 additions & 2 deletions packages/line/src/Line.js
Expand Up @@ -7,7 +7,14 @@
* file that was distributed with this source code.
*/
import React, { Fragment, useState, useMemo } from 'react'
import { withContainer, useDimensions, useTheme, SvgWrapper, CartesianMarkers } from '@nivo/core'
import {
bindDefs,
withContainer,
useDimensions,
useTheme,
SvgWrapper,
CartesianMarkers,
} from '@nivo/core'
import { useInheritedColor } from '@nivo/colors'
import { Axes, Grid } from '@nivo/axes'
import { BoxLegendSvg } from '@nivo/legends'
Expand Down Expand Up @@ -62,6 +69,9 @@ const Line = props => {
pointLabelFormat,
pointLabelYOffset,

defs,
wyze marked this conversation as resolved.
Show resolved Hide resolved
fill,

markers,

legends,
Expand Down Expand Up @@ -185,6 +195,8 @@ const Line = props => {
)),
}

const boundDefs = bindDefs(defs, series, fill)

if (enableArea) {
layerById.areas = (
<Areas
Expand Down Expand Up @@ -278,7 +290,7 @@ const Line = props => {
}

return (
<SvgWrapper width={outerWidth} height={outerHeight} margin={margin}>
<SvgWrapper defs={boundDefs} width={outerWidth} height={outerHeight} margin={margin}>
{layers.map((layer, i) => {
if (typeof layer === 'function') {
return (
Expand Down