Skip to content

Commit

Permalink
Add vico:compose factory functions for BaseAxis.Size
Browse files Browse the repository at this point in the history
Co-authored-by: Patrick Michalik <[email protected]>
  • Loading branch information
Gowsky and patrickmichalik committed Nov 10, 2024
1 parent 7a46f2a commit a8b32b4
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2024 by Patryk Goworowski and Patrick Michalik.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.patrykandpatrick.vico.compose.cartesian.axis

import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.patrykandpatrick.vico.core.cartesian.axis.BaseAxis

/** Creates a [BaseAxis.Size.Auto] instance. */
public fun BaseAxis.Size.Companion.auto(
minSize: Dp = 0.dp,
maxSize: Dp = Float.MAX_VALUE.dp,
): BaseAxis.Size.Auto = BaseAxis.Size.Auto(minSize.value, maxSize.value)

/** Creates a [BaseAxis.Size.Exact] instance. */
public fun BaseAxis.Size.Companion.exact(size: Dp): BaseAxis.Size.Exact =
BaseAxis.Size.Exact(size.value)

/** Creates a [BaseAxis.Size.Fraction] instance. */
public fun BaseAxis.Size.Companion.fraction(fraction: Float): BaseAxis.Size.Fraction =
BaseAxis.Size.Fraction(fraction)

/** Creates a [BaseAxis.Size.Text] instance. */
public fun BaseAxis.Size.Companion.text(text: CharSequence): BaseAxis.Size.Text = BaseAxis.Size.Text(text)
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public fun HorizontalAxis.Companion.rememberTop(
tickLength: Dp = Defaults.AXIS_TICK_LENGTH.dp,
guideline: LineComponent? = rememberAxisGuidelineComponent(),
itemPlacer: HorizontalAxis.ItemPlacer = remember { HorizontalAxis.ItemPlacer.aligned() },
size: BaseAxis.Size = remember { BaseAxis.Size.Auto() },
size: BaseAxis.Size = BaseAxis.Size.auto(),
titleComponent: TextComponent? = null,
title: CharSequence? = null,
): HorizontalAxis<Axis.Position.Horizontal.Top> =
Expand Down Expand Up @@ -82,7 +82,7 @@ public fun HorizontalAxis.Companion.rememberBottom(
tickLength: Dp = Defaults.AXIS_TICK_LENGTH.dp,
guideline: LineComponent? = rememberAxisGuidelineComponent(),
itemPlacer: HorizontalAxis.ItemPlacer = remember { HorizontalAxis.ItemPlacer.aligned() },
size: BaseAxis.Size = remember { BaseAxis.Size.Auto() },
size: BaseAxis.Size = BaseAxis.Size.auto(),
titleComponent: TextComponent? = null,
title: CharSequence? = null,
): HorizontalAxis<Axis.Position.Horizontal.Bottom> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public fun VerticalAxis.Companion.rememberStart(
tickLength: Dp = Defaults.AXIS_TICK_LENGTH.dp,
guideline: LineComponent? = rememberAxisGuidelineComponent(),
itemPlacer: VerticalAxis.ItemPlacer = remember { VerticalAxis.ItemPlacer.step() },
size: BaseAxis.Size = remember { BaseAxis.Size.Auto() },
size: BaseAxis.Size = BaseAxis.Size.auto(),
titleComponent: TextComponent? = null,
title: CharSequence? = null,
): VerticalAxis<Axis.Position.Vertical.Start> =
Expand Down Expand Up @@ -94,7 +94,7 @@ public fun VerticalAxis.Companion.rememberEnd(
tickLength: Dp = Defaults.AXIS_TICK_LENGTH.dp,
guideline: LineComponent? = rememberAxisGuidelineComponent(),
itemPlacer: VerticalAxis.ItemPlacer = remember { VerticalAxis.ItemPlacer.step() },
size: BaseAxis.Size = remember { BaseAxis.Size.Auto() },
size: BaseAxis.Size = BaseAxis.Size.auto(),
titleComponent: TextComponent? = null,
title: CharSequence? = null,
): VerticalAxis<Axis.Position.Vertical.End> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,5 +175,8 @@ public abstract class BaseAxis<P : Axis.Position>(

override fun hashCode(): Int = text.hashCode()
}

/** Provides access to [BaseAxis.Size] factory functions. */
public companion object
}
}

0 comments on commit a8b32b4

Please sign in to comment.