Skip to content

Commit 8917d36

Browse files
author
Robert Crocker
committed
Updated line and pie colors.
1 parent 46e8d5e commit 8917d36

File tree

4 files changed

+32
-14
lines changed

4 files changed

+32
-14
lines changed

src/App.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function App() {
2323
outerRadius={240}
2424
pieLabel={true}
2525
/>
26-
<BarChart
26+
{/*<BarChart
2727
theme="dark"
2828
height="100%"
2929
width="100%"
@@ -50,9 +50,9 @@ function App() {
5050
yGrid={true}
5151
xAxisLabel="Date"
5252
yAxisLabel="Value"
53-
/>
53+
/> */}
5454
<LineChart
55-
theme="dark"
55+
theme="light"
5656
height={'100%'}
5757
width={'100%'}
5858
data={portfolio}
@@ -67,7 +67,7 @@ function App() {
6767
legend={'right'}
6868
legendLabel="Markets"
6969
/>
70-
<ScatterPlot
70+
{/* <ScatterPlot
7171
theme="light"
7272
height="100%"
7373
width="100%"
@@ -81,7 +81,7 @@ function App() {
8181
yGrid={true}
8282
yAxis="right"
8383
yAxisLabel="Body Mass"
84-
/>
84+
/> */}
8585
</Container>
8686
);
8787
}

src/charts/LineChart/LineChart.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,21 @@ export default function LineChart({
158158
// Define how the data will drive your design
159159
// ********************
160160

161+
const numberOfKeys = Array.from(keys).length;
162+
// let discreteColors = 0;
163+
// let computedScheme: string[];
164+
// if (numberOfKeys > 3) {
165+
// discreteColors = Math.min(Array.from(keys).length, 9);
166+
// computedScheme = d3[`${colorScheme}`][discreteColors];
167+
// } else {
168+
169+
// }
161170
const discreteColors =
162-
Array.from(keys).length < 4 ? 3 : Math.min(Array.from(keys).length, 9);
163-
const computedScheme = d3[`${colorScheme}`][discreteColors];
164-
const colorScale = d3.scaleOrdinal(Array.from(computedScheme));
171+
numberOfKeys < 4 ? 3 : Math.min(Array.from(keys).length, 9);
172+
const computedScheme = Array.from(
173+
d3[`${colorScheme}`][discreteColors]
174+
).reverse();
175+
const colorScale = d3.scaleOrdinal(computedScheme);
165176
colorScale.domain(computedScheme);
166177

167178
// ********************
@@ -201,6 +212,7 @@ export default function LineChart({
201212
);
202213
}, [data, xScale, yScale, xAccessor, yAccessor, cHeight, cWidth, margin]);
203214

215+
console.log('KEYS ', keys);
204216
return (
205217
<ThemeProvider theme={themes[theme]}>
206218
<div ref={anchor} style={{ width: width, height: height }}>

src/charts/PieChart/PieChart.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,16 +145,22 @@ export default function PieChart({
145145
// Define how the data will drive your design
146146
// ********************
147147

148-
const discreteColors = Math.min(keys.length, 9);
149-
const computedScheme = d3[`${colorScheme}`][discreteColors];
150-
const colorScale = d3.scaleOrdinal(Array.from(computedScheme).reverse());
148+
const numberOfKeys = Array.from(keys).length;
149+
const discreteColors =
150+
numberOfKeys < 4 ? 3 : Math.min(Array.from(keys).length, 9);
151+
const computedScheme = Array.from(
152+
d3[`${colorScheme}`][discreteColors]
153+
).reverse();
154+
const colorScale = d3.scaleOrdinal(computedScheme);
151155
colorScale.domain(keys);
152156

153157
// ********************
154158
// STEP 5. Set up supportive elements
155159
// Render your axes, labels, legends, annotations, etc.
156160
// ********************
157161

162+
const colorLabels = [...keys].reverse();
163+
158164
const textTranform = (d: any) => {
159165
const [x, y]: number[] = arcGenerator.centroid(d);
160166
return `translate(${x}, ${y})`;
@@ -287,7 +293,7 @@ export default function PieChart({
287293
<ColorLegend
288294
theme={theme}
289295
legendLabel={legendLabel}
290-
labels={keys}
296+
labels={colorLabels}
291297
circleRadius={5 /* Radius of each color swab in legend */}
292298
colorScale={colorScale}
293299
dataTestId="pie-chart-legend"

src/styles/componentStyles.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import styled from 'styled-components';
33
export const Container = styled.div`
44
height: 100vh;
55
width: 100vw;
6-
/* background-color: #ffffff; */
7-
background-color: #1d1d1d;
6+
background-color: #ffffff;
7+
/* background-color: #1d1d1d; */
88
`;

0 commit comments

Comments
 (0)