-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from earthrise-media/add-tooltips
Add map tooltips
- Loading branch information
Showing
11 changed files
with
268 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<template> | ||
<TooltipWrapper v-if="hoveredId"> | ||
{{ sentence }} | ||
</TooltipWrapper> | ||
</template> | ||
|
||
<script setup> | ||
import * as d3 from 'd3' | ||
import { computed } from 'vue' | ||
import TooltipWrapper from '@/components/TooltipWrapper.vue' | ||
import { storeToRefs } from 'pinia' | ||
import { useMapExploreStore } from '@/stores/mapExplore' | ||
import { useCropYieldsStore } from '@/stores/cropYields' | ||
import { useFiltersStore } from '@/stores/filters' | ||
import { useContentStore } from '@/stores/siteContent' | ||
import { useCropInformationStore } from '@/stores/cropInformation' | ||
const filtersStore = useFiltersStore() | ||
const cropYieldsStore = useCropYieldsStore() | ||
const mapExploreStore = useMapExploreStore() | ||
const contentStore = useContentStore() | ||
const cropInformationStore = useCropInformationStore() | ||
const { hoveredId } = storeToRefs(mapExploreStore) | ||
const { data: yieldData } = storeToRefs(cropYieldsStore) | ||
const { selectedCrop, selectedModel } = storeToRefs(filtersStore) | ||
const { copy } = storeToRefs(contentStore) | ||
const { data: cropInfo } = storeToRefs(cropInformationStore) | ||
const sentence = computed(() => { | ||
const cropName = cropInfo.value?.find((d) => d.id === selectedCrop.value)?.label | ||
const modelDescriptor = | ||
selectedModel.value === 'future_ssp126' | ||
? 'a low emissions scenario' | ||
: 'a high emissions scenario' | ||
return `In ${modelDescriptor}, ${cropName} has a yield ratio of ${hoveredValue.value} at this location` | ||
}) | ||
const hoveredValue = computed(() => { | ||
if (!yieldData.value || !selectedCrop.value || !selectedModel.value || !hoveredId.value) return '' | ||
const columnName = `yieldratio_${selectedCrop.value}_${selectedModel.value}` | ||
const cellObject = yieldData.value.find((d) => d.id === hoveredId.value) | ||
if (!cellObject) return '' | ||
return vFormat(cellObject[columnName]) | ||
}) | ||
const vFormat = (value) => { | ||
return d3.format('.2f')(value) | ||
} | ||
</script> | ||
<style scoped></style> |
Oops, something went wrong.