-
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 #37 from earthrise-media/non-gridded-dots
Add cards and distribution plots
- Loading branch information
Showing
5 changed files
with
241 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<template> | ||
<div class="card-wrapper" @click="handleClick" :class="{ active: isActive }"> | ||
<slot></slot> | ||
|
||
<div class="info"> | ||
<div class="title"> {{ title }} </div> | ||
<p class="description"> {{ description }} </p> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
import { toRefs} from 'vue'; | ||
const props = defineProps({ | ||
title: { | ||
type: String, | ||
default: '', | ||
}, | ||
description: { | ||
type: String, | ||
default: '', | ||
}, | ||
handleClick: { | ||
type: Function, | ||
default: () => {} | ||
}, | ||
isActive: { | ||
type: Boolean, | ||
default: false | ||
} | ||
}); | ||
const {title, description, handleClick} = toRefs(props); | ||
</script> | ||
|
||
<style scoped> | ||
.card-wrapper { | ||
--title-height: 3.5rem; | ||
position: relative; | ||
overflow-y: hidden; | ||
border: 1px solid transparent; | ||
border-radius: 1rem; | ||
cursor: pointer; | ||
} | ||
.active { | ||
border-color: var(--white); | ||
} | ||
.info { | ||
transition: all 0.5s ease; | ||
position: absolute; | ||
top: calc(100% - var(--title-height)); | ||
padding: 0 1rem; | ||
display: flex; | ||
flex-direction: column; | ||
width: 100%; | ||
background: var(--white); | ||
color: var(--black); | ||
} | ||
.title { | ||
height: var(--title-height); | ||
font-size: 1.5rem; | ||
text-transform: capitalize; | ||
display: flex; | ||
align-items: center; | ||
overflow-x: hidden; | ||
text-overflow: ellipsis; | ||
white-space: nowrap; | ||
} | ||
.info:hover { | ||
transform: translateY(calc((100% - var(--title-height))*-1)); | ||
} | ||
</style> |
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,121 @@ | ||
<template> | ||
<div class="svg-wrapper" ref="wrapperRef"> | ||
<svg> | ||
<line | ||
v-for="cell in gridCells" | ||
:key="cell.id" | ||
:x1="xScale(0)" | ||
:x2="xScale(1)" | ||
:y1="yScale(cell.val)" | ||
:y2="yScale(cell.val)" | ||
:stroke="getCellColor(cell.val)" | ||
stroke-width="0.05" | ||
stroke-opacity="1" | ||
/> | ||
</svg> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
import * as d3 from 'd3'; | ||
import { useResizeObserver } from '@vueuse/core'; | ||
import { computed, toRefs, ref, onMounted } from 'vue'; | ||
import { useFiltersStore } from '@/stores/filters'; | ||
import { useCropYieldsStore } from '@/stores/cropYields'; | ||
import { storeToRefs } from 'pinia'; | ||
const props = defineProps({ | ||
scenario: { | ||
type: String, | ||
default: '', | ||
}, | ||
}); | ||
const {scenario} = toRefs(props); | ||
const cropYieldsStore = useCropYieldsStore(); | ||
const filtersStore = useFiltersStore(); | ||
const { selectedMetric, selectedCrop, availableModels, availableCrops } = storeToRefs(filtersStore); | ||
const { data: cropYieldsData } = storeToRefs(cropYieldsStore); | ||
const wrapperRef = ref(null); | ||
const width = ref(0); | ||
const height = ref(0); | ||
useResizeObserver(wrapperRef, ([entry]) => { | ||
width.value = entry.contentRect.width; | ||
height.value = entry.contentRect.height; | ||
}) | ||
const margin = computed(() => { | ||
return height.value * .2; | ||
}) | ||
const columnName = computed(() => { | ||
return [selectedMetric.value, selectedCrop.value, scenario.value].join("_") | ||
}) | ||
const metaExtent = computed(() => { | ||
// want to get extent across all scenarios and included crops so that comparisons are more useful | ||
const extents = [] | ||
availableModels.value.forEach(s => { | ||
availableCrops.value.forEach(c => { | ||
const column = [selectedMetric.value, c, s].join("_"); | ||
extents.push(cropYieldsStore.getExtent(column)) | ||
}) | ||
}) | ||
return [d3.min(extents.map(d => d[0])), d3.min(extents.map(d => d[1]))]; | ||
}) | ||
const gridCells = computed(() => { | ||
if (!cropYieldsData.value) return; | ||
return cropYieldsData.value.map((row) => { | ||
return { | ||
id: row.id, | ||
val: row[columnName.value], | ||
}; | ||
}); | ||
}); | ||
const yScale = computed(() => { | ||
return d3.scaleLinear() | ||
.domain(metaExtent.value) | ||
.range([height.value - margin.value, margin.value]) | ||
// .clamp(true); | ||
}) | ||
const xScale = computed(() => { | ||
return d3.scaleLinear() | ||
.domain([0,1]) | ||
.range([0, width.value]) | ||
}) | ||
const getCellColor = (value) => { | ||
if (!value) return 'transparent'; | ||
const scale = d3.scaleLinear() | ||
.domain([metaExtent.value[0], 0, metaExtent.value[1]]) | ||
.range(["#FF8A00", "#D4D5A5", "#1CAC50"]) | ||
.clamp(true); | ||
return scale(value); | ||
} | ||
onMounted(() => { | ||
width.value = wrapperRef.value.clientWidth; | ||
height.value = wrapperRef.value.clientHeight; | ||
}); | ||
</script> | ||
|
||
<style scoped> | ||
.svg-wrapper { | ||
height: 100%; | ||
width: 100%; | ||
padding: 1rem; | ||
} | ||
svg { | ||
width: 100%; | ||
height: 100%; | ||
} | ||
</style> |
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