gridviz 3.1.0 → 3.1.1

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 (46) hide show
  1. package/README.md +18 -15
  2. package/dist/gridviz.js +3829 -2623
  3. package/dist/gridviz.min.js +1 -1
  4. package/package.json +5 -3
  5. package/src/button/Button.js +77 -68
  6. package/src/button/FullscreenButton.js +123 -123
  7. package/src/button/ZoomButtons.js +109 -104
  8. package/src/core/GeoCanvas.js +15 -0
  9. package/src/core/Legend.js +267 -245
  10. package/src/core/Map.js +819 -670
  11. package/src/core/Tooltip.js +191 -185
  12. package/src/index.js +82 -79
  13. package/src/layer/GridLayer.js +4 -3
  14. package/src/layer/LabelLayer.js +7 -4
  15. package/src/legend/ColorCategoryLegend.js +127 -125
  16. package/src/legend/ColorDiscreteLegend.js +116 -114
  17. package/src/legend/ColorLegend.js +33 -11
  18. package/src/legend/OrientationLegend.js +94 -92
  19. package/src/legend/SizeLegend.js +8 -1
  20. package/src/legend/TernaryLegend.js +317 -314
  21. package/src/legend/VennLegend.js +202 -0
  22. package/src/style/CircleColorSizeWebGLStyle.js +249 -0
  23. package/src/style/CompositionStyle.js +1 -1
  24. package/src/style/DotDensityStyle.js +8 -4
  25. package/src/style/ImageStyle.js +1 -1
  26. package/src/style/Interpolator.js +283 -259
  27. package/src/style/IsoFenceStyle.js +1 -1
  28. package/src/style/LegoStyle.js +6 -5
  29. package/src/style/MosaicStyle.js +1 -1
  30. package/src/style/NinjaStarStyle.js +1 -1
  31. package/src/style/PillarStyle.js +1 -1
  32. package/src/style/RandomWalkInterpolator.js +213 -0
  33. package/src/style/ShadingRayStyle.js +16 -2
  34. package/src/style/ShadingStyle.js +80 -72
  35. package/src/style/ShapeColorSizeStyle.js +18 -2
  36. package/src/style/SideCategoryStyle.js +1 -1
  37. package/src/style/SideStyle.js +1 -1
  38. package/src/style/SideTanakaStyle.js +1 -1
  39. package/src/style/SquareColorCategoryWebGLStyle.js +71 -20
  40. package/src/style/SquareColorWebGLStyle.js +7 -4
  41. package/src/style/StrokeStyle.js +1 -1
  42. package/src/style/TextStyle.js +1 -1
  43. package/src/style/TimeSeriesStyle.js +14 -7
  44. package/src/utils/WebGLSquareColoringAdvanced.js +47 -9
  45. package/src/utils/scale.js +20 -0
  46. package/src/utils/webGLUtils.js +52 -0
@@ -1,185 +1,191 @@
1
- //@ts-check
2
- 'use strict'
3
-
4
- import { select } from 'd3-selection'
5
- //import { transition } from "d3-transition";
6
-
7
- /**
8
- * A generic class to make a tooltip.
9
- * It is a div element, which can be moved under the mouse pointer and filled with some information in html.
10
- * @module core
11
- */
12
- export class Tooltip {
13
- /**
14
- * @param {object} opts
15
- */
16
- constructor(opts) {
17
- opts = opts || {}
18
-
19
- /** @type {string} */
20
- this.maxWidth = opts.maxWidth || '20em'
21
- /** @type {string} */
22
- this.fontSize = opts.fontSize || '1.2em'
23
- /** @type {string} */
24
- this.background = opts.background || 'white'
25
- /** @type {string} */
26
- this.padding = opts.padding || '5px'
27
- /** @type {string} */
28
- this.border = opts.border || '0px'
29
- /** @type {string} */
30
- this['border-radius'] = opts['border-radius'] || '0px'
31
- /** @type {string} */
32
- this['box-shadow'] = opts['box-shadow'] || '5px 5px 5px grey'
33
- /** @type {string} */
34
- this['font-family'] = opts['font-family'] || 'Helvetica, Arial, sans-serif'
35
-
36
- /** @type {number} */
37
- this.transitionDuration = opts.transitionDuration || 100
38
- /** @type {number} */
39
- this.xOffset = opts.xOffset || 30
40
- /** @type {number} */
41
- this.yOffset = opts.yOffset || 20
42
- /** @type {number} */ // e.g. to prevent mouse cursor covering cell being highlighted
43
- this.yMouseOffset = opts.yMouseOffset || 0
44
- /** @type {number} */
45
- this.xMouseOffset = opts.xMouseOffset || 0
46
- /** @type {HTMLElement} */
47
- this.parentElement = opts.parentElement || document.body
48
- /** @type {HTMLElement} */
49
- this.tooltipElement = opts.tooltipElement || null
50
-
51
- /**
52
- * @public
53
- * @type {import("d3-selection").Selection} */
54
- this.tooltip = opts.tooltipElement
55
- ? select(opts.tooltipElement) // Wrap the provided HTML node in a D3 selection
56
- : select(this.parentElement).append('div').attr('id', 'gridviz-tooltip').attr('class', 'gridviz-tooltip') // create default element
57
-
58
- //initialise
59
- this.tooltip.style('max-width', this.maxWidth)
60
- this.tooltip.style('overflow', 'hidden')
61
- this.tooltip.style('font-size', this.fontSize)
62
- this.tooltip.style('background', this.background)
63
- this.tooltip.style('padding', this.padding)
64
- this.tooltip.style('border', this.border)
65
- this.tooltip.style('border-radius', this['border-radius'])
66
- this.tooltip.style('box-shadow', this['box-shadow'])
67
- this.tooltip.style('font-family', this['font-family'])
68
- this.tooltip.style('position', 'absolute')
69
- this.tooltip.style('pointer-events', 'none')
70
- this.tooltip.style('opacity', '0')
71
- this.tooltip.style('text-wrap', 'nowrap')
72
- this.tooltip.style('z-index', 99999999) // important for leaflet-gridviz etc
73
-
74
- // these placeholders are needed to prevent an infinite DOM resizeObserver loop:
75
- this.tooltip.style('left', '0')
76
- this.tooltip.style('top', '0')
77
-
78
- // a tooltip element given by the user gets the class too
79
- this.tooltip.classed('gridviz-tooltip', true)
80
-
81
- // aria-labels (thanks to wahlatlas)
82
- this.tooltip.attr('role', 'tooltip').attr('aria-live', 'polite')
83
- }
84
-
85
- /** Show the tooltip */
86
- show() {
87
- // @ts-ignore
88
- this.tooltip.transition().duration(this.transitionDuration).style('opacity', 1)
89
- }
90
-
91
- /** Hide the tooltip */
92
- hide() {
93
- // @ts-ignore
94
- this.tooltip.transition().duration(this.transitionDuration).style('opacity', 0)
95
- }
96
-
97
- /**
98
- * Set the content of the tooltip.
99
- * @param {string} html
100
- */
101
- html(html) {
102
- this.tooltip.html(html)
103
- }
104
-
105
- /**
106
- * Set the position of the tooltip at the mouse event position.
107
- * @param {MouseEvent} event
108
- */
109
- setPosition(event) {
110
- // Get the bounding rect of the parent container (map2)
111
- let parentRect = this.parentElement.getBoundingClientRect()
112
-
113
- // Get the mouse position (relative to the parent container)
114
- let x = event.clientX - parentRect.left + this.xOffset // Relative to parent
115
- let y = event.clientY - parentRect.top - this.yOffset // Relative to parent
116
-
117
- // Now, apply the position to the tooltip
118
- this.tooltip.style('left', x + 'px').style('top', y + 'px')
119
-
120
- // Ensure the tooltip stays inside the parent container
121
- this.ensureTooltipInsideContainer(event, parentRect, this.tooltip.node())
122
- }
123
- /**
124
- * @function ensureTooltipInsideContainer
125
- * @description Prevents the tooltip from overflowing out of the App container (ensures that the tooltip is inside the gridviz container)
126
- * @param {MouseEvent} event
127
- * @param {DOMRect} parentRect
128
- * @param {HTMLElement} tooltipNode
129
- */
130
- ensureTooltipInsideContainer(event, parentRect, tooltipNode) {
131
- let node = tooltipNode
132
- let parentWidth = parentRect.width
133
- let parentHeight = parentRect.height
134
-
135
- // Ensure tooltip doesn't go beyond the right edge
136
- if (node.offsetLeft + node.clientWidth > parentWidth) {
137
- let left = event.clientX - node.clientWidth - this.xOffset
138
- node.style.left = left + 'px'
139
- }
140
-
141
- // Ensure tooltip doesn't go beyond the bottom edge
142
- if (node.offsetTop + node.clientHeight > parentHeight) {
143
- node.style.top = parentHeight - node.clientHeight + 'px'
144
- }
145
-
146
- // Ensure tooltip doesn't go above the top edge
147
- if (node.offsetTop < 0) {
148
- node.style.top = 0 + 'px'
149
- }
150
-
151
- // Ensure tooltip doesn't go beyond the left edge
152
- if (node.offsetLeft < 0) {
153
- node.style.left = 0 + 'px'
154
- }
155
- }
156
-
157
- /*
158
- my.mouseover = function (event, html) {
159
- if (html) my.html(html);
160
- my.setPosition(event);
161
- my.show()
162
- //this.ensureTooltipInsideContainer();
163
- };
164
-
165
- my.mousemove = function (event) {
166
- my.setPosition(event);
167
- //this.ensureTooltipInsideContainer();
168
- };
169
-
170
- my.mouseout = function () {
171
- my.hide();
172
- };*/
173
-
174
- style(k, v) {
175
- if (arguments.length == 1) return this.tooltip.style(k)
176
- this.tooltip.style(k, v)
177
- return this
178
- }
179
-
180
- attr(k, v) {
181
- if (arguments.length == 1) return this.tooltip.attr(k)
182
- this.tooltip.attr(k, v)
183
- return this
184
- }
185
- }
1
+ //@ts-check
2
+ 'use strict'
3
+
4
+ import { select } from 'd3-selection'
5
+ //import { transition } from "d3-transition";
6
+
7
+ /**
8
+ * A generic class to make a tooltip.
9
+ * It is a div element, which can be moved under the mouse pointer and filled with some information in html.
10
+ * @module core
11
+ */
12
+ export class Tooltip {
13
+ /**
14
+ * @param {object} opts
15
+ */
16
+ constructor(opts) {
17
+ opts = opts || {}
18
+
19
+ /** @type {string} */
20
+ this.maxWidth = opts.maxWidth || '20em'
21
+ /** @type {string} */
22
+ this.fontSize = opts.fontSize || '1rem'
23
+ /** @type {string} */
24
+ this.color = opts.color || '#171a22'
25
+ /** @type {string} */
26
+ this.lineHeight = opts.lineHeight || '1.5'
27
+ /** @type {string} */
28
+ this.background = opts.background || 'white'
29
+ /** @type {string} */
30
+ this.padding = opts.padding || '4px'
31
+ /** @type {string} */
32
+ this.border = opts.border || '1px solid #d5d5d5'
33
+ /** @type {string} */
34
+ this['border-radius'] = opts['border-radius'] || '6px'
35
+ /** @type {string} */
36
+ this['box-shadow'] = opts['box-shadow'] || '0px 4px 6px rgba(0, 0, 0, 0.1), 0px 1px 3px rgba(0, 0, 0, 0.08)'
37
+ /** @type {string} */
38
+ this['font-family'] = opts['font-family'] || "'Helvetica Neue', Arial, Helvetica, sans-serif"
39
+
40
+ /** @type {number} */
41
+ this.transitionDuration = opts.transitionDuration || 100
42
+ /** @type {number} */
43
+ this.xOffset = opts.xOffset || 30
44
+ /** @type {number} */
45
+ this.yOffset = opts.yOffset || 20
46
+ /** @type {number} */ // e.g. to prevent mouse cursor covering cell being highlighted
47
+ this.yMouseOffset = opts.yMouseOffset || 0
48
+ /** @type {number} */
49
+ this.xMouseOffset = opts.xMouseOffset || 0
50
+ /** @type {HTMLElement} */
51
+ this.parentElement = opts.parentElement || document.body
52
+ /** @type {HTMLElement} */
53
+ this.tooltipElement = opts.tooltipElement || null
54
+
55
+ /**
56
+ * @public
57
+ * @type {import("d3-selection").Selection} */
58
+ this.tooltip = opts.tooltipElement
59
+ ? select(opts.tooltipElement) // Wrap the provided HTML node in a D3 selection
60
+ : select(this.parentElement).append('div').attr('id', 'gridviz-tooltip').attr('class', 'gridviz-tooltip') // create default element
61
+
62
+ //initialise
63
+ this.tooltip.style('max-width', this.maxWidth)
64
+ this.tooltip.style('overflow', 'hidden')
65
+ this.tooltip.style('font-size', this.fontSize)
66
+ this.tooltip.style('color', this.color)
67
+ this.tooltip.style('line-height', this.lineHeight)
68
+ this.tooltip.style('background', this.background)
69
+ this.tooltip.style('padding', this.padding)
70
+ this.tooltip.style('border', this.border)
71
+ this.tooltip.style('border-radius', this['border-radius'])
72
+ this.tooltip.style('box-shadow', this['box-shadow'])
73
+ this.tooltip.style('font-family', this['font-family'])
74
+ this.tooltip.style('position', 'absolute')
75
+ this.tooltip.style('pointer-events', 'none')
76
+ this.tooltip.style('opacity', '0')
77
+ this.tooltip.style('text-wrap', 'nowrap')
78
+ this.tooltip.style('z-index', 99999999) // important for leaflet-gridviz etc
79
+
80
+ // these placeholders are needed to prevent an infinite DOM resizeObserver loop:
81
+ this.tooltip.style('left', '0')
82
+ this.tooltip.style('top', '0')
83
+
84
+ // a tooltip element given by the user gets the class too
85
+ this.tooltip.classed('gridviz-tooltip', true)
86
+
87
+ // aria-labels (thanks to wahlatlas)
88
+ this.tooltip.attr('role', 'tooltip').attr('aria-live', 'polite')
89
+ }
90
+
91
+ /** Show the tooltip */
92
+ show() {
93
+ // @ts-ignore
94
+ this.tooltip.transition().duration(this.transitionDuration).style('opacity', 1)
95
+ }
96
+
97
+ /** Hide the tooltip */
98
+ hide() {
99
+ // @ts-ignore
100
+ this.tooltip.transition().duration(this.transitionDuration).style('opacity', 0)
101
+ }
102
+
103
+ /**
104
+ * Set the content of the tooltip.
105
+ * @param {string} html
106
+ */
107
+ html(html) {
108
+ this.tooltip.html(html)
109
+ }
110
+
111
+ /**
112
+ * Set the position of the tooltip at the mouse event position.
113
+ * @param {MouseEvent} event
114
+ */
115
+ setPosition(event) {
116
+ // Get the bounding rect of the parent container (map2)
117
+ let parentRect = this.parentElement.getBoundingClientRect()
118
+
119
+ // Get the mouse position (relative to the parent container)
120
+ let x = event.clientX - parentRect.left + this.xOffset // Relative to parent
121
+ let y = event.clientY - parentRect.top - this.yOffset // Relative to parent
122
+
123
+ // Now, apply the position to the tooltip
124
+ this.tooltip.style('left', x + 'px').style('top', y + 'px')
125
+
126
+ // Ensure the tooltip stays inside the parent container
127
+ this.ensureTooltipInsideContainer(event, parentRect, this.tooltip.node())
128
+ }
129
+ /**
130
+ * @function ensureTooltipInsideContainer
131
+ * @description Prevents the tooltip from overflowing out of the App container (ensures that the tooltip is inside the gridviz container)
132
+ * @param {MouseEvent} event
133
+ * @param {DOMRect} parentRect
134
+ * @param {HTMLElement} tooltipNode
135
+ */
136
+ ensureTooltipInsideContainer(event, parentRect, tooltipNode) {
137
+ let node = tooltipNode
138
+ let parentWidth = parentRect.width
139
+ let parentHeight = parentRect.height
140
+
141
+ // Ensure tooltip doesn't go beyond the right edge
142
+ if (node.offsetLeft + node.clientWidth > parentWidth) {
143
+ let left = event.clientX - node.clientWidth - this.xOffset
144
+ node.style.left = left + 'px'
145
+ }
146
+
147
+ // Ensure tooltip doesn't go beyond the bottom edge
148
+ if (node.offsetTop + node.clientHeight > parentHeight) {
149
+ node.style.top = parentHeight - node.clientHeight + 'px'
150
+ }
151
+
152
+ // Ensure tooltip doesn't go above the top edge
153
+ if (node.offsetTop < 0) {
154
+ node.style.top = 0 + 'px'
155
+ }
156
+
157
+ // Ensure tooltip doesn't go beyond the left edge
158
+ if (node.offsetLeft < 0) {
159
+ node.style.left = 0 + 'px'
160
+ }
161
+ }
162
+
163
+ /*
164
+ my.mouseover = function (event, html) {
165
+ if (html) my.html(html);
166
+ my.setPosition(event);
167
+ my.show()
168
+ //this.ensureTooltipInsideContainer();
169
+ };
170
+
171
+ my.mousemove = function (event) {
172
+ my.setPosition(event);
173
+ //this.ensureTooltipInsideContainer();
174
+ };
175
+
176
+ my.mouseout = function () {
177
+ my.hide();
178
+ };*/
179
+
180
+ style(k, v) {
181
+ if (arguments.length == 1) return this.tooltip.style(k)
182
+ this.tooltip.style(k, v)
183
+ return this
184
+ }
185
+
186
+ attr(k, v) {
187
+ if (arguments.length == 1) return this.tooltip.attr(k)
188
+ this.tooltip.attr(k, v)
189
+ return this
190
+ }
191
+ }
package/src/index.js CHANGED
@@ -1,79 +1,82 @@
1
- //@ts-check
2
- 'use strict'
3
-
4
- // the application
5
- export { Map } from './core/Map.js'
6
- export { GeoCanvas } from './core/GeoCanvas.js'
7
- export { Style } from './core/Style.js'
8
- export { Layer } from './core/Layer.js'
9
- export { Dataset } from './core/Dataset.js'
10
- export { MultiResolutionDataset } from './core/MultiResolutionDataset.js'
11
-
12
- // export dataset types
13
- export { TiledGrid } from './dataset/TiledGrid.js'
14
- export { CSVGrid } from './dataset/CSVGrid.js'
15
- export { JSGrid } from './dataset/JSGrid.js'
16
-
17
- // export styles
18
- export { ShapeColorSizeStyle } from './style/ShapeColorSizeStyle.js'
19
- export { StrokeStyle } from './style/StrokeStyle.js'
20
- export { JoyPlotStyle } from './style/JoyPlotStyle.js'
21
- export { CompositionStyle } from './style/CompositionStyle.js'
22
- export { SegmentStyle } from './style/SegmentStyle.js'
23
- export { TextStyle } from './style/TextStyle.js'
24
- export { PillarStyle } from './style/PillarStyle.js'
25
- export { SideStyle } from './style/SideStyle.js'
26
- export { ShadingRayStyle } from './style/ShadingRayStyle.js'
27
- export { ShadingStyle } from './style/ShadingStyle.js'
28
- export { SideCategoryStyle } from './style/SideCategoryStyle.js'
29
- export { DotDensityStyle } from './style/DotDensityStyle.js'
30
- export { SideTanakaStyle } from './style/SideTanakaStyle.js'
31
- export { LegoStyle } from './style/LegoStyle.js'
32
- export { SquareColorWebGLStyle } from './style/SquareColorWebGLStyle.js'
33
- export { SquareColorCategoryWebGLStyle } from './style/SquareColorCategoryWebGLStyle.js'
34
- export { MosaicStyle } from './style/MosaicStyle.js'
35
- export { NinjaStarStyle } from './style/NinjaStarStyle.js'
36
- export { TimeSeriesStyle } from './style/TimeSeriesStyle.js'
37
- export { IsoFenceStyle } from './style/IsoFenceStyle.js'
38
- export { ImageStyle } from './style/ImageStyle.js'
39
- export { Interpolator } from './style/Interpolator.js'
40
-
41
- // export additional layers
42
- export { GridLayer } from './layer/GridLayer.js'
43
- export { BackgroundLayer } from './layer/BackgroundLayer.js'
44
- export { BackgroundLayerWMS } from './layer/BackgroundLayerWMS.js'
45
- export { BackgroundLayerImage } from './layer/BackgroundLayerImage.js'
46
- export { LabelLayer } from './layer/LabelLayer.js'
47
- export { GeoJSONLayer } from './layer/GeoJSONLayer.js'
48
-
49
- // export legends
50
- export { ColorLegend } from './legend/ColorLegend.js'
51
- export { ColorDiscreteLegend } from './legend/ColorDiscreteLegend.js'
52
- export { ColorCategoryLegend } from './legend/ColorCategoryLegend.js'
53
- export {
54
- SizeLegend,
55
- sizeLegend,
56
- sizeLegendViewScale,
57
- sizeDiscreteLegend,
58
- sizeDiscreteViewScaleLegend,
59
- } from './legend/SizeLegend.js'
60
- export { OrientationLegend, orientationLegend } from './legend/OrientationLegend.js'
61
- export { TernaryLegend } from './legend/TernaryLegend.js'
62
-
63
- // export { goToStraight, zoomTo } from "./utils/zoomUtils"
64
- export * from './utils/stretching.js'
65
- export * from './utils/scale.js'
66
- export * from './utils/ternary.js'
67
- export { nice, cellsToMatrix } from './utils/utils.js'
68
-
69
- import { GeoCanvas } from './core/GeoCanvas.js'
70
- export const getParameterByName = GeoCanvas.getParameterByName
71
-
72
- // set default d3 locale
73
- import { formatDefaultLocale } from 'd3-format'
74
- formatDefaultLocale({
75
- decimal: '.',
76
- thousands: ' ',
77
- grouping: [3],
78
- currency: ['', '€'],
79
- })
1
+ //@ts-check
2
+ 'use strict'
3
+
4
+ // the application
5
+ export { Map } from './core/Map.js'
6
+ export { GeoCanvas } from './core/GeoCanvas.js'
7
+ export { Style } from './core/Style.js'
8
+ export { Layer } from './core/Layer.js'
9
+ export { Dataset } from './core/Dataset.js'
10
+ export { MultiResolutionDataset } from './core/MultiResolutionDataset.js'
11
+
12
+ // export dataset types
13
+ export { TiledGrid } from './dataset/TiledGrid.js'
14
+ export { CSVGrid } from './dataset/CSVGrid.js'
15
+ export { JSGrid } from './dataset/JSGrid.js'
16
+
17
+ // export styles
18
+ export { ShapeColorSizeStyle } from './style/ShapeColorSizeStyle.js'
19
+ export { StrokeStyle } from './style/StrokeStyle.js'
20
+ export { JoyPlotStyle } from './style/JoyPlotStyle.js'
21
+ export { CompositionStyle } from './style/CompositionStyle.js'
22
+ export { SegmentStyle } from './style/SegmentStyle.js'
23
+ export { TextStyle } from './style/TextStyle.js'
24
+ export { PillarStyle } from './style/PillarStyle.js'
25
+ export { SideStyle } from './style/SideStyle.js'
26
+ export { ShadingRayStyle } from './style/ShadingRayStyle.js'
27
+ export { ShadingStyle } from './style/ShadingStyle.js'
28
+ export { SideCategoryStyle } from './style/SideCategoryStyle.js'
29
+ export { DotDensityStyle } from './style/DotDensityStyle.js'
30
+ export { SideTanakaStyle } from './style/SideTanakaStyle.js'
31
+ export { LegoStyle } from './style/LegoStyle.js'
32
+ export { SquareColorWebGLStyle } from './style/SquareColorWebGLStyle.js'
33
+ export { SquareColorCategoryWebGLStyle } from './style/SquareColorCategoryWebGLStyle.js'
34
+ export { CircleColorSizeWebGLStyle } from './style/CircleColorSizeWebGLStyle.js'
35
+ export { MosaicStyle } from './style/MosaicStyle.js'
36
+ export { NinjaStarStyle } from './style/NinjaStarStyle.js'
37
+ export { TimeSeriesStyle } from './style/TimeSeriesStyle.js'
38
+ export { IsoFenceStyle } from './style/IsoFenceStyle.js'
39
+ export { ImageStyle } from './style/ImageStyle.js'
40
+ export { Interpolator } from './style/Interpolator.js'
41
+ export { RandomWalkInterpolator } from './style/RandomWalkInterpolator.js'
42
+
43
+ // export additional layers
44
+ export { GridLayer } from './layer/GridLayer.js'
45
+ export { BackgroundLayer } from './layer/BackgroundLayer.js'
46
+ export { BackgroundLayerWMS } from './layer/BackgroundLayerWMS.js'
47
+ export { BackgroundLayerImage } from './layer/BackgroundLayerImage.js'
48
+ export { LabelLayer } from './layer/LabelLayer.js'
49
+ export { GeoJSONLayer } from './layer/GeoJSONLayer.js'
50
+
51
+ // export legends
52
+ export { ColorLegend } from './legend/ColorLegend.js'
53
+ export { ColorDiscreteLegend } from './legend/ColorDiscreteLegend.js'
54
+ export { ColorCategoryLegend } from './legend/ColorCategoryLegend.js'
55
+ export {
56
+ SizeLegend,
57
+ sizeLegend,
58
+ sizeLegendViewScale,
59
+ sizeDiscreteLegend,
60
+ sizeDiscreteViewScaleLegend,
61
+ } from './legend/SizeLegend.js'
62
+ export { OrientationLegend, orientationLegend } from './legend/OrientationLegend.js'
63
+ export { TernaryLegend } from './legend/TernaryLegend.js'
64
+ export { VennLegend } from './legend/VennLegend.js'
65
+
66
+ // export { goToStraight, zoomTo } from "./utils/zoomUtils"
67
+ export * from './utils/stretching.js'
68
+ export * from './utils/scale.js'
69
+ export * from './utils/ternary.js'
70
+ export { nice, cellsToMatrix } from './utils/utils.js'
71
+
72
+ import { GeoCanvas } from './core/GeoCanvas.js'
73
+ export const getParameterByName = GeoCanvas.getParameterByName
74
+
75
+ // set default d3 locale
76
+ import { formatDefaultLocale } from 'd3-format'
77
+ formatDefaultLocale({
78
+ decimal: '.',
79
+ thousands: ' ',
80
+ grouping: [3],
81
+ currency: ['', '€'],
82
+ })
@@ -106,7 +106,7 @@ export class GridLayer extends Layer {
106
106
  for (const s of this.styles) {
107
107
  //check if style is visible
108
108
  if (!isVisibleAt(s, z)) continue
109
- GridLayer.addLegends(legend, s.legends, s, geoCanvas)
109
+ GridLayer.addLegends(legend, s.legends, s, geoCanvas, this.styles)
110
110
 
111
111
  //case for styles of styles, like kernel smoothing
112
112
  //TODO do better
@@ -132,11 +132,12 @@ export class GridLayer extends Layer {
132
132
  }
133
133
 
134
134
  /** @private */
135
- static addLegends(legendComp, lg, style, geoCanvas) {
136
- if (Array.isArray(lg)) for (const lg_ of lg) this.addLegends(legendComp, lg_, style, geoCanvas)
135
+ static addLegends(legendComp, lg, style, geoCanvas, layerStyles) {
136
+ if (Array.isArray(lg)) for (const lg_ of lg) this.addLegends(legendComp, lg_, style, geoCanvas, layerStyles)
137
137
  else {
138
138
  // so that hovering a swatch can highlight the cells of the style on the map
139
139
  lg.style_ = style
140
+ lg.layerStyles = layerStyles
140
141
  lg.redraw = () => (geoCanvas.redraw ? geoCanvas.redraw() : undefined)
141
142
  // The legends go in the order they are drawn, after the one placed before them. A hovered legend is
142
143
  // still in the container (see Map.redrawNow) and is left where it is: moving it would lose its mouseleave,
@@ -110,14 +110,17 @@ export class LabelLayer extends Layer {
110
110
  geoCanvas.initCanvasTransform()
111
111
 
112
112
  //draw labels, one by one
113
+ //The font, the colors... are not set again when they do not change from a label to the next one: the browser parses
114
+ //them at each assignment, which is slow.
115
+ let font
113
116
  for (const lb of this.labels) {
117
+ //check label within the view, to be drawn. First: there are many labels (180000 for Europe), a few are in the view.
118
+ if (!geoCanvas.toDraw(lb)) continue
119
+
114
120
  //get label style
115
121
  const st = this.style(lb, z)
116
122
  if (!st) continue
117
- ctx.font = st
118
-
119
- //check label within the view, to be drawn
120
- if (!geoCanvas.toDraw(lb)) continue
123
+ if (st !== font) ctx.font = font = st
121
124
 
122
125
  //position
123
126
  const xP = geoCanvas.geoToPixX(lb.x) + this.offsetPix[0]