gridviz 3.0.27 → 3.0.28
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 +0 -2
- package/dist/gridviz.js +159 -77
- package/dist/gridviz.min.js +1 -1
- package/package.json +1 -1
- package/src/index.js +1 -0
- package/src/layer/GridLayer.js +3 -2
- package/src/style/ShadingStyle.js +61 -0
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -23,6 +23,7 @@ export { SegmentStyle } from './style/SegmentStyle.js'
|
|
|
23
23
|
export { TextStyle } from './style/TextStyle.js'
|
|
24
24
|
export { PillarStyle } from './style/PillarStyle.js'
|
|
25
25
|
export { SideStyle } from './style/SideStyle.js'
|
|
26
|
+
export { ShadingStyle } from './style/ShadingStyle.js'
|
|
26
27
|
//export { ContourStyle } from './style/ContourStyle.js'
|
|
27
28
|
export { SideCategoryStyle } from './style/SideCategoryStyle.js'
|
|
28
29
|
export { DotDensityStyle } from './style/DotDensityStyle.js'
|
package/src/layer/GridLayer.js
CHANGED
|
@@ -13,7 +13,7 @@ export class GridLayer extends Layer {
|
|
|
13
13
|
/**
|
|
14
14
|
* @param {import("../core/Dataset").Dataset|import("../core/MultiResolutionDataset").MultiResolutionDataset} dataset The dataset to show.
|
|
15
15
|
* @param {Array.<import("../core/Style").Style>} styles The styles, ordered in drawing order.
|
|
16
|
-
* @param {{visible?:function(number):boolean,alpha?:function(number):number,blendOperation?:function(number):GlobalCompositeOperation,minPixelsPerCell?:number,cellInfoHTML?:function(import("../core/Dataset").Cell):string}} opts
|
|
16
|
+
* @param {{visible?:function(number):boolean,alpha?:function(number):number,blendOperation?:function(number):GlobalCompositeOperation,minPixelsPerCell?:number,cellInfoHTML?:'none'|function(import("../core/Dataset").Cell):string}} opts
|
|
17
17
|
*/
|
|
18
18
|
constructor(dataset, styles, opts = {}) {
|
|
19
19
|
super(opts)
|
|
@@ -38,7 +38,8 @@ export class GridLayer extends Layer {
|
|
|
38
38
|
/**
|
|
39
39
|
* The function returning cell information as HTML.
|
|
40
40
|
* This is typically used for tooltip information.
|
|
41
|
-
*
|
|
41
|
+
* Set to 'none' to disable cell info.
|
|
42
|
+
* @type {'none'|function(import("../core/Dataset").Cell, number):string} */
|
|
42
43
|
this.cellInfoHTML = opts.cellInfoHTML || GridLayer.defaultCellInfoHTML
|
|
43
44
|
}
|
|
44
45
|
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
//@ts-check
|
|
2
|
+
'use strict'
|
|
3
|
+
|
|
4
|
+
import { SideStyle } from './SideStyle.js'
|
|
5
|
+
import { max } from 'd3-array'
|
|
6
|
+
import { exponentialScale } from '../utils/stretching.js'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @module style
|
|
10
|
+
* @author Julien Gaffuri
|
|
11
|
+
*/
|
|
12
|
+
export class ShadingStyle extends SideStyle {
|
|
13
|
+
|
|
14
|
+
/** @param {object} opts
|
|
15
|
+
* @param {string} opts.elevation
|
|
16
|
+
* @param {boolean} opts.diamond
|
|
17
|
+
* @param {function} opts.scale
|
|
18
|
+
* @param {function} opts.width
|
|
19
|
+
* @param {number} opts.reliefDirection
|
|
20
|
+
* @param {string} opts.colorTopLeft
|
|
21
|
+
* @param {string} opts.colorBottomRight
|
|
22
|
+
*/
|
|
23
|
+
constructor(opts = {}) {
|
|
24
|
+
super(opts)
|
|
25
|
+
|
|
26
|
+
/** The cell elevation field name
|
|
27
|
+
* @type {string} */
|
|
28
|
+
const elevation = opts.elevation
|
|
29
|
+
|
|
30
|
+
// compute side value as elevation difference and attach to side
|
|
31
|
+
const sideValue = (side) => {
|
|
32
|
+
if (!side.c1) side.v = 0
|
|
33
|
+
else if (!side.c2) side.v = 0
|
|
34
|
+
else if (!side.c1[elevation]) side.v = 0
|
|
35
|
+
else if (!side.c2[elevation]) side.v = 0
|
|
36
|
+
else side.v = +side.c2[elevation] - side.c1[elevation]
|
|
37
|
+
return side.v
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// compute maximum side value for normalization
|
|
41
|
+
this.viewScale = sides => max(sides, s => sideValue(s))
|
|
42
|
+
|
|
43
|
+
const colorTopLeft = opts.colorTopLeft || '255,255,255'
|
|
44
|
+
const colorBottomRight = opts.colorBottomRight || '0,0,0'
|
|
45
|
+
const scale = opts.scale || (t=>t)
|
|
46
|
+
|
|
47
|
+
this.color = (side, resolution, z, max) => {
|
|
48
|
+
if (side.v == 0) return
|
|
49
|
+
let coeff = Math.abs(side.v / max)
|
|
50
|
+
coeff = scale(coeff)
|
|
51
|
+
if ((side.v < 0 && side.or === 'h') || (side.v > 0 && side.or === 'v'))
|
|
52
|
+
return 'rgba(' + colorTopLeft + ',' + coeff + ')'
|
|
53
|
+
return 'rgba(' + colorBottomRight + ',' + coeff + ')'
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
this.width = (_, r, z) => opts.width | Math.min(2 * z, r / 3)
|
|
57
|
+
this.diamond = opts.diamond
|
|
58
|
+
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
}
|