Skip to content
This repository has been archived by the owner on Sep 28, 2024. It is now read-only.

Add convenient data parameter to chart builders #1145

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions src/main/java/tornadofx/Charts.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tornadofx

import javafx.collections.FXCollections
import javafx.collections.ObservableList
import javafx.event.EventTarget
import javafx.scene.chart.*
Expand Down Expand Up @@ -33,38 +34,38 @@ fun PieChart.data(value: Map<String, Double>) = value.forEach { data(it.key, it.
/**
* Create a LineChart with optional title, axis and add to the parent pane. The optional op will be performed on the new instance.
*/
fun <X, Y> EventTarget.linechart(title: String? = null, x: Axis<X>, y: Axis<Y>, op: LineChart<X, Y>.() -> Unit = {}) =
LineChart<X, Y>(x, y).attachTo(this, op) { it.title = title }
fun <X, Y> EventTarget.linechart(title: String? = null, x: Axis<X>, y: Axis<Y>, data: ObservableList<XYChart.Series<X, Y>> = FXCollections.observableArrayList(), op: LineChart<X, Y>.() -> Unit = {}) =
LineChart<X, Y>(x, y, data).attachTo(this, op) { it.title = title }

/**
* Create an AreaChart with optional title, axis and add to the parent pane. The optional op will be performed on the new instance.
*/
fun <X, Y> EventTarget.areachart(title: String? = null, x: Axis<X>, y: Axis<Y>, op: AreaChart<X, Y>.() -> Unit = {}) =
AreaChart<X,Y>(x, y).attachTo(this, op){ it.title = title }
fun <X, Y> EventTarget.areachart(title: String? = null, x: Axis<X>, y: Axis<Y>, data: ObservableList<XYChart.Series<X, Y>> = FXCollections.observableArrayList(), op: AreaChart<X, Y>.() -> Unit = {}) =
AreaChart<X,Y>(x, y, data).attachTo(this, op){ it.title = title }

/**
* Create a BubbleChart with optional title, axis and add to the parent pane. The optional op will be performed on the new instance.
*/
fun <X, Y> EventTarget.bubblechart(title: String? = null, x: Axis<X>, y: Axis<Y>, op: BubbleChart<X, Y>.() -> Unit = {}) =
BubbleChart<X, Y>(x, y).attachTo(this,op){ it.title = title }
fun <X, Y> EventTarget.bubblechart(title: String? = null, x: Axis<X>, y: Axis<Y>, data: ObservableList<XYChart.Series<X, Y>> = FXCollections.observableArrayList(), op: BubbleChart<X, Y>.() -> Unit = {}) =
BubbleChart<X, Y>(x, y, data).attachTo(this,op){ it.title = title }

/**
* Create a ScatterChart with optional title, axis and add to the parent pane. The optional op will be performed on the new instance.
*/
fun <X, Y> EventTarget.scatterchart(title: String? = null, x: Axis<X>, y: Axis<Y>, op: ScatterChart<X, Y>.() -> Unit = {}) =
ScatterChart(x, y).attachTo(this,op){ it.title = title }
fun <X, Y> EventTarget.scatterchart(title: String? = null, x: Axis<X>, y: Axis<Y>, data: ObservableList<XYChart.Series<X, Y>> = FXCollections.observableArrayList(), op: ScatterChart<X, Y>.() -> Unit = {}) =
ScatterChart(x, y, data).attachTo(this,op){ it.title = title }

/**
* Create a BarChart with optional title, axis and add to the parent pane. The optional op will be performed on the new instance.
*/
fun <X, Y> EventTarget.barchart(title: String? = null, x: Axis<X>, y: Axis<Y>, op: BarChart<X, Y>.() -> Unit = {}) =
BarChart<X, Y>(x, y).attachTo(this, op){ it.title = title }
fun <X, Y> EventTarget.barchart(title: String? = null, x: Axis<X>, y: Axis<Y>, data: ObservableList<XYChart.Series<X, Y>> = FXCollections.observableArrayList(), op: BarChart<X, Y>.() -> Unit = {}) =
BarChart<X, Y>(x, y, data).attachTo(this, op){ it.title = title }

/**
* Create a BarChart with optional title, axis and add to the parent pane. The optional op will be performed on the new instance.
*/
fun <X, Y> EventTarget.stackedbarchart(title: String? = null, x: Axis<X>, y: Axis<Y>, op: StackedBarChart<X, Y>.() -> Unit = {}) =
StackedBarChart<X, Y>(x, y).attachTo(this, op) { it.title = title }
fun <X, Y> EventTarget.stackedbarchart(title: String? = null, x: Axis<X>, y: Axis<Y>, data: ObservableList<XYChart.Series<X, Y>> = FXCollections.observableArrayList(), op: StackedBarChart<X, Y>.() -> Unit = {}) =
StackedBarChart<X, Y>(x, y, data).attachTo(this, op) { it.title = title }

/**
* Add a new XYChart.Series with the given name to the given Chart. Optionally specify a list data for the new series or
Expand Down