gridviz 3.0.37 → 3.0.38

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.
@@ -13,6 +13,7 @@ export class OrientationLegend extends Legend {
13
13
  /** @param {Object} opts */
14
14
  constructor(opts) {
15
15
  super(opts)
16
+ this.setType('orientation')
16
17
  opts = opts || {}
17
18
 
18
19
  //orientation
@@ -38,7 +39,7 @@ export class OrientationLegend extends Legend {
38
39
  //title
39
40
  this.makeTitle()
40
41
 
41
- const d = this.div.append('div')
42
+ const d = this.div.append('div').classed('gridviz-legend-category', true)
42
43
 
43
44
  //compute segment color, width and length
44
45
  const color = this.color(opts.resolution, opts.z, opts.viewScale)
@@ -63,9 +64,10 @@ export class OrientationLegend extends Legend {
63
64
 
64
65
  //label
65
66
  d.append('div')
67
+ .classed('gridviz-legend-label', true)
66
68
  .style('display', 'inline')
67
69
  .style('padding-left', '5px')
68
- .style('font-size', this.labelFontSize)
70
+ .style('font-size', this.labelFontSizeCSS())
69
71
  .text(this.label + (this.labelUnitText ? ' ' : '') + this.labelUnitText)
70
72
  }
71
73
  }
@@ -15,6 +15,7 @@ export class SizeLegend extends Legend {
15
15
  /** @param {Object} opts */
16
16
  constructor(opts) {
17
17
  super(opts)
18
+ this.setType('size')
18
19
  opts = opts || {}
19
20
 
20
21
  /** A function returning the text label, from the view scale and list of cells, resolution and zoom
@@ -62,7 +63,7 @@ export class SizeLegend extends Legend {
62
63
  //format label, if specified and possible
63
64
  if (this.labelFormat && !isNaN(+label)) label = this.labelFormat(label)
64
65
 
65
- const d = this.div.append('div')
66
+ const d = this.div.append('div').classed('gridviz-legend-category', true)
66
67
  //to enable vertical centering
67
68
  //.style("position", "relative")
68
69
 
@@ -127,9 +128,10 @@ export class SizeLegend extends Legend {
127
128
 
128
129
  //label
129
130
  d.append('div')
131
+ .classed('gridviz-legend-label', true)
130
132
  .style('display', 'inline')
131
133
  .style('padding-left', '5px')
132
- .style('font-size', this.labelFontSize)
134
+ .style('font-size', this.labelFontSizeCSS())
133
135
  .text(label + (this.labelUnitText ? ' ' : '') + this.labelUnitText)
134
136
  }
135
137
  }
@@ -28,6 +28,7 @@ export class TernaryLegend extends Legend {
28
28
  this.rightText = opts.rightText || 'Category 2'
29
29
 
30
30
  this.centerCoefficient = opts.centerCoefficient || this.classifier.centerCoefficient
31
+ this.setType('ternary')
31
32
  }
32
33
 
33
34
  /**
@@ -51,6 +52,7 @@ export class TernaryLegend extends Legend {
51
52
 
52
53
  const padding = 2
53
54
  const fontSize = 12
55
+ const legend = this
54
56
 
55
57
  //make svg element
56
58
  const svg = this.div
@@ -62,6 +64,7 @@ export class TernaryLegend extends Legend {
62
64
  svg.append('text')
63
65
  .attr('x', w / 2)
64
66
  .attr('y', padding + fontSize)
67
+ .classed('gridviz-legend-label', true)
65
68
  .text(this.topText)
66
69
  .attr('font-size', fontSize)
67
70
  .attr('text-anchor', 'middle')
@@ -69,6 +72,7 @@ export class TernaryLegend extends Legend {
69
72
  svg.append('text')
70
73
  .attr('x', 0)
71
74
  .attr('y', 3 * padding + 2 * fontSize + h)
75
+ .classed('gridviz-legend-label', true)
72
76
  .text(this.leftText)
73
77
  .attr('font-size', fontSize)
74
78
  .attr('text-anchor', 'start')
@@ -76,6 +80,7 @@ export class TernaryLegend extends Legend {
76
80
  svg.append('text')
77
81
  .attr('x', w)
78
82
  .attr('y', 3 * padding + 2 * fontSize + h)
83
+ .classed('gridviz-legend-label', true)
79
84
  .text(this.rightText)
80
85
  .attr('font-size', fontSize)
81
86
  .attr('text-anchor', 'end')
@@ -96,12 +101,16 @@ export class TernaryLegend extends Legend {
96
101
  const setAttributes = (elt, color, text) => {
97
102
  //elt.raise();
98
103
  elt.attr('fill', color)
104
+ .classed('gridviz-legend-swatch', true)
99
105
  //.attr("stroke", colorOver)
100
106
  //.attr("stroke-width", 0)
101
107
  //.attr("stroke-linejoin", "round")
108
+ .style('cursor', this.interactive ? 'pointer' : null)
102
109
  .on('mouseover', function (e) {
103
110
  /*this.parentNode.appendChild(this); select(this).attr("stroke-width", selectionStrokeWidth);*/
104
111
  select(this).attr('fill', selectionColor)
112
+ // show only the cells of this class on the map
113
+ legend.highlight([color])
105
114
  if (!tt || !text) return
106
115
  tt.html(text)
107
116
  tt.setPosition(e)
@@ -110,6 +119,7 @@ export class TernaryLegend extends Legend {
110
119
  .on('mouseout', function () {
111
120
  /*select(this).attr("stroke-width", 0);*/
112
121
  select(this).attr('fill', color)
122
+ legend.highlight(null)
113
123
  if (tt) tt.hide()
114
124
  })
115
125
  if (tt && text)
@@ -45,6 +45,9 @@ export class ShapeColorSizeStyle extends Style {
45
45
 
46
46
  const r2 = resolution * 0.5
47
47
 
48
+ // the legend swatch hovered, if any: only the cells of its colour are drawn
49
+ const highlight = this.highlightColors
50
+
48
51
  // Precompute if color, size, and shape are functions, for efficiency
49
52
  const isColorFunction = typeof this.color === 'function'
50
53
  const isSizeFunction = typeof this.size === 'function'
@@ -64,6 +67,7 @@ export class ShapeColorSizeStyle extends Style {
64
67
  //@ts-ignore
65
68
  const col = colorFunction ? colorFunction(c, resolution, z, viewScale) : defaultColor
66
69
  if (!col || col === 'none') continue
70
+ if (highlight && !this.isHighlighted(col)) continue
67
71
 
68
72
  // Determine size
69
73
  //@ts-ignore
@@ -86,6 +86,8 @@ export class SquareColorCategoryWebGLStyle extends Style {
86
86
  this.y = undefined
87
87
  this.z = undefined
88
88
  this.cellsNb = undefined
89
+ /** The highlight (see Style.setHighlight) the vertices were bound with @private */
90
+ this.highlightKey = ''
89
91
  }
90
92
 
91
93
  /**
@@ -149,6 +151,8 @@ export class SquareColorCategoryWebGLStyle extends Style {
149
151
  nb = cells.length
150
152
  const verticesBuffer = new Float32Array(2 * nb)
151
153
  const iBuffer = new Float32Array(nb)
154
+ // categories shown while a legend swatch is hovered: those drawn in the colour of the swatch
155
+ const shown = this.highlightColors ? this.colors.map((c) => this.isHighlighted(c)) : null
152
156
  let n = 0
153
157
  for (let i = 0; i < nb; i++) {
154
158
  c = cells[i]
@@ -162,6 +166,7 @@ export class SquareColorCategoryWebGLStyle extends Style {
162
166
  console.log('Unexpected category index: ' + cat + ' ' + i_)
163
167
  continue
164
168
  }
169
+ if (shown && !shown[+i_]) continue
165
170
  verticesBuffer[2 * n] = c.x + r2
166
171
  verticesBuffer[2 * n + 1] = c.y + r2
167
172
  iBuffer[n] = +i_
@@ -228,7 +233,10 @@ export class SquareColorCategoryWebGLStyle extends Style {
228
233
  // x/y/z and cell count alone. The upload is also needed when the shared buffers
229
234
  // hold another style's data (bufferOwner), or the context is new to this style
230
235
  // (e.g. replaced after being lost).
231
- const contentChanged = this.mapContentChanged(geoCanvas.view, cells.length)
236
+ const highlightKey = this.highlightColors ? this.highlightColors.join('|') : ''
237
+ const highlightChanged = highlightKey !== this.highlightKey
238
+ this.highlightKey = highlightKey
239
+ const contentChanged = this.mapContentChanged(geoCanvas.view, cells.length) || highlightChanged
232
240
  if (contentChanged || contextChanged || bufferOwner(gl, POSITION_BUFFER) !== this)
233
241
  this.pointsNb = this.bindVertices(cells, resolution, z, viewScale)
234
242
  this.bindAttributes()