Comments (4)
Thank you, that helped me to find a good solution with some tinkering :) Using Compose doesn't change anything from the perspective of the inner View, so this approach works perfectly fine.
from data2viz.
There is no reason to recreate the view.
You can modify the elements and then call viz.render()
.
If you use animation, the library creates a timer on your behalf and calls the render
for you.
You can see this example: https://play.data2viz.io/sketches/BYEMwY/edit/
from data2viz.
Thank you for your answer ^^ Unfortunately, I am not sure how a visualization can be modified from the outside. The animation examples are run within the context of the objects they need to access. However, I am using Jetpack Compose to manage the state containing the data points, which uses a function for updating the graph that only has access to the view and the viz
object.
For illustration:
val dataPoints by collectDataPointState()
val viz by remember { mutableStateOf(myVisualization(dataPoints)) }
AndroidView(
factory = { context ->
val container = FrameLayout(context)
container.addView(viz.toView(context))
return@AndroidView container
},
update = { container ->
// ...?
viz.render()
}
)
Compose will use the factory method to create the initial view. Whenever the state of dataPoints
changes (in this case, a new data point gets added), the update
lambda will be called so that the graph can get updated. I would have expected to have to re-generate viz
there and call something like vizView.setViz(viz)
to do that.
Would I need to use viz.activeLayer.children[someIndex]
to access the graphic objects within? Or is there a more elegant method to do that?
from data2viz.
I didn't try Jetpack Compose yet, so please be lenient with my advice ;-).
You could keep a reference on a Group that holds all your dataPoints representation.
lateinit var pointsGroup:GroupNode
//...
fun myVisualization(dataPoints: List<MyPoint>): Viz = viz {
pointsGroup = group {
dataPoints.forEach {
addPoint(it)
}
}
fun Group.addPoint(point: MyPoint) {
circle {
//...
}
}
AndroidView(
factory = { context ->
val container = FrameLayout(context)
container.addView(viz.toView(context))
return@AndroidView container
},
update = { container ->
// ...?
pointsGroup.apply{
clear()
dataPoints.forEach {
addPoint(it)
}
}
viz.render()
}
)
This is an implementation that will drop and recreate all visual elements for each point (but keep the view and its canvas). Depending on the use case for the points update, you may choose another strategy.
from data2viz.
Related Issues (20)
- Runtime exception due to wrong casting
- Add a copy() function to all scales
- [VIZ] Stroke properties should be called strokeColor ?
- Use the latest KotlinX DateTime version HOT 1
- Android version does not support the dashedLine property of the HasStroke interface HOT 1
- Share Meta keys on KEvent
- [Feature request] Export as SVG HOT 8
- Upgrade JavaFX to version 11 HOT 1
- Manage multi line rich text
- Wrong measure text on Android and JS when the text starts or ends with whitespaces HOT 1
- Viz appears blurry on a HDPI screen, using Kotlin/JS IR compiler
- Introduce HeadlessVizContainer
- Wrong height of TextNode.measureText()
- Android: Handle view size/measurements better HOT 2
- Force Directed Graphs
- Scaling transformation is missing HOT 1
- chart in loop ? HOT 2
- Fatal Exception: java.lang.NoClassDefFoundError: Failed resolution of: Ljava/time/Instant; HOT 3
- Add Kotlin's wasm-js target
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from data2viz.