@flowmap.gl/data 8.0.0-y.14 → 8.0.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.
Files changed (58) hide show
  1. package/.turbo/turbo-build.log +2 -0
  2. package/.turbo/turbo-dev.log +670 -0
  3. package/LICENSE +2 -2
  4. package/dist/FlowmapAggregateAccessors.d.ts +4 -4
  5. package/dist/FlowmapAggregateAccessors.d.ts.map +1 -1
  6. package/dist/FlowmapAggregateAccessors.js +16 -9
  7. package/dist/FlowmapSelectors.d.ts +39 -85
  8. package/dist/FlowmapSelectors.d.ts.map +1 -1
  9. package/dist/FlowmapSelectors.js +128 -144
  10. package/dist/FlowmapState.d.ts +7 -5
  11. package/dist/FlowmapState.d.ts.map +1 -1
  12. package/dist/FlowmapState.js +6 -1
  13. package/dist/cluster/ClusterIndex.d.ts +4 -4
  14. package/dist/cluster/ClusterIndex.d.ts.map +1 -1
  15. package/dist/cluster/ClusterIndex.js +5 -17
  16. package/dist/cluster/cluster.d.ts +20 -1
  17. package/dist/cluster/cluster.d.ts.map +1 -1
  18. package/dist/cluster/cluster.js +108 -52
  19. package/dist/colors.d.ts +3 -3
  20. package/dist/colors.d.ts.map +1 -1
  21. package/dist/colors.js +19 -8
  22. package/dist/getViewStateForLocations.d.ts +2 -2
  23. package/dist/getViewStateForLocations.d.ts.map +1 -1
  24. package/dist/getViewStateForLocations.js +18 -8
  25. package/dist/index.d.ts +3 -0
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +9 -1
  28. package/dist/provider/FlowmapDataProvider.d.ts +7 -2
  29. package/dist/provider/FlowmapDataProvider.d.ts.map +1 -1
  30. package/dist/provider/FlowmapDataProvider.js +11 -6
  31. package/dist/provider/LocalFlowmapDataProvider.d.ts +15 -4
  32. package/dist/provider/LocalFlowmapDataProvider.d.ts.map +1 -1
  33. package/dist/provider/LocalFlowmapDataProvider.js +98 -81
  34. package/dist/selector-functions.d.ts +10 -0
  35. package/dist/selector-functions.d.ts.map +1 -0
  36. package/dist/selector-functions.js +65 -0
  37. package/dist/time.d.ts.map +1 -1
  38. package/dist/time.js +6 -1
  39. package/dist/types.d.ts +18 -16
  40. package/dist/types.d.ts.map +1 -1
  41. package/dist/types.js +9 -4
  42. package/dist/util.d.ts.map +1 -1
  43. package/dist/util.js +6 -1
  44. package/package.json +22 -23
  45. package/src/FlowmapAggregateAccessors.ts +21 -10
  46. package/src/FlowmapSelectors.ts +271 -264
  47. package/src/FlowmapState.ts +13 -5
  48. package/src/cluster/ClusterIndex.ts +23 -28
  49. package/src/cluster/cluster.ts +145 -56
  50. package/src/colors.ts +13 -9
  51. package/src/getViewStateForLocations.ts +6 -0
  52. package/src/index.ts +9 -0
  53. package/src/provider/FlowmapDataProvider.ts +23 -7
  54. package/src/provider/LocalFlowmapDataProvider.ts +68 -5
  55. package/src/selector-functions.ts +93 -0
  56. package/src/time.ts +6 -0
  57. package/src/types.ts +21 -13
  58. package/src/util.ts +6 -0
@@ -0,0 +1,93 @@
1
+ /*
2
+ * Copyright (c) Flowmap.gl contributors
3
+ * Copyright (c) 2018-2020 Teralytics
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ import {WebMercatorViewport} from '@math.gl/web-mercator';
8
+ import {
9
+ ClusterLevel,
10
+ isCluster,
11
+ LocationAccessors,
12
+ ViewportProps,
13
+ } from './types';
14
+ import {scaleLinear} from 'd3-scale';
15
+ import {ClusterIndex, LocationWeightGetter} from './cluster/ClusterIndex';
16
+ import {descending} from 'd3-array';
17
+
18
+ // TODO: use re-reselect
19
+
20
+ export const getViewportBoundingBox = (
21
+ viewport: ViewportProps,
22
+ maxLocationCircleSize = 0,
23
+ ): [number, number, number, number] => {
24
+ const pad = maxLocationCircleSize;
25
+ const bounds = new WebMercatorViewport({
26
+ ...viewport,
27
+ width: viewport.width + pad * 2,
28
+ height: viewport.height + pad * 2,
29
+ }).getBounds();
30
+ return [bounds[0][0], bounds[0][1], bounds[1][0], bounds[1][1]];
31
+ };
32
+
33
+ export const getFlowThicknessScale = (
34
+ magnitudeExtent: [number, number] | undefined,
35
+ ) => {
36
+ if (!magnitudeExtent) return undefined;
37
+ return scaleLinear()
38
+ .range([0.025, 0.5])
39
+ .domain([
40
+ 0,
41
+ // should support diff mode too
42
+ Math.max.apply(
43
+ null,
44
+ magnitudeExtent.map((x: number | undefined) => Math.abs(x || 0)),
45
+ ),
46
+ ]);
47
+ };
48
+
49
+ /**
50
+ * Adding meaningful cluster names.
51
+ * NOTE: this will mutate the nodes in clusterIndex
52
+ */
53
+ export function addClusterNames<L, F>(
54
+ clusterIndex: ClusterIndex<F>,
55
+ clusterLevels: ClusterLevel[],
56
+ locationsById: Map<string | number, L>,
57
+ locationAccessors: LocationAccessors<L>,
58
+ getLocationWeight: LocationWeightGetter,
59
+ ): void {
60
+ const {getLocationId, getLocationName, getLocationClusterName} =
61
+ locationAccessors;
62
+ const getName = (id: string | number) => {
63
+ const loc = locationsById.get(id);
64
+ if (loc) {
65
+ return getLocationName ? getLocationName(loc) : getLocationId(loc) || id;
66
+ }
67
+ return `"${id}"`;
68
+ };
69
+ for (const level of clusterLevels) {
70
+ for (const node of level.nodes) {
71
+ // Here mutating the nodes (adding names)
72
+ if (isCluster(node)) {
73
+ const leaves = clusterIndex.expandCluster(node);
74
+
75
+ leaves.sort((a, b) =>
76
+ descending(getLocationWeight(a), getLocationWeight(b)),
77
+ );
78
+
79
+ if (getLocationClusterName) {
80
+ node.name = getLocationClusterName(leaves);
81
+ } else {
82
+ const topId = leaves[0];
83
+ const otherId = leaves.length === 2 ? leaves[1] : undefined;
84
+ node.name = `"${getName(topId)}" and ${
85
+ otherId ? `"${getName(otherId)}"` : `${leaves.length - 1} others`
86
+ }`;
87
+ }
88
+ } else {
89
+ (node as any).name = getName(node.id);
90
+ }
91
+ }
92
+ }
93
+ }
package/src/time.ts CHANGED
@@ -1,3 +1,9 @@
1
+ /*
2
+ * Copyright (c) Flowmap.gl contributors
3
+ * Copyright (c) 2018-2020 Teralytics
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
1
7
  import {timeFormat, timeParse} from 'd3-time-format';
2
8
  import {
3
9
  timeDay,
package/src/types.ts CHANGED
@@ -1,6 +1,13 @@
1
+ /*
2
+ * Copyright (c) Flowmap.gl contributors
3
+ * Copyright (c) 2018-2020 Teralytics
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
1
7
  export type FlowmapData<L, F> = {
2
8
  locations: Iterable<L> | undefined;
3
9
  flows: Iterable<F> | undefined;
10
+ clusterLevels?: ClusterLevels;
4
11
  };
5
12
 
6
13
  export interface ViewState {
@@ -16,19 +23,19 @@ export type FlowAccessor<F, T> = (flow: F) => T; // objectInfo?: AccessorObjectI
16
23
  export type LocationAccessor<L, T> = (location: L) => T;
17
24
 
18
25
  export interface FlowAccessors<F> {
19
- getFlowOriginId: FlowAccessor<F, string>;
20
- getFlowDestId: FlowAccessor<F, string>;
26
+ getFlowOriginId: FlowAccessor<F, string | number>;
27
+ getFlowDestId: FlowAccessor<F, string | number>;
21
28
  getFlowMagnitude: FlowAccessor<F, number>;
22
29
  getFlowTime?: FlowAccessor<F, Date>; // TODO: use number instead of Date
23
30
  // getFlowColor?: FlowAccessor<string | undefined>;
24
31
  }
25
32
 
26
33
  export interface LocationAccessors<L> {
27
- getLocationId: LocationAccessor<L, string>;
34
+ getLocationId: LocationAccessor<L, string | number>;
28
35
  getLocationName?: LocationAccessor<L, string>;
29
36
  getLocationLat: LocationAccessor<L, number>;
30
37
  getLocationLon: LocationAccessor<L, number>;
31
- getLocationClusterName?: (locationIds: string[]) => string;
38
+ getLocationClusterName?: (locationIds: (string | number)[]) => string;
32
39
  // getLocationTotalIn?: LocationAccessor<number>;
33
40
  // getLocationTotalOut?: LocationAccessor<number>;
34
41
  // getLocationTotalInternal?: LocationAccessor<number>;
@@ -59,9 +66,9 @@ export interface ViewportProps {
59
66
  height: number;
60
67
  latitude: number;
61
68
  longitude: number;
62
- zoom: number;
63
- bearing: number;
64
- pitch: number;
69
+ zoom?: number;
70
+ bearing?: number;
71
+ pitch?: number;
65
72
  altitude?: number;
66
73
  maxZoom?: number;
67
74
  minZoom?: number;
@@ -74,7 +81,7 @@ export interface ViewportProps {
74
81
  }
75
82
 
76
83
  export interface ClusterNode {
77
- id: string;
84
+ id: string | number;
78
85
  zoom: number;
79
86
  lat: number;
80
87
  lon: number;
@@ -104,8 +111,8 @@ export function isLocationClusterNode<L>(l: L | ClusterNode): l is ClusterNode {
104
111
  }
105
112
 
106
113
  export interface AggregateFlow {
107
- origin: string;
108
- dest: string;
114
+ origin: string | number;
115
+ dest: string | number;
109
116
  count: number;
110
117
  aggregate: true;
111
118
  }
@@ -115,9 +122,9 @@ export function isAggregateFlow(
115
122
  ): flow is AggregateFlow {
116
123
  return (
117
124
  flow &&
118
- flow.origin !== undefined &&
119
- flow.dest !== undefined &&
120
- flow.count !== undefined &&
125
+ // flow.origin !== undefined &&
126
+ // flow.dest !== undefined &&
127
+ // flow.count !== undefined &&
121
128
  (flow.aggregate ? true : false)
122
129
  );
123
130
  }
@@ -159,6 +166,7 @@ export interface FlowLinesLayerAttributes {
159
166
  export interface LayersData {
160
167
  circleAttributes: FlowCirclesLayerAttributes;
161
168
  lineAttributes: FlowLinesLayerAttributes;
169
+ locationLabels?: string[];
162
170
  }
163
171
 
164
172
  export type LayersDataAttrValues<T> = {value: T; size: number};
package/src/util.ts CHANGED
@@ -1,3 +1,9 @@
1
+ /*
2
+ * Copyright (c) Flowmap.gl contributors
3
+ * Copyright (c) 2018-2020 Teralytics
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
1
7
  import {createSelectorCreator, defaultMemoize} from 'reselect';
2
8
 
3
9
  export const createDebugSelector = createSelectorCreator(defaultMemoize, {