Skip to content

Commit b94f6a8

Browse files
committed
Better styles, better colors
1 parent 229d39a commit b94f6a8

File tree

10 files changed

+3292
-2422
lines changed

10 files changed

+3292
-2422
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ yarn-debug.log*
2525
yarn-error.log*
2626
.history
2727
stats.html
28+
size-plugin.json

size-plugin.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/components/Chart.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const defaultProps = {
3535
getR: d => (Array.isArray(d) ? d[2] : d.radius || d.r),
3636
getPrimaryAxisID: s => s.primaryAxisID,
3737
getSecondaryAxisID: s => s.secondaryAxisID,
38-
getSeriesStyle: series => ({ color: series.originalSeries.color }),
38+
getSeriesStyle: () => ({}),
3939
getDatumStyle: () => ({}),
4040
getSeriesOrder: d => d,
4141
onHover: () => {},
@@ -65,7 +65,7 @@ export default function Chart({
6565
getR,
6666
getPrimaryAxisID,
6767
getSecondaryAxisID,
68-
getSeriesStyle,
68+
getSeriesStyle: getSeriesStyleOriginal,
6969
getDatumStyle,
7070
onClick,
7171
onFocus,
@@ -256,6 +256,14 @@ export default function Chart({
256256
primaryAxes,
257257
])
258258

259+
const getSeriesStyle = React.useCallback(
260+
(series, ...args) => ({
261+
color: series.originalSeries.color,
262+
...getSeriesStyleOriginal(series, ...args),
263+
}),
264+
[getSeriesStyleOriginal]
265+
)
266+
259267
// Decorate the chartState with computed values (or ones we just
260268
// want to pass down through context)
261269
const chartState = React.useMemo(

src/components/pipeline/useStackData.js

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,25 @@ import {
66
groupingSingle,
77
groupingSeries,
88
groupingPrimary,
9-
groupingSecondary
9+
groupingSecondary,
1010
} from '../../utils/Constants'
1111

1212
const defaultColors = [
13-
'#4ab5eb',
14-
'#fc6868',
15-
'#DECF3F',
16-
'#60BD68',
13+
'#ff3465',
14+
'#ff5454',
15+
'#ff7b3e',
1716
'#FAA43A',
18-
'#c63b89',
19-
'#1aaabe',
17+
'#ffd000',
18+
'#C8DE2B',
19+
'#97d114',
20+
'#34ce70',
21+
'#3cada4',
22+
'#14b4d3',
23+
'#048cd4',
24+
'#3447f1',
2025
'#734fe9',
21-
'#1828bd',
22-
'#cd82ad'
26+
'#cd82ad',
27+
'#c63b89',
2328
]
2429

2530
export default ({
@@ -30,7 +35,7 @@ export default ({
3035
yKey,
3136
xAxes,
3237
xKey,
33-
grouping
38+
grouping,
3439
}) => {
3540
// Make stackData
3641
return React.useMemo(() => {
@@ -50,7 +55,7 @@ export default ({
5055
series.datums.forEach(datum => {
5156
scaleTotals[axisIndex][datum.primary] = {
5257
negative: 0,
53-
positive: 0
58+
positive: 0,
5459
}
5560
})
5661
})
@@ -79,7 +84,7 @@ export default ({
7984
secondaryAxis,
8085
xValue: d[xKey],
8186
yValue: d[yKey],
82-
baseValue: 0
87+
baseValue: 0,
8388
}
8489
if (secondaryAxis.stacked) {
8590
const start = scaleTotals[secondaryAxisIndex][d.primary]
@@ -117,7 +122,7 @@ export default ({
117122
}
118123
}
119124
return datum
120-
})
125+
}),
121126
}
122127
})
123128

@@ -165,7 +170,7 @@ export default ({
165170
primaryAxis,
166171
secondaryAxis,
167172
xAxis,
168-
yAxis
173+
yAxis,
169174
})
170175

171176
return result || d
@@ -236,7 +241,7 @@ export default ({
236241
)
237242
}
238243
const result = series.Component.buildStyles(series, {
239-
defaultColors
244+
defaultColors,
240245
})
241246

242247
return result || series
@@ -251,6 +256,6 @@ export default ({
251256
xKey,
252257
yKey,
253258
xAxes,
254-
yAxes
259+
yAxes,
255260
])
256261
}

src/seriesTypes/Area.js

Lines changed: 67 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react'
22
import { area, line } from '../../d3'
33
//
44

5+
import ChartContext from '../utils/ChartContext'
56
import Utils from '../utils/Utils'
67
import { curveLinear } from '../utils/Curves'
78

@@ -10,16 +11,21 @@ import useDatumStyle from '../hooks/useDatumStyle'
1011

1112
import Path from '../primitives/Path'
1213
import Line from '../primitives/Line'
14+
import Circle from '../primitives/Circle'
1315

1416
const defaultAreaStyle = {
1517
strokeWidth: 0,
1618
}
1719

18-
const lineDefaultStyle = {
19-
strokeWidth: 3,
20+
const defaultLineStyle = {
21+
strokeWidth: 2,
2022
}
2123

22-
export default function Area({ series, showOrphans, curve }) {
24+
const circleDefaultStyle = {
25+
r: 1.5,
26+
}
27+
28+
export default function Area({ series, showOrphans, showPoints, curve }) {
2329
const areaFn = React.useMemo(
2430
() =>
2531
area()
@@ -40,10 +46,12 @@ export default function Area({ series, showOrphans, curve }) {
4046
.curve(curve),
4147
[curve]
4248
)
49+
4350
const areaPath = React.useMemo(() => areaFn(series.datums), [
4451
areaFn,
4552
series.datums,
4653
])
54+
4755
const linePath = React.useMemo(() => lineFn(series.datums), [
4856
lineFn,
4957
series.datums,
@@ -56,15 +64,14 @@ export default function Area({ series, showOrphans, curve }) {
5664
style: {
5765
...defaultAreaStyle,
5866
...style,
59-
...style.line,
6067
...style.area,
6168
},
6269
}
6370

6471
const linePathProps = {
6572
d: linePath,
6673
style: {
67-
...defaultAreaStyle,
74+
...defaultLineStyle,
6875
...style,
6976
...style.line,
7077
fill: 'none',
@@ -89,12 +96,26 @@ export default function Area({ series, showOrphans, curve }) {
8996
/>
9097
)
9198
})}
99+
{showPoints &&
100+
series.datums.map((datum, i) => {
101+
return (
102+
<Point
103+
{...{
104+
key: i,
105+
datum,
106+
style,
107+
}}
108+
/>
109+
)
110+
})}
92111
</g>
93112
)
94113
}
95114

96115
Area.defaultProps = {
97116
showOrphans: true,
117+
showLine: true,
118+
showPoints: true,
98119
curve: curveLinear,
99120
}
100121

@@ -168,7 +189,7 @@ const OrphanLine = function OrphanLine({ datum, style, all, index }) {
168189
x2: !datum || Number.isNaN(datum.x) ? null : datum.x,
169190
y2: !datum || Number.isNaN(datum.y) ? null : datum.y,
170191
style: {
171-
...lineDefaultStyle,
192+
...defaultLineStyle,
172193
...style,
173194
...style.line,
174195
...dataStyle,
@@ -182,3 +203,43 @@ const OrphanLine = function OrphanLine({ datum, style, all, index }) {
182203

183204
return <Line {...lineProps} />
184205
}
206+
207+
function Point({ datum, style }) {
208+
const [, setChartState] = React.useContext(ChartContext)
209+
210+
const dataStyle = useDatumStyle(datum)
211+
212+
const circleProps = {
213+
x: datum ? datum.x : undefined,
214+
y: datum ? datum.y : undefined,
215+
style: {
216+
...circleDefaultStyle,
217+
...style,
218+
...style.circle,
219+
...dataStyle,
220+
...dataStyle.circle,
221+
},
222+
onMouseEnter: React.useCallback(
223+
e =>
224+
setChartState(state => ({
225+
...state,
226+
element: datum,
227+
})),
228+
[datum, setChartState]
229+
),
230+
onMouseLeave: React.useCallback(
231+
e =>
232+
setChartState(state => ({
233+
...state,
234+
element: null,
235+
})),
236+
[setChartState]
237+
),
238+
}
239+
240+
if (!datum.defined) {
241+
return null
242+
}
243+
244+
return <Circle {...circleProps} />
245+
}

0 commit comments

Comments
 (0)