gridviz 3.0.41 → 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 (48) hide show
  1. package/README.md +18 -15
  2. package/dist/gridviz.js +3227 -1941
  3. package/dist/gridviz.min.js +1 -1
  4. package/package.json +6 -4
  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/Drawable.js +25 -3
  9. package/src/core/GeoCanvas.js +15 -0
  10. package/src/core/Legend.js +267 -245
  11. package/src/core/Map.js +180 -30
  12. package/src/core/Tooltip.js +191 -185
  13. package/src/dataset/TiledGrid.js +74 -24
  14. package/src/index.js +82 -79
  15. package/src/layer/GridLayer.js +196 -194
  16. package/src/layer/LabelLayer.js +7 -4
  17. package/src/legend/ColorCategoryLegend.js +127 -125
  18. package/src/legend/ColorDiscreteLegend.js +116 -114
  19. package/src/legend/ColorLegend.js +33 -11
  20. package/src/legend/OrientationLegend.js +94 -92
  21. package/src/legend/SizeLegend.js +8 -1
  22. package/src/legend/TernaryLegend.js +317 -314
  23. package/src/legend/VennLegend.js +202 -0
  24. package/src/style/CircleColorSizeWebGLStyle.js +249 -0
  25. package/src/style/CompositionStyle.js +1 -1
  26. package/src/style/DotDensityStyle.js +8 -4
  27. package/src/style/ImageStyle.js +1 -1
  28. package/src/style/Interpolator.js +31 -6
  29. package/src/style/IsoFenceStyle.js +1 -1
  30. package/src/style/LegoStyle.js +6 -5
  31. package/src/style/MosaicStyle.js +1 -1
  32. package/src/style/NinjaStarStyle.js +1 -1
  33. package/src/style/PillarStyle.js +1 -1
  34. package/src/style/RandomWalkInterpolator.js +213 -0
  35. package/src/style/ShadingRayStyle.js +16 -2
  36. package/src/style/ShadingStyle.js +80 -72
  37. package/src/style/ShapeColorSizeStyle.js +18 -2
  38. package/src/style/SideCategoryStyle.js +1 -1
  39. package/src/style/SideStyle.js +1 -1
  40. package/src/style/SideTanakaStyle.js +1 -1
  41. package/src/style/SquareColorCategoryWebGLStyle.js +71 -20
  42. package/src/style/SquareColorWebGLStyle.js +7 -4
  43. package/src/style/StrokeStyle.js +1 -1
  44. package/src/style/TextStyle.js +1 -1
  45. package/src/style/TimeSeriesStyle.js +14 -7
  46. package/src/utils/WebGLSquareColoringAdvanced.js +47 -9
  47. package/src/utils/scale.js +20 -0
  48. package/src/utils/webGLUtils.js +52 -0
@@ -1,92 +1,94 @@
1
- //@ts-check
2
- 'use strict'
3
-
4
- import { Legend } from '../core/Legend.js'
5
-
6
- /**
7
- * A legend element for segment orientation.
8
- *
9
- * @module legend
10
- * @author Joseph Davies, Julien Gaffuri
11
- */
12
- export class OrientationLegend extends Legend {
13
- /** @param {Object} opts */
14
- constructor(opts) {
15
- super(opts)
16
- this.setType('orientation')
17
- opts = opts || {}
18
-
19
- //orientation
20
- this.orientation = opts.orientation || 0
21
- //color
22
- this.color = opts.color || ((resolution, z, viewScale) => 'gray')
23
- //width
24
- this.width = opts.width || ((resolution, z, viewScale) => 3 * z)
25
- //length
26
- this.length = opts.length || ((resolution, z, viewScale) => resolution)
27
-
28
- //label
29
- this.label = opts.label || '-'
30
- }
31
-
32
- /**
33
- * @param {{ style: import("../style/SegmentStyle.js").SegmentStyle, resolution: number, z: number, viewScale:object }} opts
34
- */
35
- update(opts) {
36
- //clear
37
- this.div.selectAll('*').remove()
38
-
39
- //title
40
- this.makeTitle()
41
-
42
- const d = this.div.append('div').classed('gridviz-legend-category', true)
43
-
44
- //compute segment color, width and length
45
- const color = this.color(opts.resolution, opts.z, opts.viewScale)
46
- const widthPix = this.width(opts.resolution, opts.z, opts.viewScale) / opts.z
47
- const lengthPix = this.length(opts.resolution, opts.z, opts.viewScale) / opts.z
48
-
49
- //draw SVG segment
50
- const svgS = Math.max(lengthPix, widthPix)
51
- const svg = d.append('svg').classed('gridviz-legend-graphic', true).attr('width', svgS).attr('height', svgS).style('', 'inline-block')
52
-
53
- const cos = Math.cos((-this.orientation * Math.PI) / 180)
54
- const sin = Math.sin((-this.orientation * Math.PI) / 180)
55
- const dc = svgS * 0.5,
56
- l2 = lengthPix * 0.5
57
- svg.append('line')
58
- .classed('gridviz-legend-symbol', true)
59
- .attr('x1', dc - cos * l2)
60
- .attr('y1', dc - sin * l2)
61
- .attr('x2', dc + cos * l2)
62
- .attr('y2', dc + sin * l2)
63
- .style('stroke', color)
64
- .style('stroke-width', widthPix)
65
-
66
- //label
67
- d.append('div')
68
- .classed('gridviz-legend-label', true)
69
- .style('display', 'inline')
70
- .style('padding-left', '5px')
71
- .style('font-size', this.labelFontSizeCSS())
72
- .text(this.label + (this.labelUnitText ? ' ' : '') + this.labelUnitText)
73
- }
74
- }
75
-
76
- /**
77
- *
78
- * @param {Array.<number>} orientations
79
- * @param {Array.<string>} labels
80
- * @param {object} opts
81
- * @returns { Array.<OrientationLegend> }
82
- */
83
- export function orientationLegend(orientations, labels, opts = {}) {
84
- const legends = []
85
- for (let i = 0; i < orientations.length; i++) {
86
- opts.title = i == 0 ? opts.title : undefined
87
- opts.orientation = orientations[i]
88
- opts.label = labels[i]
89
- legends.push(new OrientationLegend(opts))
90
- }
91
- return legends
92
- }
1
+ //@ts-check
2
+ 'use strict'
3
+
4
+ import { Legend } from '../core/Legend.js'
5
+
6
+ /**
7
+ * A legend element for segment orientation.
8
+ *
9
+ * @module legend
10
+ * @author Joseph Davies, Julien Gaffuri
11
+ */
12
+ export class OrientationLegend extends Legend {
13
+ /** @param {Object} opts */
14
+ constructor(opts) {
15
+ super(opts)
16
+ this.setType('orientation')
17
+ opts = opts || {}
18
+
19
+ //orientation
20
+ this.orientation = opts.orientation || 0
21
+ //color
22
+ this.color = opts.color || ((resolution, z, viewScale) => 'gray')
23
+ //width
24
+ this.width = opts.width || ((resolution, z, viewScale) => 3 * z)
25
+ //length
26
+ this.length = opts.length || ((resolution, z, viewScale) => resolution)
27
+
28
+ //label
29
+ this.label = opts.label || '-'
30
+ }
31
+
32
+ /**
33
+ * @param {{ style: import("../style/SegmentStyle.js").SegmentStyle, resolution: number, z: number, viewScale:object }} opts
34
+ */
35
+ update(opts) {
36
+ //clear
37
+ this.div.selectAll('*').remove()
38
+
39
+ //title
40
+ this.makeTitle()
41
+
42
+ const d = this.div.append('div').classed('gridviz-legend-category', true)
43
+
44
+ //compute segment color, width and length
45
+ const color = this.color(opts.resolution, opts.z, opts.viewScale)
46
+ const widthPix = this.width(opts.resolution, opts.z, opts.viewScale) / opts.z
47
+ const lengthPix = this.length(opts.resolution, opts.z, opts.viewScale) / opts.z
48
+
49
+ //draw SVG segment
50
+ const svgS = Math.max(lengthPix, widthPix)
51
+ const svg = d.append('svg').classed('gridviz-legend-graphic', true).attr('width', svgS).attr('height', svgS).style('', 'inline-block')
52
+
53
+ const cos = Math.cos((-this.orientation * Math.PI) / 180)
54
+ const sin = Math.sin((-this.orientation * Math.PI) / 180)
55
+ const dc = svgS * 0.5,
56
+ l2 = lengthPix * 0.5
57
+ svg.append('line')
58
+ .classed('gridviz-legend-symbol', true)
59
+ .attr('x1', dc - cos * l2)
60
+ .attr('y1', dc - sin * l2)
61
+ .attr('x2', dc + cos * l2)
62
+ .attr('y2', dc + sin * l2)
63
+ .style('stroke', color)
64
+ .style('stroke-width', widthPix)
65
+
66
+ //label
67
+ d.append('div')
68
+ .classed('gridviz-legend-label', true)
69
+ .style('display', 'inline')
70
+ .style('padding-left', '5px')
71
+ .style('font-size', this.labelFontSizeCSS())
72
+ .style('fill', this.labelColorCSS())
73
+ .style('color', this.labelColorCSS())
74
+ .text(this.label + (this.labelUnitText ? ' ' : '') + this.labelUnitText)
75
+ }
76
+ }
77
+
78
+ /**
79
+ *
80
+ * @param {Array.<number>} orientations
81
+ * @param {Array.<string>} labels
82
+ * @param {object} opts
83
+ * @returns { Array.<OrientationLegend> }
84
+ */
85
+ export function orientationLegend(orientations, labels, opts = {}) {
86
+ const legends = []
87
+ for (let i = 0; i < orientations.length; i++) {
88
+ opts.title = i == 0 ? opts.title : undefined
89
+ opts.orientation = orientations[i]
90
+ opts.label = labels[i]
91
+ legends.push(new OrientationLegend(opts))
92
+ }
93
+ return legends
94
+ }
@@ -26,6 +26,11 @@ export class SizeLegend extends Legend {
26
26
  * @type { function(object, number, number):number } */
27
27
  this.size = opts.size || undefined
28
28
 
29
+ /** When the symbol size is not given with `size`, it is the scale returned by this function, from the view scale of the style, applied to the value of the label.
30
+ * For a style with a view scale for its size and another for its color, combined with viewScaleCombination: `(viewScale) => viewScale.size`
31
+ * @type { function(object):function(number):number } */
32
+ this.viewScaleFun = opts.viewScaleFun || ((viewScale) => viewScale)
33
+
29
34
  //symbol
30
35
  /** @type {(import("../core/Style").Shape)|"line"} */
31
36
  this.shape = opts.shape || 'circle'
@@ -57,7 +62,7 @@ export class SizeLegend extends Legend {
57
62
  //compute size of symbol, in pix
58
63
  let sizePix
59
64
  if (this.size) sizePix = this.size(opts.viewScale, opts.resolution, opts.z) / opts.z
60
- else sizePix = opts.viewScale(+label) / opts.z
65
+ else sizePix = this.viewScaleFun(opts.viewScale)(+label) / opts.z
61
66
  if (!sizePix) return
62
67
 
63
68
  //format label, if specified and possible
@@ -137,6 +142,8 @@ export class SizeLegend extends Legend {
137
142
  .style('display', 'inline')
138
143
  .style('padding-left', '5px')
139
144
  .style('font-size', this.labelFontSizeCSS())
145
+ .style('fill', this.labelColorCSS())
146
+ .style('color', this.labelColorCSS())
140
147
  .text(label + (this.labelUnitText ? ' ' : '') + this.labelUnitText)
141
148
  }
142
149
  }