@@ -178,35 +178,98 @@ function getColorClass(value) {
178178fetch ( 'data/prov.json' )
179179 . then ( response => response . json ( ) )
180180 . then ( provData => {
181- const container = document . getElementById ( "provinceTable" ) ;
182- const months = [ "Jan" , "Feb" , "Mar" , "Apr" , "May" , "Jun" , "Jul" , "Aug" ] ;
183- const monthKeys = [ "1" , "2" , "3" , "4" , "5" , "6" , "7" , "8" ] ;
184-
185- // Define breakpoints for 5 classes (green = high positive, red = low negative)
186-
181+ const ctx = document . getElementById ( "provinceChart" ) . getContext ( "2d" ) ;
182+ const months = [ "Jan" , "Feb" , "Mar" , "Apr" , "May" , "Jun" , "Jul" , "Aug" ] ;
183+ const monthKeys = [ "1" , "2" , "3" , "4" , "5" , "6" , "7" , "8" ] ;
187184
188185 // Sort province names alphabetically
189186 const sortedProvinces = Object . keys ( provData ) . sort ( ) ;
190187
191- // Build HTML table
192- let html = '<table><thead><tr><th class="table-head" style="width:220px">Province of Departure</th>' ;
193- months . forEach ( m => html += `<th class="table-head">${ m } </th>` ) ;
194- html += '</tr></thead><tbody>' ;
195-
196- sortedProvinces . forEach ( prov => {
197- html += `<tr><td class="table-cell" style="cursor:pointer;color:#32a6c3;text-align:left;" onclick="loadprov(\'${ prov } \')");">${ prov } </td>` ;
198- monthKeys . forEach ( k => {
199- const val = provData [ prov ] [ k ] ;
200- const cls = getColorClass ( val ) ;
201- html += `<td class="table-cell ${ cls } ">${ val . toFixed ( 1 ) } %</td>` ;
202- } ) ;
203- html += '</tr>' ;
204- } ) ;
188+ // Define a color palette
189+ const colors = [
190+ "#1b9e77" , "#d95f02" , "#7570b3" , "#e7298a" ,
191+ "#66a61e" , "#e6ab02" , "#a6761d" , "#666666" ,
192+ "#386cb0" , "#f0027f" , "#bf5b17" , "#999999"
193+ ] ;
205194
206- html += '</tbody></table>' ;
207- container . innerHTML = html ;
195+ // Build one dataset per province
196+ const datasets = sortedProvinces . map ( ( prov , i ) => ( {
197+ label : prov ,
198+ data : monthKeys . map ( k => provData [ prov ] [ k ] ) ,
199+ borderColor : colors [ i % colors . length ] ,
200+ borderWidth : 2 ,
201+ fill : false ,
202+ tension : 0.3
203+ } ) ) ;
204+
205+ // Create the line chart
206+ new Chart ( ctx , {
207+ type : 'line' ,
208+ data : {
209+ labels : months ,
210+ datasets : datasets
211+ } ,
212+ options : {
213+ responsive : false ,
214+ plugins : {
215+ title : {
216+ display : false
217+ } ,
218+ legend : {
219+ position : 'bottom' ,
220+ labels : {
221+ boxWidth : 12 ,
222+ usePointStyle : true
223+ } ,
224+ onClick : ( evt , legendItem , legend ) => {
225+ const prov = legendItem . text ; // dataset label = province name
226+ // If you hold Alt/Option (or Ctrl/Cmd), also toggle visibility like default behavior
227+ const toggleLikeDefault = evt . altKey || evt . ctrlKey || evt . metaKey || evt . shiftKey ;
228+
229+ // Open the province details overlay
230+ if ( typeof loadprov === 'function' ) {
231+ loadprov ( prov ) ; // uses your existing function to build & show the modal:contentReference[oaicite:3]{index=3}
232+ }
233+
234+ // Optional: also toggle visibility when a modifier key is held
235+ if ( toggleLikeDefault ) {
236+ const ci = legend . chart ;
237+ const index = legendItem . datasetIndex ;
238+ ci . toggleDataVisibility ( index ) ;
239+ ci . update ( ) ;
240+ }
241+ }
242+ } ,
243+ tooltip : {
244+ callbacks : {
245+ label : context => `${ context . dataset . label } : ${ context . parsed . y . toFixed ( 1 ) } %`
246+ }
247+ }
248+ } ,
249+ scales : {
250+ x : {
251+ title : {
252+ display : true ,
253+ text : 'Month'
254+ }
255+ } ,
256+ y : {
257+ title : {
258+ display : true ,
259+ text : '% Change'
260+ } ,
261+ beginAtZero : false
262+ }
263+ } ,
264+ animation : {
265+ duration : 1000 ,
266+ easing : 'easeOutQuart'
267+ }
268+ }
269+ } ) ;
208270 } ) ;
209271
272+
210273 var ports_provs = [ ] ;
211274 fetch ( 'data/ports.geojson' )
212275 . then ( response => response . json ( ) )
0 commit comments