This repository has been archived by the owner on Nov 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from bharatari/dev
v1.3.1
- Loading branch information
Showing
7 changed files
with
37 additions
and
67 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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,32 +1,28 @@ | ||
import React from 'react'; | ||
import React, { useEffect, useRef } from 'react'; | ||
import Chart from 'chart.js'; | ||
|
||
export default class Graph extends React.Component { | ||
componentDidMount() { | ||
this.initializeChart(this.props); | ||
} | ||
componentWillUnmount() { | ||
this.destroyChart(); | ||
} | ||
getChart = () => { | ||
return this.chart; | ||
}; | ||
destroyChart = () => { | ||
this.chart && this.chart.destroy(); | ||
}; | ||
initializeChart = (props) => { | ||
const { data, options, type } = props; | ||
const ctx = this.refs['canvas'].getContext('2d'); | ||
export default function Graph({ type, data, options }) { | ||
const ref = useRef(); | ||
const chartInstanceRef = useRef(); | ||
|
||
this.chart = new Chart(ctx, { | ||
useEffect(() => { | ||
const ctx = ref.current.getContext('2d'); | ||
|
||
chartInstanceRef.current = new Chart(ctx, { | ||
type: type, | ||
data: data, | ||
options: options | ||
}); | ||
}; | ||
render() { | ||
return ( | ||
<canvas ref='canvas' /> | ||
); | ||
} | ||
|
||
return () => { | ||
chartInstanceRef | ||
&& chartInstanceRef.current | ||
&& chartInstanceRef.current.destroy(); | ||
}; | ||
}, [data]) | ||
|
||
console.log('rerender') | ||
return ( | ||
<canvas ref={ref} /> | ||
); | ||
} |
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
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
94840ec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: