feat: close chart

This commit is contained in:
ysandler 2020-08-15 12:20:12 -05:00 committed by Joshua Shoemaker
parent 2d318f270a
commit fabf001076
2 changed files with 20 additions and 6 deletions

View File

@ -0,0 +1,7 @@
.chartLabel {
text-align: center;
margin: 10px auto;
}
.saveChartAsImageButton {
}

View File

@ -3,6 +3,7 @@ import FocusChart from '../../Models/Chart/FocusChart'
import { Doughnut, Bar, Line, Pie, Polar, Radar, Scatter, Bubble } from 'react-chartjs-2' import { Doughnut, Bar, Line, Pie, Polar, Radar, Scatter, Bubble } from 'react-chartjs-2'
import { Button } from 'semantic-ui-react' import { Button } from 'semantic-ui-react'
import download from 'downloadjs' import download from 'downloadjs'
import './ChartViewer.css'
class ChartViewer extends Component { class ChartViewer extends Component {
constructor () { constructor () {
@ -17,6 +18,11 @@ class ChartViewer extends Component {
document.addEventListener('setSelectedChart', this.setFocusChart) document.addEventListener('setSelectedChart', this.setFocusChart)
} }
closeChart = () => {
this.focusChart.chart = null
this.setFocusChart()
}
handleGroupByChange = (e, value) => { handleGroupByChange = (e, value) => {
this.setState({ reportValue: value.value }) this.setState({ reportValue: value.value })
} }
@ -28,12 +34,10 @@ class ChartViewer extends Component {
setFocusChart = () => { setFocusChart = () => {
const focusChart = this.focusChart.chart const focusChart = this.focusChart.chart
if (focusChart) {
this.setState({ this.setState({
chart: focusChart chart: focusChart
}) })
} }
}
renderChart = () => { renderChart = () => {
const { chart } = this.state const { chart } = this.state
@ -50,11 +54,14 @@ class ChartViewer extends Component {
} }
render = () => { render = () => {
const chart = this.state.chart || {}
return ( return (
<div className='ChartViewer'> <div className='ChartViewer'>
<h3 className='chartLabel'>{ chart.label }</h3>
{this.renderChart()} {this.renderChart()}
<br /> <br />
{ this.state.chart ? <Button fluid onClick={this.saveChart}>Save As Image</Button> : '' } { this.state.chart ? <Button className='saveChartAsImageButton' fluid primary onClick={this.saveChart}>Save As Image</Button> : '' }
{ this.state.chart ? <Button className='closeChartButton' fluid onClick={this.closeChart}>Close Chart</Button> : '' }
</div> </div>
) )
} }