Skip to content

Commit 1498992

Browse files
authored
Merge pull request #195 from Dataport/fix/text-locator-heatmap
Fix/text locator heatmap
2 parents 50eb85b + 9c73aee commit 1498992

File tree

4 files changed

+8
-23
lines changed

4 files changed

+8
-23
lines changed

packages/clients/textLocator/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Breaking: Adapt client to new backend API. Previous versions are no longer runnable due the backend API change.
66
- Feature: Implement document search, that is, the AddressSearch bar now also offers results for documents and clicking on one will retrieve a list of toponyms from the backend and resolve them against the gazetteer. Previously, we had a "get all documents regarding place" functionality. Now, a "get all places regarding document" feature is implemented. Additionally to the AddressSearch, this can be triggered on documents found in the previously implemented way; the "get all places regarding document" functionality is available from within the GeoSearch result display.
7+
- Fix: Adjust heatmap feature to match the new data structure and have it working again.
78

89
## 1.0.0-alpha.0
910

packages/clients/textLocator/src/palettes.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export const pastelPalette = [
3030
'#b3b3b3',
3131
]
3232

33-
// TODO: Use later for text search result heatmaps
3433
export const heatPalette = [
3534
'#fff5f0',
3635
'#fee2d5',

packages/clients/textLocator/src/plugins/GeometrySearch/utils/vectorDisplay.ts

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,14 @@ const getZoomFeatures = (features: OlFeature[], item: TreeViewItem | null) =>
3737

3838
const featHeat = (
3939
olFeatures: OlFeature[],
40-
titleLocationFrequency: TitleLocationFrequency
40+
locationFrequency: TitleLocationFrequency['string']['location_frequency']
4141
) => {
42-
// TODO change id from name to something id-worthy
43-
const sums: Record<string, number> = olFeatures.reduce(
44-
(accumulator, current) => ({
45-
...accumulator,
46-
// sum occurrence of toponyms cross-document
47-
[current.get('title')]:
48-
(accumulator[current.get('title')] || 0) +
49-
Object.values(titleLocationFrequency).reduce(
50-
(perTitleAccumulator, toponymToAmount) =>
51-
perTitleAccumulator + (toponymToAmount[current.get('title')] || 0),
52-
0
53-
),
54-
}),
55-
{} as Record<string, number>
56-
)
57-
const max = Math.max(...Object.values(sums))
42+
const max = Math.max(...Object.values(locationFrequency))
5843
olFeatures.forEach((feature) =>
59-
feature.set('heat', Math.floor((sums[feature.get('title')] / max) * 9))
44+
feature.set(
45+
'heat',
46+
Math.floor((locationFrequency[feature.getId() as string] / max) * 9)
47+
)
6048
)
6149
}
6250

@@ -91,7 +79,7 @@ export const updateVectorLayer = (
9179

9280
preparedFeatures.forEach((feature) => feature.set('heat', undefined))
9381
if (item?.children?.length && item.type === 'text') {
94-
featHeat(zoomFeatures, titleLocationFrequency)
82+
featHeat(zoomFeatures, titleLocationFrequency[item.id].location_frequency)
9583
}
9684

9785
vectorSource.addFeatures(preparedFeatures)

packages/clients/textLocator/src/utils/coastalGazetteer/makeRequestBody.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ const unify = (geometry: Geometry): Geometry => {
2323
// NOTE: never null, input from flatten merges as expected
2424
return (union(flatten(geometry)) as Feature<Polygon>).geometry
2525
}
26-
console.warn(
27-
`@polar/client-text-locator: Unexpected geometry in request body creation.`
28-
)
2926
return geometry
3027
}
3128

0 commit comments

Comments
 (0)