patrykandpatrick / vico

A light and extensible chart library for Android.
https://patrykandpatrick.com/vico/wiki
Apache License 2.0
2.13k stars 130 forks source link

Incorrect line colors with positive/negative values #809

Closed mak1nt0sh closed 3 months ago

mak1nt0sh commented 3 months ago

How to reproduce

    CartesianChartHost(
        chart = rememberCartesianChart(
            rememberLineCartesianLayer(
                lineProvider = LineCartesianLayer.LineProvider.series(
                    rememberLine(
                        shader = TopBottomShader(
                            topShader = DynamicShader.color(MaterialTheme.colorScheme.primary),
                            bottomShader = DynamicShader.color(MaterialTheme.customColors.negative)
                        )
                    )
                )
            ),
        modelProducer = graphModelProducer,
        scrollState = rememberVicoScrollState(scrollEnabled = false)
    )

Observed behavior

Initial colors are good. However when the data refreshes the line seems to remember previous splitY value and doesn't update. The background color is updating though.

Screenshot 2024-07-23 at 11 40 38 Screenshot 2024-07-23 at 11 40 55

Expected behavior

All was working on alpha.22. The line color respected splitY = 0

Vico version(s)

2.0.0-alpha.24

Android version(s)

Any

Additional information

No response

mak1nt0sh commented 3 months ago

Also when using marker = rememberDefaultCartesianMarker(label = rememberTextComponent()) the marker text color is also wrong and the marker component is not drawn on the line. (Maybe separate issue)

Screenshot 2024-07-23 at 11 50 34
patrickmichalik commented 3 months ago

Hello, and thanks for the report! We’re working on changes that will fix both this and the problem reported in issue #784.

The unexpected DefaultCartesianMarker label color is a direct result of the bug at hand. Regarding no Component being drawn on the line, this is expected—the default indicator value is (and always has been) null. You can add an indicator by passing a lambda that returns a Component. Here’s a simple example:

rememberDefaultCartesianMarker(
  label = rememberTextComponent(),
  indicator = remember { { shapeComponent(color = it, shape = Shape.Pill) } },
)

We plan on introducing non-null defaults for indicator and guideline.

patrickmichalik commented 3 months ago

Vico 2.0.0 Alpha 26 resolves this. Cheers!

mak1nt0sh commented 3 months ago

Just checked the alpha26, it's better but there are still same issues present. Now for zero values the line is split and for mixed negative/positive the marker color returns negative color for positive values in some cases.

chart = rememberCartesianChart(
            rememberLineCartesianLayer(
                lineProvider = LineCartesianLayer.LineProvider.series(
                    rememberLine(
                        fill = LineCartesianLayer.LineFill.double(
                            topFill = fill(MaterialTheme.colorScheme.primary),
                            bottomFill = fill(MaterialTheme.customColors.negative)
                        )
                    )
            )

oie_bbihTnxyTT3I oie_ve3UksPsF92S

patrickmichalik commented 3 months ago

Thanks for letting us know, @mak1nt0sh! Since this is more closely related to issue #784, I’ve reopened that. Please see here.