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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vega-functions",
3
- "version": "5.13.0",
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.1.1",
25
- "d3-color": "^3.0.1",
26
- "d3-geo": "^3.0.1",
27
- "vega-dataflow": "^5.7.3",
28
- "vega-expression": "^5.0.0",
29
- "vega-scale": "^7.2.0",
30
- "vega-scenegraph": "^4.9.3",
31
- "vega-selections": "^5.3.1",
32
- "vega-statistics": "^1.7.9",
33
- "vega-time": "^2.1.0",
34
- "vega-util": "^1.16.0"
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": "9a3faca4395cade9ecdfde90af98f1c53e9916b2"
39
+ "gitHead": "a7a312ebe9db675ae03bd354f193ed34a976d21f"
40
40
  }
@@ -0,0 +1 @@
1
+ export { default } from '../../rollup.config.mjs';
@@ -1,9 +1,10 @@
1
1
  import intersect from './intersect';
2
- import { Bounds } from 'vega-scenegraph';
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
- const last = lasso[lasso.length - 1];
15
+ lasso = array(lasso);
16
+ const last = lasso[lasso.length - 1];
15
17
 
16
- // Add point to lasso if distance to last point exceed minDist or its the first point
17
- if (last === undefined || Math.sqrt(((last[0] - x) ** 2) + ((last[1] - y) ** 2)) > minDist) {
18
- lasso.push([x, y]);
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
- return (lasso ?? []).reduce((svg, [x, y], i) => {
35
- return svg += i == 0
36
- ? `M ${x},${y} `
37
- : i === lasso.length - 1
38
- ? ' Z'
39
- : `L ${x},${y} `;
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
- const { x, y, mark } = unit;
56
-
57
- const bb = new Bounds().set(
58
- Number.MAX_SAFE_INTEGER,
59
- Number.MAX_SAFE_INTEGER,
60
- Number.MIN_SAFE_INTEGER,
61
- Number.MIN_SAFE_INTEGER
62
- );
63
-
64
- // Get bounding box around lasso
65
- for (const [px, py] of pixelLasso) {
66
- if (px < bb.x1) bb.x1 = px;
67
- if (px > bb.x2) bb.x2 = px;
68
- if (py < bb.y1) bb.y1 = py;
69
- if (py > bb.y2) bb.y2 = py;
70
- }
71
-
72
- // Translate bb against unit coordinates
73
- bb.translate(x, y);
74
-
75
- const intersection = intersect([[bb.x1, bb.y1], [bb.x2, bb.y2]],
76
- markname,
77
- mark);
78
-
79
- // Check every point against the lasso
80
- return intersection.filter(tuple => pointInPolygon(tuple.x, tuple.y, pixelLasso));
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
- let intersections = 0;
94
+ let intersections = 0;
97
95
 
98
- for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
99
- const [prevX, prevY] = polygon[j];
100
- const [x, y] = polygon[i];
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
- // count intersections
103
- if (((y > testy) != (prevY > testy)) && (testx < (prevX - x) * (testy - y) / (prevY - y) + x)) {
104
- intersections++;
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
- // point is in polygon if intersection count is odd
109
- return intersections & 1;
106
+ // point is in polygon if intersection count is odd
107
+ return intersections & 1;
110
108
  }
@@ -2,7 +2,7 @@ export function pinchDistance(event) {
2
2
  const t = event.touches,
3
3
  dx = t[0].clientX - t[1].clientX,
4
4
  dy = t[0].clientY - t[1].clientY;
5
- return Math.sqrt(dx * dx + dy * dy);
5
+ return Math.hypot(dx, dy);
6
6
  }
7
7
 
8
8
  export function pinchAngle(event) {
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(name, ctx) {
7
- let s;
8
- return isFunction(name) ? name
9
- : isString(name) ? (s = ctx.scales[name]) && s.value
10
- : undefined;
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';