Skip to content

Commit

Permalink
Add layer title above colourbar
Browse files Browse the repository at this point in the history
  • Loading branch information
amarkensteijn committed Nov 7, 2023
1 parent 8be49b6 commit c7e7637
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
10 changes: 9 additions & 1 deletion src/components/spatialdisplay/SpatialDisplay.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<animated-mapbox-layer :layer="layerOptions" />
</MapComponent>
<div class="colourbar-container">
<ColourBar :colourMap="legend" />
<ColourBar :colourMap="legend" :title="legendTitle" />
</div>
<DateTimeSlider
v-model:selectedDate="currentTime"
Expand Down Expand Up @@ -65,6 +65,14 @@ const legend = computed(() => {
return legendGraphic.value?.legend
})
const legendTitle = computed(() => {
if (!selectedLayer.value) return ''
const unitString = legendGraphic.value?.unit
? ` [${legendGraphic.value?.unit}]`
: ''
return `${selectedLayer.value?.title}${unitString}`
})
watch(times, () => {
const timesValue = times.value
if (timesValue) {
Expand Down
19 changes: 8 additions & 11 deletions src/components/wms/ColourBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,23 @@ import * as webOcCharts from '@deltares/fews-web-oc-charts'
interface Props {
colourMap?: webOcCharts.ColourMap
title?: string
}
const props = withDefaults(defineProps<Props>(), {
colourMap: undefined,
})
const props = withDefaults(defineProps<Props>(), {})
const isVisible = ref<boolean>(true)
let group: d3.Selection<SVGGElement, unknown, HTMLElement, any>
watch(
() => props.colourMap,
() => {
updateColourBar()
},
)
watch([() => props.colourMap, () => props.title], () => {
updateColourBar()
})
onMounted(() => {
const svg = d3.select('#colourbar')
group = svg
.append('g')
.attr('transform', 'translate(10, 5)')
.attr('transform', 'translate(10, 50)')
.style('pointer-events', 'visiblePainted')
updateColourBar()
})
Expand All @@ -48,6 +44,7 @@ function updateColourBar() {
type: 'nonlinear',
useGradients: true,
position: webOcCharts.AxisPosition.Bottom,
title: props.title,
}
new webOcCharts.ColourBar(group as any, props.colourMap, 250, 10, options)
isVisible.value = true
Expand All @@ -62,7 +59,7 @@ function updateColourBar() {
.colourbar {
fill: none;
width: 300px;
height: 35px;
height: 85px;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-rendering: optimizeLegibility;
Expand Down

0 comments on commit c7e7637

Please sign in to comment.