Skip to content

Commit

Permalink
Data label width is only 10000
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey-ananiev committed Oct 15, 2024
1 parent f8f9d96 commit a8a9246
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 16 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]
accompanist = "0.32.0"
activity = "1.8.1"
agp = "8.3.0-alpha15"
agp = "8.2.1"
androidXAnnotation = "1.7.0"
androidXCore = "1.12.0"
appcompat = "1.6.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ import com.patrykandpatrick.vico.compose.axis.horizontal.rememberBottomAxis
import com.patrykandpatrick.vico.compose.axis.vertical.rememberStartAxis
import com.patrykandpatrick.vico.compose.chart.Chart
import com.patrykandpatrick.vico.compose.chart.line.lineChart
import com.patrykandpatrick.vico.compose.component.textComponent
import com.patrykandpatrick.vico.compose.style.ProvideChartStyle
import com.patrykandpatrick.vico.compose.style.currentChartStyle
import com.patrykandpatrick.vico.core.axis.Axis
import com.patrykandpatrick.vico.core.chart.line.LineChart
import com.patrykandpatrick.vico.core.entry.ChartEntryModelProducer
import com.patrykandpatrick.vico.databinding.Chart1Binding
import com.patrykandpatrick.vico.sample.showcase.UISystem
Expand All @@ -43,9 +46,17 @@ internal fun Chart1(uiSystem: UISystem, chartEntryModelProducer: ChartEntryModel
@Composable
private fun ComposeChart1(chartEntryModelProducer: ChartEntryModelProducer) {
val marker = rememberMarker()
val defaultLines = currentChartStyle.lineChart.lines
ProvideChartStyle(rememberChartStyle(chartColors)) {
Chart(
chart = lineChart(persistentMarkers = remember(marker) { mapOf(PERSISTENT_MARKER_X to marker) }),
chart = lineChart(
lines = defaultLines.map {
LineChart.LineSpec(
dataLabel = textComponent(),
)
},
persistentMarkers = remember(marker) { mapOf(PERSISTENT_MARKER_X to marker) },
),
chartModelProducer = chartEntryModelProducer,
startAxis = rememberStartAxis(),
bottomAxis = rememberBottomAxis(guideline = null),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ private fun ComposeChart2(chartEntryModelProducer: ChartEntryModelProducer) {
LineComponent(defaultColumn.color, COLUMN_WIDTH_DP, defaultColumn.shape)
}
},
dataLabel = textComponent(),
decorations = remember(thresholdLine) { listOf(thresholdLine) },
),
isZoomEnabled = true,
chartModelProducer = chartEntryModelProducer,
startAxis = rememberStartAxis(valueFormatter = startAxisValueFormatter, itemPlacer = startAxisItemPlacer),
bottomAxis = rememberBottomAxis(itemPlacer = bottomAxisItemPlacer),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,19 +266,20 @@ public open class ColumnChart(
val canUseXSpacing =
mergeMode == MergeMode.Stack ||
mergeMode == MergeMode.Grouped && modelEntriesSize == 1
var maxWidth = when {
canUseXSpacing -> horizontalDimensions.xSpacing
mergeMode == MergeMode.Grouped ->
(columnThicknessDp + minOf(spacingDp, innerSpacingDp).half).pixels * zoom

else -> error(message = "Encountered an unexpected `MergeMode`.")
}
if (isFirst && horizontalLayout is HorizontalLayout.FullWidth) {
maxWidth = maxWidth.coerceAtMost(horizontalDimensions.startPadding.doubled)
}
if (isLast && horizontalLayout is HorizontalLayout.FullWidth) {
maxWidth = maxWidth.coerceAtMost(horizontalDimensions.endPadding.doubled)
}
val maxWidth = 10000F
// var maxWidth = when {
// canUseXSpacing -> horizontalDimensions.xSpacing
// mergeMode == MergeMode.Grouped ->
// (columnThicknessDp + minOf(spacingDp, innerSpacingDp).half).pixels * zoom
//
// else -> error(message = "Encountered an unexpected `MergeMode`.")
// }
// if (isFirst && horizontalLayout is HorizontalLayout.FullWidth) {
// maxWidth = maxWidth.coerceAtMost(horizontalDimensions.startPadding.doubled)
// }
// if (isLast && horizontalLayout is HorizontalLayout.FullWidth) {
// maxWidth = maxWidth.coerceAtMost(horizontalDimensions.endPadding.doubled)
// }
val text = dataLabelValueFormatter.formatValue(
value = dataLabelValue,
chartValues = chartValuesProvider.getChartValues(axisPosition = targetVerticalAxisPosition),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ public open class LineChart(
value = chartEntry.y,
chartValues = chartValues,
)
val maxWidth = getMaxDataLabelWidth(chartEntry, x, previousX, nextX)
val maxWidth = 10000 //getMaxDataLabelWidth(chartEntry, x, previousX, nextX)
val verticalPosition = lineSpec.dataLabelVerticalPosition.inBounds(
bounds = bounds,
distanceFromPoint = distanceFromLine,
Expand Down

0 comments on commit a8a9246

Please sign in to comment.