diff --git a/README.md b/README.md index ddd38dd..0e63177 100644 --- a/README.md +++ b/README.md @@ -42,8 +42,18 @@ import {AreaChart, BarChart, PieChart, ScatterPlot, LineChart} from "d3reactor" And you're good to go! +Stacked Bar Chart -Stacked Bar Chart +# Documentation + +For detailed information, please follow the links below: + +* [d3reactor](https://www.d3reactor.com/) +* [Area Chart](https://www.docs.d3reactor.com/docs/Charts/area-chart) +* [Bar Chart](https://www.docs.d3reactor.com/docs/Charts/bar-chart) +* [Line Chart](https://www.docs.d3reactor.com/docs/Charts/line-chart) +* [Pie Chart](https://www.docs.d3reactor.com/docs/Charts/pie-chart) +* [Scatter Plot](https://www.docs.d3reactor.com/docs/Charts/scatter-plot) diff --git a/package.json b/package.json index 7ad4aef..2d358a9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@oslabs-beta/d3reactor", - "version": "0.0.12", + "version": "0.0.13", "description": "Open-source charting library for creating performant, responsive data visualizations in React", "keywords": ["d3", "react", "chart", "graph", "svg", "visualization", "data visualization"], "main": "./dist/index.js", diff --git a/src/App.tsx b/src/App.tsx index 65b58ab..166ebcc 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,23 +1,38 @@ -import React from 'react'; +import React, {useState, useEffect } from 'react'; + import BarChart from './charts/BarChart/BarChart'; import AreaChart from './charts/AreaChart/AreaChart'; import LineChart from './charts/LineChart/LineChart'; import ScatterPlot from './charts/ScatterPlot/ScatterPlot'; import PieChart from './charts/PieChart/PieChart'; +import { Container } from './styles/componentStyles'; import portfolio from '../data/portfolio.json'; import penguins from '../data/penguins.json'; import fruit from '../data/fruit.json'; +import unemployment from '../data/unemployment.json' import skinny_fruit from '../data/skinny_fruit.json'; -import { Container } from './styles/componentStyles'; function App() { + const [pie, setPie] = useState(fruit.sort((a, b) => a.value - b.value).slice(2)) + const [bar, setBar] = useState(skinny_fruit.reverse().slice(2)) + const [area, setArea] = useState(portfolio.slice(30, 60)) + const [line, setLine] = useState(unemployment.slice(0, 60)) + const [scatter, setScatter] = useState(penguins.slice(30, 60)) + + useEffect(() => { + setTimeout(() => {setPie(fruit.sort((a, b) => a.value - b.value))}, 1000); + setTimeout(() => {setBar(skinny_fruit.reverse())}, 2000); + setTimeout(() => {setArea(portfolio.slice(0, 60))}, 4000); + setTimeout(() => {setLine(unemployment)}, 6000); + setTimeout(() => {setScatter(penguins)}, 8000); + }, []) return ( a.value - b.value)} + data={pie} label="label" value="value" outerRadius={400} @@ -27,7 +42,7 @@ function App() { theme="light" height="100%" width="100%" - data={skinny_fruit.reverse()} + data={bar} xKey="date" yKey="value" groupBy="fruit" @@ -43,7 +58,7 @@ function App() { theme="dark" height="100%" width="100%" - data={portfolio.slice(30, 60)} + data={area} xKey="date" yKey="value" xAxis="bottom" @@ -56,10 +71,11 @@ function App() { theme="light" height={'100%'} width={'100%'} - data={portfolio} + data={line} xKey="date" xDataType="date" - yKey="value" + groupBy='division' + yKey="unemployment" xAxis="bottom" yAxis="left" yGrid={true} @@ -72,7 +88,8 @@ function App() { theme="light" height="100%" width="100%" - data={penguins} + data={scatter} + groupBy={'species'} xKey="flipper_length_mm" xDataType="number" xGrid={true} @@ -82,6 +99,8 @@ function App() { yGrid={true} yAxis="right" yAxisLabel="Body Mass" + legend={'right'} + /> ); diff --git a/src/charts/AreaChart/AreaChart.tsx b/src/charts/AreaChart/AreaChart.tsx index 539e35f..26064b7 100644 --- a/src/charts/AreaChart/AreaChart.tsx +++ b/src/charts/AreaChart/AreaChart.tsx @@ -28,8 +28,6 @@ import { } from '../../utils'; import styled, { ThemeProvider } from 'styled-components'; -const { light, dark } = themes; - const Area = styled.path` fill-opacity: 0.7; `; @@ -88,7 +86,7 @@ export default function AreaChart({ const groupAccessor = (d: Data) => d[groupBy ?? '']; const groups = d3.group(data, groupAccessor); return groupBy ? Array.from(groups).map((group) => group[0]) : [yKey]; - }, [groupBy, yKey]); + }, [groupBy, yKey, data]); const transData = useMemo(() => { return groupBy diff --git a/src/charts/BarChart/BarChart.tsx b/src/charts/BarChart/BarChart.tsx index 75d2750..13539f2 100644 --- a/src/charts/BarChart/BarChart.tsx +++ b/src/charts/BarChart/BarChart.tsx @@ -24,9 +24,8 @@ import { } from '../../utils'; import { yScaleDef } from '../../functionality/yScale'; import { Label } from '../../components/Label'; -import styled, { ThemeProvider } from 'styled-components'; +import{ ThemeProvider } from 'styled-components'; -const { light, dark } = themes; export default function BarChart({ theme = 'light', @@ -75,7 +74,7 @@ export default function BarChart({ const groupAccessor = (d: Data) => d[groupBy ?? '']; const groups = d3.group(data, groupAccessor); return groupBy ? Array.from(groups).map((group) => group[0]) : [yKey]; - }, [groupBy, yKey]); + }, [groupBy, yKey, data]); const transData = useMemo(() => { return groupBy diff --git a/src/charts/LineChart/LineChart.tsx b/src/charts/LineChart/LineChart.tsx index 4593cec..7927ec9 100644 --- a/src/charts/LineChart/LineChart.tsx +++ b/src/charts/LineChart/LineChart.tsx @@ -23,9 +23,8 @@ import { d3Voronoi } from '../../functionality/voronoi'; import { Label } from '../../components/Label'; import Tooltip from '../../components/Tooltip'; -import styled, { ThemeProvider } from 'styled-components'; +import { ThemeProvider } from 'styled-components'; -const { light, dark } = themes; export default function LineChart({ theme = 'light', @@ -203,8 +202,6 @@ export default function LineChart({ margin ); }, [data, xScale, yScale, xAccessor, yAccessor, cHeight, cWidth, margin]); - - console.log('KEYS ', keys); return (
diff --git a/src/charts/PieChart/PieChart.tsx b/src/charts/PieChart/PieChart.tsx index a91b8b2..c84dba8 100644 --- a/src/charts/PieChart/PieChart.tsx +++ b/src/charts/PieChart/PieChart.tsx @@ -25,8 +25,6 @@ const PieLabel = styled.text` pointer-events: none; `; -const { light, dark } = themes; - export default function PieChart({ theme = 'light', data, @@ -60,7 +58,7 @@ export default function PieChart({ const groupAccessor = (d: Data) => d[label ?? '']; const groups: d3.InternMap = d3.group(data, groupAccessor); return Array.from(groups).map((group) => group[0]); - }, [label]); + }, [label, data]); // ******************** // STEP 2. Determine chart dimensions diff --git a/src/charts/ScatterPlot/ScatterPlot.tsx b/src/charts/ScatterPlot/ScatterPlot.tsx index 6977f3d..0774336 100644 --- a/src/charts/ScatterPlot/ScatterPlot.tsx +++ b/src/charts/ScatterPlot/ScatterPlot.tsx @@ -30,8 +30,6 @@ import { Label } from '../../components/Label'; import { ThemeProvider } from 'styled-components'; -const { light, dark } = themes; - export default function ScatterPlot({ theme = 'light', data, @@ -74,7 +72,7 @@ export default function ScatterPlot({ const groupAccessor = (d: Data) => d[groupBy ?? '']; const groups = d3.group(data, groupAccessor); return groupBy ? Array.from(groups).map((group) => group[0]) : [yKey]; - }, [groupBy, yKey]); + }, [groupBy, yKey, data]); const xAccessor: xAccessorFunc = useMemo(() => { return xType === 'number' ? (d) => d[xKey] : (d) => new Date(d[xKey]); diff --git a/src/components/ColorLegend.tsx b/src/components/ColorLegend.tsx index 15075e2..1905171 100644 --- a/src/components/ColorLegend.tsx +++ b/src/components/ColorLegend.tsx @@ -151,7 +151,7 @@ export const ColorLegend = ({ return ( )} {(type === 'top' || type === 'bottom') && - horizontalTicks.map((tick) => ( + horizontalTicks.map((tick, i) => ( @@ -167,10 +167,10 @@ function Axi({ ))} {(type === 'right' || type === 'left') && - verticalTicks.map((tick) => ( + verticalTicks.map((tick, i) => ( diff --git a/src/components/DiscreteAxis.tsx b/src/components/DiscreteAxis.tsx index 1319820..c574bd9 100644 --- a/src/components/DiscreteAxis.tsx +++ b/src/components/DiscreteAxis.tsx @@ -129,7 +129,7 @@ export const DiscreteAxis = React.memo( {ticks.map((tick: any, i: number) => ( @@ -143,7 +143,7 @@ export const DiscreteAxis = React.memo( {ticks.map((tick: any, i: number) => ( diff --git a/src/components/VoronoiWrapper.tsx b/src/components/VoronoiWrapper.tsx index dc07172..bbec776 100644 --- a/src/components/VoronoiWrapper.tsx +++ b/src/components/VoronoiWrapper.tsx @@ -18,7 +18,7 @@ export const VoronoiWrapper = React.memo( {data.map((element: Data, i: number) => (