-
Notifications
You must be signed in to change notification settings - Fork 652
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
8 changed files
with
132 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "f2x-react", | ||
"version": "0.0.1", | ||
"main": "lib/index.js", | ||
"module": "es/index.js", | ||
"dependencies": { | ||
"@antv/f2": "^3.8.1" | ||
}, | ||
"devDependencies": { | ||
"react": "^17.0.1", | ||
"react-dom": "^17.0.1" | ||
}, | ||
"files": [ | ||
"src", | ||
"dist" | ||
], | ||
"author": "yezengyue@gmail.com" | ||
} |
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,12 @@ | ||
/** @jsxImportSource react */ | ||
|
||
import { useRef } from 'react'; | ||
import useModel from './model'; | ||
|
||
export default props => { | ||
const { pixelRatio, data, children } = props; | ||
const canvasRef = useRef(null); | ||
useModel({ canvasRef, data, pixelRatio, children }); | ||
|
||
return (<canvas className="chart-canvas" ref={ canvasRef } />); | ||
} |
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,33 @@ | ||
import { useEffect, useState, Children } from 'react'; | ||
import F2 from '@antv/f2'; | ||
|
||
export default ({ canvasRef, pixelRatio, data, children }) => { | ||
// const [chart, setChart] = useState(); | ||
|
||
useEffect(() => { | ||
const canvasEl = canvasRef.current; | ||
const context = canvasEl.getContext('2d'); | ||
const chart = new F2.Chart({ | ||
context, | ||
pixelRatio: pixelRatio || 1, | ||
}); | ||
|
||
chart.source(data); | ||
|
||
Children.map(children, child => { | ||
const { type, props } = child; | ||
return type({ | ||
...props, | ||
chart, | ||
}); | ||
}); | ||
|
||
// const frontPlot = chart.get('frontPlot'); | ||
|
||
chart.render(); | ||
return; | ||
}, []); | ||
|
||
return { | ||
} | ||
} |
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,5 @@ | ||
.chart-canvas { | ||
vertical-align: top; | ||
width: 100%; | ||
height: 100%; | ||
} |
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,15 @@ | ||
|
||
export default (props) => { | ||
const { chart, position } = props; | ||
const geom = chart.interval(); | ||
geom.position(position); | ||
console.log('interval props:', props); | ||
return null; | ||
} | ||
|
||
// export default class Interval { | ||
// render() { | ||
// return null; | ||
// } | ||
// } | ||
|
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,42 @@ | ||
/** @jsxImportSource react */ | ||
|
||
import ReactDOM from 'react-dom'; | ||
import Chart from '../src/chart'; | ||
import Interval from '../src/interval'; | ||
|
||
const style = document.createElement('style'); | ||
style.setAttribute('rel', 'text/css'); | ||
style.innerHTML = ` | ||
.chart-canvas { | ||
vertical-align: top; | ||
width: 100%; | ||
height: 100%; | ||
} | ||
`; | ||
document.head.appendChild(style); | ||
|
||
const root = document.createElement('div'); | ||
document.body.appendChild(root); | ||
|
||
|
||
const data = [ | ||
{ genre: 'Sports', sold: 275 }, | ||
{ genre: 'Strategy', sold: 115 }, | ||
{ genre: 'Action', sold: 120 }, | ||
{ genre: 'Shooter', sold: 350 }, | ||
{ genre: 'Other', sold: 150 } | ||
]; | ||
|
||
const App = () => { | ||
return ( | ||
<Chart | ||
pixelRatio={ window.devicePixelRatio } | ||
data={ data } | ||
> | ||
<Interval position="genre*sold" /> | ||
</Chart> | ||
); | ||
} | ||
|
||
ReactDOM.render(<App />, root); | ||
|
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 @@ | ||
{ | ||
"compilerOptions": { | ||
"jsx": "react" | ||
}, | ||
"extends": "../../tsconfig.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 @@ | ||
import '../../typings'; |