-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
geometry.py
481 lines (358 loc) · 14.5 KB
/
geometry.py
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
#-----------------------------------------------------------------------------
# Copyright (c) 2012 - 2024, Anaconda, Inc., and Bokeh Contributors.
# All rights reserved.
#
# The full license is in the file LICENSE.txt, distributed with this software.
#-----------------------------------------------------------------------------
'''
'''
#-----------------------------------------------------------------------------
# Boilerplate
#-----------------------------------------------------------------------------
from __future__ import annotations
import logging # isort:skip
log = logging.getLogger(__name__)
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
# Bokeh imports
from ...core.enums import CoordinateUnits, Dimension
from ...core.properties import (
Bool,
CoordinateLike,
Enum,
Float,
Include,
Instance,
InstanceDefault,
Null,
Nullable,
Override,
Seq,
UnitsSpec,
field,
)
from ...core.property_aliases import BorderRadius
from ...core.property_mixins import (
LineProps,
ScalarFillProps,
ScalarHatchProps,
ScalarLineProps,
)
from ..common.properties import Coordinate
from ..coordinates import (
FrameBottom,
FrameLeft,
FrameRight,
FrameTop,
)
from .annotation import Annotation, DataAnnotation
from .arrows import ArrowHead, TeeHead
#-----------------------------------------------------------------------------
# Globals and constants
#-----------------------------------------------------------------------------
__all__ = (
"Band",
"BoxAnnotation",
"PolyAnnotation",
"Slope",
"Span",
"Whisker",
)
#-----------------------------------------------------------------------------
# General API
#-----------------------------------------------------------------------------
class BoxAnnotation(Annotation):
''' Render a shaded rectangular region as an annotation.
See :ref:`ug_basic_annotations_box_annotations` for information on plotting box annotations.
'''
# explicit __init__ to support Init signatures
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
left = Coordinate(default=lambda: FrameLeft(), help="""
The x-coordinates of the left edge of the box annotation.
""").accepts(Null, lambda _value: FrameLeft())
right = Coordinate(default=lambda: FrameRight(), help="""
The x-coordinates of the right edge of the box annotation.
""").accepts(Null, lambda _value: FrameRight())
top = Coordinate(default=lambda: FrameTop(), help="""
The y-coordinates of the top edge of the box annotation.
""").accepts(Null, lambda _value: FrameTop())
bottom = Coordinate(default=lambda: FrameBottom(), help="""
The y-coordinates of the bottom edge of the box annotation.
""").accepts(Null, lambda _value: FrameBottom())
left_units = Enum(CoordinateUnits, default="data", help="""
The unit type for the left attribute. Interpreted as |data units| by
default.
""")
right_units = Enum(CoordinateUnits, default="data", help="""
The unit type for the right attribute. Interpreted as |data units| by
default.
""")
top_units = Enum(CoordinateUnits, default="data", help="""
The unit type for the top attribute. Interpreted as |data units| by
default.
""")
bottom_units = Enum(CoordinateUnits, default="data", help="""
The unit type for the bottom attribute. Interpreted as |data units| by
default.
""")
left_limit = Nullable(Coordinate, help="""
Optional left limit for box movement.
.. note::
This property is experimental and may change at any point.
""")
right_limit = Nullable(Coordinate, help="""
Optional right limit for box movement.
.. note::
This property is experimental and may change at any point.
""")
top_limit = Nullable(Coordinate, help="""
Optional top limit for box movement.
.. note::
This property is experimental and may change at any point.
""")
bottom_limit = Nullable(Coordinate, help="""
Optional bottom limit for box movement.
.. note::
This property is experimental and may change at any point.
""")
border_radius = BorderRadius(default=0, help="""
Allows the box to have rounded corners.
.. note::
This property is experimental and may change at any point.
""")
editable = Bool(default=False, help="""
Allows to interactively modify the geometry of this box.
.. note::
This property is experimental and may change at any point.
""")
resizable = Enum("none", "left", "right", "top", "bottom", "x", "y", "all", default="all", help="""
If `editable` is set, this property allows to configure which
combinations of edges are allowed to be moved, thus allows
restrictions on resizing of the box.
.. note::
This property is experimental and may change at any point.
""")
movable = Enum("none", "x", "y", "both", default="both", help="""
If `editable` is set, this property allows to configure in which
directions the box can be moved.
.. note::
This property is experimental and may change at any point.
""")
symmetric = Bool(default=False, help="""
Indicates whether the box is resizable around its center or its corners.
.. note::
This property is experimental and may change at any point.
""")
line_props = Include(ScalarLineProps, help="""
The {prop} values for the box.
""")
fill_props = Include(ScalarFillProps, help="""
The {prop} values for the box.
""")
hatch_props = Include(ScalarHatchProps, help="""
The {prop} values for the box.
""")
hover_line_props = Include(ScalarLineProps, prefix="hover", help="""
The {prop} values for the box when hovering over.
""")
hover_fill_props = Include(ScalarFillProps, prefix="hover", help="""
The {prop} values for the box when hovering over.
""")
hover_hatch_props = Include(ScalarHatchProps, prefix="hover", help="""
The {prop} values for the box when hovering over.
""")
line_color = Override(default="#cccccc")
line_alpha = Override(default=0.3)
fill_color = Override(default="#fff9ba")
fill_alpha = Override(default=0.4)
hover_line_color = Override(default=None)
hover_line_alpha = Override(default=0.3)
hover_fill_color = Override(default=None)
hover_fill_alpha = Override(default=0.4)
class Band(DataAnnotation):
''' Render a filled area band along a dimension.
See :ref:`ug_basic_annotations_bands` for information on plotting bands.
'''
# explicit __init__ to support Init signatures
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
lower = UnitsSpec(default=field("lower"), units_enum=CoordinateUnits, units_default="data", help="""
The coordinates of the lower portion of the filled area band.
""")
upper = UnitsSpec(default=field("upper"), units_enum=CoordinateUnits, units_default="data", help="""
The coordinates of the upper portion of the filled area band.
""")
base = UnitsSpec(default=field("base"), units_enum=CoordinateUnits, units_default="data", help="""
The orthogonal coordinates of the upper and lower values.
""")
dimension = Enum(Dimension, default='height', help="""
The direction of the band can be specified by setting this property
to "height" (``y`` direction) or "width" (``x`` direction).
""")
line_props = Include(ScalarLineProps, help="""
The {prop} values for the band.
""")
line_alpha = Override(default=0.3)
line_color = Override(default="#cccccc")
fill_props = Include(ScalarFillProps, help="""
The {prop} values for the band.
""")
fill_alpha = Override(default=0.4)
fill_color = Override(default="#fff9ba")
class PolyAnnotation(Annotation):
''' Render a shaded polygonal region as an annotation.
See :ref:`ug_basic_annotations_polygon_annotations` for information on
plotting polygon annotations.
'''
# explicit __init__ to support Init signatures
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
xs = Seq(CoordinateLike, default=[], help="""
The x-coordinates of the region to draw.
""")
xs_units = Enum(CoordinateUnits, default='data', help="""
The unit type for the ``xs`` attribute. Interpreted as |data units| by
default.
""")
ys = Seq(CoordinateLike, default=[], help="""
The y-coordinates of the region to draw.
""")
ys_units = Enum(CoordinateUnits, default='data', help="""
The unit type for the ``ys`` attribute. Interpreted as |data units| by
default.
""")
editable = Bool(default=False, help="""
Allows to interactively modify the geometry of this polygon.
.. note::
This property is experimental and may change at any point.
""")
line_props = Include(ScalarLineProps, help="""
The {prop} values for the polygon.
""")
fill_props = Include(ScalarFillProps, help="""
The {prop} values for the polygon.
""")
hatch_props = Include(ScalarHatchProps, help="""
The {prop} values for the polygon.
""")
hover_line_props = Include(ScalarLineProps, prefix="hover", help="""
The {prop} values for the polygon when hovering over.
""")
hover_fill_props = Include(ScalarFillProps, prefix="hover", help="""
The {prop} values for the polygon when hovering over.
""")
hover_hatch_props = Include(ScalarHatchProps, prefix="hover", help="""
The {prop} values for the polygon when hovering over.
""")
line_color = Override(default="#cccccc")
line_alpha = Override(default=0.3)
fill_color = Override(default="#fff9ba")
fill_alpha = Override(default=0.4)
hover_line_color = Override(default=None)
hover_line_alpha = Override(default=0.3)
hover_fill_color = Override(default=None)
hover_fill_alpha = Override(default=0.4)
class Slope(Annotation):
""" Render a sloped line as an annotation.
See :ref:`ug_basic_annotations_slope` for information on plotting slopes.
"""
# explicit __init__ to support Init signatures
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
gradient = Nullable(Float, help="""
The gradient of the line, in |data units|
""")
y_intercept = Nullable(Float, help="""
The y intercept of the line, in |data units|
""")
line_props = Include(ScalarLineProps, help="""
The {prop} values for the line.
""")
above_fill_props = Include(ScalarFillProps, prefix="above", help="""
The {prop} values for the area above the line.
""")
above_hatch_props = Include(ScalarHatchProps, prefix="above", help="""
The {prop} values for the area above the line.
""")
below_fill_props = Include(ScalarFillProps, prefix="below", help="""
The {prop} values for the area below the line.
""")
below_hatch_props = Include(ScalarHatchProps, prefix="below", help="""
The {prop} values for the area below the line.
""")
above_fill_color = Override(default=None)
above_fill_alpha = Override(default=0.4)
below_fill_color = Override(default=None)
below_fill_alpha = Override(default=0.4)
class Span(Annotation):
""" Render a horizontal or vertical line span.
See :ref:`ug_basic_annotations_spans` for information on plotting spans.
"""
# explicit __init__ to support Init signatures
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
location = Nullable(CoordinateLike, help="""
The location of the span, along ``dimension``.
""")
location_units = Enum(CoordinateUnits, default='data', help="""
The unit type for the location attribute. Interpreted as "data space"
units by default.
""")
dimension = Enum(Dimension, default='width', help="""
The direction of the span can be specified by setting this property
to "height" (``y`` direction) or "width" (``x`` direction).
""")
editable = Bool(default=False, help="""
Allows to interactively modify the geometry of this span.
.. note::
This property is experimental and may change at any point.
""")
line_props = Include(ScalarLineProps, help="""
The {prop} values for the span.
""")
hover_line_props = Include(ScalarLineProps, prefix="hover", help="""
The {prop} values for the span when hovering over.
""")
hover_line_color = Override(default=None)
hover_line_alpha = Override(default=0.3)
class Whisker(DataAnnotation):
''' Render a whisker along a dimension.
See :ref:`ug_basic_annotations_whiskers` for information on plotting whiskers.
'''
# explicit __init__ to support Init signatures
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
lower = UnitsSpec(default=field("lower"), units_enum=CoordinateUnits, units_default="data", help="""
The coordinates of the lower end of the whiskers.
""")
lower_head = Nullable(Instance(ArrowHead), default=InstanceDefault(TeeHead, size=10), help="""
Instance of ``ArrowHead``.
""")
upper = UnitsSpec(default=field("upper"), units_enum=CoordinateUnits, units_default="data", help="""
The coordinates of the upper end of the whiskers.
""")
upper_head = Nullable(Instance(ArrowHead), default=InstanceDefault(TeeHead, size=10), help="""
Instance of ``ArrowHead``.
""")
base = UnitsSpec(default=field("base"), units_enum=CoordinateUnits, units_default="data", help="""
The orthogonal coordinates of the upper and lower values.
""")
dimension = Enum(Dimension, default='height', help="""
The direction of the whisker can be specified by setting this property
to "height" (``y`` direction) or "width" (``x`` direction).
""")
line_props = Include(LineProps, help="""
The {prop} values for the whisker body.
""")
level = Override(default="underlay")
#-----------------------------------------------------------------------------
# Dev API
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Private API
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Code
#-----------------------------------------------------------------------------