Skip to content

Commit 96a6b33

Browse files
committed
style(mcap): add aura to dot
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent d8ccb5f commit 96a6b33

2 files changed

Lines changed: 110 additions & 50 deletions

File tree

apps/flipcash/features/tokens/src/main/kotlin/com/flipcash/app/tokens/internal/components/marketcap/MarketCapChart.kt

Lines changed: 37 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ import androidx.compose.runtime.setValue
2323
import androidx.compose.ui.Modifier
2424
import androidx.compose.ui.draw.clip
2525
import androidx.compose.ui.graphics.Color
26+
import androidx.compose.ui.graphics.isSpecified
2627
import androidx.compose.ui.graphics.toArgb
28+
import androidx.compose.ui.platform.LocalDensity
2729
import androidx.compose.ui.res.stringResource
2830
import androidx.compose.ui.text.style.TextAlign
2931
import androidx.compose.ui.tooling.preview.Preview
@@ -253,55 +255,8 @@ private fun MarketCapChartContent(
253255
splitFraction = markerFraction + 0.005f,
254256
)
255257

256-
val markerFill = CodeTheme.colors.background
257-
258-
val activeMarker = rememberDefaultCartesianMarker(
259-
label = rememberTextComponent(
260-
color = Color.Transparent,
261-
),
262-
valueFormatter = remember {
263-
DefaultCartesianMarker.ValueFormatter.default(colorCode = false)
264-
},
265-
indicator = {
266-
shapeComponent(
267-
fill = fill(markerFill),
268-
strokeFill = fill(trendColor),
269-
strokeThickness = 2.dp,
270-
margins = Insets(4f),
271-
shape = markerCorneredShape(CorneredShape.Corner.Rounded),
272-
shadow = Shadow(
273-
radiusDp = 20f,
274-
color = trendColor.copy(0.20f).toArgb()
275-
)
276-
)
277-
},
278-
indicatorSize = CodeTheme.dimens.grid.x4,
279-
guideline = null,
280-
)
281-
282-
val persistentMarker = rememberDefaultCartesianMarker(
283-
label = rememberTextComponent(
284-
color = Color.Transparent,
285-
),
286-
valueFormatter = remember {
287-
DefaultCartesianMarker.ValueFormatter.default(colorCode = false)
288-
},
289-
indicator = { color ->
290-
shapeComponent(
291-
fill = fill(markerFill),
292-
strokeFill = fill(color),
293-
strokeThickness = 2.dp,
294-
margins = Insets(4f),
295-
shape = markerCorneredShape(CorneredShape.Corner.Rounded),
296-
shadow = Shadow(
297-
radiusDp = 20f,
298-
color = trendColor.copy(0.20f).toArgb()
299-
)
300-
)
301-
},
302-
indicatorSize = CodeTheme.dimens.grid.x4,
303-
guideline = null,
304-
)
258+
val activeMarker = rememberChartMarker(strokeFill = trendColor)
259+
val persistentMarker = rememberChartMarker()
305260

306261
val chart = rememberCartesianChart(
307262
rememberLineCartesianLayer(
@@ -323,7 +278,11 @@ private fun MarketCapChartContent(
323278
),
324279
),
325280
persistentMarkers = remember(isDragging, persistentMarker) {
326-
{ persistentMarker at 99.0 } // last point in normalized range
281+
if (isDragging) {
282+
{ persistentMarker at 99.0 }
283+
} else {
284+
{ activeMarker at 99.0 }
285+
}
327286
},
328287
markerVisibilityListener = markerVisibilityListener,
329288
markerController = CartesianMarkerController.rememberShowOnPress(consumeMoveEvents = true),
@@ -341,6 +300,34 @@ private fun MarketCapChartContent(
341300
)
342301
}
343302

303+
@Composable
304+
private fun rememberChartMarker(
305+
strokeFill: Color = Color.Unspecified,
306+
outerFill: Color = strokeFill.takeIf { it.isSpecified }?.copy(0.20f) ?: Color.Transparent,
307+
): CartesianMarker {
308+
val markerFill = CodeTheme.colors.background
309+
310+
return rememberDefaultCartesianMarker(
311+
label = rememberTextComponent(
312+
color = Color.Transparent,
313+
),
314+
valueFormatter = remember {
315+
DefaultCartesianMarker.ValueFormatter.default(colorCode = false)
316+
},
317+
indicator = { color ->
318+
outerFillShapeComponent(
319+
outerFill = fill(outerFill),
320+
margins = Insets(6f),
321+
innerFill = fill(markerFill),
322+
strokeFill = fill(strokeFill.takeIf { it.isSpecified } ?: color),
323+
strokeThickness = 2.dp,
324+
)
325+
},
326+
indicatorSize = CodeTheme.dimens.grid.x3,
327+
guideline = null,
328+
)
329+
}
330+
344331
@Composable
345332
private fun rememberSplitLineFill(
346333
leftColor: Color,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package com.flipcash.app.tokens.internal.components.marketcap
2+
3+
import android.graphics.Paint
4+
import androidx.compose.ui.unit.Dp
5+
import androidx.compose.ui.unit.dp
6+
import com.patrykandpatrick.vico.compose.common.component.shapeComponent
7+
import com.patrykandpatrick.vico.compose.common.shape.markerCorneredShape
8+
import com.patrykandpatrick.vico.core.common.DrawingContext
9+
import com.patrykandpatrick.vico.core.common.Fill
10+
import com.patrykandpatrick.vico.core.common.Insets
11+
import com.patrykandpatrick.vico.core.common.component.Component
12+
import com.patrykandpatrick.vico.core.common.shape.CorneredShape
13+
import com.patrykandpatrick.vico.core.common.shape.Shape
14+
15+
class OuterFillShapeComponent(
16+
private val outerFill: Fill,
17+
private val outerInsets: Insets,
18+
private val inner: Component,
19+
) : Component {
20+
21+
private val outerPaint = Paint().apply {
22+
style = Paint.Style.FILL
23+
isAntiAlias = true
24+
}
25+
26+
override fun draw(
27+
context: DrawingContext,
28+
left: Float,
29+
top: Float,
30+
right: Float,
31+
bottom: Float,
32+
) {
33+
val centerX = (left + right) / 2
34+
val centerY = (top + bottom) / 2
35+
36+
with(context) {
37+
val outerLeft = left - outerInsets.startDp.pixels
38+
val outerTop = top - outerInsets.topDp.pixels
39+
val outerRight = right + outerInsets.endDp.pixels
40+
val outerBottom = bottom + outerInsets.bottomDp.pixels
41+
val outerRadius = minOf(outerRight - outerLeft, outerBottom - outerTop) / 2
42+
43+
// Draw outer fill
44+
outerPaint.color = outerFill.color
45+
canvas.drawCircle(centerX, centerY, outerRadius, outerPaint)
46+
47+
// Draw inner component
48+
inner.draw(context, left, top, right, bottom)
49+
}
50+
}
51+
}
52+
53+
fun outerFillShapeComponent(
54+
outerFill: Fill,
55+
margins: Insets = Insets(4f),
56+
innerFill: Fill,
57+
strokeFill: Fill,
58+
shape: Shape = markerCorneredShape(CorneredShape.Corner.Rounded),
59+
strokeThickness: Dp = 2.dp,
60+
): Component {
61+
val inner = shapeComponent(
62+
fill = innerFill,
63+
shape = shape,
64+
strokeFill = strokeFill,
65+
strokeThickness = strokeThickness,
66+
)
67+
68+
return OuterFillShapeComponent(
69+
outerFill = outerFill,
70+
inner = inner,
71+
outerInsets = margins,
72+
)
73+
}

0 commit comments

Comments
 (0)