fix #73: echartstest.nim doesnt work (#75)

This commit is contained in:
Timothee Cour 2018-09-28 09:24:39 +02:00 • committed by Andreas Rumpf
commit 1ccd8b1c16

View file

@ -1,5 +1,3 @@
import karax / [kbase, vdom, kdom, vstyles, karax, karaxdsl, jdict, jstrutils, jjson] import karax / [kbase, vdom, kdom, vstyles, karax, karaxdsl, jdict, jstrutils, jjson]
type type
@ -9,18 +7,13 @@ type
var var
currentView = Customers currentView = Customers
setOnHashChange(proc(hash: cstring) =
if hash == cstring"#/Products": currentView = Products
else: currentView = Customers
)
type type
EChart* = ref object EChart* = ref object
proc echartsInit(n: Element): EChart {.importc: "echarts.init".} proc echartsInit(n: Element): EChart {.importc: "echarts.init".}
proc setOption(x: EChart; option: JsonNode) {.importcpp.} proc setOption(x: EChart; option: JsonNode) {.importcpp.}
proc postRender() = proc postRender(data: RouterData) =
if currentView == Products: if currentView == Products:
let myChart = echartsInit(kdom.getElementById("echartSection")) let myChart = echartsInit(kdom.getElementById("echartSection"))
# specify chart configuration item and data # specify chart configuration item and data
@ -44,7 +37,11 @@ proc postRender() =
} }
myChart.setOption(option) myChart.setOption(option)
proc createDom(): VNode = proc createDom(data: RouterData): VNode =
let hash = data.hashPart
if hash == cstring"#/Products": currentView = Products
else: currentView = Customers
result = buildHtml(tdiv): result = buildHtml(tdiv):
ul(class = "tabs"): ul(class = "tabs"):
for v in low(Views)..high(Views): for v in low(Views)..high(Views):