XYGraph

fun <X, Y> XYGraph(xAxisModel: AxisModel<X>, yAxisModel: AxisModel<Y>, xAxisContent: AxisContent<X>, yAxisContent: AxisContent<Y>, modifier: Modifier = Modifier, gridStyle: GridStyle = rememberGridStyle(), gestureConfig: GestureConfig = GestureConfig(), onPointerEvent: XYGraphPointerEventScope<X, Y>.(PointerEvent) -> Unit? = null, content: @Composable XYGraphScope<X, Y>.() -> Unit)

A composable that lays out a chart consisting of two axes, a grid, and plot content.

The layout process is performed in several steps:

  1. The sizes of the axis titles are determined.

  2. The axis models are consulted to determine the tick values.

  3. The axis labels are sub-composed and measured to determine their sizes.

  4. The remaining space is allocated to the plot area.

  5. The grid, axes, and plot content are composed and placed in the plot area.

The content of the XYGraph is a Composable lambda that receives an XYGraphScope. This scope provides the context of the graph's axes and allows for the conversion between data coordinates and screen coordinates, which is necessary for plotting data.

Parameters

X

The data type for the x-axis.

Y

The data type for the y-axis.

xAxisModel

The AxisModel for the x-axis, which controls the range, coordinate transformation, and tick marks.

yAxisModel

The AxisModel for the y-axis, which controls the range, coordinate transformation, and tick marks.

xAxisContent

The content for the x-axis, including the title and labels. See AxisContent.

yAxisContent

The content for the y-axis, including the title and labels. See AxisContent.

modifier

The modifier to be applied to the graph.

gridStyle

The styling for the major and minor grid lines. See GridStyle.

gestureConfig

Configuration for pan and zoom gestures. See GestureConfig.

onPointerEvent

A callback that is invoked when a pointer event occurs within the plot area. The XYGraphPointerEventScope provides a scale function to convert from screen to data coordinates.

content

The composable content to be displayed within the graph, which typically includes one or more plot types like io.github.koalaplot.core.line.LinePlot or io.github.koalaplot.core.line.AreaPlot.


fun <X, Y> XYGraph(xAxisModel: AxisModel<X>, yAxisModel: AxisModel<Y>, modifier: Modifier = Modifier, xAxisStyle: AxisStyle = rememberAxisStyle(), xAxisLabels: @Composable (X) -> Unit = {}, xAxisTitle: @Composable () -> Unit = {}, yAxisStyle: AxisStyle = rememberAxisStyle(), yAxisLabels: @Composable (Y) -> Unit = {}, yAxisTitle: @Composable () -> Unit = {}, horizontalMajorGridLineStyle: LineStyle? = KoalaPlotTheme.axis.majorGridlineStyle, horizontalMinorGridLineStyle: LineStyle? = KoalaPlotTheme.axis.minorGridlineStyle, verticalMajorGridLineStyle: LineStyle? = KoalaPlotTheme.axis.majorGridlineStyle, verticalMinorGridLineStyle: LineStyle? = KoalaPlotTheme.axis.minorGridlineStyle, gestureConfig: GestureConfig = GestureConfig(), onPointerMove: (X, Y) -> Unit? = null, content: @Composable XYGraphScope<X, Y>.() -> Unit)

Deprecated

Use the overload that accepts AxisContent and GridStyle objects instead.

Replace with

XYGraph(
        xAxisModel = xAxisModel,
        yAxisModel = yAxisModel,
        modifier = modifier,
        xAxisContent = AxisContent(
            style = xAxisStyle,
            labels = { xAxisLabels(it) },
            title = xAxisTitle,
        ),
        yAxisContent = AxisContent(
            style = yAxisStyle,
            labels = { yAxisLabels(it) },
            title = yAxisTitle,
        ),
        gridStyle = GridStyle(
            horizontalMajorStyle = horizontalMajorGridLineStyle,
            horizontalMinorStyle = horizontalMinorGridLineStyle,
            verticalMajorStyle = verticalMajorGridLineStyle,
            verticalMinorStyle = verticalMinorGridLineStyle,
        ),
        gestureConfig = gestureConfig,
        onPointerMove = onPointerMove,
        content = content,
    )

Provides a set of X-Y axes and grid for displaying X-Y plots.

Parameters

X

The data type for the x-axis

Y

The data type for the y-axis

xAxisModel

x-axis state controlling the display of the axis and coordinate transformation

yAxisModel

y-axis state controlling the display of the axis and coordinate transformation

xAxisStyle

Style for the x-axis

xAxisLabels

Composable to display labels for specific x-axis values

xAxisTitle

Title for the X-axis

yAxisStyle

Style for the y-axis

yAxisLabels

Composable to display labels for specific y-axis values

yAxisTitle

Title for the y-axis

gestureConfig

Configuration for gesture handling. See GestureConfig

onPointerMove

Callback invoked when the pointer moves with the current pointer position in plot coordinates

content

The content to be displayed, which should include one plot for each series to be plotted on this XYGraph.


fun <X, Y> XYGraph(xAxisModel: AxisModel<X>, yAxisModel: AxisModel<Y>, modifier: Modifier = Modifier, xAxisStyle: AxisStyle = rememberAxisStyle(), xAxisLabels: (X) -> String = { it.toString() }, xAxisTitle: String? = null, yAxisStyle: AxisStyle = rememberAxisStyle(), yAxisLabels: (Y) -> String = { it.toString() }, yAxisTitle: String? = null, horizontalMajorGridLineStyle: LineStyle? = KoalaPlotTheme.axis.majorGridlineStyle, horizontalMinorGridLineStyle: LineStyle? = KoalaPlotTheme.axis.minorGridlineStyle, verticalMajorGridLineStyle: LineStyle? = KoalaPlotTheme.axis.majorGridlineStyle, verticalMinorGridLineStyle: LineStyle? = KoalaPlotTheme.axis.minorGridlineStyle, gestureConfig: GestureConfig = GestureConfig(), onPointerMove: (X, Y) -> Unit? = null, content: @Composable XYGraphScope<X, Y>.() -> Unit)

Deprecated

This overload is deprecated. Call the primary XYGraph function and use the rememberXAxisContent() and rememberYAxisContent() helpers.

Replace with

XYGraph(
        xAxisModel = xAxisModel,
        yAxisModel = yAxisModel,
        modifier = modifier,
        xAxisContent = rememberStringAxisContent(label = xAxisLabels, title = xAxisTitle, style = xAxisStyle),
        yAxisContent = rememberStringAxisContent(label = yAxisLabels, title = yAxisTitle, style = yAxisStyle),
        gridStyle = GridStyle(
            horizontalMajorStyle = horizontalMajorGridLineStyle,
            horizontalMinorStyle = horizontalMinorGridLineStyle,
            verticalMajorStyle = verticalMajorGridLineStyle,
            verticalMinorStyle = verticalMinorGridLineStyle
        ),
        gestureConfig = gestureConfig,
        onPointerMove = onPointerMove,
        content = content
    )

An XYGraph overload that takes Strings for axis labels and titles instead of Composables for use cases where custom styling is not required.

Provides a set of X-Y axes and grid for displaying an X-Y plot.

Parameters

X

The data type for the x-axis

Y

The data type for the y-axis

xAxisModel

x-axis state controlling the display of the axis and coordinate transformation

yAxisModel

y-axis state controlling the display of the axis and coordinate transformation

xAxisStyle

Style for the x-axis

xAxisLabels

String factory of x-axis label Strings

xAxisTitle

Title for the X-axis

yAxisStyle

Style for the y-axis

yAxisLabels

String factory of y-axis label Strings

yAxisTitle

Title for the y-axis

gestureConfig

Configuration for gesture handling. See GestureConfig

onPointerMove

Callback invoked when the pointer moves with the current pointer position in plot coordinates

content

The content to be displayed within this graph, which should include one plot for each data series to be plotted.