gridviz 2.1.7 → 2.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/README.md +125 -124
  2. package/dist/gridviz.js +8021 -7991
  3. package/dist/gridviz.min.js +1 -1
  4. package/package.json +77 -77
  5. package/src/App.js +705 -705
  6. package/src/BackgroundLayer.js +182 -182
  7. package/src/BackgroundLayerWMS.js +131 -131
  8. package/src/Dataset.js +76 -76
  9. package/src/DatasetComponent.js +101 -101
  10. package/src/GeoCanvas.js +420 -420
  11. package/src/LabelLayer.js +190 -190
  12. package/src/Layer.js +103 -103
  13. package/src/Legend.js +86 -86
  14. package/src/LineLayer.js +150 -150
  15. package/src/Style.js +129 -129
  16. package/src/Tooltip.js +180 -172
  17. package/src/dataset/COGeo.js +24 -24
  18. package/src/dataset/CSVGrid.js +104 -104
  19. package/src/dataset/GeoTIFF.js +127 -127
  20. package/src/dataset/GridTile.js +41 -41
  21. package/src/dataset/LGrid.js +54 -54
  22. package/src/dataset/TiledGrid.js +264 -264
  23. package/src/index.js +71 -71
  24. package/src/legend/ColorCategoryLegend.js +124 -124
  25. package/src/legend/ColorDiscreteLegend.js +103 -103
  26. package/src/legend/ColorLegend.js +124 -124
  27. package/src/legend/SegmentOrientationLegend.js +87 -87
  28. package/src/legend/SegmentWidthLegend.js +97 -97
  29. package/src/legend/SizeLegend.js +141 -141
  30. package/src/style/CompositionStyle.js +300 -300
  31. package/src/style/ContourStyle.js +54 -54
  32. package/src/style/DotDensityStyle.js +156 -156
  33. package/src/style/IsoFenceStyle.js +262 -240
  34. package/src/style/JoyPlotStyle.js +135 -135
  35. package/src/style/LegoStyle.js +112 -112
  36. package/src/style/MosaicStyle.js +107 -107
  37. package/src/style/NinjaStarStyle.js +125 -125
  38. package/src/style/PillarStyle.js +230 -230
  39. package/src/style/SegmentStyle.js +142 -142
  40. package/src/style/ShapeColorSizeStyle.js +126 -126
  41. package/src/style/SideCatStyle.js +172 -172
  42. package/src/style/SideStyle.js +216 -216
  43. package/src/style/SquareColorCatWGLStyle.js +120 -120
  44. package/src/style/SquareColorWGLStyle.js +146 -146
  45. package/src/style/StrokeStyle.js +131 -131
  46. package/src/style/TanakaStyle.js +160 -160
  47. package/src/style/TextStyle.js +132 -132
  48. package/src/style/TimeSeriesStyle.js +250 -250
  49. package/src/utils/Utils.js +35 -35
  50. package/src/utils/WebGLRectangleColoring.js +106 -106
  51. package/src/utils/WebGLSquareColoring.js +118 -118
  52. package/src/utils/WebGLSquareColoringAdvanced.js +230 -230
  53. package/src/utils/WebGLSquareColoringCatAdvanced.js +133 -133
  54. package/src/utils/WebGLSquareColoringKS.js +153 -153
  55. package/src/utils/stretching.js +131 -131
  56. package/src/utils/webGLUtils.js +71 -71
  57. package/src/utils/zoomUtils.js +142 -142
@@ -1,160 +1,160 @@
1
- //@ts-check
2
- 'use strict'
3
-
4
- import { SquareColorWGLStyle } from './SquareColorWGLStyle.js'
5
- import { SideStyle } from './SideStyle.js'
6
-
7
- /**
8
- *
9
- * @see https://manifold.net/doc/mfd9/example__tanaka_contours.htm
10
- *
11
- * @author Julien Gaffuri
12
- */
13
- export class TanakaStyle {
14
- /**
15
- * @param {string} col
16
- * @param {object} opts
17
- * @returns {Array.<import("../Style").Style>}
18
- */
19
- static get(col, opts) {
20
- opts = opts || {}
21
-
22
- //get colors from d3 ramps, if 'nb' is specified
23
- if (opts.nb != undefined) {
24
- if (opts.nb < 2) {
25
- console.error('unexpected number of colors in tanaka (<2): ' + opts.nb)
26
- opts.nb = 2
27
- }
28
- if (!opts.color) {
29
- console.error('color function not defined in tanaka')
30
- opts.color = () => 'gray'
31
- }
32
- opts.colors = []
33
- for (let i = 0; i < opts.nb; i++) opts.colors.push(opts.color(i / (opts.nb - 1)))
34
- }
35
-
36
- /**
37
- * The colors.
38
- * @type {Array.<string>} */
39
- opts.colors = opts.colors || ['#a9bb9e', '#c9dcaa', '#fde89f', '#f9a579', '#eb444b']
40
- const nb = opts.colors.length
41
-
42
- /** A function to compute 't' from the value v
43
- * @type {function(number,number,import("../Style").Stat):number} */
44
- opts.tFun = opts.tFun || ((v, r, s) => (v - s.min) / (s.max - s.min))
45
-
46
- //shadow colors
47
- opts.colDark = opts.colDark || '#111'
48
- opts.colBright = opts.colBright || '#ddd'
49
-
50
- //width of the segment (share of the resolution)
51
- opts.widthFactor = opts.widthFactor || 0.08
52
-
53
- //shading
54
- opts.newShading = opts.newShading
55
- opts.newShadingWidthPix = opts.newShadingWidthPix || 2
56
- //transparency value, within [0,1]
57
- opts.newShadingTr =
58
- opts.newShadingTr ||
59
- ((sideValue, sideStat) =>
60
- Math.abs(sideValue) / Math.max(Math.abs(sideStat.min), Math.abs(sideStat.max)))
61
-
62
- /**
63
- * @param {number} t A cell t value, within [0,1].
64
- * @returns the class number for the value
65
- */
66
- const getClass = (t) => {
67
- if (isNaN(t) || t == undefined) {
68
- console.error('Unexpected t value 1: ' + t)
69
- return -9
70
- }
71
- for (let i = 0; i < nb; i++) if (t <= (i + 1) / nb) return i
72
- console.error('Unexpected t value 2: ' + t)
73
- return -9
74
- }
75
-
76
- const colStyle = new SquareColorWGLStyle({
77
- colorCol: col,
78
- colors: opts.colors,
79
- tFun: (v, r, s) => {
80
- const t = opts.tFun(v, r, s)
81
- const c = getClass(t)
82
- return c / (nb - 1)
83
- },
84
- //stretching: { fun: "expRev", alpha: -7 },
85
- size: (r, zf) => r + 0.5 * zf, //that is to ensure no gap between same class cells is visible
86
- filter: opts.filter,
87
- })
88
-
89
- /*
90
- if no web gl:
91
- const colStyle = new ShapeColorSizeStyle({
92
- colorCol: col,
93
- //the color corresponding to the class
94
- color: (v, r, s, zf) => {
95
- if (v == 0 && opts.tFun && isNaN(opts.tFun(v, r, s)))
96
- return undefined
97
- return opts.colors[getClass(opts.tFun ? opts.tFun(v, r, s) : v)]
98
- },
99
- shape: () => "square",
100
- size: (v, r, s, zf) => r + 0.5 * zf, //that is to ensure no gap between same class cells is visible
101
- })
102
- */
103
-
104
- /** The side style, for the shadow effect */
105
- const sideStyle = new SideStyle({
106
- valueCol: col,
107
- value: (v1, v2, r, s, zf) => {
108
- //compute the number of classes of difference
109
- if (v1 === undefined && v2 === undefined) return 0
110
- else if (v2 === undefined) {
111
- const t = opts.tFun(v1, r, s)
112
- if (t == undefined || isNaN(t)) throw new Error('Unexpected value: ' + v1 + ' - ' + t)
113
- const c = getClass(t)
114
- return c + 1
115
- } else if (v1 === undefined) {
116
- const t = opts.tFun(v2, r, s)
117
- if (t == undefined || isNaN(t)) throw new Error('Unexpected value: ' + v2 + ' - ' + t)
118
- const c = getClass(t)
119
- return -c - 1
120
- }
121
- const t1 = opts.tFun(v1, r, s)
122
- if (t1 == undefined || isNaN(t1)) throw new Error('Unexpected value: ' + v1 + ' - ' + t1)
123
- const t2 = opts.tFun(v2, r, s)
124
- if (t2 == undefined || isNaN(t2)) throw new Error('Unexpected value: ' + v2 + ' - ' + t2)
125
- const c1 = getClass(t1)
126
- const c2 = getClass(t2)
127
- return -c2 + c1
128
- },
129
-
130
- color: opts.newShading
131
- ? //black with transparency depending on difference
132
- (side, r, s, z) => {
133
- const tr = opts.newShadingTr(side.value, s)
134
- return (side.value > 0 && side.or === 'h') || (side.value < 0 && side.or === 'v')
135
- ? 'rgba(255,255,100,' + tr + ')'
136
- : 'rgba(0,0,0,' + tr + ')'
137
- }
138
- : //white or black, depending on orientation and value
139
- (side, r, s, z) => {
140
- if (side.value === 0) return
141
- //return "gray"
142
- if (side.or === 'v') return side.value < 0 ? opts.colBright : opts.colDark
143
- return side.value < 0 ? opts.colDark : opts.colBright
144
- },
145
-
146
- width: opts.newShading
147
- ? //fill size
148
- (side, r, s, z) => {
149
- return opts.newShadingWidthPix * z
150
- }
151
- : //width depends on the value, that is the number of classes of difference
152
- (side, r, s, z) =>
153
- opts.widthFactor * r * Math.abs(side.value) * (side.or === 'v' ? 0.5 : 1),
154
-
155
- filter: opts.filter,
156
- })
157
-
158
- return [colStyle, sideStyle]
159
- }
160
- }
1
+ //@ts-check
2
+ 'use strict'
3
+
4
+ import { SquareColorWGLStyle } from './SquareColorWGLStyle.js'
5
+ import { SideStyle } from './SideStyle.js'
6
+
7
+ /**
8
+ *
9
+ * @see https://manifold.net/doc/mfd9/example__tanaka_contours.htm
10
+ *
11
+ * @author Julien Gaffuri
12
+ */
13
+ export class TanakaStyle {
14
+ /**
15
+ * @param {string} col
16
+ * @param {object} opts
17
+ * @returns {Array.<import("../Style").Style>}
18
+ */
19
+ static get(col, opts) {
20
+ opts = opts || {}
21
+
22
+ //get colors from d3 ramps, if 'nb' is specified
23
+ if (opts.nb != undefined) {
24
+ if (opts.nb < 2) {
25
+ console.error('unexpected number of colors in tanaka (<2): ' + opts.nb)
26
+ opts.nb = 2
27
+ }
28
+ if (!opts.color) {
29
+ console.error('color function not defined in tanaka')
30
+ opts.color = () => 'gray'
31
+ }
32
+ opts.colors = []
33
+ for (let i = 0; i < opts.nb; i++) opts.colors.push(opts.color(i / (opts.nb - 1)))
34
+ }
35
+
36
+ /**
37
+ * The colors.
38
+ * @type {Array.<string>} */
39
+ opts.colors = opts.colors || ['#a9bb9e', '#c9dcaa', '#fde89f', '#f9a579', '#eb444b']
40
+ const nb = opts.colors.length
41
+
42
+ /** A function to compute 't' from the value v
43
+ * @type {function(number,number,import("../Style").Stat):number} */
44
+ opts.tFun = opts.tFun || ((v, r, s) => (v - s.min) / (s.max - s.min))
45
+
46
+ //shadow colors
47
+ opts.colDark = opts.colDark || '#111'
48
+ opts.colBright = opts.colBright || '#ddd'
49
+
50
+ //width of the segment (share of the resolution)
51
+ opts.widthFactor = opts.widthFactor || 0.08
52
+
53
+ //shading
54
+ opts.newShading = opts.newShading
55
+ opts.newShadingWidthPix = opts.newShadingWidthPix || 2
56
+ //transparency value, within [0,1]
57
+ opts.newShadingTr =
58
+ opts.newShadingTr ||
59
+ ((sideValue, sideStat) =>
60
+ Math.abs(sideValue) / Math.max(Math.abs(sideStat.min), Math.abs(sideStat.max)))
61
+
62
+ /**
63
+ * @param {number} t A cell t value, within [0,1].
64
+ * @returns the class number for the value
65
+ */
66
+ const getClass = (t) => {
67
+ if (isNaN(t) || t == undefined) {
68
+ console.error('Unexpected t value 1: ' + t)
69
+ return -9
70
+ }
71
+ for (let i = 0; i < nb; i++) if (t <= (i + 1) / nb) return i
72
+ console.error('Unexpected t value 2: ' + t)
73
+ return -9
74
+ }
75
+
76
+ const colStyle = new SquareColorWGLStyle({
77
+ colorCol: col,
78
+ colors: opts.colors,
79
+ tFun: (v, r, s) => {
80
+ const t = opts.tFun(v, r, s)
81
+ const c = getClass(t)
82
+ return c / (nb - 1)
83
+ },
84
+ //stretching: { fun: "expRev", alpha: -7 },
85
+ size: (r, zf) => r + 0.5 * zf, //that is to ensure no gap between same class cells is visible
86
+ filter: opts.filter,
87
+ })
88
+
89
+ /*
90
+ if no web gl:
91
+ const colStyle = new ShapeColorSizeStyle({
92
+ colorCol: col,
93
+ //the color corresponding to the class
94
+ color: (v, r, s, zf) => {
95
+ if (v == 0 && opts.tFun && isNaN(opts.tFun(v, r, s)))
96
+ return undefined
97
+ return opts.colors[getClass(opts.tFun ? opts.tFun(v, r, s) : v)]
98
+ },
99
+ shape: () => "square",
100
+ size: (v, r, s, zf) => r + 0.5 * zf, //that is to ensure no gap between same class cells is visible
101
+ })
102
+ */
103
+
104
+ /** The side style, for the shadow effect */
105
+ const sideStyle = new SideStyle({
106
+ valueCol: col,
107
+ value: (v1, v2, r, s, zf) => {
108
+ //compute the number of classes of difference
109
+ if (v1 === undefined && v2 === undefined) return 0
110
+ else if (v2 === undefined) {
111
+ const t = opts.tFun(v1, r, s)
112
+ if (t == undefined || isNaN(t)) throw new Error('Unexpected value: ' + v1 + ' - ' + t)
113
+ const c = getClass(t)
114
+ return c + 1
115
+ } else if (v1 === undefined) {
116
+ const t = opts.tFun(v2, r, s)
117
+ if (t == undefined || isNaN(t)) throw new Error('Unexpected value: ' + v2 + ' - ' + t)
118
+ const c = getClass(t)
119
+ return -c - 1
120
+ }
121
+ const t1 = opts.tFun(v1, r, s)
122
+ if (t1 == undefined || isNaN(t1)) throw new Error('Unexpected value: ' + v1 + ' - ' + t1)
123
+ const t2 = opts.tFun(v2, r, s)
124
+ if (t2 == undefined || isNaN(t2)) throw new Error('Unexpected value: ' + v2 + ' - ' + t2)
125
+ const c1 = getClass(t1)
126
+ const c2 = getClass(t2)
127
+ return -c2 + c1
128
+ },
129
+
130
+ color: opts.newShading
131
+ ? //black with transparency depending on difference
132
+ (side, r, s, z) => {
133
+ const tr = opts.newShadingTr(side.value, s)
134
+ return (side.value > 0 && side.or === 'h') || (side.value < 0 && side.or === 'v')
135
+ ? 'rgba(255,255,100,' + tr + ')'
136
+ : 'rgba(0,0,0,' + tr + ')'
137
+ }
138
+ : //white or black, depending on orientation and value
139
+ (side, r, s, z) => {
140
+ if (side.value === 0) return
141
+ //return "gray"
142
+ if (side.or === 'v') return side.value < 0 ? opts.colBright : opts.colDark
143
+ return side.value < 0 ? opts.colDark : opts.colBright
144
+ },
145
+
146
+ width: opts.newShading
147
+ ? //fill size
148
+ (side, r, s, z) => {
149
+ return opts.newShadingWidthPix * z
150
+ }
151
+ : //width depends on the value, that is the number of classes of difference
152
+ (side, r, s, z) =>
153
+ opts.widthFactor * r * Math.abs(side.value) * (side.or === 'v' ? 0.5 : 1),
154
+
155
+ filter: opts.filter,
156
+ })
157
+
158
+ return [colStyle, sideStyle]
159
+ }
160
+ }
@@ -1,132 +1,132 @@
1
- //@ts-check
2
- 'use strict'
3
-
4
- import { Style } from '../Style.js'
5
-
6
- /**
7
- *
8
- * @author Julien Gaffuri
9
- */
10
- export class TextStyle extends Style {
11
- /** @param {object} opts */
12
- constructor(opts) {
13
- super(opts)
14
- opts = opts || {}
15
-
16
- /** The name of the column/attribute of the tabular data where to retrieve the variable for text.
17
- * @type {string} */
18
- this.textCol = opts.textCol
19
-
20
- /** A function returning the text of a cell.
21
- * @type {function(number,number,import("../Style").Stat|undefined,number):string} */
22
- this.text = opts.text || ((v, r, s, z) => 'X')
23
-
24
- /** The name of the column/attribute of the tabular data where to retrieve the variable for color.
25
- * @type {string} */
26
- this.colorCol = opts.colorCol
27
-
28
- /** A function returning the color of the cell.
29
- * @type {function(number,number,import("../Style").Stat|undefined,number):string} */
30
- this.color = opts.color || (() => '#EA6BAC')
31
-
32
- /** The name of the column/attribute of the tabular data where to retrieve the variable for font size.
33
- * @type {string} */
34
- this.fontSizeCol = opts.fontSizeCol
35
-
36
- /** A function returning the font size of a cell in geo unit.
37
- * @type {function(number,number,import("../Style").Stat|undefined,number):number} */
38
- this.fontSize = opts.fontSize || ((v, r, s, z) => r * 0.8)
39
-
40
- /** The text font family.
41
- * @type {string} */
42
- this.fontFamily = opts.fontFamily || 'Arial'
43
-
44
- /** The text font weight.
45
- * @type {string} */
46
- this.fontWeight = opts.fontWeight || 'bold'
47
- }
48
-
49
- /**
50
- * Draw cells as text.
51
- *
52
- * @param {Array.<import("../Dataset").Cell>} cells
53
- * @param {number} r
54
- * @param {import("../GeoCanvas").GeoCanvas} cg
55
- */
56
- draw(cells, r, cg) {
57
- //filter
58
- if (this.filter) cells = cells.filter(this.filter)
59
-
60
- //zoom factor
61
- const zf = cg.getZf()
62
-
63
- let statText
64
- if (this.textCol) {
65
- //compute text variable statistics
66
- statText = Style.getStatistics(cells, (c) => c[this.textCol], true)
67
- }
68
-
69
- let statColor
70
- if (this.colorCol) {
71
- //compute color variable statistics
72
- statColor = Style.getStatistics(cells, (c) => c[this.colorCol], true)
73
- }
74
-
75
- let statFontSize
76
- if (this.fontSizeCol) {
77
- //if size is used, sort cells by size so that the biggest are drawn first
78
- cells.sort((c1, c2) => c2[this.fontSizeCol] - c1[this.fontSizeCol])
79
- //and compute size variable statistics
80
- statFontSize = Style.getStatistics(cells, (c) => c[this.fontSizeCol], true)
81
- }
82
-
83
- //draw with HTML canvas
84
- //in screen coordinates
85
- cg.initCanvasTransform()
86
-
87
- for (let cell of cells) {
88
- //get cell text
89
- const text = this.text ? this.text(cell[this.textCol], r, statText, zf) : undefined
90
- if (text == undefined || text == null || text + '' === '') continue
91
-
92
- //color
93
- const col = this.color ? this.color(cell[this.colorCol], r, statColor, zf) : undefined
94
- if (!col) continue
95
- cg.ctx.fillStyle = col
96
-
97
- //font size
98
- //size - in pixel unit
99
- const fontSizePix = this.fontSize(cell[this.fontSizeCol], r, statFontSize, zf) / zf
100
-
101
- //set font
102
- const fontFamily = this.fontFamily || 'Arial'
103
- const fontWeight = this.fontWeight || 'bold'
104
- cg.ctx.font = fontWeight + ' ' + fontSizePix + 'px ' + fontFamily
105
-
106
- //get offset
107
- const offset = this.offset(cell, r, zf)
108
-
109
- //text position
110
- cg.ctx.textAlign = 'center'
111
- const tx = cg.geoToPixX(cell.x + r * 0.5 + offset.dx)
112
- const ty = cg.geoToPixY(cell.y + r * 0.5 + offset.dy) + fontSizePix * 0.3 //it should be 0.5 but 0.3 seems to work better
113
-
114
- //draw the text
115
- cg.ctx.fillText(text, tx, ty)
116
- }
117
-
118
- //update legends
119
- this.updateLegends({ style: this, r: r, zf: zf, sColor: statColor })
120
- }
121
-
122
- /**
123
- * Build a function [0,1]->string for characters legend
124
- *
125
- * @param {Array.<string>} chars
126
- * @returns {function(number):string}
127
- */
128
- static getCharLegendFun(chars) {
129
- const nb = chars.length
130
- return (t) => (t == 0 ? '' : t == 1 ? chars[nb - 1] : chars[Math.floor(t * nb)])
131
- }
132
- }
1
+ //@ts-check
2
+ 'use strict'
3
+
4
+ import { Style } from '../Style.js'
5
+
6
+ /**
7
+ *
8
+ * @author Julien Gaffuri
9
+ */
10
+ export class TextStyle extends Style {
11
+ /** @param {object} opts */
12
+ constructor(opts) {
13
+ super(opts)
14
+ opts = opts || {}
15
+
16
+ /** The name of the column/attribute of the tabular data where to retrieve the variable for text.
17
+ * @type {string} */
18
+ this.textCol = opts.textCol
19
+
20
+ /** A function returning the text of a cell.
21
+ * @type {function(number,number,import("../Style").Stat|undefined,number):string} */
22
+ this.text = opts.text || ((v, r, s, z) => 'X')
23
+
24
+ /** The name of the column/attribute of the tabular data where to retrieve the variable for color.
25
+ * @type {string} */
26
+ this.colorCol = opts.colorCol
27
+
28
+ /** A function returning the color of the cell.
29
+ * @type {function(number,number,import("../Style").Stat|undefined,number):string} */
30
+ this.color = opts.color || (() => '#EA6BAC')
31
+
32
+ /** The name of the column/attribute of the tabular data where to retrieve the variable for font size.
33
+ * @type {string} */
34
+ this.fontSizeCol = opts.fontSizeCol
35
+
36
+ /** A function returning the font size of a cell in geo unit.
37
+ * @type {function(number,number,import("../Style").Stat|undefined,number):number} */
38
+ this.fontSize = opts.fontSize || ((v, r, s, z) => r * 0.8)
39
+
40
+ /** The text font family.
41
+ * @type {string} */
42
+ this.fontFamily = opts.fontFamily || 'Arial'
43
+
44
+ /** The text font weight.
45
+ * @type {string} */
46
+ this.fontWeight = opts.fontWeight || 'bold'
47
+ }
48
+
49
+ /**
50
+ * Draw cells as text.
51
+ *
52
+ * @param {Array.<import("../Dataset").Cell>} cells
53
+ * @param {number} r
54
+ * @param {import("../GeoCanvas").GeoCanvas} cg
55
+ */
56
+ draw(cells, r, cg) {
57
+ //filter
58
+ if (this.filter) cells = cells.filter(this.filter)
59
+
60
+ //zoom factor
61
+ const zf = cg.getZf()
62
+
63
+ let statText
64
+ if (this.textCol) {
65
+ //compute text variable statistics
66
+ statText = Style.getStatistics(cells, (c) => c[this.textCol], true)
67
+ }
68
+
69
+ let statColor
70
+ if (this.colorCol) {
71
+ //compute color variable statistics
72
+ statColor = Style.getStatistics(cells, (c) => c[this.colorCol], true)
73
+ }
74
+
75
+ let statFontSize
76
+ if (this.fontSizeCol) {
77
+ //if size is used, sort cells by size so that the biggest are drawn first
78
+ cells.sort((c1, c2) => c2[this.fontSizeCol] - c1[this.fontSizeCol])
79
+ //and compute size variable statistics
80
+ statFontSize = Style.getStatistics(cells, (c) => c[this.fontSizeCol], true)
81
+ }
82
+
83
+ //draw with HTML canvas
84
+ //in screen coordinates
85
+ cg.initCanvasTransform()
86
+
87
+ for (let cell of cells) {
88
+ //get cell text
89
+ const text = this.text ? this.text(cell[this.textCol], r, statText, zf) : undefined
90
+ if (text == undefined || text == null || text + '' === '') continue
91
+
92
+ //color
93
+ const col = this.color ? this.color(cell[this.colorCol], r, statColor, zf) : undefined
94
+ if (!col) continue
95
+ cg.ctx.fillStyle = col
96
+
97
+ //font size
98
+ //size - in pixel unit
99
+ const fontSizePix = this.fontSize(cell[this.fontSizeCol], r, statFontSize, zf) / zf
100
+
101
+ //set font
102
+ const fontFamily = this.fontFamily || 'Arial'
103
+ const fontWeight = this.fontWeight || 'bold'
104
+ cg.ctx.font = fontWeight + ' ' + fontSizePix + 'px ' + fontFamily
105
+
106
+ //get offset
107
+ const offset = this.offset(cell, r, zf)
108
+
109
+ //text position
110
+ cg.ctx.textAlign = 'center'
111
+ const tx = cg.geoToPixX(cell.x + r * 0.5 + offset.dx)
112
+ const ty = cg.geoToPixY(cell.y + r * 0.5 + offset.dy) + fontSizePix * 0.3 //it should be 0.5 but 0.3 seems to work better
113
+
114
+ //draw the text
115
+ cg.ctx.fillText(text, tx, ty)
116
+ }
117
+
118
+ //update legends
119
+ this.updateLegends({ style: this, r: r, zf: zf, sColor: statColor })
120
+ }
121
+
122
+ /**
123
+ * Build a function [0,1]->string for characters legend
124
+ *
125
+ * @param {Array.<string>} chars
126
+ * @returns {function(number):string}
127
+ */
128
+ static getCharLegendFun(chars) {
129
+ const nb = chars.length
130
+ return (t) => (t == 0 ? '' : t == 1 ? chars[nb - 1] : chars[Math.floor(t * nb)])
131
+ }
132
+ }