An open API service indexing awesome lists of open source software.

https://github.com/3moly/compose-data-viz

Ready-to-use Canvas and Graph visualization components similar to Miro-style canvas or Obsidian’s graph.
https://github.com/3moly/compose-data-viz

compose-multiplatform compose-ui force graphs ui

Last synced: 5 months ago
JSON representation

Ready-to-use Canvas and Graph visualization components similar to Miro-style canvas or Obsidian’s graph.

Awesome Lists containing this project

README

          

![Maven Central Version](https://img.shields.io/maven-central/v/io.github.3moly/compose-data-viz)




[android, wasm, js, ios, jvm, macos]

# compose-data-vizualization

You need Miro whiteboard or Graph nodes like in Obsidian App in Compose multiplatform?


This library can help you. Most prepared motions and actions with Whiteboard and Graph are given.

Open demo site in wasm (mobile friendly):

https://composedataviz.3moly.com/

```gradle
implementation("io.github.3moly:compose-data-viz:0.1.0")

// The core module is needed only if you split models of this library from ui.
// (Be aware that it includes compose.foundation for Offset and Color classes)
implementation("io.github.3moly:compose-data-viz-core:0.1.0")
```

### Sample code

In sample module there is WhiteboardSample and GraphSample functions.
With them you can understand faster how to deal with the library.

### Whiteboard

The key part is a shape. For library it's important to know about 3 fields.

```kotlin
interface Shape {
val id: Long
val position: Offset
val size: Offset
}
```

And you can inherit above interface for more fields you wish to use in a Drawing process.

```kotlin
data class CustomShape(
override val id: Long,
override val position: Offset,
override val size: Offset,

val backgroundColor: Color?,
val data: ShapeData
) : Shape
```

So then every shape of your CustomShape will show through method in under code.
And Modifier with calculated size and location will show in DrawShapeState.
So you can use this Modifier for drawing Shape, you can draw any shape you want.

```kotlin
onDrawBlock: @Composable (DrawShapeState) -> Unit
```

```kotlin
@Composable
fun , Id> Whiteboard(
consume: Boolean,
modifier: Modifier,
action: Action?,
backgroundModifier: Modifier,
connectionsModifier: Modifier,
settings: CanvasSettings,
zoom: Float,
roundToNearest: Int?,
connectionDragBlankId: Id,
userCoordinate: Offset,
isDrawing: Boolean,
shapes: List,
connections: List>,
drawingPaths: List,
onActionSet: (Action?) -> Unit,
onAddPath: (StylusPath) -> Unit,
onMoveShape: (Int, Offset) -> Unit,
onResizeShape: (Int, Offset, Offset) -> Unit,
onAddConnection: (AddShapeConnection) -> Unit,
onZoomChange: (Float) -> Unit,
onUserCoordinateChange: (Offset) -> Unit,
settingsPanel: @Composable (position: Offset, action: Action, onDoneAction: () -> Unit) -> Unit,
onDrawBlock: @Composable (DrawShapeState) -> Unit,
) {
//...
}
```

### Graph

```kotlin
@Composable
fun Graph(
modifier: Modifier = Modifier,
userPosition: Offset,
zoom: Float,

stateNodes: List>,
coordinates: Map,
velocities: Map,
connections: Map>,

viewSettings: GraphViewSettings,
onCentralGlobalPosition: (Offset) -> Unit,
onZoomChange: (Float) -> Unit,
watchNodeId: Id? = null,
io: CoroutineContext,
onNodeClick: (GraphNode) -> Unit,
onCoordinatesUpdate: (Map) -> Unit = {},
onVelocitiesUpdate: (Map) -> Unit = {},
primaryColor: Color,
fontColor: Color,
circleColor: Color,
circleLineColor: Color
) {
//...
}
```

## Used in

- [CedarJam](https://github.com/3moly/CedarJam)