scoop:scoop.ui.component:0.1.0
src/chart/options.scoop
Selected production source · src/chart/options.scoop
1
package scoop.ui.component3
import scoop.graphics.text.FontCollection4
import scoop.math.*5
import scoop.ui.*6
import scoop.ui.style.*8
public enum ChartAxisKind {9
Category, Linear10
}12
public enum ChartDomain {13
Auto, Fixed(val minimum: Double, val maximum: Double)14
}16
public class ChartAxis public constructor(17
public val kind: ChartAxisKind = ChartAxisKind.Linear,18
public val domain: ChartDomain = ChartDomain.Auto,19
public val includeZero: Boolean = false,20
public val nice: Boolean = true,21
public val tickCount: Int = 5,22
public val shown: Boolean = true,23
public val grid: Boolean = true,24
public val formatter: ((Double) -> String)? = None25
) {26
init {27
requireComponent(tickCount > 0, "chart tick count must be positive")28
when (domain) {29
case Fixed(val low, val high) -> requireComponent(30
low.isFinite() && high.isFinite() && high > low,31
"chart domain must be finite and increasing"32
);33
case Auto -> {}34
}35
}36
}38
internal val chartCategoryAxis = ChartAxis(ChartAxisKind.Category, grid = false)40
internal val chartValueAxis = ChartAxis()42
public class ChartTooltipOptions public constructor(43
public val hideLabel: Boolean = false,44
public val hideIndicator: Boolean = false,45
public val indicator: ChartIndicator = ChartIndicator.Dot,46
public val formatter: ((ChartTooltipEntry) -> String)? = None,47
public val labelFormatter: ((ChartDatum) -> String)? = None48
)50
public class ChartLegendOptions public constructor(51
public val hideIcon: Boolean = false,52
public val formatter: ((ChartSeries) -> String)? = None53
)55
public class ChartProps public constructor(56
public val model: ChartModel,57
public val kind: ChartKind = ChartKind.Line,58
public val orientation: Orientation = Orientation.Vertical,59
public val curve: ChartCurve = ChartCurve.Linear,60
public val stack: ChartStack = ChartStack.None,61
public val connectMissing: Boolean = false,62
public val xAxis: ChartAxis = ChartAxis(ChartAxisKind.Category, grid = false),63
public val yAxis: ChartAxis = ChartAxis(),64
public val pointRadius: Double = 3.0,65
public val barRadius: Double = 4.0,66
public val barGap: Double = 0.2,67
public val labels: Boolean = false,68
public val startAngle: Double = -PI / 2.0,69
public val endAngle: Double = 3.0 * PI / 2.0,70
public val innerRadius: Double = 0.0,71
public val width: Double? = None,72
public val height: Double? = None,73
public val legend: Boolean = true,74
public val tooltip: Boolean = true,75
public val legendOptions: ChartLegendOptions = ChartLegendOptions(),76
public val tooltipOptions: ChartTooltipOptions = ChartTooltipOptions(),77
public val tooltipContent: ((ChartTooltipPayload) -> View)? = None,78
public val center: View? = None,79
public val active: Binding<ChartSelection?>? = None,80
public val focus: FocusOptions = FocusOptions(),81
public val enabled: Boolean = true,82
public val fonts: FontCollection? = None,83
public val theme: ThemeSource? = None,84
public val semantics: ComponentSemantics = ComponentSemantics()85
) {86
init {87
nonnegative(pointRadius, "invalid chart point radius")88
nonnegative(barRadius, "invalid chart bar radius")89
requireComponent(90
barGap.isFinite() && barGap >= 0.0 && barGap < 1.0,91
"chart bar gap must be in [0, 1)"92
)93
when (width) {94
case Some(val value) -> nonnegative(value, "invalid chart width");95
case None -> {}96
}97
when (height) {98
case Some(val value) -> nonnegative(value, "invalid chart height");99
case None -> {}100
}101
requireComponent(yAxis.kind == ChartAxisKind.Linear, "chart value axis must be linear")102
val sweep = endAngle - startAngle103
requireComponent(104
startAngle.isFinite() && endAngle.isFinite() && sweep != 0.0 && abs(sweep) <= TAU,105
"chart angle span must be finite, nonzero and at most one turn"106
)107
requireComponent(108
innerRadius.isFinite() && innerRadius >= 0.0 && innerRadius < 1.0,109
"chart inner radius must be in [0, 1)"110
)111
}112
}114
public class ChartBuilder internal constructor() {115
public var kind: ChartKind = ChartKind.Line116
public var orientation: Orientation = Orientation.Vertical117
public var curve: ChartCurve = ChartCurve.Linear118
public var stack: ChartStack = ChartStack.None119
public var connectMissing: Boolean = false120
public var xAxis: ChartAxis = chartCategoryAxis121
public var yAxis: ChartAxis = chartValueAxis122
public var pointRadius: Double = 3.0123
public var barRadius: Double = 4.0124
public var barGap: Double = 0.2125
public var labels: Boolean = false126
public var startAngle: Double = -PI / 2.0127
public var endAngle: Double = 3.0 * PI / 2.0128
public var innerRadius: Double = 0.0129
public var width: Double? = None130
public var height: Double? = None131
public var legend: Boolean = true132
public var tooltip: Boolean = true133
public var legendOptions: ChartLegendOptions = ChartLegendOptions()134
public var tooltipOptions: ChartTooltipOptions = ChartTooltipOptions()135
public var tooltipContent: ((ChartTooltipPayload) -> View)? = None136
public var center: View? = None137
public var active: Binding<ChartSelection?>? = None138
public var focus: FocusOptions = FocusOptions()139
public var enabled: Boolean = true140
public var fonts: FontCollection? = None141
public var theme: ThemeSource? = None142
public var semantics: ComponentSemantics = ComponentSemantics()143
public var key: ViewKey = ViewKey.Position144
internal fun build(model: ChartModel): View =145
component(146
ChartProps(147
model,148
kind,149
orientation,150
curve,151
stack,152
connectMissing,153
xAxis,154
yAxis,155
pointRadius,156
barRadius,157
barGap,158
labels,159
startAngle,160
endAngle,161
innerRadius,162
width,163
height,164
legend,165
tooltip,166
legendOptions,167
tooltipOptions,168
tooltipContent,169
center,170
active,171
focus,172
enabled,173
fonts,174
theme,175
semantics176
),177
{ props, scope -> Chart(props, scope) },178
key179
)180
}182
public fun chart(model: ChartModel, configure: ChartBuilder.() -> Unit = {}): View {183
val builder = ChartBuilder();184
builder.configure();185
return builder.build(model)186
}