This repository was archived by the owner on Jan 23, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +578
-531
lines changed Expand file tree Collapse file tree 5 files changed +578
-531
lines changed Original file line number Diff line number Diff line change 11# Changelog
22## Entries
33
4+ ## v1.0.4
5+
6+ - Validate legend colors
7+
8+
49## v1.0.3
510
611- Release for Grafana 6+ support
Original file line number Diff line number Diff line change 3131 "@types/jest" : " 27.0.2" ,
3232 "@types/lodash" : " ^4.14.194" ,
3333 "@types/moment" : " ^2.13.0" ,
34+ "@types/tinycolor2" : " 1.4.3" ,
35+ "tinycolor2" : " 1.6.0" ,
3436 "jest" : " 26.6.3" ,
3537 "jest-canvas-mock" : " 2.3.0" ,
3638 "jest-config" : " ^27.5.1" ,
Original file line number Diff line number Diff line change 11/**
22 * @jest -environment jsdom
33 */
4- import WorldMap from './worldmap' ;
4+ import WorldMap , { DEFAULT_COLOR } from './worldmap' ;
55import DataBuilder from './test/data_builder' ;
66import * as _ from 'lodash' ;
77
@@ -308,7 +308,7 @@ describe('Worldmap', () => {
308308 '<div class="info legend leaflet-control"><div class="legend-item">' +
309309 '<i style="background:red"></i> < 2</div><div class="legend-item"><i style="background:blue"></i> 2–4</div>' +
310310 '<div class="legend-item"><i style="background:green"></i> 4–6</div>' +
311- ' <div class="legend-item"><i style="background:undefined "></i> 6+</div></div>'
311+ ` <div class="legend-item"><i style="background:${ DEFAULT_COLOR } "></i> 6+</div></div>`
312312 ) ;
313313 } ) ;
314314 } ) ;
Original file line number Diff line number Diff line change 11import * as _ from 'lodash' ;
22import * as L from './libs/leaflet' ;
33import WorldmapCtrl from './worldmap_ctrl' ;
4+ import tinycolor from 'tinycolor2' ;
45
56const tileServers = {
67 'CartoDB Positron' : {
@@ -69,15 +70,15 @@ export default class WorldMap {
6970 let legendHtml = '' ;
7071 legendHtml +=
7172 '<div class="legend-item"><i style="background:' +
72- this . ctrl . panel . colors [ 0 ] +
73+ getColor ( this . ctrl . panel . colors [ 0 ] ) +
7374 '"></i> ' +
7475 '< ' +
7576 thresholds [ 0 ] +
7677 '</div>' ;
7778 for ( let index = 0 ; index < thresholds . length ; index += 1 ) {
7879 legendHtml +=
7980 '<div class="legend-item"><i style="background:' +
80- this . ctrl . panel . colors [ index + 1 ] +
81+ getColor ( this . ctrl . panel . colors [ index + 1 ] ) +
8182 '"></i> ' +
8283 thresholds [ index ] +
8384 ( thresholds [ index + 1 ] ? '–' + thresholds [ index + 1 ] + '</div>' : '+' ) ;
@@ -264,3 +265,11 @@ export default class WorldMap {
264265 this . map . remove ( ) ;
265266 }
266267}
268+
269+ export const DEFAULT_COLOR = '#CCC' ;
270+ function getColor ( c : string ) : string {
271+ if ( tinycolor ( c ) . isValid ( ) ) {
272+ return c ;
273+ }
274+ return DEFAULT_COLOR ;
275+ }
You can’t perform that action at this time.
0 commit comments