From 403146760ae578daca974e12f1f9f72b5937a558 Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Tue, 16 Jul 2019 16:50:28 +0200 Subject: Fixed chart updates (#73) --- .../src/main/kotlin/pl/treksoft/kvision/chart/ChartCanvas.kt | 8 ++++++-- .../src/main/kotlin/pl/treksoft/kvision/chart/js/Chart.kt | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'kvision-modules/kvision-chart/src/main/kotlin') diff --git a/kvision-modules/kvision-chart/src/main/kotlin/pl/treksoft/kvision/chart/ChartCanvas.kt b/kvision-modules/kvision-chart/src/main/kotlin/pl/treksoft/kvision/chart/ChartCanvas.kt index 8d7c49a7..a37d0a8f 100644 --- a/kvision-modules/kvision-chart/src/main/kotlin/pl/treksoft/kvision/chart/ChartCanvas.kt +++ b/kvision-modules/kvision-chart/src/main/kotlin/pl/treksoft/kvision/chart/ChartCanvas.kt @@ -38,7 +38,9 @@ internal class ChartCanvas( var configuration: Configuration = configuration set(value) { field = value - jsChart?.config = value.toJs(this::translate) + val newConfig = value.toJs(this::translate) + if (newConfig.data != null) jsChart?.data = newConfig.data!! + if (newConfig.options != null) jsChart?.options = newConfig.options!! jsChart?.update() } @@ -46,7 +48,9 @@ internal class ChartCanvas( override fun render(): VNode { if (lastLanguage != null && lastLanguage != I18n.language) { - jsChart?.config = configuration.toJs(this::translate) + val newConfig = configuration.toJs(this::translate) + if (newConfig.data != null) jsChart?.data = newConfig.data!! + if (newConfig.options != null) jsChart?.options = newConfig.options!! jsChart?.update() } return render("canvas") diff --git a/kvision-modules/kvision-chart/src/main/kotlin/pl/treksoft/kvision/chart/js/Chart.kt b/kvision-modules/kvision-chart/src/main/kotlin/pl/treksoft/kvision/chart/js/Chart.kt index 7fb47bb0..e6bd9841 100644 --- a/kvision-modules/kvision-chart/src/main/kotlin/pl/treksoft/kvision/chart/js/Chart.kt +++ b/kvision-modules/kvision-chart/src/main/kotlin/pl/treksoft/kvision/chart/js/Chart.kt @@ -61,6 +61,7 @@ open external class Chart { open var config: ChartConfiguration = definedExternally open var data: ChartData = definedExternally + open var options: ChartOptions = definedExternally open fun destroy(): Any = definedExternally open fun update(duration: Any? = definedExternally, lazy: Any? = definedExternally): Any = definedExternally open fun render(duration: Any? = definedExternally, lazy: Any? = definedExternally): Any = definedExternally -- cgit