I'm drawing a bar chart with vega-lite in a Vue.js SPA. The encoding section of the main data layer looks like this:
encoding: {
x: {field: 'word', type: 'ordinal', sort: '-count'},
y: {field: 'count', type: 'quantitative'},
tooltip: [{field: 'word'}, {field: 'count'}, {field: 'doc_count'}]
}
… and in the Vue component method that updates the chart, I have this:
vegaEmbed('#vis', spec)
.then(({_spec, view}) => {
view.addEventListener('click', function (event, item) {
if (item) {
vueComponent.onWordClicked(item.datum.word);
}
})
})
… which, to complete all of that, calls this:
onWordClicked(word) {
this.$router.push({path: 'words', params: {word: word}});
}
All of this works exactly as I expect: you hover over a bar, a tooltip is displayed, you click the bar, and you are navigated to a different route in the SPA.
BUT… the tooltip stays on screen, unless and until you navigate back to the chart page and hover over the bars, in which case the tooltip can be reinvoked and then dismissed when you mouse out.
Any ideas on how to make the tooltip go away when the Vue path changes? I've tried playing around with the view.tooltip(...)
method, but suspect that's overkill (I'm happy with the default tooltip) and may not even solve my problem.
Thanks.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…