@flowmap.gl/data 8.0.0-alpha.2 → 8.0.0-alpha.6
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/dist/{FlowMapAggregateAccessors.d.ts → FlowmapAggregateAccessors.d.ts} +6 -6
- package/dist/{FlowMapAggregateAccessors.d.ts.map → FlowmapAggregateAccessors.d.ts.map} +1 -1
- package/dist/{FlowMapAggregateAccessors.js → FlowmapAggregateAccessors.js} +3 -3
- package/dist/{FlowMapSelectors.d.ts → FlowmapSelectors.d.ts} +47 -45
- package/dist/FlowmapSelectors.d.ts.map +1 -0
- package/dist/FlowmapSelectors.js +869 -0
- package/dist/{FlowMapState.d.ts → FlowmapState.d.ts} +5 -2
- package/dist/FlowmapState.d.ts.map +1 -0
- package/dist/FlowmapState.js +2 -0
- package/dist/colors.d.ts +6 -6
- package/dist/colors.d.ts.map +1 -1
- package/dist/colors.js +42 -17
- package/dist/getViewStateForLocations.d.ts +12 -10
- package/dist/getViewStateForLocations.d.ts.map +1 -1
- package/dist/getViewStateForLocations.js +4 -1
- package/dist/index.d.ts +9 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -6
- package/dist/provider/FlowmapDataProvider.d.ts +16 -0
- package/dist/provider/FlowmapDataProvider.d.ts.map +1 -0
- package/dist/provider/FlowmapDataProvider.js +17 -0
- package/dist/provider/LocalFlowmapDataProvider.d.ts +20 -0
- package/dist/provider/LocalFlowmapDataProvider.d.ts.map +1 -0
- package/dist/provider/LocalFlowmapDataProvider.js +95 -0
- package/dist/provider/WorkerFlowmapDataProvider.d.ts +42 -0
- package/dist/provider/WorkerFlowmapDataProvider.d.ts.map +1 -0
- package/dist/provider/WorkerFlowmapDataProvider.js +82 -0
- package/dist/provider/WorkerFlowmapDataProviderWorker.d.ts +2 -0
- package/dist/provider/WorkerFlowmapDataProviderWorker.d.ts.map +1 -0
- package/dist/provider/WorkerFlowmapDataProviderWorker.js +4 -0
- package/dist/provider/createWorkerDataProvider.d.ts +3 -0
- package/dist/provider/createWorkerDataProvider.d.ts.map +1 -0
- package/dist/provider/createWorkerDataProvider.js +21 -0
- package/dist/types.d.ts +2 -2
- package/dist/types.js +1 -1
- package/dist/util.d.ts +0 -1
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +1 -4
- package/package.json +7 -2
- package/src/{FlowMapAggregateAccessors.ts → FlowmapAggregateAccessors.ts} +6 -6
- package/src/{FlowMapSelectors.ts → FlowmapSelectors.ts} +154 -113
- package/src/{FlowMapState.ts → FlowmapState.ts} +4 -1
- package/src/colors.ts +50 -16
- package/src/getViewStateForLocations.ts +20 -16
- package/src/index.ts +9 -6
- package/src/provider/{FlowMapDataProvider.ts → FlowmapDataProvider.ts} +14 -12
- package/src/provider/LocalFlowmapDataProvider.ts +119 -0
- package/src/provider/WorkerFlowmapDataProvider.ts +121 -0
- package/src/provider/WorkerFlowmapDataProviderWorker.ts +4 -0
- package/src/provider/createWorkerDataProvider.ts +18 -0
- package/src/types.ts +2 -2
- package/src/util.ts +0 -4
- package/dist/FlowMapSelectors.d.ts.map +0 -1
- package/dist/FlowMapSelectors.js +0 -834
- package/dist/FlowMapState.d.ts.map +0 -1
- package/dist/FlowMapState.js +0 -2
- package/dist/provider/FlowMapDataProvider.d.ts +0 -16
- package/dist/provider/FlowMapDataProvider.d.ts.map +0 -1
- package/dist/provider/FlowMapDataProvider.js +0 -17
- package/dist/provider/LocalFlowMapDataProvider.d.ts +0 -20
- package/dist/provider/LocalFlowMapDataProvider.d.ts.map +0 -1
- package/dist/provider/LocalFlowMapDataProvider.js +0 -87
- package/src/provider/LocalFlowMapDataProvider.ts +0 -105
|
@@ -1,22 +1,28 @@
|
|
|
1
1
|
import {BoundingBox, viewport} from '@mapbox/geo-viewport';
|
|
2
2
|
import {geoBounds} from 'd3-geo';
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import type {
|
|
4
|
+
FeatureCollection,
|
|
5
|
+
GeometryCollection,
|
|
6
|
+
GeometryObject,
|
|
7
|
+
} from 'geojson';
|
|
8
|
+
import type {ViewportProps, ViewState} from './types';
|
|
5
9
|
|
|
6
10
|
export type LocationProperties = any;
|
|
7
11
|
|
|
12
|
+
export type GetViewStateOptions = {
|
|
13
|
+
pad?: number;
|
|
14
|
+
tileSize?: number;
|
|
15
|
+
minZoom?: number;
|
|
16
|
+
maxZoom?: number;
|
|
17
|
+
};
|
|
18
|
+
|
|
8
19
|
export function getViewStateForFeatures(
|
|
9
20
|
featureCollection:
|
|
10
21
|
| FeatureCollection<GeometryObject, LocationProperties>
|
|
11
22
|
| GeometryCollection,
|
|
12
23
|
size: [number, number],
|
|
13
|
-
opts?:
|
|
14
|
-
|
|
15
|
-
tileSize?: number;
|
|
16
|
-
minZoom?: number;
|
|
17
|
-
maxZoom?: number;
|
|
18
|
-
},
|
|
19
|
-
): ViewState {
|
|
24
|
+
opts?: GetViewStateOptions,
|
|
25
|
+
): ViewState & {width: number; height: number} {
|
|
20
26
|
const {pad = 0.05, tileSize = 512, minZoom = 0, maxZoom = 100} = opts || {};
|
|
21
27
|
const [[x1, y1], [x2, y2]] = geoBounds(featureCollection as any);
|
|
22
28
|
const bounds: BoundingBox = [
|
|
@@ -25,12 +31,15 @@ export function getViewStateForFeatures(
|
|
|
25
31
|
x2 + pad * (x2 - x1),
|
|
26
32
|
y2 + pad * (y2 - y1),
|
|
27
33
|
];
|
|
34
|
+
const [width, height] = size;
|
|
28
35
|
const {
|
|
29
36
|
center: [longitude, latitude],
|
|
30
37
|
zoom,
|
|
31
38
|
} = viewport(bounds, size, undefined, undefined, tileSize, true);
|
|
32
39
|
|
|
33
40
|
return {
|
|
41
|
+
width,
|
|
42
|
+
height,
|
|
34
43
|
longitude,
|
|
35
44
|
latitude,
|
|
36
45
|
zoom: Math.max(Math.min(maxZoom, zoom), minZoom),
|
|
@@ -43,13 +52,8 @@ export function getViewStateForLocations(
|
|
|
43
52
|
locations: any[],
|
|
44
53
|
getLocationCentroid: (location: any) => [number, number],
|
|
45
54
|
size: [number, number],
|
|
46
|
-
opts?:
|
|
47
|
-
|
|
48
|
-
tileSize?: number;
|
|
49
|
-
minZoom?: number;
|
|
50
|
-
maxZoom?: number;
|
|
51
|
-
},
|
|
52
|
-
): ViewState {
|
|
55
|
+
opts?: GetViewStateOptions,
|
|
56
|
+
): ViewState & {width: number; height: number} {
|
|
53
57
|
return getViewStateForFeatures(
|
|
54
58
|
{
|
|
55
59
|
type: 'GeometryCollection',
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
export * from './types';
|
|
2
2
|
export * from './colors';
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
3
|
+
export * from './FlowmapState';
|
|
4
|
+
export * from './FlowmapSelectors';
|
|
5
5
|
export * from './time';
|
|
6
6
|
export * from './getViewStateForLocations';
|
|
7
|
-
export * from './provider/
|
|
8
|
-
export {default as
|
|
9
|
-
export type {default as
|
|
10
|
-
export {default as
|
|
7
|
+
export * from './provider/FlowmapDataProvider';
|
|
8
|
+
export {default as FlowmapAggregateAccessors} from './FlowmapAggregateAccessors';
|
|
9
|
+
export type {default as FlowmapDataProvider} from './provider/FlowmapDataProvider';
|
|
10
|
+
export {default as LocalFlowmapDataProvider} from './provider/LocalFlowmapDataProvider';
|
|
11
|
+
export {default as createWorkerDataProvider} from './provider/createWorkerDataProvider';
|
|
12
|
+
export {default as WorkerFlowmapDataProvider} from './provider/WorkerFlowmapDataProvider';
|
|
13
|
+
export * from './provider/WorkerFlowmapDataProvider';
|
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
import {AggregateFlow, Cluster, LocationAccessors, LocationTotals} from '..';
|
|
2
|
-
import {
|
|
2
|
+
import {FlowmapState} from '../FlowmapState';
|
|
3
3
|
import {
|
|
4
4
|
ClusterNode,
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
FlowmapData,
|
|
6
|
+
FlowmapDataAccessors,
|
|
7
7
|
LayersData,
|
|
8
8
|
ViewportProps,
|
|
9
9
|
} from '../types';
|
|
10
10
|
|
|
11
|
-
export default interface
|
|
12
|
-
setAccessors(accessors:
|
|
11
|
+
export default interface FlowmapDataProvider<L, F> {
|
|
12
|
+
setAccessors(accessors: FlowmapDataAccessors<L, F>): void;
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
setFlowmapState(flowmapState: FlowmapState): Promise<void>;
|
|
15
15
|
|
|
16
16
|
// clearData(): void;
|
|
17
17
|
|
|
18
|
-
getViewportForLocations(
|
|
18
|
+
getViewportForLocations(
|
|
19
|
+
dims: [number, number],
|
|
20
|
+
): Promise<ViewportProps | undefined>;
|
|
19
21
|
|
|
20
22
|
// getFlowTotals(): Promise<FlowTotals>;
|
|
21
23
|
|
|
@@ -36,9 +38,9 @@ export default interface FlowMapDataProvider<L, F> {
|
|
|
36
38
|
getLayersData(): Promise<LayersData | undefined>;
|
|
37
39
|
}
|
|
38
40
|
|
|
39
|
-
export function
|
|
41
|
+
export function isFlowmapData<L, F>(
|
|
40
42
|
data: Record<string, any>,
|
|
41
|
-
): data is
|
|
43
|
+
): data is FlowmapData<L, F> {
|
|
42
44
|
return (
|
|
43
45
|
data &&
|
|
44
46
|
data.locations &&
|
|
@@ -48,12 +50,12 @@ export function isFlowMapData<L, F>(
|
|
|
48
50
|
);
|
|
49
51
|
}
|
|
50
52
|
|
|
51
|
-
export function
|
|
53
|
+
export function isFlowmapDataProvider<L, F>(
|
|
52
54
|
dataProvider: Record<string, any>,
|
|
53
|
-
): dataProvider is
|
|
55
|
+
): dataProvider is FlowmapDataProvider<L, F> {
|
|
54
56
|
return (
|
|
55
57
|
dataProvider &&
|
|
56
|
-
typeof dataProvider.
|
|
58
|
+
typeof dataProvider.setFlowmapState === 'function' &&
|
|
57
59
|
typeof dataProvider.getViewportForLocations === 'function' &&
|
|
58
60
|
typeof dataProvider.getFlowByIndex === 'function' &&
|
|
59
61
|
typeof dataProvider.getLocationById === 'function' &&
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import type FlowmapDataProvider from './FlowmapDataProvider';
|
|
2
|
+
import type {
|
|
3
|
+
Cluster,
|
|
4
|
+
ClusterNode,
|
|
5
|
+
FlowmapData,
|
|
6
|
+
FlowmapDataAccessors,
|
|
7
|
+
LayersData,
|
|
8
|
+
LocationTotals,
|
|
9
|
+
ViewportProps,
|
|
10
|
+
AggregateFlow,
|
|
11
|
+
} from '../types';
|
|
12
|
+
import {FlowmapState} from '../FlowmapState';
|
|
13
|
+
import FlowmapSelectors from '../FlowmapSelectors';
|
|
14
|
+
import {
|
|
15
|
+
GetViewStateOptions,
|
|
16
|
+
getViewStateForLocations,
|
|
17
|
+
} from '../getViewStateForLocations';
|
|
18
|
+
|
|
19
|
+
export default class LocalFlowmapDataProvider<L, F>
|
|
20
|
+
implements FlowmapDataProvider<L, F>
|
|
21
|
+
{
|
|
22
|
+
private selectors: FlowmapSelectors<L, F>;
|
|
23
|
+
private flowmapData: FlowmapData<L, F> | undefined;
|
|
24
|
+
private flowmapState: FlowmapState | undefined;
|
|
25
|
+
|
|
26
|
+
constructor(accessors: FlowmapDataAccessors<L, F>) {
|
|
27
|
+
// scope selectors to the concrete instance of FlowmapDataProvider
|
|
28
|
+
this.selectors = new FlowmapSelectors<L, F>(accessors);
|
|
29
|
+
this.flowmapData = undefined;
|
|
30
|
+
this.flowmapState = undefined;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
setAccessors(accessors: FlowmapDataAccessors<L, F>) {
|
|
34
|
+
this.selectors.setAccessors(accessors);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async setFlowmapData(flowmapData: FlowmapData<L, F>): Promise<void> {
|
|
38
|
+
this.flowmapData = flowmapData;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async setFlowmapState(flowmapState: FlowmapState): Promise<void> {
|
|
42
|
+
this.flowmapState = flowmapState;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async getFlowByIndex(idx: number): Promise<F | AggregateFlow | undefined> {
|
|
46
|
+
if (!this.flowmapState || !this.flowmapData) {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
const flows = this.selectors.getFlowsForFlowmapLayer(
|
|
50
|
+
this.flowmapState,
|
|
51
|
+
this.flowmapData,
|
|
52
|
+
);
|
|
53
|
+
return flows?.[idx];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async getLocationByIndex(idx: number): Promise<L | ClusterNode | undefined> {
|
|
57
|
+
if (!this.flowmapState || !this.flowmapData) {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
const locations = this.selectors.getLocationsForFlowmapLayer(
|
|
61
|
+
this.flowmapState,
|
|
62
|
+
this.flowmapData,
|
|
63
|
+
);
|
|
64
|
+
return locations?.[idx];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async getLayersData(): Promise<LayersData | undefined> {
|
|
68
|
+
if (!this.flowmapState || !this.flowmapData) {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
return this.selectors.getLayersData(this.flowmapState, this.flowmapData);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async getLocationById(id: string): Promise<L | Cluster | undefined> {
|
|
75
|
+
if (!this.flowmapState || !this.flowmapData) {
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
const clusterIndex = this.selectors.getClusterIndex(
|
|
79
|
+
this.flowmapState,
|
|
80
|
+
this.flowmapData,
|
|
81
|
+
);
|
|
82
|
+
if (clusterIndex) {
|
|
83
|
+
const cluster = clusterIndex.getClusterById(id);
|
|
84
|
+
if (cluster) {
|
|
85
|
+
return cluster;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const locationsById = this.selectors.getLocationsById(
|
|
89
|
+
this.flowmapState,
|
|
90
|
+
this.flowmapData,
|
|
91
|
+
);
|
|
92
|
+
return locationsById?.get(id);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async getTotalsForLocation(id: string): Promise<LocationTotals | undefined> {
|
|
96
|
+
if (!this.flowmapState || !this.flowmapData) {
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
return this.selectors
|
|
100
|
+
.getLocationTotals(this.flowmapState, this.flowmapData)
|
|
101
|
+
?.get(id);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async getViewportForLocations(
|
|
105
|
+
dims: [number, number],
|
|
106
|
+
opts?: GetViewStateOptions,
|
|
107
|
+
): Promise<ViewportProps | undefined> {
|
|
108
|
+
if (!this.flowmapData?.locations) {
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
// @ts-ignore
|
|
112
|
+
return getViewStateForLocations(
|
|
113
|
+
this.flowmapData.locations,
|
|
114
|
+
this.selectors.accessors.getLocationCentroid,
|
|
115
|
+
dims,
|
|
116
|
+
opts,
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import FlowmapDataProvider from './FlowmapDataProvider';
|
|
2
|
+
import {
|
|
3
|
+
Cluster,
|
|
4
|
+
ClusterNode,
|
|
5
|
+
FlowmapData,
|
|
6
|
+
FlowmapDataAccessors,
|
|
7
|
+
LayersData,
|
|
8
|
+
LocationTotals,
|
|
9
|
+
ViewportProps,
|
|
10
|
+
} from '../types';
|
|
11
|
+
import {FlowmapState} from '../FlowmapState';
|
|
12
|
+
import {AggregateFlow} from '..';
|
|
13
|
+
import LocalFlowmapDataProvider from './LocalFlowmapDataProvider';
|
|
14
|
+
import {load} from '@loaders.gl/core';
|
|
15
|
+
import {CSVLoader} from '@loaders.gl/csv';
|
|
16
|
+
|
|
17
|
+
const LOADERS = [CSVLoader];
|
|
18
|
+
|
|
19
|
+
export type WorkerDataProviderProps = {
|
|
20
|
+
flows: {
|
|
21
|
+
url: string;
|
|
22
|
+
columns: {
|
|
23
|
+
originId: string;
|
|
24
|
+
destId: string;
|
|
25
|
+
count: string;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
locations: {
|
|
29
|
+
url: string;
|
|
30
|
+
columns: {
|
|
31
|
+
id: string;
|
|
32
|
+
name: string;
|
|
33
|
+
lat: string;
|
|
34
|
+
lon: string;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export type LocationDatum = Record<string, unknown>;
|
|
40
|
+
export type FlowDatum = Record<string, unknown>;
|
|
41
|
+
|
|
42
|
+
export default class WorkerFlowmapDataProvider
|
|
43
|
+
implements FlowmapDataProvider<LocationDatum, FlowDatum>
|
|
44
|
+
{
|
|
45
|
+
private props: WorkerDataProviderProps;
|
|
46
|
+
private localProvider: LocalFlowmapDataProvider<LocationDatum, FlowDatum>;
|
|
47
|
+
private flowmapState: FlowmapState | undefined;
|
|
48
|
+
|
|
49
|
+
constructor(props: WorkerDataProviderProps) {
|
|
50
|
+
this.props = props;
|
|
51
|
+
this.localProvider = new LocalFlowmapDataProvider({
|
|
52
|
+
getFlowOriginId: (flow) => flow[props.flows.columns.originId] as string,
|
|
53
|
+
getFlowDestId: (flow) => flow[props.flows.columns.destId] as string,
|
|
54
|
+
getFlowMagnitude: (flow) => flow[props.flows.columns.count] as number,
|
|
55
|
+
// getFlowTime: (flow) => flow.time,
|
|
56
|
+
getLocationCentroid: (location) => [
|
|
57
|
+
location[props.locations.columns.lon] as number,
|
|
58
|
+
location[props.locations.columns.lat] as number,
|
|
59
|
+
],
|
|
60
|
+
getLocationName: (location) =>
|
|
61
|
+
location[props.locations.columns.name] as string,
|
|
62
|
+
getLocationId: (location) =>
|
|
63
|
+
location[props.locations.columns.id] as string,
|
|
64
|
+
});
|
|
65
|
+
this.flowmapState = undefined;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async loadData() {
|
|
69
|
+
const [locations, flows] = await Promise.all([
|
|
70
|
+
load(this.props.locations.url, LOADERS),
|
|
71
|
+
load(this.props.flows.url, LOADERS),
|
|
72
|
+
]);
|
|
73
|
+
await this.localProvider.setFlowmapData({locations, flows});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
setAccessors(accessors: FlowmapDataAccessors<LocationDatum, FlowDatum>) {
|
|
77
|
+
throw new Error('Not supported');
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async setFlowmapData(
|
|
81
|
+
flowmapData: FlowmapData<LocationDatum, FlowDatum>,
|
|
82
|
+
): Promise<void> {
|
|
83
|
+
throw new Error('Not supported');
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async setFlowmapState(flowmapState: FlowmapState): Promise<void> {
|
|
87
|
+
await this.localProvider.setFlowmapState(flowmapState);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async getFlowByIndex(
|
|
91
|
+
idx: number,
|
|
92
|
+
): Promise<FlowDatum | AggregateFlow | undefined> {
|
|
93
|
+
return this.localProvider.getFlowByIndex(idx);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async getLocationByIndex(
|
|
97
|
+
idx: number,
|
|
98
|
+
): Promise<LocationDatum | ClusterNode | undefined> {
|
|
99
|
+
return this.localProvider.getLocationByIndex(idx);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async getLayersData(): Promise<LayersData | undefined> {
|
|
103
|
+
return await this.localProvider.getLayersData();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async getLocationById(
|
|
107
|
+
id: string,
|
|
108
|
+
): Promise<LocationDatum | Cluster | undefined> {
|
|
109
|
+
return this.localProvider.getLocationById(id);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async getTotalsForLocation(id: string): Promise<LocationTotals | undefined> {
|
|
113
|
+
return this.localProvider.getTotalsForLocation(id);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
getViewportForLocations(
|
|
117
|
+
dims: [number, number],
|
|
118
|
+
): Promise<ViewportProps | undefined> {
|
|
119
|
+
return this.localProvider.getViewportForLocations(dims);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as Comlink from 'comlink';
|
|
2
|
+
import WorkerFlowmapDataProvider, {
|
|
3
|
+
WorkerDataProviderProps,
|
|
4
|
+
} from './WorkerFlowmapDataProvider';
|
|
5
|
+
|
|
6
|
+
export default async function createWorkerDataProvider(
|
|
7
|
+
props: WorkerDataProviderProps,
|
|
8
|
+
): Promise<WorkerFlowmapDataProvider> {
|
|
9
|
+
const worker = new Worker(
|
|
10
|
+
new URL('./' + 'WorkerFlowmapDataProviderWorker', import.meta.url),
|
|
11
|
+
);
|
|
12
|
+
const WorkerFlowmapDataProvider =
|
|
13
|
+
Comlink.wrap<WorkerFlowmapDataProvider>(worker);
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
const provider = await new WorkerFlowmapDataProvider(props);
|
|
16
|
+
await provider.loadData();
|
|
17
|
+
return provider;
|
|
18
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type FlowmapData<L, F> = {
|
|
2
2
|
locations: L[] | undefined;
|
|
3
3
|
flows: F[] | undefined;
|
|
4
4
|
};
|
|
@@ -33,7 +33,7 @@ export interface LocationAccessors<L> {
|
|
|
33
33
|
// getLocationTotalInternal?: LocationAccessor<number>;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
export type
|
|
36
|
+
export type FlowmapDataAccessors<L, F> = LocationAccessors<L> &
|
|
37
37
|
FlowAccessors<F>;
|
|
38
38
|
|
|
39
39
|
export interface LocationTotals {
|
package/src/util.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import {createSelectorCreator, defaultMemoize} from 'reselect';
|
|
2
2
|
|
|
3
|
-
export function flatMap<S, T>(xs: S[], f: (item: S) => T | T[]): T[] {
|
|
4
|
-
return xs.reduce((acc: T[], x: S) => acc.concat(f(x)), []);
|
|
5
|
-
}
|
|
6
|
-
|
|
7
3
|
export const createDebugSelector = createSelectorCreator(defaultMemoize, {
|
|
8
4
|
equalityCheck: (previousVal: any, currentVal: any) => {
|
|
9
5
|
const rv = currentVal === previousVal;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FlowMapSelectors.d.ts","sourceRoot":"","sources":["../src/FlowMapSelectors.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAC,WAAW,EAAyB,MAAM,UAAU,CAAC;AAE7D,OAAO,EAIL,kBAAkB,EACnB,MAAM,UAAU,CAAC;AAGlB,OAAO,EAEL,YAAY,EAGb,MAAM,wBAAwB,CAAC;AAChC,OAAkB,EAChB,UAAU,EACV,cAAc,EAMf,MAAM,UAAU,CAAC;AAClB,OAAO,yBAAyB,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAIL,kBAAkB,EACnB,MAAM,QAAQ,CAAC;AAChB,OAAO,EACL,aAAa,EACb,OAAO,EACP,WAAW,EACX,WAAW,EAEX,0BAA0B,EAC1B,wBAAwB,EACxB,WAAW,EACX,oBAAoB,EAGpB,UAAU,EACV,kBAAkB,EAClB,cAAc,EACf,MAAM,SAAS,CAAC;AAKjB,aAAK,UAAU,GAAG,GAAG,CAAC;AAEtB,oBAAY,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,kBAAkB,CAChD,YAAY,EACZ,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,EACjB,CAAC,CACF,CAAC;AAEF,MAAM,CAAC,OAAO,OAAO,gBAAgB,CAAC,CAAC,EAAE,CAAC;IACxC,SAAS,EAAE,yBAAyB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;gBAE/B,SAAS,EAAE,oBAAoB,CAAC,CAAC,EAAE,CAAC,CAAC;IAKjD,YAAY,CAAC,SAAS,EAAE,oBAAoB,CAAC,CAAC,EAAE,CAAC,CAAC;IAIlD,eAAe,UAAW,YAAY,SAAS,YAAY,CAAC,EAAE,CAAC,CAAC,qBAClD;IACd,mBAAmB,U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