Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.

Commit f46de80

Browse files
authored
fix loadDataPoints concurrency issue (#42)
Co-authored-by: wujekbogdan <[email protected]>
1 parent 44c2815 commit f46de80

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/js/points.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,22 +125,28 @@ function parseCityLabelItem(item) {
125125
}
126126

127127
function loadCityLabels() {
128-
loadData(
129-
new URL("../../asset/labels.tsv", import.meta.url),
130-
parseCityLabelItem,
131-
cityLabels, // Store city labels in the cityLabels array
132-
() => {},
133-
);
128+
return new Promise((resolve) => {
129+
loadData(
130+
new URL("../../asset/labels.tsv", import.meta.url),
131+
parseCityLabelItem, // sets cityLabelsByClusterId
132+
cityLabels, // Store city labels in the cityLabels array
133+
() => {
134+
resolve();
135+
},
136+
);
137+
});
134138
}
135139

136-
export function loadDataPoints() {
140+
export async function loadDataPoints() {
141+
await loadCityLabels();
142+
// `parseDataPointItem` relies on `cityLabelsByClusterId`, which is populated by `loadCityLabels`.
143+
// So, we need to ensure that city labels are fully loaded before loading data points.
137144
loadData(
138145
new URL("../../asset/data.tsv", import.meta.url),
139146
parseDataPointItem,
140147
data, // Separate array for data points
141148
handleDataPointsLoaded,
142149
);
143-
loadCityLabels(); // Load city labels after loading data points
144150
}
145151

146152
export function loadConcepts() {

0 commit comments

Comments
 (0)