Skip to content

Commit

Permalink
Merge pull request #104 from oslabs-beta/dev
Browse files Browse the repository at this point in the history
HotFix
  • Loading branch information
hi2dmitri authored Feb 8, 2022
2 parents 439a11e + e2c5061 commit 2de6cca
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 34 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,18 @@ import {AreaChart, BarChart, PieChart, ScatterPlot, LineChart} from "d3reactor"

And you're good to go!

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

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

# 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)


2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
35 changes: 27 additions & 8 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<Container className="app">
<PieChart
theme="dark"
data={fruit.sort((a, b) => a.value - b.value)}
data={pie}
label="label"
value="value"
outerRadius={400}
Expand All @@ -27,7 +42,7 @@ function App() {
theme="light"
height="100%"
width="100%"
data={skinny_fruit.reverse()}
data={bar}
xKey="date"
yKey="value"
groupBy="fruit"
Expand All @@ -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"
Expand All @@ -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}
Expand All @@ -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}
Expand All @@ -82,6 +99,8 @@ function App() {
yGrid={true}
yAxis="right"
yAxisLabel="Body Mass"
legend={'right'}

/>
</Container>
);
Expand Down
4 changes: 1 addition & 3 deletions src/charts/AreaChart/AreaChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
`;
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions src/charts/BarChart/BarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions src/charts/LineChart/LineChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -203,8 +202,6 @@ export default function LineChart({
margin
);
}, [data, xScale, yScale, xAccessor, yAccessor, cHeight, cWidth, margin]);

console.log('KEYS ', keys);
return (
<ThemeProvider theme={themes[theme]}>
<div ref={anchor} style={{ width: width, height: height }}>
Expand Down
4 changes: 1 addition & 3 deletions src/charts/PieChart/PieChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ const PieLabel = styled.text`
pointer-events: none;
`;

const { light, dark } = themes;

export default function PieChart({
theme = 'light',
data,
Expand Down Expand Up @@ -60,7 +58,7 @@ export default function PieChart({
const groupAccessor = (d: Data) => d[label ?? ''];
const groups: d3.InternMap<any, any[]> = d3.group(data, groupAccessor);
return Array.from(groups).map((group) => group[0]);
}, [label]);
}, [label, data]);

// ********************
// STEP 2. Determine chart dimensions
Expand Down
4 changes: 1 addition & 3 deletions src/charts/ScatterPlot/ScatterPlot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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]);
Expand Down
2 changes: 1 addition & 1 deletion src/components/ColorLegend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export const ColorLegend = ({
return (
<g
className="tick"
key={domainValue}
key={i}
transform={`translate(
${EXTRA_LEGEND_MARGIN + circleRadius},
${
Expand Down
8 changes: 4 additions & 4 deletions src/components/ContinuousAxis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,21 +156,21 @@ function Axi({
/>
)}
{(type === 'top' || type === 'bottom') &&
horizontalTicks.map((tick) => (
horizontalTicks.map((tick, i) => (
<TickText
data-testid="d3reactor-ticktext"
key={JSON.stringify(tick)}
key={i}
style={getTickStyle(type)}
transform={getTickTranslation(type, tick)}
>
{getFormattedTick(tick)}
</TickText>
))}
{(type === 'right' || type === 'left') &&
verticalTicks.map((tick) => (
verticalTicks.map((tick, i) => (
<TickText
data-testid="d3reactor-ticktext"
key={JSON.stringify(tick)}
key={i}
style={getTickStyle(type)}
transform={getTickTranslation(type, tick)}
>
Expand Down
4 changes: 2 additions & 2 deletions src/components/DiscreteAxis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export const DiscreteAxis = React.memo(
{ticks.map((tick: any, i: number) => (
<TickText
data-testid="d3reactor-ticktext"
key={JSON.stringify(tick)}
key={i}
style={getTickStyle(type, tick)}
transform={getTickTranslation(type, tick, i)}
>
Expand All @@ -143,7 +143,7 @@ export const DiscreteAxis = React.memo(
{ticks.map((tick: any, i: number) => (
<TickText
data-testid="d3reactor-ticktext"
key={JSON.stringify(tick.slice(0, 10))}
key={i}
style={getTickStyle(type, tick.slice(0, 10))}
transform={getTickTranslation(type, tick.slice(0, 10), i)}
>
Expand Down
2 changes: 1 addition & 1 deletion src/components/VoronoiWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const VoronoiWrapper = React.memo(
<g className="voronoi-wrapper">
{data.map((element: Data, i: number) => (
<VoronoiCell
key={JSON.stringify(element)}
key={i}
fill="none"
stroke="none"
opacity={0.5}
Expand Down

0 comments on commit 2de6cca

Please sign in to comment.