gridviz 2.1.13 → 2.1.15
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.
- package/README.md +124 -125
- package/dist/gridviz.js +8900 -8368
- package/dist/gridviz.min.js +1 -1
- package/package.json +77 -77
- package/src/App.js +760 -758
- package/src/BackgroundLayer.js +182 -182
- package/src/BackgroundLayerWMS.js +131 -131
- package/src/Dataset.js +76 -76
- package/src/DatasetComponent.js +113 -113
- package/src/GeoCanvas.js +420 -420
- package/src/LabelLayer.js +190 -190
- package/src/Layer.js +103 -103
- package/src/Legend.js +86 -86
- package/src/LineLayer.js +150 -150
- package/src/Style.js +131 -129
- package/src/Tooltip.js +182 -180
- package/src/button/Button.js +66 -54
- package/src/button/FullscreenButton.js +120 -98
- package/src/button/ZoomButtons.js +95 -72
- package/src/dataset/COGeo.js +24 -24
- package/src/dataset/CSVGrid.js +104 -104
- package/src/dataset/GeoTIFF.js +127 -127
- package/src/dataset/GridTile.js +41 -41
- package/src/dataset/LGrid.js +54 -54
- package/src/dataset/TiledGrid.js +264 -264
- package/src/index.js +73 -71
- package/src/legend/ColorCategoryLegend.js +124 -124
- package/src/legend/ColorDiscreteLegend.js +103 -103
- package/src/legend/ColorLegend.js +128 -128
- package/src/legend/SegmentOrientationLegend.js +87 -87
- package/src/legend/SegmentWidthLegend.js +101 -101
- package/src/legend/SizeLegend.js +141 -141
- package/src/style/CompositionStyle.js +300 -300
- package/src/style/CompositionStyle_.js +293 -0
- package/src/style/ContourStyle.js +54 -54
- package/src/style/DotDensityStyle.js +156 -156
- package/src/style/IsoFenceStyle.js +262 -262
- package/src/style/JoyPlotStyle.js +135 -135
- package/src/style/LegoStyle.js +112 -112
- package/src/style/MosaicStyle.js +107 -107
- package/src/style/NinjaStarStyle.js +125 -125
- package/src/style/PillarStyle.js +230 -230
- package/src/style/SegmentStyle.js +142 -142
- package/src/style/ShapeColorSizeStyle.js +152 -152
- package/src/style/ShapeColorSizeStyle_.js +108 -0
- package/src/style/SideCatStyle.js +172 -172
- package/src/style/SideStyle.js +216 -216
- package/src/style/SquareColorCatWGLStyle.js +120 -120
- package/src/style/SquareColorWGLStyle.js +146 -146
- package/src/style/StrokeStyle.js +131 -131
- package/src/style/TanakaStyle.js +160 -160
- package/src/style/TextStyle.js +132 -132
- package/src/style/TimeSeriesStyle.js +259 -259
- package/src/utils/Utils.js +35 -35
- package/src/utils/WebGLRectangleColoring.js +106 -106
- package/src/utils/WebGLSquareColoring.js +118 -118
- package/src/utils/WebGLSquareColoringAdvanced.js +230 -230
- package/src/utils/WebGLSquareColoringCatAdvanced.js +133 -133
- package/src/utils/WebGLSquareColoringKS.js +153 -153
- package/src/utils/stretching.js +154 -131
- package/src/utils/webGLUtils.js +71 -71
- package/src/utils/zoomUtils.js +142 -142
package/src/index.js
CHANGED
|
@@ -1,71 +1,73 @@
|
|
|
1
|
-
//@ts-check
|
|
2
|
-
'use strict'
|
|
3
|
-
|
|
4
|
-
// the application
|
|
5
|
-
export { App } from './App.js'
|
|
6
|
-
export { GeoCanvas } from './GeoCanvas.js'
|
|
7
|
-
export { Style } from './Style.js'
|
|
8
|
-
export { Layer } from './Layer.js'
|
|
9
|
-
export { Dataset } from './Dataset.js'
|
|
10
|
-
export { DatasetComponent } from './DatasetComponent.js'
|
|
11
|
-
|
|
12
|
-
// export dataset types
|
|
13
|
-
export { TiledGrid } from './dataset/TiledGrid.js'
|
|
14
|
-
export { GridTile } from './dataset/GridTile.js'
|
|
15
|
-
export { CSVGrid } from './dataset/CSVGrid.js'
|
|
16
|
-
export { LGrid } from './dataset/LGrid.js'
|
|
17
|
-
//export { GeoTIFF } from "./dataset/GeoTIFF"
|
|
18
|
-
|
|
19
|
-
// export styles
|
|
20
|
-
export { ShapeColorSizeStyle } from './style/ShapeColorSizeStyle.js'
|
|
21
|
-
export {
|
|
22
|
-
export {
|
|
23
|
-
export {
|
|
24
|
-
export {
|
|
25
|
-
export {
|
|
26
|
-
export {
|
|
27
|
-
export {
|
|
28
|
-
export {
|
|
29
|
-
export {
|
|
30
|
-
export {
|
|
31
|
-
export {
|
|
32
|
-
export {
|
|
33
|
-
export {
|
|
34
|
-
export {
|
|
35
|
-
export {
|
|
36
|
-
export {
|
|
37
|
-
export {
|
|
38
|
-
export {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
export
|
|
43
|
-
export {
|
|
44
|
-
export {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
export
|
|
49
|
-
export {
|
|
50
|
-
export {
|
|
51
|
-
export {
|
|
52
|
-
export {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
export
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
1
|
+
//@ts-check
|
|
2
|
+
'use strict'
|
|
3
|
+
|
|
4
|
+
// the application
|
|
5
|
+
export { App } from './App.js'
|
|
6
|
+
export { GeoCanvas } from './GeoCanvas.js'
|
|
7
|
+
export { Style } from './Style.js'
|
|
8
|
+
export { Layer } from './Layer.js'
|
|
9
|
+
export { Dataset } from './Dataset.js'
|
|
10
|
+
export { DatasetComponent } from './DatasetComponent.js'
|
|
11
|
+
|
|
12
|
+
// export dataset types
|
|
13
|
+
export { TiledGrid } from './dataset/TiledGrid.js'
|
|
14
|
+
export { GridTile } from './dataset/GridTile.js'
|
|
15
|
+
export { CSVGrid } from './dataset/CSVGrid.js'
|
|
16
|
+
export { LGrid } from './dataset/LGrid.js'
|
|
17
|
+
//export { GeoTIFF } from "./dataset/GeoTIFF"
|
|
18
|
+
|
|
19
|
+
// export styles
|
|
20
|
+
export { ShapeColorSizeStyle } from './style/ShapeColorSizeStyle.js'
|
|
21
|
+
export { ShapeColorSizeStyle_ } from './style/ShapeColorSizeStyle_.js'
|
|
22
|
+
export { StrokeStyle } from './style/StrokeStyle.js'
|
|
23
|
+
export { JoyPlotStyle } from './style/JoyPlotStyle.js'
|
|
24
|
+
export { CompositionStyle } from './style/CompositionStyle.js'
|
|
25
|
+
export { CompositionStyle_ } from './style/CompositionStyle_.js'
|
|
26
|
+
export { SegmentStyle } from './style/SegmentStyle.js'
|
|
27
|
+
export { TextStyle } from './style/TextStyle.js'
|
|
28
|
+
export { PillarStyle } from './style/PillarStyle.js'
|
|
29
|
+
export { SideStyle } from './style/SideStyle.js'
|
|
30
|
+
export { ContourStyle } from './style/ContourStyle.js'
|
|
31
|
+
export { SideCatStyle } from './style/SideCatStyle.js'
|
|
32
|
+
export { DotDensityStyle } from './style/DotDensityStyle.js'
|
|
33
|
+
export { TanakaStyle } from './style/TanakaStyle.js'
|
|
34
|
+
export { LegoStyle } from './style/LegoStyle.js'
|
|
35
|
+
export { SquareColorWGLStyle } from './style/SquareColorWGLStyle.js'
|
|
36
|
+
export { SquareColorCatWGLStyle } from './style/SquareColorCatWGLStyle.js'
|
|
37
|
+
export { MosaicStyle } from './style/MosaicStyle.js'
|
|
38
|
+
export { NinjaStarStyle } from './style/NinjaStarStyle.js'
|
|
39
|
+
export { TimeSeriesStyle } from './style/TimeSeriesStyle.js'
|
|
40
|
+
export { IsoFenceStyle } from './style/IsoFenceStyle.js'
|
|
41
|
+
|
|
42
|
+
// export additional layers
|
|
43
|
+
export { BackgroundLayer } from './BackgroundLayer.js'
|
|
44
|
+
export { BackgroundLayerWMS } from './BackgroundLayerWMS.js'
|
|
45
|
+
export { LabelLayer } from './LabelLayer.js'
|
|
46
|
+
export { LineLayer as BoundaryLayer } from './LineLayer.js'
|
|
47
|
+
|
|
48
|
+
// export legends
|
|
49
|
+
export { ColorLegend } from './legend/ColorLegend.js'
|
|
50
|
+
export { ColorDiscreteLegend } from './legend/ColorDiscreteLegend.js'
|
|
51
|
+
export { ColorCategoryLegend } from './legend/ColorCategoryLegend.js'
|
|
52
|
+
export { SizeLegend } from './legend/SizeLegend.js'
|
|
53
|
+
export { SegmentWidthLegend } from './legend/SegmentWidthLegend.js'
|
|
54
|
+
export { SegmentOrientationLegend } from './legend/SegmentOrientationLegend.js'
|
|
55
|
+
|
|
56
|
+
// export { goToStraight, zoomTo } from "./utils/zoomUtils"
|
|
57
|
+
export * from './utils/stretching.js'
|
|
58
|
+
|
|
59
|
+
export { getClass } from './utils/Utils.js'
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
import { GeoCanvas } from './GeoCanvas.js'
|
|
64
|
+
export const getParameterByName = GeoCanvas.getParameterByName
|
|
65
|
+
|
|
66
|
+
// set default d3 locale
|
|
67
|
+
import { formatDefaultLocale } from 'd3-format'
|
|
68
|
+
formatDefaultLocale({
|
|
69
|
+
decimal: '.',
|
|
70
|
+
thousands: ' ',
|
|
71
|
+
grouping: [3],
|
|
72
|
+
currency: ['', '€'],
|
|
73
|
+
})
|
|
@@ -1,124 +1,124 @@
|
|
|
1
|
-
//@ts-check
|
|
2
|
-
'use strict'
|
|
3
|
-
|
|
4
|
-
import { Legend } from '../Legend.js'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* A legend element for color categrories.
|
|
8
|
-
*
|
|
9
|
-
* @author Joseph Davies, Julien Gaffuri
|
|
10
|
-
*/
|
|
11
|
-
export class ColorCategoryLegend extends Legend {
|
|
12
|
-
/** @param {Object} opts */
|
|
13
|
-
constructor(opts) {
|
|
14
|
-
super(opts)
|
|
15
|
-
opts = opts || {}
|
|
16
|
-
|
|
17
|
-
//col/categories array, in display order
|
|
18
|
-
/**
|
|
19
|
-
* @private
|
|
20
|
-
* @type {Array.<Array.<string>>} */
|
|
21
|
-
this.colCat = opts.colCat || [['gray', '-']]
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* @private
|
|
25
|
-
* @type {import("../Style").Shape} */
|
|
26
|
-
this.shape = opts.shape || 'circle'
|
|
27
|
-
this.dimension = opts.dimension || { r: 8 }
|
|
28
|
-
this.strokeColor = opts.strokeColor || 'gray'
|
|
29
|
-
this.strokeWidth = opts.strokeWidth || 1
|
|
30
|
-
|
|
31
|
-
this.title = opts.title
|
|
32
|
-
this.titleFontSize = opts.titleFontSize || '0.8em'
|
|
33
|
-
this.titleFontWeight = opts.titleFontWeight || 'bold'
|
|
34
|
-
|
|
35
|
-
//label
|
|
36
|
-
this.labelFontSize = opts.labelFontSize || '0.8em'
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* @param {{ style: import("../Style").Style, r: number, zf: number, sSize: import("../Style").Stat, sColor: import("../Style").Stat }} opts
|
|
41
|
-
*/
|
|
42
|
-
update(opts) {
|
|
43
|
-
//clear
|
|
44
|
-
this.div.selectAll('*').remove()
|
|
45
|
-
|
|
46
|
-
//build
|
|
47
|
-
|
|
48
|
-
//title
|
|
49
|
-
if (this.title)
|
|
50
|
-
this.div
|
|
51
|
-
.append('div')
|
|
52
|
-
.style('font-size', this.titleFontSize)
|
|
53
|
-
.style('font-weight', this.titleFontWeight)
|
|
54
|
-
.style('margin-bottom', '7px')
|
|
55
|
-
.text(this.title)
|
|
56
|
-
|
|
57
|
-
//categories
|
|
58
|
-
const nb = this.colCat.length
|
|
59
|
-
if (nb == 0) return
|
|
60
|
-
|
|
61
|
-
for (let i = 0; i < nb; i++) {
|
|
62
|
-
const cat = this.colCat[i]
|
|
63
|
-
|
|
64
|
-
//make div for category
|
|
65
|
-
const d = this.div.append('div')
|
|
66
|
-
//to enable vertical centering
|
|
67
|
-
//.style("position", "relative")
|
|
68
|
-
|
|
69
|
-
const sw = this.strokeWidth
|
|
70
|
-
|
|
71
|
-
//draw graphic element: box / circle
|
|
72
|
-
if (this.shape === 'square') {
|
|
73
|
-
const h = this.dimension.h || 15
|
|
74
|
-
const w = this.dimension.w || 20
|
|
75
|
-
d.append('div')
|
|
76
|
-
.style('display', 'inline')
|
|
77
|
-
|
|
78
|
-
.append('svg')
|
|
79
|
-
.attr('width', w + 2 * sw)
|
|
80
|
-
.attr('height', h + 2 * sw)
|
|
81
|
-
|
|
82
|
-
.append('rect')
|
|
83
|
-
.attr('x', sw)
|
|
84
|
-
.attr('y', sw)
|
|
85
|
-
.attr('width', w)
|
|
86
|
-
.attr('height', h)
|
|
87
|
-
.style('fill', cat[0])
|
|
88
|
-
.style('stroke', this.strokeColor)
|
|
89
|
-
.style('stroke-width', this.strokeWidth)
|
|
90
|
-
} else if (this.shape === 'circle') {
|
|
91
|
-
const r = this.dimension.r || 8
|
|
92
|
-
const h = 2 * r + 2 * sw
|
|
93
|
-
d.append('div')
|
|
94
|
-
.style('display', 'inline')
|
|
95
|
-
|
|
96
|
-
.append('svg')
|
|
97
|
-
.attr('width', h)
|
|
98
|
-
.attr('height', h)
|
|
99
|
-
|
|
100
|
-
.append('circle')
|
|
101
|
-
.attr('cx', r + sw)
|
|
102
|
-
.attr('cy', r + sw)
|
|
103
|
-
.attr('r', r)
|
|
104
|
-
.style('fill', cat[0])
|
|
105
|
-
.style('stroke', this.strokeColor)
|
|
106
|
-
.style('stroke-width', this.strokeWidth)
|
|
107
|
-
} else {
|
|
108
|
-
throw new Error('Unexpected shape:' + this.shape)
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
//write label text
|
|
112
|
-
d.append('div')
|
|
113
|
-
//show on right of graphic
|
|
114
|
-
.style('display', 'inline')
|
|
115
|
-
|
|
116
|
-
//center vertically
|
|
117
|
-
//.style("position", "absolute").style("top", "0").style("bottom", "0")
|
|
118
|
-
|
|
119
|
-
.style('padding-left', '5px')
|
|
120
|
-
.style('font-size', this.labelFontSize)
|
|
121
|
-
.text(cat[1])
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
1
|
+
//@ts-check
|
|
2
|
+
'use strict'
|
|
3
|
+
|
|
4
|
+
import { Legend } from '../Legend.js'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A legend element for color categrories.
|
|
8
|
+
*
|
|
9
|
+
* @author Joseph Davies, Julien Gaffuri
|
|
10
|
+
*/
|
|
11
|
+
export class ColorCategoryLegend extends Legend {
|
|
12
|
+
/** @param {Object} opts */
|
|
13
|
+
constructor(opts) {
|
|
14
|
+
super(opts)
|
|
15
|
+
opts = opts || {}
|
|
16
|
+
|
|
17
|
+
//col/categories array, in display order
|
|
18
|
+
/**
|
|
19
|
+
* @private
|
|
20
|
+
* @type {Array.<Array.<string>>} */
|
|
21
|
+
this.colCat = opts.colCat || [['gray', '-']]
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @private
|
|
25
|
+
* @type {import("../Style").Shape} */
|
|
26
|
+
this.shape = opts.shape || 'circle'
|
|
27
|
+
this.dimension = opts.dimension || { r: 8 }
|
|
28
|
+
this.strokeColor = opts.strokeColor || 'gray'
|
|
29
|
+
this.strokeWidth = opts.strokeWidth || 1
|
|
30
|
+
|
|
31
|
+
this.title = opts.title
|
|
32
|
+
this.titleFontSize = opts.titleFontSize || '0.8em'
|
|
33
|
+
this.titleFontWeight = opts.titleFontWeight || 'bold'
|
|
34
|
+
|
|
35
|
+
//label
|
|
36
|
+
this.labelFontSize = opts.labelFontSize || '0.8em'
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @param {{ style: import("../Style").Style, r: number, zf: number, sSize: import("../Style").Stat, sColor: import("../Style").Stat }} opts
|
|
41
|
+
*/
|
|
42
|
+
update(opts) {
|
|
43
|
+
//clear
|
|
44
|
+
this.div.selectAll('*').remove()
|
|
45
|
+
|
|
46
|
+
//build
|
|
47
|
+
|
|
48
|
+
//title
|
|
49
|
+
if (this.title)
|
|
50
|
+
this.div
|
|
51
|
+
.append('div')
|
|
52
|
+
.style('font-size', this.titleFontSize)
|
|
53
|
+
.style('font-weight', this.titleFontWeight)
|
|
54
|
+
.style('margin-bottom', '7px')
|
|
55
|
+
.text(this.title)
|
|
56
|
+
|
|
57
|
+
//categories
|
|
58
|
+
const nb = this.colCat.length
|
|
59
|
+
if (nb == 0) return
|
|
60
|
+
|
|
61
|
+
for (let i = 0; i < nb; i++) {
|
|
62
|
+
const cat = this.colCat[i]
|
|
63
|
+
|
|
64
|
+
//make div for category
|
|
65
|
+
const d = this.div.append('div')
|
|
66
|
+
//to enable vertical centering
|
|
67
|
+
//.style("position", "relative")
|
|
68
|
+
|
|
69
|
+
const sw = this.strokeWidth
|
|
70
|
+
|
|
71
|
+
//draw graphic element: box / circle
|
|
72
|
+
if (this.shape === 'square') {
|
|
73
|
+
const h = this.dimension.h || 15
|
|
74
|
+
const w = this.dimension.w || 20
|
|
75
|
+
d.append('div')
|
|
76
|
+
.style('display', 'inline')
|
|
77
|
+
|
|
78
|
+
.append('svg')
|
|
79
|
+
.attr('width', w + 2 * sw)
|
|
80
|
+
.attr('height', h + 2 * sw)
|
|
81
|
+
|
|
82
|
+
.append('rect')
|
|
83
|
+
.attr('x', sw)
|
|
84
|
+
.attr('y', sw)
|
|
85
|
+
.attr('width', w)
|
|
86
|
+
.attr('height', h)
|
|
87
|
+
.style('fill', cat[0])
|
|
88
|
+
.style('stroke', this.strokeColor)
|
|
89
|
+
.style('stroke-width', this.strokeWidth)
|
|
90
|
+
} else if (this.shape === 'circle') {
|
|
91
|
+
const r = this.dimension.r || 8
|
|
92
|
+
const h = 2 * r + 2 * sw
|
|
93
|
+
d.append('div')
|
|
94
|
+
.style('display', 'inline')
|
|
95
|
+
|
|
96
|
+
.append('svg')
|
|
97
|
+
.attr('width', h)
|
|
98
|
+
.attr('height', h)
|
|
99
|
+
|
|
100
|
+
.append('circle')
|
|
101
|
+
.attr('cx', r + sw)
|
|
102
|
+
.attr('cy', r + sw)
|
|
103
|
+
.attr('r', r)
|
|
104
|
+
.style('fill', cat[0])
|
|
105
|
+
.style('stroke', this.strokeColor)
|
|
106
|
+
.style('stroke-width', this.strokeWidth)
|
|
107
|
+
} else {
|
|
108
|
+
throw new Error('Unexpected shape:' + this.shape)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
//write label text
|
|
112
|
+
d.append('div')
|
|
113
|
+
//show on right of graphic
|
|
114
|
+
.style('display', 'inline')
|
|
115
|
+
|
|
116
|
+
//center vertically
|
|
117
|
+
//.style("position", "absolute").style("top", "0").style("bottom", "0")
|
|
118
|
+
|
|
119
|
+
.style('padding-left', '5px')
|
|
120
|
+
.style('font-size', this.labelFontSize)
|
|
121
|
+
.text(cat[1])
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -1,103 +1,103 @@
|
|
|
1
|
-
//@ts-check
|
|
2
|
-
'use strict'
|
|
3
|
-
|
|
4
|
-
import { Legend } from '../Legend.js'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* A legend element for discrete color style.
|
|
8
|
-
* Inspiration: https://observablehq.com/@d3/color-legend
|
|
9
|
-
*
|
|
10
|
-
* @author Julien Gaffuri
|
|
11
|
-
*/
|
|
12
|
-
export class ColorDiscreteLegend extends Legend {
|
|
13
|
-
/** @param {Object} opts */
|
|
14
|
-
constructor(opts) {
|
|
15
|
-
super(opts)
|
|
16
|
-
opts = opts || {}
|
|
17
|
-
|
|
18
|
-
/** @private @type {Array.<Array.<string>>} */
|
|
19
|
-
this.colors = opts.colors
|
|
20
|
-
/** @private @type {Array.<Array.<string>>} */
|
|
21
|
-
this.breaksText = opts.breaksText
|
|
22
|
-
|
|
23
|
-
this.width = opts.width || 300
|
|
24
|
-
this.height = opts.height || 15
|
|
25
|
-
|
|
26
|
-
this.title = opts.title
|
|
27
|
-
this.titleFontSize = opts.titleFontSize || '0.8em'
|
|
28
|
-
this.titleFontWeight = opts.titleFontWeight || 'bold'
|
|
29
|
-
|
|
30
|
-
this.tickSize = opts.tickSize || 3
|
|
31
|
-
|
|
32
|
-
//label
|
|
33
|
-
this.labelFontSize = opts.labelFontSize || '0.8em'
|
|
34
|
-
this.invert = opts.invert
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* @param {{ style: import("../Style").Style, r: number, zf: number, sSize: import("../Style").Stat, sColor: import("../Style").Stat }} opts
|
|
39
|
-
*/
|
|
40
|
-
update(opts) {
|
|
41
|
-
//clear
|
|
42
|
-
this.div.selectAll('*').remove()
|
|
43
|
-
|
|
44
|
-
//build
|
|
45
|
-
|
|
46
|
-
//title
|
|
47
|
-
if (this.title)
|
|
48
|
-
this.div
|
|
49
|
-
.append('div')
|
|
50
|
-
.style('font-size', this.titleFontSize)
|
|
51
|
-
.style('font-weight', this.titleFontWeight)
|
|
52
|
-
.style('margin-bottom', '7px')
|
|
53
|
-
.text(this.title)
|
|
54
|
-
|
|
55
|
-
//classes
|
|
56
|
-
const nb = this.colors.length
|
|
57
|
-
if (nb == 0) return
|
|
58
|
-
const w = this.width / nb
|
|
59
|
-
|
|
60
|
-
//make svg element
|
|
61
|
-
const svg = this.div
|
|
62
|
-
.append('svg')
|
|
63
|
-
.attr('width', this.width)
|
|
64
|
-
.attr('height', this.height + this.tickSize + 2 + 10)
|
|
65
|
-
|
|
66
|
-
//draw graphic elements
|
|
67
|
-
for (let i = 0; i < nb; i++) {
|
|
68
|
-
svg.append('rect')
|
|
69
|
-
.attr('x', i * w)
|
|
70
|
-
.attr('y', 0)
|
|
71
|
-
.attr('width', w)
|
|
72
|
-
.attr('height', this.height)
|
|
73
|
-
.style('fill', this.colors[i])
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
//tick line
|
|
77
|
-
for (let i = 1; i < nb; i++) {
|
|
78
|
-
svg.append('line')
|
|
79
|
-
.attr('x1', w * i)
|
|
80
|
-
.attr('y1', 0)
|
|
81
|
-
.attr('x2', w * i)
|
|
82
|
-
.attr('y2', this.height + this.tickSize)
|
|
83
|
-
.style('stroke', 'black')
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
//labels
|
|
87
|
-
for (let i = 1; i < nb; i++) {
|
|
88
|
-
//prepare label
|
|
89
|
-
svg.append('text')
|
|
90
|
-
.attr('id', 'ticklabel_' + i)
|
|
91
|
-
.attr('x', w * i)
|
|
92
|
-
.attr('y', this.height + this.tickSize + 2)
|
|
93
|
-
.style('font-size', this.labelFontSize)
|
|
94
|
-
//.style("font-weight", "bold")
|
|
95
|
-
//.style("font-family", "Arial")
|
|
96
|
-
.style('text-anchor', i == 0 ? 'start' : i == this.ticks - 1 ? 'end' : 'middle')
|
|
97
|
-
.style('alignment-baseline', 'top')
|
|
98
|
-
.style('dominant-baseline', 'hanging')
|
|
99
|
-
.style('pointer-events', 'none')
|
|
100
|
-
.text(this.breaksText[i - 1])
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
1
|
+
//@ts-check
|
|
2
|
+
'use strict'
|
|
3
|
+
|
|
4
|
+
import { Legend } from '../Legend.js'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A legend element for discrete color style.
|
|
8
|
+
* Inspiration: https://observablehq.com/@d3/color-legend
|
|
9
|
+
*
|
|
10
|
+
* @author Julien Gaffuri
|
|
11
|
+
*/
|
|
12
|
+
export class ColorDiscreteLegend extends Legend {
|
|
13
|
+
/** @param {Object} opts */
|
|
14
|
+
constructor(opts) {
|
|
15
|
+
super(opts)
|
|
16
|
+
opts = opts || {}
|
|
17
|
+
|
|
18
|
+
/** @private @type {Array.<Array.<string>>} */
|
|
19
|
+
this.colors = opts.colors
|
|
20
|
+
/** @private @type {Array.<Array.<string>>} */
|
|
21
|
+
this.breaksText = opts.breaksText
|
|
22
|
+
|
|
23
|
+
this.width = opts.width || 300
|
|
24
|
+
this.height = opts.height || 15
|
|
25
|
+
|
|
26
|
+
this.title = opts.title
|
|
27
|
+
this.titleFontSize = opts.titleFontSize || '0.8em'
|
|
28
|
+
this.titleFontWeight = opts.titleFontWeight || 'bold'
|
|
29
|
+
|
|
30
|
+
this.tickSize = opts.tickSize || 3
|
|
31
|
+
|
|
32
|
+
//label
|
|
33
|
+
this.labelFontSize = opts.labelFontSize || '0.8em'
|
|
34
|
+
this.invert = opts.invert
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @param {{ style: import("../Style").Style, r: number, zf: number, sSize: import("../Style").Stat, sColor: import("../Style").Stat }} opts
|
|
39
|
+
*/
|
|
40
|
+
update(opts) {
|
|
41
|
+
//clear
|
|
42
|
+
this.div.selectAll('*').remove()
|
|
43
|
+
|
|
44
|
+
//build
|
|
45
|
+
|
|
46
|
+
//title
|
|
47
|
+
if (this.title)
|
|
48
|
+
this.div
|
|
49
|
+
.append('div')
|
|
50
|
+
.style('font-size', this.titleFontSize)
|
|
51
|
+
.style('font-weight', this.titleFontWeight)
|
|
52
|
+
.style('margin-bottom', '7px')
|
|
53
|
+
.text(this.title)
|
|
54
|
+
|
|
55
|
+
//classes
|
|
56
|
+
const nb = this.colors.length
|
|
57
|
+
if (nb == 0) return
|
|
58
|
+
const w = this.width / nb
|
|
59
|
+
|
|
60
|
+
//make svg element
|
|
61
|
+
const svg = this.div
|
|
62
|
+
.append('svg')
|
|
63
|
+
.attr('width', this.width)
|
|
64
|
+
.attr('height', this.height + this.tickSize + 2 + 10)
|
|
65
|
+
|
|
66
|
+
//draw graphic elements
|
|
67
|
+
for (let i = 0; i < nb; i++) {
|
|
68
|
+
svg.append('rect')
|
|
69
|
+
.attr('x', i * w)
|
|
70
|
+
.attr('y', 0)
|
|
71
|
+
.attr('width', w)
|
|
72
|
+
.attr('height', this.height)
|
|
73
|
+
.style('fill', this.colors[i])
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
//tick line
|
|
77
|
+
for (let i = 1; i < nb; i++) {
|
|
78
|
+
svg.append('line')
|
|
79
|
+
.attr('x1', w * i)
|
|
80
|
+
.attr('y1', 0)
|
|
81
|
+
.attr('x2', w * i)
|
|
82
|
+
.attr('y2', this.height + this.tickSize)
|
|
83
|
+
.style('stroke', 'black')
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
//labels
|
|
87
|
+
for (let i = 1; i < nb; i++) {
|
|
88
|
+
//prepare label
|
|
89
|
+
svg.append('text')
|
|
90
|
+
.attr('id', 'ticklabel_' + i)
|
|
91
|
+
.attr('x', w * i)
|
|
92
|
+
.attr('y', this.height + this.tickSize + 2)
|
|
93
|
+
.style('font-size', this.labelFontSize)
|
|
94
|
+
//.style("font-weight", "bold")
|
|
95
|
+
//.style("font-family", "Arial")
|
|
96
|
+
.style('text-anchor', i == 0 ? 'start' : i == this.ticks - 1 ? 'end' : 'middle')
|
|
97
|
+
.style('alignment-baseline', 'top')
|
|
98
|
+
.style('dominant-baseline', 'hanging')
|
|
99
|
+
.style('pointer-events', 'none')
|
|
100
|
+
.text(this.breaksText[i - 1])
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|