In my karax app I have a page with some vega-lite charts and a pop out side menu. Every time there is a button click using the side menu (or other button like for switching between langauges) each chart reloads which causes vega-lite to automatically re-fetch the data based on a url. This is ok if the button is rarely used, but not good for buttons frequently used. What I want is to be able to modify other VNodes on page without reloading the chart and causing multiple api calls. If I remove setForeignNodeId("viz") it stops the automatic reload issue but results in the error Uncaught Error: Error: unhandled exception: karax.nim(644, 14) `same(kxi.currentTree, document.getElementById(kxi.rootId)) which prevents any redraws.
proc renderPage(data: RouterData): VNode =
result = buildHtml(tdiv):
tdiv(id="contentsmenu"):
button(id="sideBarButton", class="openbtn", onclick = openNav): text " ☰ "
tdiv(id="mySidebar", class="sidebar"):
a(href="javascript:void(0)", class="closebtn", onclick = closeNav): text "x"
a(href="#"): text "Top"
a(href="#TOCC1"): text "Menu Item 1"
tdiv(id="viz")
proc postRenderStrategicIndicators(data: RouterData) =
vegaEmbed(kstring"#viz", kstring"/spec/kpi_c1.json", vloptions)
setRenderer renderStrategicIndicators, "ROOT", postRenderStrategicIndicators
setForeignNodeId("viz")
Seems like vegaEmbed is modifying the div in a way that Karax doesn't like, so probably something like this:
proc renderPage(data: RouterData): VNode =
result = buildHtml(tdiv):
tdiv(id="contentsmenu"):
button(id="sideBarButton", class="openbtn", onclick = openNav): text " ☰ "
tdiv(id="mySidebar", class="sidebar"):
a(href="javascript:void(0)", class="closebtn", onclick = closeNav): text "x"
a(href="#"): text "Top"
a(href="#TOCC1"): text "Menu Item 1"
tdiv(id="viz-wrapper"):
tdiv(id="viz")
proc postRenderStrategicIndicators(data: RouterData) =
vegaEmbed(kstring"#viz", kstring"/spec/kpi_c1.json", vloptions)
setRenderer renderStrategicIndicators, "ROOT", postRenderStrategicIndicators
setForeignNodeId("viz-wrapper")
Thanks for the suggestion. I gave it a try but it still resulted in the same issue. What is working for me for now was to forget about postRender and do something like:
setRenderer createDom
redrawSync()
vegaEmbed(kstring"#viz", kstring"/spec/kpi_c1.json", vloptions)
setForeignNodeId("viz")