Skip to content

Commit

Permalink
Merge pull request #195 from Dataport/fix/text-locator-heatmap
Browse files Browse the repository at this point in the history
Fix/text locator heatmap
  • Loading branch information
warm-coolguy authored Nov 18, 2024
2 parents 50eb85b + 9c73aee commit 1498992
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 23 deletions.
1 change: 1 addition & 0 deletions packages/clients/textLocator/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Breaking: Adapt client to new backend API. Previous versions are no longer runnable due the backend API change.
- 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.
- Fix: Adjust heatmap feature to match the new data structure and have it working again.

## 1.0.0-alpha.0

Expand Down
1 change: 0 additions & 1 deletion packages/clients/textLocator/src/palettes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export const pastelPalette = [
'#b3b3b3',
]

// TODO: Use later for text search result heatmaps
export const heatPalette = [
'#fff5f0',
'#fee2d5',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,14 @@ const getZoomFeatures = (features: OlFeature[], item: TreeViewItem | null) =>

const featHeat = (
olFeatures: OlFeature[],
titleLocationFrequency: TitleLocationFrequency
locationFrequency: TitleLocationFrequency['string']['location_frequency']
) => {
// TODO change id from name to something id-worthy
const sums: Record<string, number> = olFeatures.reduce(
(accumulator, current) => ({
...accumulator,
// sum occurrence of toponyms cross-document
[current.get('title')]:
(accumulator[current.get('title')] || 0) +
Object.values(titleLocationFrequency).reduce(
(perTitleAccumulator, toponymToAmount) =>
perTitleAccumulator + (toponymToAmount[current.get('title')] || 0),
0
),
}),
{} as Record<string, number>
)
const max = Math.max(...Object.values(sums))
const max = Math.max(...Object.values(locationFrequency))
olFeatures.forEach((feature) =>
feature.set('heat', Math.floor((sums[feature.get('title')] / max) * 9))
feature.set(
'heat',
Math.floor((locationFrequency[feature.getId() as string] / max) * 9)
)
)
}

Expand Down Expand Up @@ -91,7 +79,7 @@ export const updateVectorLayer = (

preparedFeatures.forEach((feature) => feature.set('heat', undefined))
if (item?.children?.length && item.type === 'text') {
featHeat(zoomFeatures, titleLocationFrequency)
featHeat(zoomFeatures, titleLocationFrequency[item.id].location_frequency)
}

vectorSource.addFeatures(preparedFeatures)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ const unify = (geometry: Geometry): Geometry => {
// NOTE: never null, input from flatten merges as expected
return (union(flatten(geometry)) as Feature<Polygon>).geometry
}
console.warn(
`@polar/client-text-locator: Unexpected geometry in request body creation.`
)
return geometry
}

Expand Down

0 comments on commit 1498992

Please sign in to comment.