-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
186 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { scaleBand, scaleLinear, scaleOrdinal } from 'd3'; | ||
|
||
const width = 500; | ||
const height = 300; | ||
|
||
const data = [ | ||
{ | ||
name: 'kevin', | ||
group: 'A', | ||
value: 25, | ||
}, | ||
{ | ||
name: 'alan', | ||
group: 'A', | ||
value: 15, | ||
}, | ||
{ | ||
name: 'camille', | ||
group: 'B', | ||
value: 8, | ||
}, | ||
{ | ||
name: 'toto', | ||
group: 'B', | ||
value: 6, | ||
}, | ||
]; | ||
|
||
export const Graph12 = () => { | ||
const xScale = ''; | ||
|
||
const yScale = ''; | ||
|
||
const colorScale = ''; | ||
|
||
return ( | ||
<svg width={500} height={300}> | ||
{data.map((d, i) => { | ||
return null; // TODO | ||
})} | ||
</svg> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// File used to render something in codesandbox only | ||
import ReactDOM from 'react-dom'; | ||
import { Graph } from './Graph'; | ||
|
||
const rootElement = document.getElementById('root'); | ||
ReactDOM.render(<Graph />, rootElement); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "pie-chart-basic", | ||
"version": "1.0.0", | ||
"description": "", | ||
"keywords": [], | ||
"main": "index.js", | ||
"dependencies": { | ||
"react": "17.0.2", | ||
"react-dom": "17.0.2", | ||
"react-scripts": "4.0.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/runtime": "7.13.8", | ||
"typescript": "4.1.3" | ||
}, | ||
"scripts": { | ||
"start": "react-scripts start", | ||
"build": "react-scripts build", | ||
"test": "react-scripts test --env=jsdom", | ||
"eject": "react-scripts eject" | ||
}, | ||
"browserslist": [ | ||
">0.2%", | ||
"not dead", | ||
"not ie <= 11", | ||
"not op_mini all" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { scaleBand, scaleLinear, scaleOrdinal } from 'd3'; | ||
|
||
const width = 500; | ||
const height = 300; | ||
|
||
const data = [ | ||
{ | ||
name: 'kevin', | ||
group: 'A', | ||
value: 25, | ||
}, | ||
{ | ||
name: 'alan', | ||
group: 'A', | ||
value: 15, | ||
}, | ||
{ | ||
name: 'camille', | ||
group: 'B', | ||
value: 8, | ||
}, | ||
{ | ||
name: 'toto', | ||
group: 'B', | ||
value: 6, | ||
}, | ||
]; | ||
|
||
export const Graph12 = () => { | ||
const xScale = scaleLinear().domain([0, 100]).range([0, width]); | ||
|
||
const yScale = scaleBand() | ||
.domain(['kevin', 'alan', 'camille', 'toto']) | ||
.range([0, height]) | ||
.padding(0.1); | ||
|
||
const colorScale = scaleOrdinal() | ||
.domain(['A', 'B']) | ||
.range(['orange', 'blue']); | ||
|
||
return ( | ||
<svg width={500} height={300}> | ||
{data.map((d, i) => { | ||
return ( | ||
<rect | ||
key={i} | ||
x={xScale(0)} | ||
y={yScale(d.name)} | ||
height={yScale.bandwidth()} | ||
width={xScale(d.value)} | ||
fill={colorScale(d.group)} | ||
/> | ||
); | ||
})} | ||
</svg> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// File used to render something in codesandbox only | ||
import ReactDOM from 'react-dom'; | ||
import { Graph } from './Graph'; | ||
|
||
const rootElement = document.getElementById('root'); | ||
ReactDOM.render(<Graph />, rootElement); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "pie-chart-basic", | ||
"version": "1.0.0", | ||
"description": "", | ||
"keywords": [], | ||
"main": "index.js", | ||
"dependencies": { | ||
"react": "17.0.2", | ||
"react-dom": "17.0.2", | ||
"react-scripts": "4.0.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/runtime": "7.13.8", | ||
"typescript": "4.1.3" | ||
}, | ||
"scripts": { | ||
"start": "react-scripts start", | ||
"build": "react-scripts build", | ||
"test": "react-scripts test --env=jsdom", | ||
"eject": "react-scripts eject" | ||
}, | ||
"browserslist": [ | ||
">0.2%", | ||
"not dead", | ||
"not ie <= 11", | ||
"not op_mini all" | ||
] | ||
} |