Skip to content

Commit 2de6cca

Browse files
authored
Merge pull request #104 from oslabs-beta/dev
HotFix
2 parents 439a11e + e2c5061 commit 2de6cca

File tree

12 files changed

+53
-34
lines changed

12 files changed

+53
-34
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,18 @@ import {AreaChart, BarChart, PieChart, ScatterPlot, LineChart} from "d3reactor"
4242

4343
And you're good to go!
4444

45+
<img width="1100" alt="Stacked Bar Chart" src="https://user-images.githubusercontent.com/83976244/152201874-6b5e51a7-92a0-473d-abc7-9f06b45bc525.png">
4546

46-
<img width="1100" alt="Stacked Bar Chart" src="https://user-images.githubusercontent.com/83976244/152202135-2f15b0e9-62da-47c5-aa61-9db4a2a7b80c.png">
4747

48+
# Documentation
49+
50+
For detailed information, please follow the links below:
51+
52+
* [d3reactor](https://www.d3reactor.com/)
53+
* [Area Chart](https://www.docs.d3reactor.com/docs/Charts/area-chart)
54+
* [Bar Chart](https://www.docs.d3reactor.com/docs/Charts/bar-chart)
55+
* [Line Chart](https://www.docs.d3reactor.com/docs/Charts/line-chart)
56+
* [Pie Chart](https://www.docs.d3reactor.com/docs/Charts/pie-chart)
57+
* [Scatter Plot](https://www.docs.d3reactor.com/docs/Charts/scatter-plot)
4858

4959

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@oslabs-beta/d3reactor",
3-
"version": "0.0.12",
3+
"version": "0.0.13",
44
"description": "Open-source charting library for creating performant, responsive data visualizations in React",
55
"keywords": ["d3", "react", "chart", "graph", "svg", "visualization", "data visualization"],
66
"main": "./dist/index.js",

src/App.tsx

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,38 @@
1-
import React from 'react';
1+
import React, {useState, useEffect } from 'react';
2+
23
import BarChart from './charts/BarChart/BarChart';
34
import AreaChart from './charts/AreaChart/AreaChart';
45
import LineChart from './charts/LineChart/LineChart';
56
import ScatterPlot from './charts/ScatterPlot/ScatterPlot';
67
import PieChart from './charts/PieChart/PieChart';
8+
import { Container } from './styles/componentStyles';
79

810
import portfolio from '../data/portfolio.json';
911
import penguins from '../data/penguins.json';
1012
import fruit from '../data/fruit.json';
13+
import unemployment from '../data/unemployment.json'
1114
import skinny_fruit from '../data/skinny_fruit.json';
1215

13-
import { Container } from './styles/componentStyles';
1416

1517
function App() {
18+
const [pie, setPie] = useState(fruit.sort((a, b) => a.value - b.value).slice(2))
19+
const [bar, setBar] = useState(skinny_fruit.reverse().slice(2))
20+
const [area, setArea] = useState(portfolio.slice(30, 60))
21+
const [line, setLine] = useState(unemployment.slice(0, 60))
22+
const [scatter, setScatter] = useState(penguins.slice(30, 60))
23+
24+
useEffect(() => {
25+
setTimeout(() => {setPie(fruit.sort((a, b) => a.value - b.value))}, 1000);
26+
setTimeout(() => {setBar(skinny_fruit.reverse())}, 2000);
27+
setTimeout(() => {setArea(portfolio.slice(0, 60))}, 4000);
28+
setTimeout(() => {setLine(unemployment)}, 6000);
29+
setTimeout(() => {setScatter(penguins)}, 8000);
30+
}, [])
1631
return (
1732
<Container className="app">
1833
<PieChart
1934
theme="dark"
20-
data={fruit.sort((a, b) => a.value - b.value)}
35+
data={pie}
2136
label="label"
2237
value="value"
2338
outerRadius={400}
@@ -27,7 +42,7 @@ function App() {
2742
theme="light"
2843
height="100%"
2944
width="100%"
30-
data={skinny_fruit.reverse()}
45+
data={bar}
3146
xKey="date"
3247
yKey="value"
3348
groupBy="fruit"
@@ -43,7 +58,7 @@ function App() {
4358
theme="dark"
4459
height="100%"
4560
width="100%"
46-
data={portfolio.slice(30, 60)}
61+
data={area}
4762
xKey="date"
4863
yKey="value"
4964
xAxis="bottom"
@@ -56,10 +71,11 @@ function App() {
5671
theme="light"
5772
height={'100%'}
5873
width={'100%'}
59-
data={portfolio}
74+
data={line}
6075
xKey="date"
6176
xDataType="date"
62-
yKey="value"
77+
groupBy='division'
78+
yKey="unemployment"
6379
xAxis="bottom"
6480
yAxis="left"
6581
yGrid={true}
@@ -72,7 +88,8 @@ function App() {
7288
theme="light"
7389
height="100%"
7490
width="100%"
75-
data={penguins}
91+
data={scatter}
92+
groupBy={'species'}
7693
xKey="flipper_length_mm"
7794
xDataType="number"
7895
xGrid={true}
@@ -82,6 +99,8 @@ function App() {
8299
yGrid={true}
83100
yAxis="right"
84101
yAxisLabel="Body Mass"
102+
legend={'right'}
103+
85104
/>
86105
</Container>
87106
);

src/charts/AreaChart/AreaChart.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ import {
2828
} from '../../utils';
2929
import styled, { ThemeProvider } from 'styled-components';
3030

31-
const { light, dark } = themes;
32-
3331
const Area = styled.path`
3432
fill-opacity: 0.7;
3533
`;
@@ -88,7 +86,7 @@ export default function AreaChart({
8886
const groupAccessor = (d: Data) => d[groupBy ?? ''];
8987
const groups = d3.group(data, groupAccessor);
9088
return groupBy ? Array.from(groups).map((group) => group[0]) : [yKey];
91-
}, [groupBy, yKey]);
89+
}, [groupBy, yKey, data]);
9290

9391
const transData = useMemo(() => {
9492
return groupBy

src/charts/BarChart/BarChart.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ import {
2424
} from '../../utils';
2525
import { yScaleDef } from '../../functionality/yScale';
2626
import { Label } from '../../components/Label';
27-
import styled, { ThemeProvider } from 'styled-components';
27+
import{ ThemeProvider } from 'styled-components';
2828

29-
const { light, dark } = themes;
3029

3130
export default function BarChart({
3231
theme = 'light',
@@ -75,7 +74,7 @@ export default function BarChart({
7574
const groupAccessor = (d: Data) => d[groupBy ?? ''];
7675
const groups = d3.group(data, groupAccessor);
7776
return groupBy ? Array.from(groups).map((group) => group[0]) : [yKey];
78-
}, [groupBy, yKey]);
77+
}, [groupBy, yKey, data]);
7978

8079
const transData = useMemo(() => {
8180
return groupBy

src/charts/LineChart/LineChart.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ import { d3Voronoi } from '../../functionality/voronoi';
2323
import { Label } from '../../components/Label';
2424
import Tooltip from '../../components/Tooltip';
2525

26-
import styled, { ThemeProvider } from 'styled-components';
26+
import { ThemeProvider } from 'styled-components';
2727

28-
const { light, dark } = themes;
2928

3029
export default function LineChart({
3130
theme = 'light',
@@ -203,8 +202,6 @@ export default function LineChart({
203202
margin
204203
);
205204
}, [data, xScale, yScale, xAccessor, yAccessor, cHeight, cWidth, margin]);
206-
207-
console.log('KEYS ', keys);
208205
return (
209206
<ThemeProvider theme={themes[theme]}>
210207
<div ref={anchor} style={{ width: width, height: height }}>

src/charts/PieChart/PieChart.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ const PieLabel = styled.text`
2525
pointer-events: none;
2626
`;
2727

28-
const { light, dark } = themes;
29-
3028
export default function PieChart({
3129
theme = 'light',
3230
data,
@@ -60,7 +58,7 @@ export default function PieChart({
6058
const groupAccessor = (d: Data) => d[label ?? ''];
6159
const groups: d3.InternMap<any, any[]> = d3.group(data, groupAccessor);
6260
return Array.from(groups).map((group) => group[0]);
63-
}, [label]);
61+
}, [label, data]);
6462

6563
// ********************
6664
// STEP 2. Determine chart dimensions

src/charts/ScatterPlot/ScatterPlot.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ import { Label } from '../../components/Label';
3030

3131
import { ThemeProvider } from 'styled-components';
3232

33-
const { light, dark } = themes;
34-
3533
export default function ScatterPlot({
3634
theme = 'light',
3735
data,
@@ -74,7 +72,7 @@ export default function ScatterPlot({
7472
const groupAccessor = (d: Data) => d[groupBy ?? ''];
7573
const groups = d3.group(data, groupAccessor);
7674
return groupBy ? Array.from(groups).map((group) => group[0]) : [yKey];
77-
}, [groupBy, yKey]);
75+
}, [groupBy, yKey, data]);
7876

7977
const xAccessor: xAccessorFunc = useMemo(() => {
8078
return xType === 'number' ? (d) => d[xKey] : (d) => new Date(d[xKey]);

src/components/ColorLegend.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export const ColorLegend = ({
151151
return (
152152
<g
153153
className="tick"
154-
key={domainValue}
154+
key={i}
155155
transform={`translate(
156156
${EXTRA_LEGEND_MARGIN + circleRadius},
157157
${

src/components/ContinuousAxis.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,21 +156,21 @@ function Axi({
156156
/>
157157
)}
158158
{(type === 'top' || type === 'bottom') &&
159-
horizontalTicks.map((tick) => (
159+
horizontalTicks.map((tick, i) => (
160160
<TickText
161161
data-testid="d3reactor-ticktext"
162-
key={JSON.stringify(tick)}
162+
key={i}
163163
style={getTickStyle(type)}
164164
transform={getTickTranslation(type, tick)}
165165
>
166166
{getFormattedTick(tick)}
167167
</TickText>
168168
))}
169169
{(type === 'right' || type === 'left') &&
170-
verticalTicks.map((tick) => (
170+
verticalTicks.map((tick, i) => (
171171
<TickText
172172
data-testid="d3reactor-ticktext"
173-
key={JSON.stringify(tick)}
173+
key={i}
174174
style={getTickStyle(type)}
175175
transform={getTickTranslation(type, tick)}
176176
>

0 commit comments

Comments
 (0)