@@ -6,7 +6,7 @@ import { faXmark, faRotateLeft, faCircleInfo } from '@fortawesome/free-solid-svg
66import { LoadingSpinner } from '../loading' ;
77import { fetchAllFromFeaturesAPI } from "../../services/api" ;
88
9- import { plugin , options } from './config' ;
9+ import { plugin , options , noDataPlugin } from './config' ;
1010import { dataPreprocess , getYAxisLabel , getChangedGHGStationId , getStationCode , isChartZoomed } from "./helper" ;
1111import './index.css' ;
1212
@@ -23,6 +23,7 @@ export class ConcentrationChart extends Component {
2323 showChartInstructions : true ,
2424 chartDataIsLoading : false ,
2525 dataAccessLink : "" ,
26+ noData : false ,
2627 } ;
2728 this . dataPreprocess = dataPreprocess ;
2829 this . getYAxisLabel = getYAxisLabel ;
@@ -72,8 +73,14 @@ export class ConcentrationChart extends Component {
7273 this . chart = new Chart ( this . chartCanvas , {
7374 type : 'line' ,
7475 data : dataset ,
75- options : options ,
76- plugins : [ plugin ]
76+ options : {
77+ ...options ,
78+ plugins : {
79+ ...options . plugins ,
80+ noDataMessage : { enabled : this . state . noData } ,
81+ } ,
82+ } ,
83+ plugins : [ plugin , noDataPlugin ] ,
7784 } ) ;
7885
7986 this . chart . options . scales . y . title . text = dataPointLabel ;
@@ -86,7 +93,7 @@ export class ConcentrationChart extends Component {
8693 }
8794
8895 this . prepareChart ( ) ;
89- }
96+ } ;
9097
9198 prepareChart = ( ) => {
9299 let currentStationId = this . getChangedGHGStationId ( this . props . selectedStationId , this . props . ghg ) ;
@@ -97,19 +104,23 @@ export class ConcentrationChart extends Component {
97104 this . fetchStationData ( currentStationId ) . then ( data => {
98105 const { time, concentration } = data ;
99106 // Post data fetch, check if the chart title needs to be modified (for race conditions when multiple stations are clicked).
100- this . changeTitle ( currentStationId ) ;
101- this . updateChart ( concentration , time ) ;
102- this . setInitialScaleLimits ( ) ;
107+ const noData = ! time . length ;
108+ this . setState ( { noData } , ( ) => {
109+ this . changeTitle ( currentStationId ) ;
110+ this . updateChart ( concentration , time , noData ) ;
111+ } ) ;
112+ if ( ! noData ) this . setInitialScaleLimits ( ) ;
103113 } ) ;
104- }
114+ } ;
105115
106- updateChart = ( data , label ) => {
116+ updateChart = ( data , label , noData ) => {
107117 if ( this . chart ) {
108118 // first reset the zoom
109119 this . chart . resetZoom ( ) ;
110120 this . chart . options . plugins . tooltip . enabled = false ;
111121
112122 let labelY = this . getYAxisLabel ( this . props . ghg ) ;
123+ this . chart . options . plugins . noDataMessage . enabled = noData ;
113124 this . chart . data . datasets [ 0 ] . label = labelY ;
114125 this . chart . options . scales . y . title . text = labelY ;
115126
@@ -188,28 +199,28 @@ export class ConcentrationChart extends Component {
188199 return (
189200 < Box id = "chart-box" style = { this . props . style } >
190201 < div id = "chart-container" style = { { width : "100%" , height :"100%" } } >
191- < div id = "chart-tools" >
192- < div id = "chart-tools-left" >
193- < div id = "chart-instructions-container" >
194- < div className = "icon-and-instructions" >
195- < FontAwesomeIcon
196- icon = { faCircleInfo }
197- // style={{margin: "12px"}}
202+ < div id = "chart-tools" >
203+ < div id = "chart-tools-left" >
204+ < div id = "chart-instructions-container" >
205+ < div className = "icon-and-instructions" >
206+ < FontAwesomeIcon
207+ icon = { faCircleInfo }
208+ // style={{margin: "12px"}}
198209 onMouseEnter = { ( ) => this . setState ( { showChartInstructions : true } ) }
199210 onMouseLeave = { ( ) => this . setState ( { showChartInstructions : false } ) }
200- />
211+ />
201212 { this . state . showChartInstructions && < div id = "chart-instructions" >
202213 < p > 1. Click and drag, scroll or pinch on the chart to zoom in.</ p >
203214 < p > 2. Hover over data points when zoomed in to see the values.</ p >
204215 < p > 3. Click on the rectangle boxes on the side to toggle chart.</ p >
205216 </ div >
206217 }
207- </ div >
208218 </ div >
209219 </ div >
210- < div id = "chart-tools-right" >
220+ </ div >
221+ < div id = "chart-tools-right" >
211222 { this . state . dataAccessLink && < a id = "data-access-link" href = { this . state . dataAccessLink } target = "_blank" rel = 'noreferrer' > Data Access Link ↗</ a > }
212- < div id = "chart-controls" >
223+ < div id = "chart-controls" >
213224 < FontAwesomeIcon id = "zoom-reset-button" icon = { faRotateLeft } title = "Reset Zoom" onClick = { this . handleRefresh } />
214225 < FontAwesomeIcon id = "chart-close-button" icon = { faXmark } title = "Close" onClick = { this . handleClose } />
215226 </ div >
@@ -218,13 +229,13 @@ export class ConcentrationChart extends Component {
218229 {
219230 this . state . chartDataIsLoading && < LoadingSpinner />
220231 }
221- < canvas
232+ < canvas
222233 id = "chart"
223234 className = 'fullWidth'
224235 style = { { width : "100%" , height : "100%" } }
225236 ref = { chartCanvas => ( this . chartCanvas = chartCanvas ) }
226- />
227- </ div >
237+ />
238+ </ div >
228239 </ Box >
229240 ) ;
230241 }
0 commit comments