Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variadic line width #802

Merged
merged 5 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Next Next commit
Correct color markers in tooltip, update future_changes.md
  • Loading branch information
IKupriyanov-HORIS committed Jun 28, 2023
commit 9e39a0a875f119ddab4e99314acd1c587ba94174
271 changes: 271 additions & 0 deletions docs/f-23c/aes_size_variadic_with_mapping.ipynb

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions future_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
See: [example notebook](https://nbviewer.org/github/JetBrains/lets-plot/blob/master/docs/f-23c/tooltips_disable_splitting.ipynb).


- Variadic line sizes in `geom_line()` and `geom_path()` with `size` mapping.
See: [example notebook](https://nbviewer.org/github/JetBrains/lets-plot/blob/master/docs/f-23c/aes_size_variadic_with_mapping.ipynb).


### Changed

- [BREAKING] `geom_boxplot()` no longer support parameter `sampling`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,25 @@ class TargetCollectorHelper(
fun addVariadicPaths(paths: List<List<PathData>>) {
val hintKind = VERTICAL_TOOLTIP.takeIf { ctx.flipped } ?: HORIZONTAL_TOOLTIP

paths.forEach { path ->
val flattenPath = path
.flatMap(PathData::points)
.let { reduce(it, 0.5) { p1, p2 -> p1.coord.subtract(p2.coord).length() } }
for (path in paths) {
val pathAesIndex = mutableMapOf<Int, DataPointAesthetics>()
for (subPath in path) {
for (p in subPath.aesthetics) {
// Do not use aes from p - if size and colour are mapped the colour of the tooltip marker
// and line colour will be different
pathAesIndex[p.index()] = subPath.aes
}
}

val flattenPathData = PathData(flattenPath)
val aesIndex = flattenPathData.aesthetics.associateBy(
keySelector = DataPointAesthetics::index,
valueTransform = { it }
)
val flattenPathData = path
.flatMap(PathData::points) // make a single path to make tooltips in HOVER mode work correctly
.let { reduce(it, 0.5) { p1, p2 -> p1.coord.subtract(p2.coord).length() } }
.let(::PathData)

targetCollector.addPath(
flattenPathData.coordinates,
{ i -> flattenPathData.aesthetics[i].index() },
TooltipParams(markerColorsFactory = { i: Int -> colorMarkerMapper(aesIndex[i]!!) }),
TooltipParams(markerColorsFactory = { i: Int -> colorMarkerMapper(pathAesIndex[i]!!) }),
hintKind
)
}
Expand Down