gridviz 3.0.9 → 3.0.11

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gridviz",
3
- "version": "3.0.9",
3
+ "version": "3.0.11",
4
4
  "description": "Visualization tool for gridded statistics",
5
5
  "keywords": [
6
6
  "statistics",
@@ -23,7 +23,7 @@
23
23
  "license": "EUPL-1.2",
24
24
  "repository": {
25
25
  "type": "git",
26
- "url": "https://github.com/eurostat/gridviz.git"
26
+ "url": "git+https://github.com/eurostat/gridviz.git"
27
27
  },
28
28
  "bugs": {
29
29
  "url": "https://github.com/eurostat/gridviz/issues",
@@ -40,7 +40,7 @@
40
40
  "start": "export NODE_OPTIONS=--openssl-legacy-provider && webpack --config webpack.config.dev.cjs",
41
41
  "start-dev": "webpack --config webpack.config.dev.cjs",
42
42
  "server": "webpack serve -c webpack.config.dev.cjs",
43
- "doc": "./node_modules/.bin/jsdoc -c docs/jsdoc/jsdoc.conf.json",
43
+ "doc": "jsdoc -c docs/jsdoc/jsdoc.conf.json",
44
44
  "bp": "webpack --config webpack.config.prod.cjs",
45
45
  "test": "jest"
46
46
  },
@@ -59,16 +59,11 @@
59
59
  "jsdoc": "^4.0.2"
60
60
  },
61
61
  "devDependencies": {
62
- "@babel/core": "^7.9.0",
63
- "@babel/plugin-transform-runtime": "^7.12.1",
64
- "@babel/preset-env": "^7.9.0",
65
- "@babel/runtime": "^7.12.1",
62
+ "@babel/preset-env": "^7.25.4",
66
63
  "babel-loader": "^8.1.0",
67
- "jest": "^26.6.1",
68
64
  "jshint": "^2.12.0",
69
65
  "prettier": "2.8.8",
70
- "puppeteer": "^9.1.1",
71
- "webpack": "^5.89.0",
66
+ "webpack": "^5.94.0",
72
67
  "webpack-cli": "^5.1.4",
73
68
  "webpack-dev-server": "^4.15.1",
74
69
  "webpack-livereload-plugin": "^3.0.2"
@@ -18,16 +18,15 @@ export class Button {
18
18
  * opts.y
19
19
  */
20
20
  constructor(opts = {}) {
21
-
22
21
  this.map = opts.map
23
22
  this.parentNode = opts.parentNode || opts.map.container
24
23
 
25
24
  // the div element
26
- if (this.id) this.div = select('#' + this.id)
25
+ if (opts.id) this.div = select('#' + opts.id)
27
26
 
28
27
  if (!this.div || this.div.empty()) {
29
28
  this.div = select(document.createElement('div'))
30
- if (this.id) this.div.attr('id', this.id)
29
+ if (opts.id) this.div.attr('id', opts.id)
31
30
  }
32
31
 
33
32
  if (opts.title) this.div.attr('title', opts.title)
@@ -37,7 +36,10 @@ export class Button {
37
36
  if (opts.onClickFunction) this.div.on('click', opts.onClickFunction)
38
37
 
39
38
  //set styles
40
- this.style('box-shadow', '0 7px 8px rgba(0,47,103,.08), 0 0 22px rgba(0,47,103,.04), 0 12px 17px rgba(0,47,103,.04), 0 -4px 4px rgba(0,47,103,.04)') //.ecl-u-shadow-3
39
+ this.style(
40
+ 'box-shadow',
41
+ '0 7px 8px rgba(0,47,103,.08), 0 0 22px rgba(0,47,103,.04), 0 12px 17px rgba(0,47,103,.04), 0 -4px 4px rgba(0,47,103,.04)'
42
+ ) //.ecl-u-shadow-3
41
43
  this.style('background-color', '#ffffff')
42
44
  this.style('position', 'absolute')
43
45
  this.style('cursor', 'pointer')
@@ -48,7 +50,6 @@ export class Button {
48
50
  this.style('height', '30px')
49
51
  // this.style(padding , '4px'
50
52
 
51
-
52
53
  // append to parent
53
54
  this.parentNode.appendChild(this.div.node())
54
55
  }
@@ -29,11 +29,40 @@ export class GeoJSONLayer extends Layer {
29
29
  * @type {function(object):boolean} */
30
30
  this.preprocess = opts.preprocess
31
31
 
32
+ //for points
33
+ /**
34
+ * @private
35
+ * @type {function(object,number):string} */
36
+ this.shape = opts.shape || ((f, z) => 'circle')
37
+ /**
38
+ * In pixel
39
+ * @private
40
+ * @type {function(object,number):number} */
41
+ this.size = opts.size || ((f, z) => 10)
42
+ /**
43
+ * @private
44
+ * @type {function(object,number):string} */
45
+ this.strokeStyle = opts.strokeStyle || ((f, z) => 'red')
46
+ /**
47
+ * @private
48
+ * @type {function(object,number):string} */
49
+ this.fillStyle = opts.fillStyle || ((f, z) => 'black')
50
+ /**
51
+ * In pixel
52
+ * @private
53
+ * @type {function(object,number):number} */
54
+ this.lineWidth = opts.lineWidth || ((f, z) => 2)
55
+
56
+
57
+
58
+ //for lines
59
+
32
60
  /**
33
61
  * @private
34
62
  * @type {function(object,number):string} */
35
63
  this.color = opts.color || ((f, z) => 'gray')
36
64
  /**
65
+ * In pixel
37
66
  * @private
38
67
  * @type {function(object,number):number} */
39
68
  this.width = opts.width || ((f, z) => 2)
@@ -42,6 +71,7 @@ export class GeoJSONLayer extends Layer {
42
71
  * @type {function(object,number):Array.<number>|undefined} */
43
72
  this.lineDash = opts.lineDash || ((f, z) => undefined)
44
73
 
74
+
45
75
  /**
46
76
  * @private
47
77
  * @type {Array.<object> | undefined} */
@@ -53,6 +83,7 @@ export class GeoJSONLayer extends Layer {
53
83
  this.loadingStatus = 'notLoaded'
54
84
  }
55
85
 
86
+
56
87
  /**
57
88
  * Draw the layer.
58
89
  * @param {import("../core/GeoCanvas.js").GeoCanvas} geoCanvas The canvas where to draw the layer.
@@ -65,34 +96,73 @@ export class GeoJSONLayer extends Layer {
65
96
  return
66
97
  }
67
98
 
68
- //TODO sort lines by width ?
69
-
70
99
  //
71
100
  const z = geoCanvas.view.z
72
101
 
73
102
  for (const f of this.fs) {
74
- const cs = f.geometry.coordinates
75
- if (cs.length < 2) continue
76
-
77
- //set color
78
- const col = this.color(f, z)
79
- if (!col || col == 'none') continue
80
- geoCanvas.ctx.strokeStyle = col
81
-
82
- //set linewidth
83
- const wP = this.width(f, z)
84
- if (!wP || wP < 0) continue
85
- geoCanvas.ctx.lineWidth = wP * z
86
-
87
- //set line dash
88
- const ldP = this.lineDash(f, z)
89
- if (ldP) geoCanvas.ctx.setLineDash(ldP)
90
-
91
- //draw line
92
- geoCanvas.ctx.beginPath()
93
- geoCanvas.ctx.moveTo(cs[0][0], cs[0][1])
94
- for (let i = 1; i < cs.length; i++) geoCanvas.ctx.lineTo(cs[i][0], cs[i][1])
95
- geoCanvas.ctx.stroke()
103
+ const gt = f.geometry.type
104
+
105
+ if (gt == "Point") {
106
+ const c = f.geometry.coordinates
107
+
108
+ //get style parameters for the point feature
109
+ const shape = this.shape(f,z)
110
+ if(!shape || shape=="none") continue
111
+ const size = this.size(f,z) * z
112
+ if(!size) continue
113
+ const strokeStyle = this.strokeStyle(f,z)
114
+ const fillStyle = this.fillStyle(f,z)
115
+ const lineWidth = this.lineWidth(f,z) * z
116
+
117
+ //set canvas drawing parameters
118
+ if(strokeStyle) geoCanvas.ctx.strokeStyle = strokeStyle
119
+ if(fillStyle) geoCanvas.ctx.fillStyle = fillStyle
120
+ if(lineWidth) geoCanvas.ctx.lineWidth = lineWidth
121
+
122
+ if (shape == "circle") {
123
+ //draw circle - fill and stroke
124
+ geoCanvas.ctx.beginPath()
125
+ geoCanvas.ctx.arc(c[0], c[1], size / 2, 0, 2 * Math.PI, false)
126
+ if(fillStyle) geoCanvas.ctx.fill()
127
+ if(strokeStyle && lineWidth) geoCanvas.ctx.stroke()
128
+ } else if (shape == "square") {
129
+ //draw square - fill and stroke
130
+ geoCanvas.ctx.beginPath()
131
+ geoCanvas.ctx.rect(c[0] - size / 2, c[1] - size / 2, size, size)
132
+ if(fillStyle) geoCanvas.ctx.fill()
133
+ if(strokeStyle && lineWidth) geoCanvas.ctx.stroke()
134
+ } else {
135
+ console.error("Unexpected shape for point geojson: " + shape)
136
+ }
137
+
138
+ } else if (gt == "LineString") {
139
+
140
+ const cs = f.geometry.coordinates
141
+ if (cs.length < 2) continue
142
+
143
+ //set color
144
+ const col = this.color(f, z)
145
+ if (!col || col == 'none') continue
146
+ geoCanvas.ctx.strokeStyle = col
147
+
148
+ //set linewidth
149
+ const wP = this.width(f, z)
150
+ if (!wP || wP < 0) continue
151
+ geoCanvas.ctx.lineWidth = wP * z
152
+
153
+ //set line dash
154
+ const ldP = this.lineDash(f, z)
155
+ if (ldP) geoCanvas.ctx.setLineDash(ldP)
156
+
157
+ //draw line
158
+ geoCanvas.ctx.beginPath()
159
+ geoCanvas.ctx.moveTo(cs[0][0], cs[0][1])
160
+ for (let i = 1; i < cs.length; i++) geoCanvas.ctx.lineTo(cs[i][0], cs[i][1])
161
+ geoCanvas.ctx.stroke()
162
+ } else {
163
+ console.log("Unsupported geometry type in GeoJSONLayer: " + gt)
164
+ }
165
+
96
166
  }
97
167
 
98
168
  //...
@@ -82,6 +82,7 @@ export class ColorDiscreteLegend extends Legend {
82
82
 
83
83
  let label = breaks[i - 1]
84
84
  if (isNaN(label) || label == undefined) continue
85
+ if(this.labelFormat) label = this.labelFormat(label)
85
86
 
86
87
  //label
87
88
  svg.append('text')
@@ -51,6 +51,7 @@ export class SideCategoryStyle extends SideStyle {
51
51
  //draw sides
52
52
 
53
53
  geoCanvas.ctx.lineCap = 'butt'
54
+ const r2 = resolution*0.5
54
55
  for (let side of sides) {
55
56
 
56
57
  //get category codes for both cells
@@ -73,8 +74,8 @@ export class SideCategoryStyle extends SideStyle {
73
74
  if (code2) {
74
75
  geoCanvas.ctx.beginPath()
75
76
  geoCanvas.ctx.strokeStyle = this.color[code2]
76
- geoCanvas.ctx.moveTo(side.x, side.y + w2)
77
- geoCanvas.ctx.lineTo(side.x + resolution, side.y + w2)
77
+ geoCanvas.ctx.moveTo(side.x-r2, side.y + w2)
78
+ geoCanvas.ctx.lineTo(side.x+r2, side.y + w2)
78
79
  geoCanvas.ctx.stroke()
79
80
  }
80
81
 
@@ -82,8 +83,8 @@ export class SideCategoryStyle extends SideStyle {
82
83
  if (code1) {
83
84
  geoCanvas.ctx.beginPath()
84
85
  geoCanvas.ctx.strokeStyle = this.color[code1]
85
- geoCanvas.ctx.moveTo(side.x, side.y - w2)
86
- geoCanvas.ctx.lineTo(side.x + resolution, side.y - w2)
86
+ geoCanvas.ctx.moveTo(side.x-r2, side.y - w2)
87
+ geoCanvas.ctx.lineTo(side.x+r2, side.y - w2)
87
88
  geoCanvas.ctx.stroke()
88
89
  }
89
90
  } else {
@@ -91,8 +92,8 @@ export class SideCategoryStyle extends SideStyle {
91
92
  if (code2) {
92
93
  geoCanvas.ctx.beginPath()
93
94
  geoCanvas.ctx.strokeStyle = this.color[code2]
94
- geoCanvas.ctx.moveTo(side.x + w2, side.y)
95
- geoCanvas.ctx.lineTo(side.x + w2, side.y + resolution)
95
+ geoCanvas.ctx.moveTo(side.x + w2, side.y-r2)
96
+ geoCanvas.ctx.lineTo(side.x + w2, side.y+r2)
96
97
  geoCanvas.ctx.stroke()
97
98
  }
98
99
 
@@ -100,8 +101,8 @@ export class SideCategoryStyle extends SideStyle {
100
101
  if (code1) {
101
102
  geoCanvas.ctx.beginPath()
102
103
  geoCanvas.ctx.strokeStyle = this.color[code1]
103
- geoCanvas.ctx.moveTo(side.x - w2, side.y)
104
- geoCanvas.ctx.lineTo(side.x - w2, side.y + resolution)
104
+ geoCanvas.ctx.moveTo(side.x - w2, side.y-r2)
105
+ geoCanvas.ctx.lineTo(side.x - w2, side.y+r2)
105
106
  geoCanvas.ctx.stroke()
106
107
  }
107
108
  }