@flowmap.gl/data 8.0.0-alpha.3 → 8.0.0-alpha.7
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} +45 -44
- package/dist/FlowmapSelectors.d.ts.map +1 -0
- package/dist/FlowmapSelectors.js +870 -0
- package/dist/{FlowMapState.d.ts → FlowmapState.d.ts} +4 -2
- package/dist/{FlowMapState.d.ts.map → FlowmapState.d.ts.map} +1 -1
- package/dist/{FlowMapState.js → FlowmapState.js} +1 -1
- package/dist/colors.d.ts +5 -5
- package/dist/colors.d.ts.map +1 -1
- package/dist/colors.js +6 -6
- package/dist/getViewStateForLocations.d.ts +18 -11
- package/dist/getViewStateForLocations.d.ts.map +1 -1
- package/dist/getViewStateForLocations.js +21 -18
- 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 -3
- package/src/{FlowMapAggregateAccessors.ts → FlowmapAggregateAccessors.ts} +6 -6
- package/src/{FlowMapSelectors.ts → FlowmapSelectors.ts} +157 -122
- package/src/{FlowMapState.ts → FlowmapState.ts} +3 -1
- package/src/colors.ts +7 -7
- package/src/getViewStateForLocations.ts +39 -35
- 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 -835
- 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
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
*
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
import {
|
|
19
|
+
import {WebMercatorViewport} from '@math.gl/web-mercator';
|
|
20
20
|
import {ascending, descending, extent, min} from 'd3-array';
|
|
21
21
|
import {nest} from 'd3-collection';
|
|
22
22
|
import {ScaleLinear, scaleLinear, scaleSqrt} from 'd3-scale';
|
|
@@ -44,8 +44,8 @@ import getColors, {
|
|
|
44
44
|
isDiffColors,
|
|
45
45
|
isDiffColorsRGBA,
|
|
46
46
|
} from './colors';
|
|
47
|
-
import
|
|
48
|
-
import {
|
|
47
|
+
import FlowmapAggregateAccessors from './FlowmapAggregateAccessors';
|
|
48
|
+
import {FlowmapState} from './FlowmapState';
|
|
49
49
|
import {
|
|
50
50
|
getTimeGranularityByKey,
|
|
51
51
|
getTimeGranularityByOrder,
|
|
@@ -60,85 +60,85 @@ import {
|
|
|
60
60
|
FlowAccessors,
|
|
61
61
|
FlowCirclesLayerAttributes,
|
|
62
62
|
FlowLinesLayerAttributes,
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
FlowmapData,
|
|
64
|
+
FlowmapDataAccessors,
|
|
65
65
|
isCluster,
|
|
66
66
|
isLocationClusterNode,
|
|
67
67
|
LayersData,
|
|
68
68
|
LocationFilterMode,
|
|
69
69
|
LocationTotals,
|
|
70
70
|
} from './types';
|
|
71
|
-
import {flatMap} from './util';
|
|
72
71
|
|
|
73
72
|
const MAX_CLUSTER_ZOOM_LEVEL = 20;
|
|
74
|
-
const NUMBER_OF_FLOWS_TO_DISPLAY = 5000;
|
|
75
73
|
type KDBushTree = any;
|
|
76
74
|
|
|
77
75
|
export type Selector<L, F, T> = ParametricSelector<
|
|
78
|
-
|
|
79
|
-
|
|
76
|
+
FlowmapState,
|
|
77
|
+
FlowmapData<L, F>,
|
|
80
78
|
T
|
|
81
79
|
>;
|
|
82
80
|
|
|
83
|
-
export default class
|
|
84
|
-
accessors:
|
|
81
|
+
export default class FlowmapSelectors<L, F> {
|
|
82
|
+
accessors: FlowmapAggregateAccessors<L, F>;
|
|
85
83
|
|
|
86
|
-
constructor(accessors:
|
|
87
|
-
this.accessors = new
|
|
84
|
+
constructor(accessors: FlowmapDataAccessors<L, F>) {
|
|
85
|
+
this.accessors = new FlowmapAggregateAccessors(accessors);
|
|
88
86
|
this.setAccessors(accessors);
|
|
89
87
|
}
|
|
90
88
|
|
|
91
|
-
setAccessors(accessors:
|
|
92
|
-
this.accessors = new
|
|
89
|
+
setAccessors(accessors: FlowmapDataAccessors<L, F>) {
|
|
90
|
+
this.accessors = new FlowmapAggregateAccessors(accessors);
|
|
93
91
|
}
|
|
94
92
|
|
|
95
|
-
getFetchedFlows = (state:
|
|
93
|
+
getFetchedFlows = (state: FlowmapState, props: FlowmapData<L, F>) =>
|
|
96
94
|
props.flows;
|
|
97
|
-
getFetchedLocations = (state:
|
|
95
|
+
getFetchedLocations = (state: FlowmapState, props: FlowmapData<L, F>) =>
|
|
98
96
|
props.locations;
|
|
99
|
-
|
|
97
|
+
getMaxTopFlowsDisplayNum = (state: FlowmapState, props: FlowmapData<L, F>) =>
|
|
98
|
+
state.settingsState.maxTopFlowsDisplayNum;
|
|
99
|
+
getSelectedLocations = (state: FlowmapState, props: FlowmapData<L, F>) =>
|
|
100
100
|
state.filterState.selectedLocations;
|
|
101
|
-
getLocationFilterMode = (state:
|
|
101
|
+
getLocationFilterMode = (state: FlowmapState, props: FlowmapData<L, F>) =>
|
|
102
102
|
state.filterState.locationFilterMode;
|
|
103
|
-
getClusteringEnabled = (state:
|
|
103
|
+
getClusteringEnabled = (state: FlowmapState, props: FlowmapData<L, F>) =>
|
|
104
104
|
state.settingsState.clusteringEnabled;
|
|
105
|
-
getLocationTotalsEnabled = (state:
|
|
105
|
+
getLocationTotalsEnabled = (state: FlowmapState, props: FlowmapData<L, F>) =>
|
|
106
106
|
state.settingsState.locationTotalsEnabled;
|
|
107
|
-
getZoom = (state:
|
|
107
|
+
getZoom = (state: FlowmapState, props: FlowmapData<L, F>) =>
|
|
108
108
|
state.viewport.zoom;
|
|
109
|
-
getViewport = (state:
|
|
109
|
+
getViewport = (state: FlowmapState, props: FlowmapData<L, F>) =>
|
|
110
110
|
state.viewport;
|
|
111
|
-
getSelectedTimeRange = (state:
|
|
111
|
+
getSelectedTimeRange = (state: FlowmapState, props: FlowmapData<L, F>) =>
|
|
112
112
|
state.filterState.selectedTimeRange;
|
|
113
113
|
|
|
114
114
|
getColorSchemeKey: Selector<L, F, string | undefined> = (
|
|
115
|
-
state:
|
|
116
|
-
props:
|
|
115
|
+
state: FlowmapState,
|
|
116
|
+
props: FlowmapData<L, F>,
|
|
117
117
|
) => state.settingsState.colorScheme;
|
|
118
118
|
|
|
119
119
|
getDarkMode: Selector<L, F, boolean> = (
|
|
120
|
-
state:
|
|
121
|
-
props:
|
|
120
|
+
state: FlowmapState,
|
|
121
|
+
props: FlowmapData<L, F>,
|
|
122
122
|
) => state.settingsState.darkMode;
|
|
123
123
|
|
|
124
124
|
getFadeEnabled: Selector<L, F, boolean> = (
|
|
125
|
-
state:
|
|
126
|
-
props:
|
|
125
|
+
state: FlowmapState,
|
|
126
|
+
props: FlowmapData<L, F>,
|
|
127
127
|
) => state.settingsState.fadeEnabled;
|
|
128
128
|
|
|
129
129
|
getFadeOpacityEnabled: Selector<L, F, boolean> = (
|
|
130
|
-
state:
|
|
131
|
-
props:
|
|
130
|
+
state: FlowmapState,
|
|
131
|
+
props: FlowmapData<L, F>,
|
|
132
132
|
) => state.settingsState.fadeOpacityEnabled;
|
|
133
133
|
|
|
134
134
|
getFadeAmount: Selector<L, F, number> = (
|
|
135
|
-
state:
|
|
136
|
-
props:
|
|
135
|
+
state: FlowmapState,
|
|
136
|
+
props: FlowmapData<L, F>,
|
|
137
137
|
) => state.settingsState.fadeAmount;
|
|
138
138
|
|
|
139
139
|
getAnimate: Selector<L, F, boolean> = (
|
|
140
|
-
state:
|
|
141
|
-
props:
|
|
140
|
+
state: FlowmapState,
|
|
141
|
+
props: FlowmapData<L, F>,
|
|
142
142
|
) => state.settingsState.animationEnabled;
|
|
143
143
|
|
|
144
144
|
getInvalidLocationIds: Selector<L, F, string[] | undefined> = createSelector(
|
|
@@ -309,11 +309,11 @@ export default class FlowMapSelectors<L, F> {
|
|
|
309
309
|
|
|
310
310
|
const getLocationWeight = makeLocationWeightGetter(
|
|
311
311
|
flows,
|
|
312
|
-
this.accessors.
|
|
312
|
+
this.accessors.getFlowmapDataAccessors(),
|
|
313
313
|
);
|
|
314
314
|
const clusterLevels = clusterLocations(
|
|
315
315
|
locations,
|
|
316
|
-
this.accessors.
|
|
316
|
+
this.accessors.getFlowmapDataAccessors(),
|
|
317
317
|
getLocationWeight,
|
|
318
318
|
{
|
|
319
319
|
maxZoom: MAX_CLUSTER_ZOOM_LEVEL,
|
|
@@ -321,7 +321,7 @@ export default class FlowMapSelectors<L, F> {
|
|
|
321
321
|
);
|
|
322
322
|
const clusterIndex = buildIndex<F>(clusterLevels);
|
|
323
323
|
const {getLocationName, getLocationClusterName} =
|
|
324
|
-
this.accessors.
|
|
324
|
+
this.accessors.getFlowmapDataAccessors();
|
|
325
325
|
|
|
326
326
|
// Adding meaningful names
|
|
327
327
|
const getName = (id: string) => {
|
|
@@ -416,7 +416,7 @@ export default class FlowMapSelectors<L, F> {
|
|
|
416
416
|
},
|
|
417
417
|
);
|
|
418
418
|
|
|
419
|
-
getClusterZoom = (state:
|
|
419
|
+
getClusterZoom = (state: FlowmapState, props: FlowmapData<L, F>) => {
|
|
420
420
|
const {settingsState} = state;
|
|
421
421
|
if (!settingsState.clusteringEnabled) return undefined;
|
|
422
422
|
if (settingsState.clusteringAuto || settingsState.clusteringLevel == null) {
|
|
@@ -487,7 +487,7 @@ export default class FlowMapSelectors<L, F> {
|
|
|
487
487
|
},
|
|
488
488
|
);
|
|
489
489
|
|
|
490
|
-
|
|
490
|
+
_getFlowmapColors = createSelector(
|
|
491
491
|
this.getDiffMode,
|
|
492
492
|
this.getColorSchemeKey,
|
|
493
493
|
this.getDarkMode,
|
|
@@ -498,12 +498,12 @@ export default class FlowMapSelectors<L, F> {
|
|
|
498
498
|
getColors,
|
|
499
499
|
);
|
|
500
500
|
|
|
501
|
-
|
|
502
|
-
this.
|
|
503
|
-
(
|
|
504
|
-
return isDiffColors(
|
|
505
|
-
? getDiffColorsRGBA(
|
|
506
|
-
: getColorsRGBA(
|
|
501
|
+
getFlowmapColorsRGBA = createSelector(
|
|
502
|
+
this._getFlowmapColors,
|
|
503
|
+
(flowmapColors) => {
|
|
504
|
+
return isDiffColors(flowmapColors)
|
|
505
|
+
? getDiffColorsRGBA(flowmapColors)
|
|
506
|
+
: getColorsRGBA(flowmapColors);
|
|
507
507
|
},
|
|
508
508
|
);
|
|
509
509
|
|
|
@@ -550,12 +550,12 @@ export default class FlowMapSelectors<L, F> {
|
|
|
550
550
|
// : flows,
|
|
551
551
|
flows,
|
|
552
552
|
clusterZoom,
|
|
553
|
-
this.accessors.
|
|
553
|
+
this.accessors.getFlowmapDataAccessors(),
|
|
554
554
|
);
|
|
555
555
|
} else {
|
|
556
556
|
aggregated = aggregateFlows(
|
|
557
557
|
flows,
|
|
558
|
-
this.accessors.
|
|
558
|
+
this.accessors.getFlowmapDataAccessors(),
|
|
559
559
|
);
|
|
560
560
|
}
|
|
561
561
|
aggregated.sort((a, b) =>
|
|
@@ -676,12 +676,12 @@ export default class FlowMapSelectors<L, F> {
|
|
|
676
676
|
this.getMaxLocationCircleSize,
|
|
677
677
|
(viewport, maxLocationCircleSize) => {
|
|
678
678
|
const pad = maxLocationCircleSize;
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
viewport.
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
679
|
+
const bounds = new WebMercatorViewport({
|
|
680
|
+
...viewport,
|
|
681
|
+
width: viewport.width + pad * 2,
|
|
682
|
+
height: viewport.height + pad * 2,
|
|
683
|
+
}).getBounds();
|
|
684
|
+
return [bounds[0][0], bounds[0][1], bounds[1][0], bounds[1][1]];
|
|
685
685
|
},
|
|
686
686
|
);
|
|
687
687
|
|
|
@@ -851,8 +851,8 @@ export default class FlowMapSelectors<L, F> {
|
|
|
851
851
|
);
|
|
852
852
|
|
|
853
853
|
getLocationTotalsExtent = (
|
|
854
|
-
state:
|
|
855
|
-
props:
|
|
854
|
+
state: FlowmapState,
|
|
855
|
+
props: FlowmapData<L, F>,
|
|
856
856
|
): [number, number] | undefined => {
|
|
857
857
|
if (state.settingsState.adaptiveScalesEnabled) {
|
|
858
858
|
return this._getLocationTotalsForViewportExtent(state, props);
|
|
@@ -861,17 +861,19 @@ export default class FlowMapSelectors<L, F> {
|
|
|
861
861
|
}
|
|
862
862
|
};
|
|
863
863
|
|
|
864
|
-
|
|
864
|
+
getFlowsForFlowmapLayer: Selector<L, F, (F | AggregateFlow)[] | undefined> =
|
|
865
865
|
createSelector(
|
|
866
866
|
this.getSortedAggregatedFilteredFlows,
|
|
867
867
|
this.getLocationIdsInViewport,
|
|
868
868
|
this.getSelectedLocationsSet,
|
|
869
869
|
this.getLocationFilterMode,
|
|
870
|
+
this.getMaxTopFlowsDisplayNum,
|
|
870
871
|
(
|
|
871
872
|
flows,
|
|
872
873
|
locationIdsInViewport,
|
|
873
874
|
selectedLocationsSet,
|
|
874
875
|
locationFilterMode,
|
|
876
|
+
maxTopFlowsDisplayNum,
|
|
875
877
|
) => {
|
|
876
878
|
if (!flows || !locationIdsInViewport) return undefined;
|
|
877
879
|
const picked: (F | AggregateFlow)[] = [];
|
|
@@ -898,7 +900,7 @@ export default class FlowMapSelectors<L, F> {
|
|
|
898
900
|
}
|
|
899
901
|
}
|
|
900
902
|
// Only keep top
|
|
901
|
-
if (pickedCount >
|
|
903
|
+
if (pickedCount > maxTopFlowsDisplayNum) break;
|
|
902
904
|
}
|
|
903
905
|
// assuming they are sorted in descending order,
|
|
904
906
|
// we need ascending for rendering
|
|
@@ -907,11 +909,11 @@ export default class FlowMapSelectors<L, F> {
|
|
|
907
909
|
);
|
|
908
910
|
|
|
909
911
|
_getFlowMagnitudeExtent = (
|
|
910
|
-
state:
|
|
911
|
-
props:
|
|
912
|
+
state: FlowmapState,
|
|
913
|
+
props: FlowmapData<L, F>,
|
|
912
914
|
): [number, number] | undefined => {
|
|
913
915
|
if (state.settingsState.adaptiveScalesEnabled) {
|
|
914
|
-
const flows = this.
|
|
916
|
+
const flows = this.getFlowsForFlowmapLayer(state, props);
|
|
915
917
|
if (flows) {
|
|
916
918
|
const rv = extent(flows, this.accessors.getFlowMagnitude);
|
|
917
919
|
return rv[0] !== undefined && rv[1] !== undefined ? rv : undefined;
|
|
@@ -1033,7 +1035,7 @@ export default class FlowMapSelectors<L, F> {
|
|
|
1033
1035
|
},
|
|
1034
1036
|
);
|
|
1035
1037
|
|
|
1036
|
-
|
|
1038
|
+
getLocationsForFlowmapLayer: Selector<
|
|
1037
1039
|
L,
|
|
1038
1040
|
F,
|
|
1039
1041
|
Array<L | ClusterNode> | undefined
|
|
@@ -1063,11 +1065,11 @@ export default class FlowMapSelectors<L, F> {
|
|
|
1063
1065
|
},
|
|
1064
1066
|
);
|
|
1065
1067
|
|
|
1066
|
-
|
|
1068
|
+
getLocationsForFlowmapLayerById: Selector<
|
|
1067
1069
|
L,
|
|
1068
1070
|
F,
|
|
1069
1071
|
Map<string, L | ClusterNode> | undefined
|
|
1070
|
-
> = createSelector(this.
|
|
1072
|
+
> = createSelector(this.getLocationsForFlowmapLayer, (locations) => {
|
|
1071
1073
|
if (!locations) return undefined;
|
|
1072
1074
|
return locations.reduce(
|
|
1073
1075
|
(m, d) => (m.set(this.accessors.getLocationId(d), d), m),
|
|
@@ -1076,10 +1078,10 @@ export default class FlowMapSelectors<L, F> {
|
|
|
1076
1078
|
});
|
|
1077
1079
|
|
|
1078
1080
|
getLayersData: Selector<L, F, LayersData> = createSelector(
|
|
1079
|
-
this.
|
|
1080
|
-
this.
|
|
1081
|
-
this.
|
|
1082
|
-
this.
|
|
1081
|
+
this.getLocationsForFlowmapLayer,
|
|
1082
|
+
this.getFlowsForFlowmapLayer,
|
|
1083
|
+
this.getFlowmapColorsRGBA,
|
|
1084
|
+
this.getLocationsForFlowmapLayerById,
|
|
1083
1085
|
this.getLocationIdsInViewport,
|
|
1084
1086
|
this.getInCircleSizeGetter,
|
|
1085
1087
|
this.getOutCircleSizeGetter,
|
|
@@ -1088,7 +1090,7 @@ export default class FlowMapSelectors<L, F> {
|
|
|
1088
1090
|
(
|
|
1089
1091
|
locations,
|
|
1090
1092
|
flows,
|
|
1091
|
-
|
|
1093
|
+
flowmapColors,
|
|
1092
1094
|
locationsById,
|
|
1093
1095
|
locationIdsInViewport,
|
|
1094
1096
|
getInCircleSize,
|
|
@@ -1099,7 +1101,7 @@ export default class FlowMapSelectors<L, F> {
|
|
|
1099
1101
|
return this._prepareLayersData(
|
|
1100
1102
|
locations,
|
|
1101
1103
|
flows,
|
|
1102
|
-
|
|
1104
|
+
flowmapColors,
|
|
1103
1105
|
locationsById,
|
|
1104
1106
|
locationIdsInViewport,
|
|
1105
1107
|
getInCircleSize,
|
|
@@ -1110,11 +1112,11 @@ export default class FlowMapSelectors<L, F> {
|
|
|
1110
1112
|
},
|
|
1111
1113
|
);
|
|
1112
1114
|
|
|
1113
|
-
prepareLayersData(state:
|
|
1114
|
-
const locations = this.
|
|
1115
|
-
const flows = this.
|
|
1116
|
-
const
|
|
1117
|
-
const locationsById = this.
|
|
1115
|
+
prepareLayersData(state: FlowmapState, props: FlowmapData<L, F>): LayersData {
|
|
1116
|
+
const locations = this.getLocationsForFlowmapLayer(state, props) || [];
|
|
1117
|
+
const flows = this.getFlowsForFlowmapLayer(state, props) || [];
|
|
1118
|
+
const flowmapColors = this.getFlowmapColorsRGBA(state, props);
|
|
1119
|
+
const locationsById = this.getLocationsForFlowmapLayerById(state, props);
|
|
1118
1120
|
const locationIdsInViewport = this.getLocationIdsInViewport(state, props);
|
|
1119
1121
|
const getInCircleSize = this.getInCircleSizeGetter(state, props);
|
|
1120
1122
|
const getOutCircleSize = this.getOutCircleSizeGetter(state, props);
|
|
@@ -1122,7 +1124,7 @@ export default class FlowMapSelectors<L, F> {
|
|
|
1122
1124
|
return this._prepareLayersData(
|
|
1123
1125
|
locations,
|
|
1124
1126
|
flows,
|
|
1125
|
-
|
|
1127
|
+
flowmapColors,
|
|
1126
1128
|
locationsById,
|
|
1127
1129
|
locationIdsInViewport,
|
|
1128
1130
|
getInCircleSize,
|
|
@@ -1135,7 +1137,7 @@ export default class FlowMapSelectors<L, F> {
|
|
|
1135
1137
|
_prepareLayersData(
|
|
1136
1138
|
locations: (L | ClusterNode)[] | undefined,
|
|
1137
1139
|
flows: (F | AggregateFlow)[] | undefined,
|
|
1138
|
-
|
|
1140
|
+
flowmapColors: DiffColorsRGBA | ColorsRGBA,
|
|
1139
1141
|
locationsById: Map<string, L | ClusterNode> | undefined,
|
|
1140
1142
|
locationIdsInViewport: Set<string> | undefined,
|
|
1141
1143
|
getInCircleSize: (locationId: string) => number,
|
|
@@ -1163,67 +1165,100 @@ export default class FlowMapSelectors<L, F> {
|
|
|
1163
1165
|
number,
|
|
1164
1166
|
];
|
|
1165
1167
|
const flowColorScale = getFlowColorScale(
|
|
1166
|
-
|
|
1168
|
+
flowmapColors,
|
|
1167
1169
|
flowMagnitudeExtent,
|
|
1168
1170
|
false,
|
|
1169
1171
|
);
|
|
1170
1172
|
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
+
// Using a generator here helps to avoid creating intermediary arrays
|
|
1174
|
+
const circlePositions = Float32Array.from(
|
|
1175
|
+
(function* () {
|
|
1176
|
+
for (const location of locations) {
|
|
1177
|
+
// yield* effectively works as flatMap here
|
|
1178
|
+
yield* getLocationCentroid(location);
|
|
1179
|
+
}
|
|
1180
|
+
})(),
|
|
1173
1181
|
);
|
|
1174
1182
|
|
|
1175
1183
|
// TODO: diff mode
|
|
1176
|
-
const circleColor = isDiffColorsRGBA(
|
|
1177
|
-
?
|
|
1178
|
-
:
|
|
1179
|
-
|
|
1180
|
-
const circleColors =
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
}),
|
|
1184
|
+
const circleColor = isDiffColorsRGBA(flowmapColors)
|
|
1185
|
+
? flowmapColors.positive.locationCircles.inner
|
|
1186
|
+
: flowmapColors.locationCircles.inner;
|
|
1187
|
+
|
|
1188
|
+
const circleColors = Uint8Array.from(
|
|
1189
|
+
(function* () {
|
|
1190
|
+
for (const location of locations) {
|
|
1191
|
+
yield* circleColor;
|
|
1192
|
+
}
|
|
1193
|
+
})(),
|
|
1194
|
+
);
|
|
1195
|
+
|
|
1196
|
+
const inCircleRadii = Float32Array.from(
|
|
1197
|
+
(function* () {
|
|
1198
|
+
for (const location of locations) {
|
|
1199
|
+
const id = getLocationId(location);
|
|
1200
|
+
yield locationIdsInViewport?.has(id) ? getInCircleSize(id) : 1.0;
|
|
1201
|
+
}
|
|
1202
|
+
})(),
|
|
1186
1203
|
);
|
|
1187
|
-
const outCircleRadii =
|
|
1188
|
-
|
|
1189
|
-
const
|
|
1190
|
-
|
|
1191
|
-
|
|
1204
|
+
const outCircleRadii = Float32Array.from(
|
|
1205
|
+
(function* () {
|
|
1206
|
+
for (const location of locations) {
|
|
1207
|
+
const id = getLocationId(location);
|
|
1208
|
+
yield locationIdsInViewport?.has(id) ? getOutCircleSize(id) : 1.0;
|
|
1209
|
+
}
|
|
1210
|
+
})(),
|
|
1192
1211
|
);
|
|
1193
1212
|
|
|
1194
|
-
const sourcePositions =
|
|
1195
|
-
|
|
1213
|
+
const sourcePositions = Float32Array.from(
|
|
1214
|
+
(function* () {
|
|
1215
|
+
for (const flow of flows) {
|
|
1216
|
+
yield* getCentroid(getFlowOriginId(flow));
|
|
1217
|
+
}
|
|
1218
|
+
})(),
|
|
1196
1219
|
);
|
|
1197
|
-
const targetPositions =
|
|
1198
|
-
|
|
1220
|
+
const targetPositions = Float32Array.from(
|
|
1221
|
+
(function* () {
|
|
1222
|
+
for (const flow of flows) {
|
|
1223
|
+
yield* getCentroid(getFlowDestId(flow));
|
|
1224
|
+
}
|
|
1225
|
+
})(),
|
|
1199
1226
|
);
|
|
1200
|
-
const thicknesses =
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1227
|
+
const thicknesses = Float32Array.from(
|
|
1228
|
+
(function* () {
|
|
1229
|
+
for (const flow of flows) {
|
|
1230
|
+
yield flowThicknessScale
|
|
1231
|
+
? flowThicknessScale(getFlowMagnitude(flow)) || 0
|
|
1232
|
+
: 0;
|
|
1233
|
+
}
|
|
1234
|
+
})(),
|
|
1204
1235
|
);
|
|
1205
|
-
const endpointOffsets =
|
|
1206
|
-
|
|
1207
|
-
const
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
Math.max(getInCircleSize(originId), getOutCircleSize(originId))
|
|
1211
|
-
Math.max(getInCircleSize(destId), getOutCircleSize(destId))
|
|
1212
|
-
|
|
1213
|
-
}),
|
|
1236
|
+
const endpointOffsets = Float32Array.from(
|
|
1237
|
+
(function* () {
|
|
1238
|
+
for (const flow of flows) {
|
|
1239
|
+
const originId = getFlowOriginId(flow);
|
|
1240
|
+
const destId = getFlowDestId(flow);
|
|
1241
|
+
yield Math.max(getInCircleSize(originId), getOutCircleSize(originId));
|
|
1242
|
+
yield Math.max(getInCircleSize(destId), getOutCircleSize(destId));
|
|
1243
|
+
}
|
|
1244
|
+
})(),
|
|
1214
1245
|
);
|
|
1215
|
-
const flowLineColors =
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1246
|
+
const flowLineColors = Uint8Array.from(
|
|
1247
|
+
(function* () {
|
|
1248
|
+
for (const flow of flows) {
|
|
1249
|
+
yield* flowColorScale(getFlowMagnitude(flow));
|
|
1250
|
+
}
|
|
1251
|
+
})(),
|
|
1219
1252
|
);
|
|
1220
1253
|
|
|
1221
1254
|
const staggeringValues = animationEnabled
|
|
1222
|
-
?
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1255
|
+
? Float32Array.from(
|
|
1256
|
+
(function* () {
|
|
1257
|
+
for (const f of flows) {
|
|
1258
|
+
// @ts-ignore
|
|
1259
|
+
yield new alea(`${getFlowOriginId(f)}-${getFlowDestId(f)}`)();
|
|
1260
|
+
}
|
|
1261
|
+
})(),
|
|
1227
1262
|
)
|
|
1228
1263
|
: undefined;
|
|
1229
1264
|
|
|
@@ -18,9 +18,11 @@ export interface SettingsState {
|
|
|
18
18
|
darkMode: boolean;
|
|
19
19
|
fadeAmount: number;
|
|
20
20
|
colorScheme: string | undefined;
|
|
21
|
+
highlightColor: string;
|
|
22
|
+
maxTopFlowsDisplayNum: number;
|
|
21
23
|
}
|
|
22
24
|
|
|
23
|
-
export interface
|
|
25
|
+
export interface FlowmapState {
|
|
24
26
|
filterState: FilterState;
|
|
25
27
|
settingsState: SettingsState;
|
|
26
28
|
viewport: ViewportProps;
|
package/src/colors.ts
CHANGED
|
@@ -28,7 +28,7 @@ import {range} from 'd3-array';
|
|
|
28
28
|
import {scalePow, scaleSequential, scaleSequentialPow} from 'd3-scale';
|
|
29
29
|
import {interpolateBasis, interpolateRgbBasis} from 'd3-interpolate';
|
|
30
30
|
import {color as d3color, hcl, rgb as colorRgb} from 'd3-color';
|
|
31
|
-
import {SettingsState} from './
|
|
31
|
+
import {SettingsState} from './FlowmapState';
|
|
32
32
|
|
|
33
33
|
const DEFAULT_OUTLINE_COLOR = '#fff';
|
|
34
34
|
const DEFAULT_DIMMED_OPACITY = 0.4;
|
|
@@ -100,7 +100,7 @@ const getColorSteps = (interpolate: (x: number) => string) =>
|
|
|
100
100
|
.reverse();
|
|
101
101
|
|
|
102
102
|
const FLOW_MIN_COLOR = 'rgba(240,240,240,0.5)';
|
|
103
|
-
export const
|
|
103
|
+
export const GRAYISH = [FLOW_MIN_COLOR, ColorScheme.primary];
|
|
104
104
|
const schemeBluYl = [
|
|
105
105
|
'#f7feae',
|
|
106
106
|
'#b7e6a5',
|
|
@@ -134,7 +134,6 @@ export const schemeTeal = [
|
|
|
134
134
|
export const DEFAULT_COLOR_SCHEME = schemeTeal;
|
|
135
135
|
export const COLOR_SCHEMES: {[key: string]: string[]} = {
|
|
136
136
|
Blues: asScheme(schemeBlues),
|
|
137
|
-
BluesPale: BLUES_PALE,
|
|
138
137
|
BluGrn: [
|
|
139
138
|
'#c4e6c3',
|
|
140
139
|
'#96d2a4',
|
|
@@ -186,6 +185,7 @@ export const COLOR_SCHEMES: {[key: string]: string[]} = {
|
|
|
186
185
|
],
|
|
187
186
|
Emrld: schemeEmrld,
|
|
188
187
|
GnBu: asScheme(schemeGnBu),
|
|
188
|
+
Grayish: GRAYISH,
|
|
189
189
|
Greens: asScheme(schemeGreens),
|
|
190
190
|
Greys: asScheme(schemeGreys),
|
|
191
191
|
Inferno: getColorSteps(interpolateInferno),
|
|
@@ -330,7 +330,7 @@ const diffColors: DiffColors = {
|
|
|
330
330
|
outlineColor: 'rgb(230,233,237)',
|
|
331
331
|
};
|
|
332
332
|
|
|
333
|
-
export function
|
|
333
|
+
export function getFlowmapColors(
|
|
334
334
|
settingsState: SettingsState,
|
|
335
335
|
): Colors | DiffColors {
|
|
336
336
|
return getColors(
|
|
@@ -550,7 +550,7 @@ export interface LocationCircleColors {
|
|
|
550
550
|
incoming?: string;
|
|
551
551
|
highlighted?: string;
|
|
552
552
|
empty?: string;
|
|
553
|
-
|
|
553
|
+
outlineEmptyMix?: number;
|
|
554
554
|
}
|
|
555
555
|
|
|
556
556
|
export interface LocationAreaColors {
|
|
@@ -597,7 +597,7 @@ export interface LocationCircleColorsRGBA {
|
|
|
597
597
|
incoming: RGBA;
|
|
598
598
|
highlighted: RGBA;
|
|
599
599
|
empty: RGBA;
|
|
600
|
-
|
|
600
|
+
outlineEmptyMix: number;
|
|
601
601
|
}
|
|
602
602
|
|
|
603
603
|
export interface LocationAreaColorsRGBA {
|
|
@@ -682,7 +682,7 @@ function getFlowAndCircleColors(
|
|
|
682
682
|
flowColorHighlighted,
|
|
683
683
|
),
|
|
684
684
|
empty: emptyColor,
|
|
685
|
-
|
|
685
|
+
outlineEmptyMix: inputColors?.locationCircles?.outlineEmptyMix ?? 0.4,
|
|
686
686
|
},
|
|
687
687
|
};
|
|
688
688
|
}
|