-
Notifications
You must be signed in to change notification settings - Fork 24
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
10 changed files
with
203 additions
and
0 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,25 @@ | ||
import { line } from 'd3'; | ||
|
||
// Positions in pixels | ||
const data = [ | ||
{ x: 0, y: 40 }, | ||
{ x: 50, y: 70 }, | ||
{ x: 100, y: 150 }, | ||
{ x: 200, y: 50 }, | ||
{ x: 300, y: 250 }, | ||
]; | ||
|
||
export const Graph = () => { | ||
// Use the line() function of d3 to create a path generator that expects data as input | ||
const lineGenerator = ''; | ||
|
||
// Use the lineGenerator function above to build the path string | ||
const path = ''; | ||
|
||
return ( | ||
<svg width={500} height={300} style={{ overflow: 'visible' }}> | ||
{/* The path built above is used here for the d argument */} | ||
<path d={path} fill="none" stroke="#69b3a2" /> | ||
</svg> | ||
); | ||
}; |
24 changes: 24 additions & 0 deletions
24
viz/exercise/d3AreaFunctionPractice/d3LineFunctionBasicSolution/Graph.tsx
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,24 @@ | ||
import { line } from 'd3'; | ||
|
||
// Positions in pixels | ||
const data = [ | ||
{ x: 0, y: 40 }, | ||
{ x: 50, y: 70 }, | ||
{ x: 100, y: 150 }, | ||
{ x: 200, y: 50 }, | ||
{ x: 300, y: 250 }, | ||
]; | ||
|
||
export const Graph = () => { | ||
const lineGenerator = line() | ||
.x((d) => d.x) | ||
.y((d) => d.y); | ||
|
||
const path = lineGenerator(data); | ||
|
||
return ( | ||
<svg width={500} height={300} style={{ overflow: 'visible' }}> | ||
<path d={path} fill="none" stroke="#69b3a2" /> | ||
</svg> | ||
); | ||
}; |
6 changes: 6 additions & 0 deletions
6
viz/exercise/d3AreaFunctionPractice/d3LineFunctionBasicSolution/index.js
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); |
29 changes: 29 additions & 0 deletions
29
viz/exercise/d3AreaFunctionPractice/d3LineFunctionBasicSolution/package.json
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,29 @@ | ||
{ | ||
"name": "pie-chart-basic", | ||
"version": "1.0.0", | ||
"description": "", | ||
"keywords": [], | ||
"main": "index.js", | ||
"dependencies": { | ||
"react": "17.0.2", | ||
"d3": "7.1.1", | ||
"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,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,29 @@ | ||
{ | ||
"name": "pie-chart-basic", | ||
"version": "1.0.0", | ||
"description": "", | ||
"keywords": [], | ||
"main": "index.js", | ||
"dependencies": { | ||
"react": "17.0.2", | ||
"d3": "7.1.1", | ||
"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,25 @@ | ||
import { area } from 'd3'; | ||
|
||
// Positions in pixels | ||
const data = [ | ||
{ x: 0, y: 40 }, | ||
{ x: 50, y: 70 }, | ||
{ x: 100, y: 150 }, | ||
{ x: 200, y: 50 }, | ||
{ x: 300, y: 250 }, | ||
]; | ||
|
||
export const Graph = () => { | ||
const areaGenerator = area() | ||
.x((d) => d.x) | ||
.y0((d) => 300) // y0 is the Y coordinate of the BOTTOM of the area. 300 is the very bottom! | ||
.y1((d) => d.y); // y1 is the top | ||
|
||
const path = areaGenerator(data); | ||
|
||
return ( | ||
<svg width={500} height={300} style={{ overflow: 'visible' }}> | ||
<path d={path} fill="grey" stroke="#69b3a2" /> | ||
</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,29 @@ | ||
{ | ||
"name": "pie-chart-basic", | ||
"version": "1.0.0", | ||
"description": "", | ||
"keywords": [], | ||
"main": "index.js", | ||
"dependencies": { | ||
"react": "17.0.2", | ||
"d3": "7.1.1", | ||
"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" | ||
] | ||
} |