Skip to content

Commit

Permalink
Differentiate without color (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
eevajonnapanula committed Jul 16, 2023
1 parent 5e98304 commit 66f3744
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
Expand Up @@ -20,6 +20,7 @@ import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.MaterialTheme
Expand All @@ -35,6 +36,8 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.graphics.StrokeCap
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.layout.positionInParent
Expand All @@ -51,6 +54,7 @@ import androidx.compose.ui.text.ExperimentalTextApi
import androidx.compose.ui.text.rememberTextMeasurer
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
import com.eevajonna.graphexample.R
Expand Down Expand Up @@ -292,18 +296,23 @@ fun Graph(
color = graphColors.techColor,
highlightedItemX = highlightedX,
highlighterColor = highlighterColor,
strokeCap = StrokeCap.Round,
)
drawData(
pixelPointsForIct,
color = graphColors.ictColor,
highlightedItemX = highlightedX,
highlighterColor = highlighterColor,
strokeCap = StrokeCap.Square,
dashed = true,
)
drawData(
pixelPointsForTotal,
color = graphColors.totalColor,
highlightedItemX = highlightedX,
highlighterColor = highlighterColor,
strokeCap = StrokeCap.Butt,
strokeWidth = 12.dp.toPx(),
)
}

Expand Down
Expand Up @@ -192,6 +192,9 @@ fun DrawScope.drawData(
color: Color,
highlightedItemX: Float?,
highlighterColor: Color,
strokeWidth: Float = 8.dp.toPx(),
strokeCap: StrokeCap = StrokeCap.Round,
dashed: Boolean = false,
) {
val path = Path()

Expand All @@ -217,23 +220,23 @@ fun DrawScope.drawData(
drawPath(
path,
color = color,
style = Stroke(width = 3f),
style = Stroke(width = 3f, pathEffect = if (dashed) PathEffect.dashPathEffect(floatArrayOf(10f, 10f), 0f) else null),
)

drawPoints(
pixelPoints.map { Offset(it.x + 20f, it.y) },
PointMode.Points,
color = color,
strokeWidth = 8.dp.toPx(),
cap = StrokeCap.Round,
strokeWidth = strokeWidth,
cap = strokeCap,
)

drawPoints(
filterHighlighted(pixelPoints, highlightedItemX).map { Offset(it.x + 20f, it.y) },
PointMode.Points,
color = highlighterColor,
strokeWidth = 8.dp.toPx(),
cap = StrokeCap.Square,
strokeWidth = strokeWidth,
cap = strokeCap,
)
}

Expand Down

0 comments on commit 66f3744

Please sign in to comment.