vega-functions 5.13.0 → 5.13.2
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.
Potentially problematic release.
This version of vega-functions might be problematic. Click here for more details.
- package/LICENSE +1 -1
- package/build/vega-functions.js +301 -383
- package/build/vega-functions.min.js +1 -1
- package/build/vega-functions.min.js.map +1 -1
- package/build/vega-functions.module.js +120 -160
- package/package.json +14 -14
- package/rollup.config.mjs +1 -0
- package/src/functions/lasso.js +57 -59
- package/src/functions/pinch.js +1 -1
- package/src/scales.js +14 -5
- package/rollup.config.js +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vega-functions",
|
|
3
|
-
"version": "5.13.
|
|
3
|
+
"version": "5.13.2",
|
|
4
4
|
"description": "Custom functions for the Vega expression language.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vega",
|
|
@@ -15,26 +15,26 @@
|
|
|
15
15
|
"repository": "vega/vega",
|
|
16
16
|
"scripts": {
|
|
17
17
|
"prebuild": "rimraf build",
|
|
18
|
-
"build": "rollup -c",
|
|
18
|
+
"build": "rollup -c rollup.config.mjs",
|
|
19
19
|
"pretest": "yarn build --config-test",
|
|
20
20
|
"test": "tape 'test/**/*-test.js'",
|
|
21
21
|
"prepublishOnly": "yarn test && yarn build"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"d3-array": "^3.
|
|
25
|
-
"d3-color": "^3.0
|
|
26
|
-
"d3-geo": "^3.0
|
|
27
|
-
"vega-dataflow": "^5.7.
|
|
28
|
-
"vega-expression": "^5.
|
|
29
|
-
"vega-scale": "^7.
|
|
30
|
-
"vega-scenegraph": "^4.
|
|
31
|
-
"vega-selections": "^5.
|
|
32
|
-
"vega-statistics": "^1.
|
|
33
|
-
"vega-time": "^2.1.
|
|
34
|
-
"vega-util": "^1.
|
|
24
|
+
"d3-array": "^3.2.2",
|
|
25
|
+
"d3-color": "^3.1.0",
|
|
26
|
+
"d3-geo": "^3.1.0",
|
|
27
|
+
"vega-dataflow": "^5.7.5",
|
|
28
|
+
"vega-expression": "^5.1.0",
|
|
29
|
+
"vega-scale": "^7.3.0",
|
|
30
|
+
"vega-scenegraph": "^4.10.2",
|
|
31
|
+
"vega-selections": "^5.4.1",
|
|
32
|
+
"vega-statistics": "^1.8.1",
|
|
33
|
+
"vega-time": "^2.1.1",
|
|
34
|
+
"vega-util": "^1.17.1"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"vega-format": "^1.1.0"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "a7a312ebe9db675ae03bd354f193ed34a976d21f"
|
|
40
40
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from '../../rollup.config.mjs';
|
package/src/functions/lasso.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import intersect from './intersect';
|
|
2
|
-
import {
|
|
2
|
+
import {Bounds} from 'vega-scenegraph';
|
|
3
|
+
import {array} from 'vega-util';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Appends a new point to the lasso
|
|
6
|
-
*
|
|
7
|
+
*
|
|
7
8
|
* @param {*} lasso the lasso in pixel space
|
|
8
9
|
* @param {*} x the x coordinate in pixel space
|
|
9
10
|
* @param {*} y the y coordinate in pixel space
|
|
@@ -11,73 +12,70 @@ import { Bounds } from 'vega-scenegraph';
|
|
|
11
12
|
* @returns a new array containing the lasso with the new point
|
|
12
13
|
*/
|
|
13
14
|
export function lassoAppend(lasso, x, y, minDist = 5) {
|
|
14
|
-
|
|
15
|
+
lasso = array(lasso);
|
|
16
|
+
const last = lasso[lasso.length - 1];
|
|
15
17
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return [...lasso];
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return lasso;
|
|
18
|
+
// Add point to lasso if its the first point or distance to last point exceed minDist
|
|
19
|
+
return (last === undefined || Math.hypot(last[0] - x, last[1] - y) > minDist)
|
|
20
|
+
? [...lasso, [x, y]]
|
|
21
|
+
: lasso;
|
|
24
22
|
}
|
|
25
23
|
|
|
26
24
|
|
|
27
25
|
/**
|
|
28
26
|
* Generates a svg path command which draws a lasso
|
|
29
|
-
*
|
|
27
|
+
*
|
|
30
28
|
* @param {*} lasso the lasso in pixel space in the form [[x,y], [x,y], ...]
|
|
31
29
|
* @returns the svg path command that draws the lasso
|
|
32
30
|
*/
|
|
33
31
|
export function lassoPath(lasso) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
32
|
+
return array(lasso).reduce((svg, [x, y], i) => {
|
|
33
|
+
return svg += i == 0
|
|
34
|
+
? `M ${x},${y} `
|
|
35
|
+
: i === lasso.length - 1
|
|
36
|
+
? ' Z'
|
|
37
|
+
: `L ${x},${y} `;
|
|
38
|
+
}, '');
|
|
41
39
|
}
|
|
42
40
|
|
|
43
41
|
|
|
44
42
|
|
|
45
43
|
/**
|
|
46
44
|
* Inverts the lasso from pixel space to an array of vega scenegraph tuples
|
|
47
|
-
*
|
|
45
|
+
*
|
|
48
46
|
* @param {*} data the dataset
|
|
49
47
|
* @param {*} pixelLasso the lasso in pixel space, [[x,y], [x,y], ...]
|
|
50
48
|
* @param {*} unit the unit where the lasso is defined
|
|
51
|
-
*
|
|
49
|
+
*
|
|
52
50
|
* @returns an array of vega scenegraph tuples
|
|
53
51
|
*/
|
|
54
52
|
export function intersectLasso(markname, pixelLasso, unit) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
53
|
+
const { x, y, mark } = unit;
|
|
54
|
+
|
|
55
|
+
const bb = new Bounds().set(
|
|
56
|
+
Number.MAX_SAFE_INTEGER,
|
|
57
|
+
Number.MAX_SAFE_INTEGER,
|
|
58
|
+
Number.MIN_SAFE_INTEGER,
|
|
59
|
+
Number.MIN_SAFE_INTEGER
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
// Get bounding box around lasso
|
|
63
|
+
for (const [px, py] of pixelLasso) {
|
|
64
|
+
if (px < bb.x1) bb.x1 = px;
|
|
65
|
+
if (px > bb.x2) bb.x2 = px;
|
|
66
|
+
if (py < bb.y1) bb.y1 = py;
|
|
67
|
+
if (py > bb.y2) bb.y2 = py;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Translate bb against unit coordinates
|
|
71
|
+
bb.translate(x, y);
|
|
72
|
+
|
|
73
|
+
const intersection = intersect([[bb.x1, bb.y1], [bb.x2, bb.y2]],
|
|
74
|
+
markname,
|
|
75
|
+
mark);
|
|
76
|
+
|
|
77
|
+
// Check every point against the lasso
|
|
78
|
+
return intersection.filter(tuple => pointInPolygon(tuple.x, tuple.y, pixelLasso));
|
|
81
79
|
}
|
|
82
80
|
|
|
83
81
|
|
|
@@ -85,26 +83,26 @@ export function intersectLasso(markname, pixelLasso, unit) {
|
|
|
85
83
|
/**
|
|
86
84
|
* Performs a test if a point is inside a polygon based on the idea from
|
|
87
85
|
* https://wrf.ecse.rpi.edu/Research/Short_Notes/pnpoly.html
|
|
88
|
-
*
|
|
86
|
+
*
|
|
89
87
|
* This method will not need the same start/end point since it wraps around the edges of the array
|
|
90
|
-
*
|
|
88
|
+
*
|
|
91
89
|
* @param {*} test a point to test against
|
|
92
90
|
* @param {*} polygon a polygon in the form [[x,y], [x,y], ...]
|
|
93
91
|
* @returns true if the point lies inside the polygon, false otherwise
|
|
94
92
|
*/
|
|
95
93
|
function pointInPolygon(testx, testy, polygon) {
|
|
96
|
-
|
|
94
|
+
let intersections = 0;
|
|
97
95
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
96
|
+
for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
|
|
97
|
+
const [prevX, prevY] = polygon[j];
|
|
98
|
+
const [x, y] = polygon[i];
|
|
101
99
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
100
|
+
// count intersections
|
|
101
|
+
if (((y > testy) != (prevY > testy)) && (testx < (prevX - x) * (testy - y) / (prevY - y) + x)) {
|
|
102
|
+
intersections++;
|
|
106
103
|
}
|
|
104
|
+
}
|
|
107
105
|
|
|
108
|
-
|
|
109
|
-
|
|
106
|
+
// point is in polygon if intersection count is odd
|
|
107
|
+
return intersections & 1;
|
|
110
108
|
}
|
package/src/functions/pinch.js
CHANGED
package/src/scales.js
CHANGED
|
@@ -2,12 +2,21 @@ import {ScalePrefix} from './constants';
|
|
|
2
2
|
import {scaleVisitor} from './visitors';
|
|
3
3
|
import {Literal} from 'vega-expression';
|
|
4
4
|
import {isFunction, isString, stringValue} from 'vega-util';
|
|
5
|
+
import {isRegisteredScale} from 'vega-scale';
|
|
5
6
|
|
|
6
|
-
export function getScale(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
export function getScale(nameOrFunction, ctx) {
|
|
8
|
+
|
|
9
|
+
if (isFunction(nameOrFunction)) {
|
|
10
|
+
return nameOrFunction;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (isString(nameOrFunction)) {
|
|
14
|
+
const maybeScale = ctx.scales[nameOrFunction];
|
|
15
|
+
return (maybeScale && isRegisteredScale(maybeScale.value)) ? maybeScale.value : undefined;
|
|
16
|
+
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return undefined;
|
|
11
20
|
}
|
|
12
21
|
|
|
13
22
|
export function internalScaleFunctions(codegen, fnctx, visitors) {
|
package/rollup.config.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from '../../rollup.config';
|