1+ package org.jetbrains.letsPlot.geom
2+
3+ import org.jetbrains.letsPlot.Geom.labelRepel
4+ import org.jetbrains.letsPlot.Stat
5+ import org.jetbrains.letsPlot.intern.Layer
6+ import org.jetbrains.letsPlot.intern.Options
7+ import org.jetbrains.letsPlot.intern.layer.*
8+ import org.jetbrains.letsPlot.intern.layer.geom.LabelParameters
9+ import org.jetbrains.letsPlot.intern.layer.geom.LabelRepelAesthetics
10+ import org.jetbrains.letsPlot.intern.layer.geom.LabelRepelMapping
11+ import org.jetbrains.letsPlot.intern.layer.geom.RepelParameters
12+ import org.jetbrains.letsPlot.pos.positionIdentity
13+ import org.jetbrains.letsPlot.spatial.SpatialDataset
14+ import org.jetbrains.letsPlot.tooltips.TooltipOptions
15+
16+ @Suppress(" ClassName" )
17+ /* *
18+ * Add repelling text labels with background boxes to the plot.
19+ *
20+ * ## Examples
21+ *
22+ * - [ggrepel.ipynb](https://nbviewer.org/github/JetBrains/lets-plot-kotlin/blob/master/docs/examples/jupyter-notebooks/f-4.11.0/ggrepel.ipynb)
23+ *
24+ * @param data The data to be displayed in this layer. If null, the default, the data
25+ * is inherited from the plot data as specified in the call to [letsPlot][org.jetbrains.letsPlot.letsPlot].
26+ * @param stat The statistical transformation to use on the data for this layer.
27+ * Supported transformations: `Stat.identity`, `Stat.bin()`, `Stat.count()`, etc. see [Stat][org.jetbrains.letsPlot.Stat].
28+ * @param position Position adjustment: `positionIdentity`, `positionStack()`,
29+ * `positionDodge()`, etc. see [Position](https://lets-plot.org/kotlin/-lets--plot--kotlin/org.jetbrains.letsPlot.pos/).
30+ * @param showLegend default = true.
31+ * false - do not show legend for this layer.
32+ * @param inheritAes default = true.
33+ * false - do not combine the layer aesthetic mappings with the plot shared mappings.
34+ * @param manualKey String or result of the call to the `layerKey()` function.
35+ * The key to show in the manual legend. Specifies the text for the legend label or advanced settings using the `layerKey()` function.
36+ * @param sampling Result of the call to the `samplingXxx()` function.
37+ * To prevent any sampling for this layer pass value `samplingNone`.
38+ * For more info see [sampling.html](https://lets-plot.org/kotlin/sampling.html).
39+ * @param tooltips Result of the call to the `layerTooltips()` function.
40+ * Specifies appearance, style and content.
41+ * Set `tooltips = tooltipsNone` to hide tooltips from the layer.
42+ * @param map Data-structure containing series of planar shapes and, optionally,
43+ * associated data series (for example: names of States and their boundaries).
44+ *
45+ * Supported shapes: Point and MultiPoint.
46+ * All coordinates should be encoded as decimal degrees in WGS84 coordinate reference system.
47+ *
48+ * Can be used with parameter `mapJoin` for joining data and map coordinates.
49+ * @param mapJoin Pair of Names or Pair of Lists of Names.
50+ * Specifies column names to join the `data` and the `map` coordinates on.
51+ * - Pair.first: column name or list of column names in the `data` dataframe.
52+ * - Pair.second: column name or list of column names in the `map` dataframe.
53+ * @param useCRS By default, all coordinates are converted into degrees of longitude and latitude,
54+ * and these map coordinates are projected onto the screen coordinates using Mercator projection.
55+ * Specify useCRS = "provided" to keep the SpatialDataset's original coordinate reference system (CRS).
56+ * @param x X-axis value.
57+ * @param y Y-axis value.
58+ * @param label Text to add to plot.
59+ * @param alpha Transparency level of a layer.
60+ * Understands numbers between 0 and 1.
61+ * @param color Color of the geometry.
62+ * For more info see: [aesthetics.html#color-and-fill](https://lets-plot.org/kotlin/aesthetics.html#color-and-fill).
63+ * @param fill Background color of the label.
64+ * For more info see: [aesthetics.html#color-and-fill](https://lets-plot.org/kotlin/aesthetics.html#color-and-fill).
65+ * @param size Font size.
66+ * @param family default = "sans".
67+ * For more info see: [aesthetics.html#font-family](https://lets-plot.org/kotlin/aesthetics.html#font-family).
68+ * @param fontface default = "plain".
69+ * For more info see: [aesthetics.html#font-face](https://lets-plot.org/kotlin/aesthetics.html#font-face).
70+ * @param hjust ("left", "middle", "right") or number between 0 ("left") and 1 ("right")
71+ * or "inward" (aligns label towards the plot center), "outward" (away from the plot center).
72+ * Horizontal label alignment.
73+ * @param vjust ("bottom", "center", "top") or number between 0 ("bottom") and 1 ("top")
74+ * or "inward" (aligns label towards the plot center), "outward" (away from the plot center).
75+ * Vertical label alignment.
76+ * @param angle Label rotation angle in degrees.
77+ * @param lineheight Line height multiplier applied to the font size in the case of multi-line text.
78+ * @param labelFormat Specifies the format pattern for displaying mapped values.
79+ * @param naText default = "n/a". Text to show for missing values.
80+ * @param nudgeX Horizontal adjustment to nudge labels by.
81+ * @param nudgeY Vertical adjustment to nudge labels by.
82+ * @param labelPadding Amount of padding around label. Defaults to 0.25 of font size.
83+ * @param labelR Radius of rounded corners. Defaults to 0.15 of label height.
84+ * @param labelSize default = 1.0. Size of label border.
85+ * @param alphaStroke default = false.
86+ * Enables the applying of 'alpha' to 'color' (label text and border).
87+ * @param sizeUnit Relates the size of the text label to the length of the unit step along one of the axes.
88+ * Possible values: "x", "y". If not specified, no fitting is performed.
89+ * @param nudgeUnit ("identity", "size", "px") Units for x and y nudging.
90+ * Possible values:
91+ * - "identity": a unit of 1 corresponds to a difference of 1 in data space;
92+ * - "size": a unit of 1 corresponds to the diameter of a point with `size=1`;
93+ * - "px": the unit is measured in screen pixels.
94+ * @param colorBy default = "color" ("fill", "color", "paint_a", "paint_b", "paint_c").
95+ * Defines the color aesthetic for the geometry.
96+ * @param fillBy default = "fill" ("fill", "color", "paint_a", "paint_b", "paint_c").
97+ * Defines the fill aesthetic for the geometry.
98+ * @param checkOverlap Skips plotting text that overlaps previous text in the same layer.
99+ * @param seed Random seed for reproducibility.
100+ * @param maxIter Maximum number of iterations for the repulsion algorithm.
101+ * @param maxTime Maximum allowed time in seconds for resolving label collisions.
102+ * @param direction default = "both" ("both", "x", "y").
103+ * Defines the direction in which labels can be moved.
104+ * @param pointPadding Padding around the data point.
105+ * @param boxPadding Padding around the label box.
106+ * @param maxOverlaps Max number of overlapping labels to allow.
107+ * @param minSegmentLength Minimum length of the connecting line segment. Shorter ones are omitted.
108+ * @param arrow Specification for arrow head, as created by `arrow()` function.
109+ * @param mapping Set of aesthetic mappings.
110+ * Aesthetic mappings describe the way that variables in the data are
111+ * mapped to plot "aesthetics".
112+ *
113+ *
114+ * Format patterns in the `labelFormat` parameter can be just a number format (like "d") or
115+ * a string template where number format is surrounded by curly braces: "{d} cylinders".
116+ * For more info see: [formats.html](https://lets-plot.org/kotlin/formats.html)
117+ * Note: the "$" must be escaped as "\$".
118+ *
119+ * Examples:
120+ * - ".2f" -> "12.45"
121+ * - "Score: {.2f}" -> "Score: 12.45"
122+ * - "Score: {}" -> "Score: 12.454789"
123+ *
124+ */
125+ class geomLabelRepel (
126+ data : Map <* , * >? = null ,
127+ stat : StatOptions = Stat .identity,
128+ position : PosOptions = positionIdentity,
129+ showLegend : Boolean = true ,
130+ inheritAes : Boolean? = null ,
131+ manualKey : Any? = null ,
132+ sampling : SamplingOptions ? = null ,
133+ tooltips : TooltipOptions ? = null ,
134+ override val map : SpatialDataset ? = null ,
135+ override val mapJoin : Pair <Any , Any >? = null ,
136+ override val useCRS : String? = null ,
137+ override val x : Number ? = null ,
138+ override val y : Number ? = null ,
139+ override val label : String? = null ,
140+ override val alpha : Number ? = null ,
141+ override val color : Any? = null ,
142+ override val fill : Any? = null ,
143+ override val size : Number ? = null ,
144+ override val family : String? = null ,
145+ override val fontface : String? = null ,
146+ override val hjust : Any? = null ,
147+ override val vjust : Any? = null ,
148+ override val angle : Number ? = null ,
149+ override val shape : Any? = null ,
150+ override val pointSize : Any? = null ,
151+ override val pointStroke : Any? = null ,
152+ override val segmentColor : Any? = null ,
153+ override val segmentSize : Any? = null ,
154+ override val segmentAlpha : Any? = null ,
155+ override val linetype : Any? = null ,
156+ override val lineheight : Number ? = null ,
157+ override val labelFormat : String? = null ,
158+ override val naText : String? = null ,
159+ override val nudgeX : Number ? = null ,
160+ override val nudgeY : Number ? = null ,
161+ override val nudgeUnit : String? = null ,
162+ override val labelPadding : Number ? = null ,
163+ override val labelR : Number ? = null ,
164+ override val labelSize : Number ? = null ,
165+ override val alphaStroke : Boolean? = null ,
166+ override val sizeUnit : String? = null ,
167+ override val colorBy : String? = null ,
168+ override val fillBy : String? = null ,
169+ override val checkOverlap : Boolean? = null ,
170+ override val seed : Int? = null ,
171+ override val maxIter : Int? = null ,
172+ override val maxTime : Double? = null ,
173+ override val direction : String? = null ,
174+ override val pointPadding : Float? = null ,
175+ override val boxPadding : Float? = null ,
176+ override val maxOverlaps : Int? = null ,
177+ override val minSegmentLength : Float? = null ,
178+ override val arrow : Map <String , Any >? = null ,
179+ mapping : LabelRepelMapping .() -> Unit = {},
180+ ) : LabelRepelAesthetics,
181+ LabelParameters ,
182+ RepelParameters ,
183+ WithSizeUnitOption ,
184+ WithSpatialParameters ,
185+ WithColorOption ,
186+ WithFillOption ,
187+ Layer (
188+ mapping = LabelRepelMapping ().apply (mapping).seal(),
189+ data = data,
190+ geom = labelRepel(),
191+ stat = stat,
192+ position = position,
193+ showLegend = showLegend,
194+ inheritAes = inheritAes,
195+ manualKey = manualKey,
196+ sampling = sampling,
197+ tooltips = tooltips
198+ ) {
199+ override fun seal (): Options {
200+ return super <LabelRepelAesthetics >.seal() +
201+ super <LabelParameters >.seal() +
202+ super <RepelParameters >.seal() +
203+ super <WithSizeUnitOption >.seal() +
204+ super <WithColorOption >.seal() +
205+ super <WithFillOption >.seal()
206+ }
207+ }
0 commit comments