Skip to content

Commit d1a7402

Browse files
authored
Merge pull request #54 from zakhenry/fix/text-updating
fix(Dynamic graphs): Fix text labels not updating when dynamically updated
2 parents f97a2a6 + 07fc6b4 commit d1a7402

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

examples/src/main/kotlin/misc/dynamicBars.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ fun main() {
2222
name to Bar {
2323
x.strings = initialValue.map { "Column: $it" }
2424
y.numbers = initialValue
25+
textsList = initialValue.map { "Initial value of this datapoint is: ${it}"}
2526
this.name = name
2627
}
2728
}
@@ -58,6 +59,7 @@ fun main() {
5859
val yValues = bar.y.doubles
5960
yValues[columnIndex] = Random.nextInt(0,100).toDouble()
6061
bar.y.doubles = yValues
62+
bar.textsList = yValues.map { "Updated value of this datapoint is: ${it}"}
6163
}
6264
}
6365
}
@@ -68,4 +70,4 @@ fun main() {
6870
readLine()
6971

7072
server.close()
71-
}
73+
}

plotlykt-core/src/jsMain/kotlin/kscience/plotly/plotlyElement.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,15 @@ fun HTMLElement.plot(plot: Plot, plotlyConfig: PlotlyConfig = PlotlyConfig()) {
3131
traceData.z = arrayOf(traceData.z)
3232
}
3333

34+
if (trace.text.value != null) {
35+
traceData.text = arrayOf(traceData.text)
36+
}
37+
3438
PlotlyJs.restyle(this, traceData, arrayOf(index))
3539
}
3640
}
3741
}
3842

3943
fun HTMLElement.plot(plotlyConfig: PlotlyConfig = PlotlyConfig(), plotBuilder: Plot.() -> Unit) {
4044
plot(Plot().apply(plotBuilder), plotlyConfig)
41-
}
45+
}

0 commit comments

Comments
 (0)