-
Notifications
You must be signed in to change notification settings - Fork 47
/
AestheticsUtil.kt
72 lines (57 loc) · 2.23 KB
/
AestheticsUtil.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* Copyright (c) 2020. JetBrains s.r.o.
* Use of this source code is governed by the MIT license that can be found in the LICENSE file.
*/
package jetbrains.datalore.plot.base.aes
import jetbrains.datalore.base.values.Color
import jetbrains.datalore.base.values.Colors.solid
import jetbrains.datalore.plot.base.DataPointAesthetics
import jetbrains.datalore.plot.base.render.point.UpdatableShape
import jetbrains.datalore.vis.svg.SvgShape
import jetbrains.datalore.vis.svg.SvgUtils
object AestheticsUtil {
//affects bar, smooth, area and ribbon
internal const val ALPHA_CONTROLS_BOTH = false
fun fill(filled: Boolean, solid: Boolean, p: DataPointAesthetics): Color {
if (filled) {
return p.fill()!!
} else if (solid) {
return p.color()!!
}
return Color.TRANSPARENT
}
fun decorate(shape: UpdatableShape, filled: Boolean, solid: Boolean, p: DataPointAesthetics, strokeWidth: Double) {
val fill = fill(filled, solid, p)
val stroke = p.color()!!
var fillAlpha = 0.0
if (filled || solid) {
fillAlpha = alpha(fill, p)
}
var strokeAlpha = 0.0
if (strokeWidth > 0) {
strokeAlpha = alpha(stroke, p)
}
shape.update(fill, fillAlpha, stroke, strokeAlpha, strokeWidth)
}
fun alpha(color: Color, p: DataPointAesthetics): Double {
return if (solid(color)) { // only apply 'aes' alpha to solid colors
p.alpha()!!
} else SvgUtils.alpha2opacity(color.alpha)
// else, override with color's alpha
}
fun strokeWidth(p: DataPointAesthetics) = AesScaling.strokeWidth(p)
fun pointStrokeWidth(p: DataPointAesthetics) = AesScaling.pointStrokeWidth(p)
fun textSize(p: DataPointAesthetics) = AesScaling.textSize(p)
fun updateStroke(shape: SvgShape, p: DataPointAesthetics, applyAlpha: Boolean) {
shape.strokeColor().set(p.color())
if (solid(p.color()!!) && applyAlpha) {
shape.strokeOpacity().set(p.alpha())
}
}
fun updateFill(shape: SvgShape, p: DataPointAesthetics) {
shape.fillColor().set(p.fill())
if (solid(p.fill()!!)) {
shape.fillOpacity().set(p.alpha())
}
}
}