simetri.canvas.style_map
This module contains the Style classes used to set the style of shapes, lines, text, and tags. Shape and Tag objects use the maps to create aliases for style attributes.
Examples: shape.style.line_style.color is aliased by shape.line_color tag.style.fill_style.pattern_style.line_style.width is aliased by tag.pattern_line_width Documentation list all aliases for each style class.
1"""This module contains the Style classes used to set the style of shapes, lines, text, 2and tags. Shape and Tag objects use the maps to create aliases for style attributes. 3 4Examples: 5shape.style.line_style.color is aliased by shape.line_color 6tag.style.fill_style.pattern_style.line_style.width is aliased by tag.pattern_line_width 7Documentation list all aliases for each style class. 8""" 9# to do: Change this so that IDEs can find the classes and methods. 10 11from typing import List, Optional, Sequence, Union 12from dataclasses import dataclass 13 14from ..settings.settings import defaults 15from ..graphics.common import get_unique_id, VOID 16from ..graphics.all_enums import ( 17 Align, 18 Anchor, 19 BackStyle, 20 BlendMode, 21 FillMode, 22 FontFamily, 23 FontSize, 24 FrameShape, 25 LineCap, 26 LineJoin, 27 MarkerType, 28 PatternType, 29 ShadeType, 30 Types, 31) 32from ..colors.colors import Color 33 34 35def _set_style_args(obj, attribs, exact=None, prefix=None): 36 """Set the style arguments for the given object. 37 38 Args: 39 obj: The object to set the style arguments for. 40 attribs: List of attributes to set. 41 exact: List of exact attributes to set. 42 prefix: Prefix to use for the attributes. 43 """ 44 for attrib in attribs: 45 if exact and attrib in exact: 46 default = defaults.get(attrib, VOID) 47 if default != VOID: 48 setattr(obj, attrib, default) 49 else: 50 if prefix: 51 setattr(obj, attrib, defaults[f"{prefix}_{attrib}"]) 52 else: 53 default = defaults.get(attrib, VOID) 54 if default != VOID: 55 setattr(obj, attrib, default) 56 57 58def _get_style_attribs(style: Types.STYLE, prefix: str = None, exact: list = None, exclude: list = None) -> List[str]: 59 """Get the list of attributes from the given Style object. 60 61 Args: 62 style (Types.STYLE): The style object to get attributes from. 63 prefix (str, optional): The prefix to use for the attributes. Defaults to None. 64 exact (list, optional): List of exact attributes to include. Defaults to None. 65 exclude (list, optional): List of attributes to exclude. Defaults to None. 66 67 Returns: 68 List[str]: List of attributes. 69 """ 70 attribs = style.__dict__.keys() 71 res = [] 72 for attrib in attribs: 73 if attrib in exclude: 74 continue 75 if attrib in exact: 76 res.append(attrib) 77 else: 78 res.append(f"{prefix}_{attrib}") 79 return res 80 81 82@dataclass 83class FontStyle: 84 """FontStyle is used to set the font, color, and style of text. 85 86 Attributes: 87 font_family (str): The font family. 88 color (Color): The color of the font. 89 family (Union[FontFamily, str]): The font family. 90 size (Union[FontSize, float]): The size of the font. 91 bold (bool): Whether the font is bold. 92 italic (bool): Whether the font is italic. 93 small_caps (bool): Whether the font uses small caps. 94 old_style_nums (bool): Whether the font uses old style numbers. 95 overline (bool): Whether the font has an overline. 96 strike_through (bool): Whether the font has a strike through. 97 underline (bool): Whether the font is underlined. 98 blend_mode (BlendMode): The blend mode of the font. 99 alpha (float): The alpha value of the font. 100 """ 101 102 font_family: str = None 103 color: Color = None 104 family: Union[FontFamily, str] = None 105 size: Union[FontSize, float] = None 106 bold: bool = None 107 italic: bool = None 108 small_caps: bool = None 109 old_style_nums: bool = None 110 overline: bool = None 111 strike_through: bool = None 112 underline: bool = None 113 blend_mode: BlendMode = None 114 alpha: float = None 115 116 def __post_init__(self): 117 """Initialize the FontStyle object.""" 118 exact = [ 119 "bold", 120 "italic", 121 "small_caps", 122 "old_style_nums", 123 "overline", 124 "strike_through", 125 "underline", 126 "draw_frame", 127 "font_family", 128 ] 129 exclude = [] 130 131 _style_init( 132 self, 133 exact=exact, 134 exclude=exclude, 135 prefix="font", 136 subtype=Types.FONT_STYLE, 137 ) 138 self._exact = exact 139 self._exclude = exclude 140 141 142@dataclass 143class GridStyle: 144 """GridStyle is used to set the grid color, alpha, width, and pattern. 145 146 Attributes: 147 line_color (Color): The color of the grid lines. 148 line_width (float): The width of the grid lines. 149 alpha (float): The alpha value of the grid. 150 back_color (Color): The background color of the grid. 151 """ 152 153 line_color: Color = None 154 line_width: float = None 155 alpha: float = None 156 # width: float = None 157 # height: float = None 158 back_color: Color = None 159 160 def __post_init__(self): 161 """Initialize the GridStyle object.""" 162 exact = [] 163 exclude = [] 164 165 _style_init( 166 self, 167 exact=exact, 168 exclude=exclude, 169 prefix="grid", 170 subtype=Types.GRID_STYLE, 171 ) 172 self._exact = exact 173 self._exclude = exclude 174 175 def __str__(self): 176 """Return a string representation of the GridStyle object.""" 177 return f"GridStyle: {self.id}" 178 179 def __repr__(self): 180 """Return a string representation of the GridStyle object.""" 181 return f"GridStyle: {self.id}" 182 183 def _get_attributes(self): 184 """Get the attributes of the GridStyle object.""" 185 attribs = [x for x in self.__dict__ if not x.startswith("_")] 186 res = [] 187 for attrib in attribs: 188 if attrib in self._exact: 189 res.append(attrib) 190 else: 191 res.append(f"grid_{attrib}") 192 193 194@dataclass 195class MarkerStyle: 196 """MarkerStyle is used to set the marker type, size, and color of a shape. 197 198 Attributes: 199 marker_type (MarkerType): The type of the marker. 200 size (float): The size of the marker. 201 color (Color): The color of the marker. 202 radius (float): The radius of the marker. 203 """ 204 205 marker_type: MarkerType = None 206 size: float = None 207 color: Color = None 208 radius: float = None 209 210 def __post_init__(self): 211 """Initialize the MarkerStyle object.""" 212 exact = ["marker_type"] 213 exclude = [] 214 _style_init( 215 self, 216 exact=exact, 217 exclude=exclude, 218 prefix="marker", 219 subtype=Types.MARKER_STYLE, 220 ) 221 self._exact = exact 222 self._exclude = exclude 223 224 def __str__(self): 225 """Return a string representation of the MarkerStyle object.""" 226 return f"Marker: {self.type}" 227 228 229@dataclass 230class LineStyle: 231 """LineStyle is used to set the line color, alpha, width, and pattern of a shape. 232 233 Attributes: 234 color (Color): The color of the line. 235 alpha (float): The alpha value of the line. 236 width (int): The width of the line. 237 dash_array (Optional[Sequence[float]]): The dash array of the line. 238 dash_phase (float): The dash phase of the line. 239 cap (LineCap): The cap style of the line. 240 join (LineJoin): The join style of the line. 241 miter_limit (float): The miter limit of the line. 242 fillet_radius (float): The fillet radius of the line. 243 marker_style (MarkerStyle): The marker style of the line. 244 smooth (bool): Whether the line is smooth. 245 stroke (bool): Whether the line is stroked. 246 draw_markers (bool): Whether to draw markers on the line. 247 draw_fillets (bool): Whether to draw fillets on the line. 248 markers_only (bool): Whether to draw only markers on the line. 249 double_lines (bool): Whether to draw double lines. 250 double_distance (float): The distance between double lines. 251 """ 252 253 # To do: Add support for arrows 254 color: Color = None 255 alpha: float = None 256 width: int = None 257 dash_array: Optional[Sequence[float]] = None 258 dash_phase: float = None 259 cap: LineCap = None 260 join: LineJoin = None 261 miter_limit: float = None 262 fillet_radius: float = None 263 marker_style: MarkerStyle = None 264 smooth: bool = None 265 stroke: bool = None 266 draw_markers: bool = None 267 draw_fillets: bool = None 268 markers_only: bool = None 269 double_lines: bool = None 270 double_distance: float = None 271 272 def __post_init__(self): 273 """Initialize the LineStyle object.""" 274 exact = [ 275 "smooth", 276 "stroke", 277 "fillet_radius", 278 "draw_fillets", 279 "draw_markers", 280 "markers_only", 281 "double", 282 "double_distance", 283 "double_lines", 284 ] 285 exclude = ["marker_style"] 286 _style_init( 287 self, exact, exclude, prefix="line", subtype=Types.LINE_STYLE 288 ) 289 self._exact = exact 290 self._exclude = exclude 291 self.marker_style = MarkerStyle() 292 293 def __str__(self): 294 """Return a string representation of the LineStyle object.""" 295 return f"LineStyle: {self.id}" 296 297 298def _style_init(style, exact=None, exclude=None, prefix="", subtype=None): 299 """Initialize the style object. 300 301 Args: 302 style: The style object to initialize. 303 exact: List of exact attributes to include. 304 exclude: List of attributes to exclude. 305 prefix: Prefix to use for the attributes. 306 subtype: The subtype of the style. 307 """ 308 if exclude is None: 309 exclude = [] 310 if exact is None: 311 exact = [] 312 attribs = [x for x in style.__dict__ if x not in exclude] 313 _set_style_args(style, attribs, exact, prefix=prefix) 314 315 style.attribs = _get_style_attribs(style, prefix=prefix, exact=exact, exclude=exclude) 316 style.id = get_unique_id(style) 317 style.type = Types.STYLE 318 style.subtype = subtype 319 320 321@dataclass # used for creating patterns 322class PatternStyle: 323 """PatternStyle is used to set the pattern type, color, distance, angle, shift, line width, radius, and points. 324 325 Attributes: 326 pattern_type (PatternType): The type of the pattern. 327 color (Color): The color of the pattern. 328 distance (float): The distance between pattern elements. 329 angle (float): The angle of the pattern. 330 x_shift (float): The x-axis shift of the pattern. 331 y_shift (float): The y-axis shift of the pattern. 332 line_width (float): The line width of the pattern. 333 radius (float): The radius of the pattern elements. 334 points (int): The number of points in the pattern. 335 """ 336 337 pattern_type: PatternType = None # LINES, HATCH, DOTS, STARS 338 color: Color = None 339 distance: float = None 340 angle: float = None 341 x_shift: float = None 342 y_shift: float = None 343 line_width: float = None 344 radius: float = None # used for dots, stars 345 points: int = None # number of petals. Used for stars 346 347 def __post_init__(self): 348 """Initialize the PatternStyle object.""" 349 exact = ["stroke", "pattern_type"] 350 exclude = [] 351 _style_init( 352 self, 353 exact=exact, 354 exclude=exclude, 355 prefix="pattern", 356 subtype=Types.PATTERN_STYLE, 357 ) 358 self._exact = exact 359 self._exclude = exclude 360 361 def __str__(self): 362 """Return a string representation of the PatternStyle object.""" 363 return f"Pattern: {self.type}" 364 365 366# \usetikzlibrary{shadings} 367@dataclass 368class ShadeStyle: 369 """ShadeStyle uses TikZ shading library to create colors with gradients. 370 371 Attributes: 372 shade_type (ShadeType): The type of the shade. 373 axis_angle (float): The axis angle of the shade. 374 ball_color (Color): The color of the ball. 375 bottom_color (Color): The bottom color of the shade. 376 color_wheel (Color): The color wheel of the shade. 377 color_wheel_black (bool): Whether the color wheel includes black. 378 color_wheel_white (bool): Whether the color wheel includes white. 379 inner_color (Color): The inner color of the shade. 380 left_color (Color): The left color of the shade. 381 lower_left_color (Color): The lower left color of the shade. 382 lower_right_color (Color): The lower right color of the shade. 383 middle_color (Color): The middle color of the shade. 384 outer_color (Color): The outer color of the shade. 385 right_color (Color): The right color of the shade. 386 top_color (Color): The top color of the shade. 387 upper_left_color (Color): The upper left color of the shade. 388 upper_right_color (Color): The upper right color of the shade. 389 """ 390 391 shade_type: ShadeType = None 392 axis_angle: float = None 393 ball_color: Color = None 394 bottom_color: Color = None 395 color_wheel: Color = None 396 color_wheel_black: bool = None 397 color_wheel_white: bool = None 398 inner_color: Color = None 399 left_color: Color = None 400 lower_left_color: Color = None 401 lower_right_color: Color = None 402 middle_color: Color = None 403 outer_color: Color = None 404 right_color: Color = None 405 top_color: Color = None 406 upper_left_color: Color = None 407 upper_right_color: Color = None 408 409 def __post_init__(self): 410 """Initialize the ShadeStyle object.""" 411 exact = [ 412 "shade_type", 413 "axis_angle", 414 "color_wheel_black", 415 "color_wheel_white", 416 "top_color", 417 "bottom_color", 418 "left_color", 419 "right_color", 420 "middle_color", 421 "inner_color", 422 "outer_color", 423 "upper_left_color", 424 "upper_right_color", 425 "lower_left_color", 426 "lower_right_color", 427 "color_wheel", 428 ] 429 exact = ["shade_type"] 430 exclude = [] 431 _style_init( 432 self, 433 exact=exact, 434 exclude=exclude, 435 prefix="shade", 436 subtype=Types.SHADE_STYLE, 437 ) 438 self._exact = exact 439 self._exclude = exclude 440 441 442@dataclass 443class FillStyle: 444 """FillStyle is used to set the fill color, alpha, and pattern of a shape. 445 446 Attributes: 447 color (Color): The fill color. 448 alpha (float): The alpha value of the fill. 449 fill (bool): Whether the shape is filled. 450 back_style (BackStyle): The back style of the fill. 451 mode (FillMode): The fill mode. 452 pattern_style (PatternStyle): The pattern style of the fill. 453 shade_style (ShadeStyle): The shade style of the fill. 454 grid_style (GridStyle): The grid style of the fill. 455 """ 456 457 color: Color = None 458 alpha: float = None 459 fill: bool = None 460 back_style: BackStyle = None 461 mode: FillMode = None 462 pattern_style: PatternStyle = None 463 shade_style: ShadeStyle = None 464 grid_style: GridStyle = None 465 466 def __post_init__(self): 467 """Initialize the FillStyle object.""" 468 self.shade_style = ShadeStyle() 469 self.grid_style = GridStyle() 470 self.pattern_style = PatternStyle() 471 exact = ["fill", "back_style"] 472 exclude = ["pattern_style", "shade_style", "grid_style"] 473 _style_init( 474 self, exact, exclude, prefix="fill", subtype=Types.FILL_STYLE 475 ) 476 self._exact = exact 477 self._exclude = exclude 478 479 def __str__(self): 480 """Return a string representation of the FillStyle object.""" 481 return f"FillStyle: {self.id}" 482 483 def __repr__(self): 484 """Return a string representation of the FillStyle object.""" 485 return f"FillStyle: {self.id}" 486 487 def _get_attributes(self): 488 """Get the attributes of the FillStyle object.""" 489 attribs = [x for x in self.__dict__ if not x.startswith("_")] 490 res = [] 491 for attrib in attribs: 492 if attrib in self._exact: 493 res.append(attrib) 494 else: 495 res.append(f"fill_{attrib}") 496 497 498@dataclass 499class ShapeStyle: 500 """ShapeStyle is used to set the fill and line style of a shape. 501 502 Attributes: 503 line_style (LineStyle): The line style of the shape. 504 fill_style (FillStyle): The fill style of the shape. 505 alpha (float): The alpha value of the shape. 506 """ 507 508 line_style: LineStyle = None 509 fill_style: FillStyle = None 510 alpha: float = None 511 512 def __post_init__(self): 513 """Initialize the ShapeStyle object.""" 514 self.line_style = LineStyle() 515 self.fill_style = FillStyle() 516 self.marker_style = MarkerStyle() 517 self.alpha = defaults["alpha"] 518 exact = ["alpha"] 519 exclude = ["line_style", "fill_style"] 520 _style_init( 521 self, 522 exact=exact, 523 exclude=exclude, 524 prefix="", 525 subtype=Types.SHAPE_STYLE, 526 ) 527 self._exact = exact 528 self._exclude = exclude 529 530 def __str__(self): 531 """Return a string representation of the ShapeStyle object.""" 532 return f"ShapeStyle: {self.id}" 533 534 def __repr__(self): 535 """Return a string representation of the ShapeStyle object.""" 536 return f"ShapeStyle: {self.id}" 537 538 539@dataclass 540class FrameStyle: 541 """FrameStyle is used to set the frame shape, line style, fill style, and size of a shape. 542 543 Attributes: 544 shape (FrameShape): The shape of the frame. 545 line_style (LineStyle): The line style of the frame. 546 fill_style (FillStyle): The fill style of the frame. 547 inner_sep (float): The inner separation of the frame. 548 inner_xsep (float): The inner x-axis separation of the frame. 549 inner_ysep (float): The inner y-axis separation of the frame. 550 outer_sep (float): The outer separation of the frame. 551 min_width (float): The minimum width of the frame. 552 min_height (float): The minimum height of the frame. 553 min_size (float): The minimum size of the frame. 554 alpha (float): The alpha value of the frame. 555 """ 556 557 shape: FrameShape = None 558 line_style: LineStyle = None 559 fill_style: FillStyle = None 560 inner_sep: float = None 561 inner_xsep: float = None 562 inner_ysep: float = None 563 outer_sep: float = None 564 min_width: float = None 565 min_height: float = None 566 min_size: float = None 567 alpha: float = None 568 569 def __post_init__(self): 570 """Initialize the FrameStyle object.""" 571 self.line_style = LineStyle() 572 self.fill_style = FillStyle() 573 exact = [] 574 exclude = ["line_style", "fill_style"] 575 _style_init( 576 self, 577 exact=exact, 578 exclude=exclude, 579 prefix="frame", 580 subtype=Types.FRAME_STYLE, 581 ) 582 self._exact = exact 583 self._exclude = exclude 584 585 586@dataclass 587class TagStyle: 588 """TagStyle is used to set the font, color, and style of tag objects. 589 590 Attributes: 591 align (Align): The alignment of the tag. 592 alpha (float): The alpha value of the tag. 593 bold (bool): Whether the tag is bold. 594 italic (bool): Whether the tag is italic. 595 anchor (Anchor): The anchor of the tag. 596 blend_mode (BlendMode): The blend mode of the tag. 597 draw_frame (bool): Whether to draw a frame around the tag. 598 font_style (FontStyle): The font style of the tag. 599 frame_style (FrameStyle): The frame style of the tag. 600 text_width (float): The text width of the tag. 601 """ 602 603 align: Align = None 604 alpha: float = None 605 bold: bool = None 606 italic: bool = None 607 anchor: Anchor = None 608 blend_mode: BlendMode = None 609 draw_frame: bool = None 610 font_style: FontStyle = None 611 frame_style: FrameStyle = None 612 text_width: float = None 613 614 def __post_init__(self): 615 """Initialize the TagStyle object.""" 616 self.font_style = FontStyle() 617 self.frame_style = FrameStyle() 618 self.alpha = defaults["tag_alpha"] 619 self.bold = defaults["bold"] 620 self.italic = defaults["italic"] 621 self.align = defaults["tag_align"] 622 self.blend_mode = defaults["tag_blend_mode"] 623 self.text_width = defaults["text_width"] 624 exact = [ 625 "alpha", 626 "blend_mode", 627 "draw_frame", 628 "anchor", 629 "bold", 630 "italic", 631 "text_width" 632 ] 633 exclude = ["font_style", "frame_style"] 634 635 _style_init( 636 self, 637 exact=exact, 638 exclude=exclude, 639 prefix="tag", 640 subtype=Types.TAG_STYLE, 641 ) 642 self._exact = exact 643 self._exclude = exclude 644 645 def __str__(self): 646 """Return a string representation of the TagStyle object.""" 647 return f"TagStyle: {self.id}" 648 649 def __repr__(self): 650 """Return a string representation of the TagStyle object.""" 651 return f"TagStyle: {self.id}" 652 653 654# frame_style_map = {} 655 656frame_style_map = { 657 'alpha': ('frame_style', 'alpha'), 658 'back_style': ('frame_style.fill_style', 'back_style'), 659 'double_distance': ('frame_style.line_style', 'double_distance'), 660 'double_lines': ('frame_style.line_style', 'double_lines'), 661 'draw_fillets': ('frame_style.line_style', 'draw_fillets'), 662 'draw_markers': ('frame_style.line_style', 'draw_markers'), 663 'fill': ('frame_style.fill_style', 'fill'), 664 'fill_alpha': ('frame_style.fill_style', 'alpha'), 665 'fill_color': ('frame_style.fill_style', 'color'), 666 'fill_mode': ('frame_style.fill_style', 'mode'), 667 'fillet_radius': ('frame_style.line_style', 'fillet_radius'), 668 'inner_sep': ('frame_style', 'inner_sep'), 669 'line_alpha': ('frame_style.line_style', 'alpha'), 670 'line_cap': ('frame_style.line_style', 'cap'), 671 'line_color': ('frame_style.line_style', 'color'), 672 'line_dash_array': ('frame_style.line_style', 'dash_array'), 673 'line_dash_phase': ('frame_style.line_style', 'dash_phase'), 674 'line_join': ('frame_style.line_style', 'join'), 675 'line_miter_limit': ('frame_style.line_style', 'miter_limit'), 676 'line_width': ('frame_style.line_style', 'width'), 677 'markers_only': ('frame_style.line_style', 'markers_only'), 678 'min_height': ('frame_style', 'min_height'), 679 'min_size': ('frame_style', 'min_size'), 680 'min_width': ('frame_style', 'min_width'), 681 'outer_sep': ('frame_style', 'outer_sep'), 682 'shape': ('frame_style', 'shape'), 683 'smooth': ('frame_style.line_style', 'smooth'), 684 'stroke': ('frame_style.line_style', 'stroke'), 685} 686 687 688def _set_frame_style_alias_map(debug=False): 689 """Set the frame style alias map. 690 691 Args: 692 debug (bool, optional): Whether to enable debug mode. Defaults to False. 693 694 Returns: 695 dict: The frame style alias map. 696 """ 697 line_style = LineStyle() 698 fill_style = FillStyle() 699 700 styles = [line_style, fill_style] 701 paths = ["frame_style.line_style", "frame_style.fill_style"] 702 prefixes = ["line", "fill"] 703 704 _set_style_alias_map(frame_style_map, styles, paths, prefixes, debug=debug) 705 frame_style_map["shape"] = ("frame_style", "shape") 706 frame_style_map["inner_sep"] = ("frame_style", "inner_sep") 707 frame_style_map["outer_sep"] = ("frame_style", "outer_sep") 708 frame_style_map["min_width"] = ("frame_style", "min_width") 709 frame_style_map["min_height"] = ("frame_style", "min_height") 710 frame_style_map["min_size"] = ("frame_style", "min_size") 711 frame_style_map["alpha"] = ("frame_style", "alpha") 712 713 return frame_style_map 714 715 716# marker_style_map = {} 717 718marker_style_map = { 719 'back_style': ('marker_style.fill_style', 'back_style'), 720 'double_distance': ('marker_style.line_style', 'double_distance'), 721 'double_lines': ('marker_style.line_style', 'double_lines'), 722 'draw_fillets': ('marker_style.line_style', 'draw_fillets'), 723 'draw_markers': ('marker_style.line_style', 'draw_markers'), 724 'fill': ('marker_style.fill_style', 'fill'), 725 'fill_alpha': ('marker_style.fill_style', 'alpha'), 726 'fill_color': ('marker_style.fill_style', 'color'), 727 'fill_mode': ('marker_style.fill_style', 'mode'), 728 'fillet_radius': ('marker_style.line_style', 'fillet_radius'), 729 'line_alpha': ('marker_style.line_style', 'alpha'), 730 'line_cap': ('marker_style.line_style', 'cap'), 731 'line_color': ('marker_style.line_style', 'color'), 732 'line_dash_array': ('marker_style.line_style', 'dash_array'), 733 'line_dash_phase': ('marker_style.line_style', 'dash_phase'), 734 'line_join': ('marker_style.line_style', 'join'), 735 'line_miter_limit': ('marker_style.line_style', 'miter_limit'), 736 'line_width': ('marker_style.line_style', 'width'), 737 'marker_alpha': ('marker_style', 'alpha'), 738 'marker_radius': ('marker_style', 'radius'), 739 'marker_size': ('marker_style', 'size'), 740 'marker_type': ('marker_style', 'marker_type'), 741 'markers_only': ('marker_style.line_style', 'markers_only'), 742 'smooth': ('marker_style.line_style', 'smooth'), 743 'stroke': ('marker_style.line_style', 'stroke'), 744} 745 746def _set_marker_style_alias_map(debug=False): 747 """Set the marker style alias map. 748 749 Args: 750 debug (bool, optional): Whether to enable debug mode. Defaults to False. 751 752 Returns: 753 dict: The marker style alias map. 754 """ 755 line_style = LineStyle() 756 fill_style = FillStyle() 757 758 styles = [line_style, fill_style] 759 paths = ["marker_style.line_style", "marker_style.fill_style"] 760 prefixes = ["line", "fill"] 761 762 _set_style_alias_map(marker_style_map, styles, paths, prefixes, debug=debug) 763 764 marker_style_map["marker_type"] = ("marker_style", "marker_type") 765 marker_style_map["marker_alpha"] = ("marker_style", "alpha") 766 marker_style_map["marker_size"] = ("marker_style", "size") 767 marker_style_map["marker_radius"] = ("marker_style", "radius") 768 769 return marker_style_map 770 771 772# tag_style_map = {} 773tag_style_map = { 774 'align': ('style', 'align'), 775 'alpha': ('style', 'alpha'), 776 'back_color': ('style.frame_style.fill_style', 'color'), 777 'back_style': ('style.frame_style.fill_style', 'back_style'), 778 'blend_mode': ('style', 'blend_mode'), 779 'bold': ('style.font_style', 'bold'), 780 'double_distance': ('style.frame_style.line_style', 'double_distance'), 781 'double_lines': ('style.frame_style.line_style', 'double_lines'), 782 'draw_fillets': ('style.frame_style.line_style', 'draw_fillets'), 783 'draw_frame': ('style', 'draw_frame'), 784 'draw_markers': ('style.frame_style.line_style', 'draw_markers'), 785 'fill': ('style.frame_style.fill_style', 'fill'), 786 'fill_alpha': ('style.frame_style.fill_style', 'alpha'), 787 'fill_color': ('style.frame_style.fill_style', 'color'), 788 'fill_mode': ('style.frame_style.fill_style', 'mode'), 789 'fillet_radius': ('style.frame_style.line_style', 'fillet_radius'), 790 'font_alpha': ('style.font_style', 'alpha'), 791 'font_blend_mode': ('style.font_style', 'blend_mode'), 792 'font_color': ('style.font_style', 'color'), 793 'font_family': ('style.font_style', 'font_family'), 794 'font_size': ('style.font_style', 'size'), 795 'frame_alpha': ('style.frame_style', 'alpha'), 796 'frame_inner_sep': ('style.frame_style', 'inner_sep'), 797 'frame_inner_xsep': ('style.frame_style', 'inner_xsep'), 798 'frame_inner_ysep': ('style.frame_style', 'inner_ysep'), 799 'frame_min_height': ('style.frame_style', 'min_height'), 800 'frame_min_size': ('style.frame_style', 'min_size'), 801 'frame_min_width': ('style.frame_style', 'min_width'), 802 'frame_outer_sep': ('style.frame_style', 'outer_sep'), 803 'frame_shape': ('style.frame_style', 'shape'), 804 'grid_alpha': ('style.frame_style.fill_style.grid_style', 'alpha'), 805 'grid_back_color': ('style.frame_style.fill_style.grid_style', 'back_color'), 806 'grid_line_color': ('style.frame_style.fill_style.grid_style', 'line_color'), 807 'grid_line_width': ('style.frame_style.fill_style.grid_style', 'line_width'), 808 'italic': ('style.font_style', 'italic'), 809 'line_alpha': ('style.frame_style.line_style', 'alpha'), 810 'line_cap': ('style.frame_style.line_style', 'cap'), 811 'line_color': ('style.frame_style.line_style', 'color'), 812 'line_dash_array': ('style.frame_style.line_style', 'dash_array'), 813 'line_dash_phase': ('style.frame_style.line_style', 'dash_phase'), 814 'line_join': ('style.frame_style.line_style', 'join'), 815 'line_miter_limit': ('style.frame_style.line_style', 'miter_limit'), 816 'line_width': ('style.frame_style.line_style', 'width'), 817 'marker_color': ('style.frame_style.line_style.marker_style', 'color'), 818 'marker_radius': ('style.frame_style.line_style.marker_style', 'radius'), 819 'marker_size': ('style.frame_style.line_style.marker_style', 'size'), 820 'marker_type': ('style.frame_style.line_style.marker_style', 'marker_type'), 821 'markers_only': ('style.frame_style.line_style', 'markers_only'), 822 'old_style_nums': ('style.font_style', 'old_style_nums'), 823 'overline': ('style.font_style', 'overline'), 824 'pattern_angle': ('style.frame_style.fill_style.pattern_style', 'angle'), 825 'pattern_color': ('style.frame_style.fill_style.pattern_style', 'color'), 826 'pattern_distance': ('style.frame_style.fill_style.pattern_style', 'distance'), 827 'pattern_line_width': ('style.frame_style.fill_style.pattern_style', 'line_width'), 828 'pattern_points': ('style.frame_style.fill_style.pattern_style', 'points'), 829 'pattern_radius': ('style.frame_style.fill_style.pattern_style', 'radius'), 830 'pattern_type': ('style.frame_style.fill_style.pattern_style', 'pattern_type'), 831 'pattern_x_shift': ('style.frame_style.fill_style.pattern_style', 'x_shift'), 832 'pattern_y_shift': ('style.frame_style.fill_style.pattern_style', 'y_shift'), 833 'shade_axis_angle': ('style.frame_style.fill_style.shade_style', 'axis_angle'), 834 'shade_ball_color': ('style.frame_style.fill_style.shade_style', 'ball_color'), 835 'shade_bottom_color': ('style.frame_style.fill_style.shade_style', 'bottom_color'), 836 'shade_color_wheel': ('style.frame_style.fill_style.shade_style', 'color_wheel'), 837 'shade_color_wheel_black': ('style.frame_style.fill_style.shade_style', 'color_wheel_black'), 838 'shade_color_wheel_white': ('style.frame_style.fill_style.shade_style', 'color_wheel_white'), 839 'shade_inner_color': ('style.frame_style.fill_style.shade_style', 'inner_color'), 840 'shade_left_color': ('style.frame_style.fill_style.shade_style', 'left_color'), 841 'shade_lower_left_color': ('style.frame_style.fill_style.shade_style', 'lower_left_color'), 842 'shade_lower_right_color': ('style.frame_style.fill_style.shade_style', 'lower_right_color'), 843 'shade_middle_color': ('style.frame_style.fill_style.shade_style', 'middle_color'), 844 'shade_outer_color': ('style.frame_style.fill_style.shade_style', 'outer_color'), 845 'shade_right_color': ('style.frame_style.fill_style.shade_style', 'right_color'), 846 'shade_top_color': ('style.frame_style.fill_style.shade_style', 'top_color'), 847 'shade_type': ('style.frame_style.fill_style.shade_style', 'shade_type'), 848 'shade_upper_left_color': ('style.frame_style.fill_style.shade_style', 'upper_left_color'), 849 'shade_upper_right_color': ('style.frame_style.fill_style.shade_style', 'upper_right_color'), 850 'small_caps': ('style.font_style', 'small_caps'), 851 'smooth': ('style.frame_style.line_style', 'smooth'), 852 'strike_through': ('style.font_style', 'strike_through'), 853 'stroke': ('style.frame_style.line_style', 'stroke'), 854 'underline': ('style.font_style', 'underline'), 855} 856 857 858def _set_tag_style_alias_map(debug=False): 859 """Set the tag style alias map. 860 861 Args: 862 debug (bool, optional): Whether to enable debug mode. Defaults to False. 863 864 Returns: 865 dict: The tag style alias map. 866 """ 867 font_style = FontStyle() 868 frame_style = FrameStyle() 869 fill_style = FillStyle() 870 line_style = LineStyle() 871 pattern_style = PatternStyle() 872 shade_style = ShadeStyle() 873 grid_style = GridStyle() 874 marker_style = MarkerStyle() 875 876 styles = [ 877 font_style, 878 line_style, 879 fill_style, 880 marker_style, 881 frame_style, 882 pattern_style, 883 shade_style, 884 grid_style, 885 ] 886 paths = [ 887 "style.font_style", 888 "style.frame_style.line_style", 889 "style.frame_style.fill_style", 890 "style.frame_style.line_style.marker_style", 891 "style.frame_style", 892 "style.frame_style.fill_style.pattern_style", 893 "style.frame_style.fill_style.shade_style", 894 "style.frame_style.fill_style.grid_style", 895 ] 896 prefixes = ["font", "line", "fill", "marker", "frame", "pattern", "shade", "grid"] 897 898 _set_style_alias_map(tag_style_map, styles, paths, prefixes, debug=debug) 899 tag_style_map["alpha"] = ("style", "alpha") 900 tag_style_map["align"] = ("style", "align") 901 tag_style_map["blend_mode"] = ("style", "blend_mode") 902 tag_style_map["draw_frame"] = ("style", "draw_frame") 903 tag_style_map["back_color"] = ("style.frame_style.fill_style", "color") 904 tag_style_map["align"] = ("style", "align") 905 return tag_style_map 906 907 908# fill_style_map = {} 909 910fill_style_map = { 911 'alpha': ('fill_style', 'alpha'), 912 'color': ('fill_style', 'color'), 913 'grid_alpha': ('fill_style.grid_style', 'alpha'), 914 'grid_back_color': ('fill_style.grid_style', 'back_color'), 915 'grid_line_color': ('fill_style.grid_style', 'line_color'), 916 'grid_line_width': ('fill_style.grid_style', 'line_width'), 917 'mode': ('fill_style', 'mode'), 918 'pattern_angle': ('fill_style.pattern_style', 'angle'), 919 'pattern_color': ('fill_style.pattern_style', 'color'), 920 'pattern_distance': ('fill_style.pattern_style', 'distance'), 921 'pattern_line_width': ('fill_style.pattern_style', 'line_width'), 922 'pattern_points': ('fill_style.pattern_style', 'points'), 923 'pattern_radius': ('fill_style.pattern_style', 'radius'), 924 'pattern_type': ('fill_style.pattern_style', 'pattern_type'), 925 'pattern_x_shift': ('fill_style.pattern_style', 'x_shift'), 926 'pattern_y_shift': ('fill_style.pattern_style', 'y_shift'), 927 'shade_axis_angle': ('fill_style.shade_style', 'axis_angle'), 928 'shade_ball_color': ('fill_style.shade_style', 'ball_color'), 929 'shade_bottom_color': ('fill_style.shade_style', 'bottom_color'), 930 'shade_color_wheel': ('fill_style.shade_style', 'color_wheel'), 931 'shade_color_wheel_black': ('fill_style.shade_style', 'color_wheel_black'), 932 'shade_color_wheel_white': ('fill_style.shade_style', 'color_wheel_white'), 933 'shade_inner_color': ('fill_style.shade_style', 'inner_color'), 934 'shade_left_color': ('fill_style.shade_style', 'left_color'), 935 'shade_lower_left_color': ('fill_style.shade_style', 'lower_left_color'), 936 'shade_lower_right_color': ('fill_style.shade_style', 'lower_right_color'), 937 'shade_middle_color': ('fill_style.shade_style', 'middle_color'), 938 'shade_outer_color': ('fill_style.shade_style', 'outer_color'), 939 'shade_right_color': ('fill_style.shade_style', 'right_color'), 940 'shade_top_color': ('fill_style.shade_style', 'top_color'), 941 'shade_type': ('fill_style.shade_style', 'shade_type'), 942 'shade_upper_left_color': ('fill_style.shade_style', 'upper_left_color'), 943 'shade_upper_right_color': ('fill_style.shade_style', 'upper_right_color'), 944} 945 946def _set_fill_style_alias_map(debug=False): 947 """Set the fill style alias map. 948 949 Args: 950 debug (bool, optional): Whether to enable debug mode. Defaults to False. 951 952 Returns: 953 dict: The fill style alias map. 954 """ 955 pattern_style = PatternStyle() 956 shade_style = ShadeStyle() 957 grid_style = GridStyle() 958 959 styles = [pattern_style, shade_style, grid_style] 960 paths = [ 961 "fill_style.pattern_style", 962 "fill_style.shade_style", 963 "fill_style.grid_style", 964 ] 965 prefixes = ["pattern", "shade", "grid"] 966 967 _set_style_alias_map(fill_style_map, styles, paths, prefixes, debug=debug) 968 fill_style_map["alpha"] = ("fill_style", "alpha") 969 fill_style_map["color"] = ("fill_style", "color") 970 fill_style_map["mode"] = ("fill_style", "mode") 971 972 return fill_style_map 973 974 975# pattern_style_map = {} 976 977pattern_style_map = { 978'alpha': ('pattern_style', 'alpha'), 979'pattern_angle': ('pattern_style', 'angle'), 980'pattern_color': ('pattern_style', 'color'), 981'pattern_distance': ('pattern_style', 'distance'), 982'pattern_line_width': ('pattern_style', 'line_width'), 983'pattern_points': ('pattern_style', 'points'), 984'pattern_radius': ('pattern_style', 'radius'), 985'pattern_type': ('pattern_style', 'pattern_type'), 986'pattern_x_shift': ('pattern_style', 'x_shift'), 987'pattern_y_shift': ('pattern_style', 'y_shift'), 988} 989 990def _set_pattern_style_alias_map(debug=False): 991 """Set the pattern style alias map. 992 993 Args: 994 debug (bool, optional): Whether to enable debug mode. Defaults to False. 995 996 Returns: 997 dict: The pattern style alias map. 998 """ 999 pattern_style = PatternStyle() 1000 1001 styles = [pattern_style] 1002 paths = ["pattern_style"] 1003 prefixes = ["pattern"] 1004 1005 _set_style_alias_map(pattern_style_map, styles, paths, prefixes, debug=debug) 1006 pattern_style_map["alpha"] = ("pattern_style", "alpha") 1007 1008 return pattern_style_map 1009 1010 1011# line_style_map = {} 1012line_style_map = { 1013 'double_distance': ('line_style', 'double_distance'), 1014 'double_lines': ('line_style', 'double_lines'), 1015 'draw_fillets': ('line_style', 'draw_fillets'), 1016 'draw_markers': ('line_style', 'draw_markers'), 1017 'fillet_radius': ('line_style', 'fillet_radius'), 1018 'line_alpha': ('line_style', 'alpha'), 1019 'line_cap': ('line_style', 'cap'), 1020 'line_color': ('line_style', 'color'), 1021 'line_dash_array': ('line_style', 'dash_array'), 1022 'line_dash_phase': ('line_style', 'dash_phase'), 1023 'line_join': ('line_style', 'join'), 1024 'line_miter_limit': ('line_style', 'miter_limit'), 1025 'line_width': ('line_style', 'width'), 1026 'marker_color': ('line_style.marker_style', 'color'), 1027 'marker_radius': ('line_style.marker_style', 'radius'), 1028 'marker_size': ('line_style.marker_style', 'size'), 1029 'marker_type': ('line_style.marker_style', 'marker_type'), 1030 'markers_only': ('line_style', 'markers_only'), 1031 'smooth': ('line_style', 'smooth'), 1032 'stroke': ('line_style', 'stroke'), 1033} 1034 1035 1036def _set_line_style_alias_map(debug=False): 1037 """Set the line style alias map. 1038 1039 Args: 1040 debug (bool, optional): Whether to enable debug mode. Defaults to False. 1041 1042 Returns: 1043 dict: The line style alias map. 1044 """ 1045 line_style = LineStyle() 1046 marker_style = MarkerStyle() 1047 1048 styles = [line_style, marker_style] 1049 paths = ["line_style", "line_style.marker_style"] 1050 prefixes = ["line", "marker"] 1051 1052 _set_style_alias_map(line_style_map, styles, paths, prefixes, debug=debug) 1053 1054 return line_style_map 1055 1056 1057shape_style_map_ = {} # if any of the styles are changed, the alias-map must be updated!!! 1058 1059shape_style_map = { 1060 'alpha': ('style', 'alpha'), 1061 'back_style': ('style.fill_style', 'back_style'), 1062 'double_distance': ('style.line_style', 'double_distance'), 1063 'double_lines': ('style.line_style', 'double_lines'), 1064 'draw_fillets': ('style.line_style', 'draw_fillets'), 1065 'draw_markers': ('style.line_style', 'draw_markers'), 1066 'fill': ('style.fill_style', 'fill'), 1067 'fill_alpha': ('style.fill_style', 'alpha'), 1068 'fill_color': ('style.fill_style', 'color'), 1069 'fill_mode': ('style.fill_style', 'mode'), 1070 'fillet_radius': ('style.line_style', 'fillet_radius'), 1071 'grid_alpha': ('style.fill_style.grid_style', 'alpha'), 1072 'grid_back_color': ('style.fill_style.grid_style', 'back_color'), 1073 'grid_line_color': ('style.fill_style.grid_style', 'line_color'), 1074 'grid_line_width': ('style.fill_style.grid_style', 'line_width'), 1075 'line_alpha': ('style.line_style', 'alpha'), 1076 'line_cap': ('style.line_style', 'cap'), 1077 'line_color': ('style.line_style', 'color'), 1078 'line_dash_array': ('style.line_style', 'dash_array'), 1079 'line_dash_phase': ('style.line_style', 'dash_phase'), 1080 'line_join': ('style.line_style', 'join'), 1081 'line_miter_limit': ('style.line_style', 'miter_limit'), 1082 'line_width': ('style.line_style', 'width'), 1083 'marker_color': ('style.line_style.marker_style', 'color'), 1084 'marker_radius': ('style.line_style.marker_style', 'radius'), 1085 'marker_size': ('style.line_style.marker_style', 'size'), 1086 'marker_type': ('style.line_style.marker_style', 'marker_type'), 1087 'markers_only': ('style.line_style', 'markers_only'), 1088 'pattern_angle': ('style.fill_style.pattern_style', 'angle'), 1089 'pattern_color': ('style.fill_style.pattern_style', 'color'), 1090 'pattern_distance': ('style.fill_style.pattern_style', 'distance'), 1091 'pattern_line_width': ('style.fill_style.pattern_style', 'line_width'), 1092 'pattern_points': ('style.fill_style.pattern_style', 'points'), 1093 'pattern_radius': ('style.fill_style.pattern_style', 'radius'), 1094 'pattern_type': ('style.fill_style.pattern_style', 'pattern_type'), 1095 'pattern_x_shift': ('style.fill_style.pattern_style', 'x_shift'), 1096 'pattern_y_shift': ('style.fill_style.pattern_style', 'y_shift'), 1097 'shade_axis_angle': ('style.fill_style.shade_style', 'axis_angle'), 1098 'shade_ball_color': ('style.fill_style.shade_style', 'ball_color'), 1099 'shade_bottom_color': ('style.fill_style.shade_style', 'bottom_color'), 1100 'shade_color_wheel': ('style.fill_style.shade_style', 'color_wheel'), 1101 'shade_color_wheel_black': ('style.fill_style.shade_style', 'color_wheel_black'), 1102 'shade_color_wheel_white': ('style.fill_style.shade_style', 'color_wheel_white'), 1103 'shade_inner_color': ('style.fill_style.shade_style', 'inner_color'), 1104 'shade_left_color': ('style.fill_style.shade_style', 'left_color'), 1105 'shade_lower_left_color': ('style.fill_style.shade_style', 'lower_left_color'), 1106 'shade_lower_right_color': ('style.fill_style.shade_style', 'lower_right_color'), 1107 'shade_middle_color': ('style.fill_style.shade_style', 'middle_color'), 1108 'shade_outer_color': ('style.fill_style.shade_style', 'outer_color'), 1109 'shade_right_color': ('style.fill_style.shade_style', 'right_color'), 1110 'shade_top_color': ('style.fill_style.shade_style', 'top_color'), 1111 'shade_type': ('style.fill_style.shade_style', 'shade_type'), 1112 'shade_upper_left_color': ('style.fill_style.shade_style', 'upper_left_color'), 1113 'shade_upper_right_color': ('style.fill_style.shade_style', 'upper_right_color'), 1114 'smooth': ('style.line_style', 'smooth'), 1115 'stroke': ('style.line_style', 'stroke')} 1116 1117 1118def _set_shape_style_alias_map(debug=False): 1119 """Set the shape style alias map. 1120 1121 Args: 1122 debug (bool, optional): Whether to enable debug mode. Defaults to False. 1123 1124 Returns: 1125 dict: The shape style alias map. 1126 """ 1127 line_style = LineStyle() 1128 fill_style = FillStyle() 1129 marker_style = MarkerStyle() 1130 pattern_style = PatternStyle() 1131 shade_style = ShadeStyle() 1132 grid_style = GridStyle() 1133 1134 styles = [ 1135 line_style, 1136 fill_style, 1137 marker_style, 1138 pattern_style, 1139 shade_style, 1140 grid_style, 1141 ] 1142 paths = [ 1143 "style.line_style", 1144 "style.fill_style", 1145 "style.line_style.marker_style", 1146 "style.fill_style.pattern_style", 1147 "style.fill_style.shade_style", 1148 "style.fill_style.grid_style", 1149 ] 1150 prefixes = ["line", "fill", "marker", "pattern", "shade", "grid"] 1151 1152 _set_style_alias_map(shape_style_map, styles, paths, prefixes, debug=debug) 1153 shape_style_map["alpha"] = ("style", "alpha") 1154 return shape_style_map 1155 1156 1157def _set_style_alias_map(map_dict, styles, paths, prefixes, debug=False): 1158 """Set the style alias map. 1159 1160 Args: 1161 map_dict (dict): The dictionary to store the alias map. 1162 styles (list): List of style objects. 1163 paths (list): List of paths to the style objects. 1164 prefixes (list): List of prefixes for the style attributes. 1165 debug (bool, optional): Whether to enable debug mode. Defaults to False. 1166 1167 Returns: 1168 dict: The style alias map. 1169 """ 1170 for i, style in enumerate(styles): 1171 style_attribs = style.attribs 1172 exact = style._exact 1173 exclude = style._exclude 1174 style_path = paths[i] 1175 prefix = prefixes[i] 1176 1177 for alias in style_attribs: 1178 if alias in exact or alias in exclude: 1179 attrib = alias 1180 else: 1181 attrib = alias.replace(f"{prefix}_", "") 1182 if debug: 1183 if alias in map_dict: 1184 print(f"Duplicate style attribute: {alias}") 1185 print(f"{style_path}.{attrib}", alias) 1186 map_dict[alias] = (style_path, attrib) 1187 1188 return map_dict 1189 1190 1191# shape_args = [] 1192 1193shape_args = [ 1194 'alpha', 1195 'back_style', 1196 'dist_tol', 1197 'double_distance', 1198 'double_lines', 1199 'draw_fillets', 1200 'draw_markers', 1201 'fill', 1202 'fill_alpha', 1203 'fill_color', 1204 'fill_mode', 1205 'fillet_radius', 1206 'grid_alpha', 1207 'grid_back_color', 1208 'grid_line_color', 1209 'grid_line_width', 1210 'line_alpha', 1211 'line_cap', 1212 'line_color', 1213 'line_dash_array', 1214 'line_dash_phase', 1215 'line_join', 1216 'line_miter_limit', 1217 'line_width', 1218 'marker_color', 1219 'marker_radius', 1220 'marker_size', 1221 'marker_type', 1222 'markers_only', 1223 'pattern_angle', 1224 'pattern_color', 1225 'pattern_distance', 1226 'pattern_line_width', 1227 'pattern_points', 1228 'pattern_radius', 1229 'pattern_type', 1230 'pattern_x_shift', 1231 'pattern_y_shift', 1232 'points', 1233 'shade_axis_angle', 1234 'shade_ball_color', 1235 'shade_bottom_color', 1236 'shade_color_wheel', 1237 'shade_color_wheel_black', 1238 'shade_color_wheel_white', 1239 'shade_inner_color', 1240 'shade_left_color', 1241 'shade_lower_left_color', 1242 'shade_lower_right_color', 1243 'shade_middle_color', 1244 'shade_outer_color', 1245 'shade_right_color', 1246 'shade_top_color', 1247 'shade_type', 1248 'shade_upper_left_color', 1249 'shade_upper_right_color', 1250 'smooth', 1251 'stroke', 1252 'subtype', 1253 'xform_matrix', 1254] 1255 1256 1257def _set_shape_args(debug=False): 1258 shape_args.extend(list(shape_style_map.keys())) 1259 shape_args.extend(["subtype", "xform_matrix", "points", "dist_tol"]) 1260 1261# These are applicable to Canvas and Batch objects. They are set in \begin{scope}[...]. 1262group_args = [ 1263 "blend_mode", 1264 "clip", 1265 "mask", 1266 "even_odd_rule", 1267 "transparency_group", 1268 "blend_group", 1269 "alpha", 1270 "line_alpha", 1271 "fill_alpha", 1272 "text_alpha", 1273] 1274 1275# batch_args = [] 1276 1277batch_args = [ 1278'alpha', 1279'back_style', 1280'blend_group', 1281'blend_mode', 1282'clip', 1283'dist_tol', 1284'double_distance', 1285'double_lines', 1286'draw_fillets', 1287'draw_markers', 1288'even_odd_rule', 1289'fill', 1290'fill_alpha', 1291'fill_color', 1292'fill_mode', 1293'fillet_radius', 1294'grid_alpha', 1295'grid_back_color', 1296'grid_line_color', 1297'grid_line_width', 1298'line_alpha', 1299'line_cap', 1300'line_color', 1301'line_dash_array', 1302'line_dash_phase', 1303'line_join', 1304'line_miter_limit', 1305'line_width', 1306'marker_color', 1307'marker_radius', 1308'marker_size', 1309'marker_type', 1310'markers_only', 1311'mask', 1312'modifiers', 1313'pattern_angle', 1314'pattern_color', 1315'pattern_distance', 1316'pattern_line_width', 1317'pattern_points', 1318'pattern_radius', 1319'pattern_type', 1320'pattern_x_shift', 1321'pattern_y_shift', 1322'shade_axis_angle', 1323'shade_ball_color', 1324'shade_bottom_color', 1325'shade_color_wheel', 1326'shade_color_wheel_black', 1327'shade_color_wheel_white', 1328'shade_inner_color', 1329'shade_left_color', 1330'shade_lower_left_color', 1331'shade_lower_right_color', 1332'shade_middle_color', 1333'shade_outer_color', 1334'shade_right_color', 1335'shade_top_color', 1336'shade_type', 1337'shade_upper_left_color', 1338'shade_upper_right_color', 1339'smooth', 1340'stroke', 1341'subtype', 1342'text_alpha', 1343'transparency_group', 1344] 1345 1346 1347def _set_batch_args(debug=False): 1348 batch_args.extend(list(shape_style_map.keys())) 1349 batch_args.extend(["subtype", "dist_tol", "modifiers", "dist_tol"]) 1350 batch_args.extend(group_args) 1351 print() 1352 1353canvas_args = ["size", "back_color", "border"] 1354canvas_args.extend(group_args) 1355 1356shape_aliases_dict = {} 1357 1358 1359def _set_shape_aliases_dict(shape): 1360 """Set the shape aliases dictionary. 1361 1362 Args: 1363 shape: The shape object to set aliases for. 1364 """ 1365 for alias, path_attrib in shape_style_map.items(): 1366 style_path, attrib = path_attrib 1367 obj = shape 1368 for attrib_name in style_path.split("."): 1369 obj = obj.__dict__[attrib_name] 1370 1371 if obj is not shape: 1372 shape_aliases_dict[alias] = (obj, attrib) 1373 self.__dict__["_aliasses"] = _aliasses 1374 1375 1376# From: https://tikz.dev/library-patterns#pgf.patterns 1377 1378# LINES pattern example 1379# \usetikzlibrary {patterns,patterns.meta} 1380# \begin{tikzpicture} 1381# \draw[pattern={horizontal lines},pattern color=orange] 1382# (0,0) rectangle +(1,1); 1383# \draw[pattern={Lines[yshift=.5pt]},pattern color=blue] 1384# (0,0) rectangle +(1,1); 1385 1386# \draw[pattern={vertical lines},pattern color=orange] 1387# (1,0) rectangle +(1,1); 1388# \draw[pattern={Lines[angle=90,yshift=-.5pt]},pattern color=blue] 1389# (1,0) rectangle +(1,1); 1390 1391# \draw[pattern={north east lines},pattern color=orange] 1392# (0,1) rectangle +(1,1); 1393# \draw[pattern={Lines[angle=45,distance={3pt/sqrt(2)}]},pattern color=blue] 1394# (0,1) rectangle +(1,1); 1395 1396# \draw[pattern={north west lines},pattern color=orange] 1397# (1,1) rectangle +(1,1); 1398# \draw[pattern={Lines[angle=-45,distance={3pt/sqrt(2)}]},pattern color=blue] 1399# (1,1) rectangle +(1,1); 1400# \end{tikzpicture} 1401 1402# HATCH pattern example 1403# \usetikzlibrary {patterns,patterns.meta} 1404# \begin{tikzpicture} 1405# \draw[pattern={grid},pattern color=orange] 1406# (0,0) rectangle +(1,1); 1407# \draw[pattern={Hatch},pattern color=blue] 1408# (0,0) rectangle +(1,1); 1409 1410# \draw[pattern={crosshatch},pattern color=orange] 1411# (1,0) rectangle +(1,1); 1412# \draw[pattern={Hatch[angle=45,distance={3pt/sqrt(2)},xshift=.1pt]}, 1413# pattern color=blue] (1,0) rectangle +(1,1); 1414# \end{tikzpicture} 1415 1416# DOTS pattern example 1417# \usetikzlibrary {patterns,patterns.meta} 1418# \begin{tikzpicture} 1419# \draw[pattern={dots},pattern color=orange] 1420# (0,0) rectangle +(1,1); 1421# \draw[pattern={Dots},pattern color=blue] 1422# (0,0) rectangle +(1,1); 1423 1424# \draw[pattern={crosshatch dots},pattern color=orange] 1425# (1,0) rectangle +(1,1); 1426# \draw[pattern={Dots[angle=45,distance={3pt/sqrt(2)}]}, 1427# pattern color=blue] (1,0) rectangle +(1,1); 1428# \end{tikzpicture} 1429 1430# STARS pattern example 1431# \usetikzlibrary {patterns,patterns.meta} 1432# \begin{tikzpicture} 1433# \draw[pattern={fivepointed stars},pattern color=orange] 1434# (0,0) rectangle +(1,1); 1435# \draw[pattern={Stars},pattern color=blue] 1436# (0,0) rectangle +(1,1); 1437 1438# \draw[pattern={sixpointed stars},pattern color=orange] 1439# (1,0) rectangle +(1,1); 1440# \draw[pattern={Stars[points=6]},pattern color=blue] 1441# (1,0) rectangle +(1,1); 1442# \end{tikzpicture} 1443 1444# Declare pattern custom pattern 1445# \tikzdeclarepattern{⟨config⟩} 1446 1447# A pattern declared with \pgfdeclarepattern can only execute pgf code. This 1448# command extends the functionality to also allow TikZ code. All the same keys 1449# of \pgfdeclarepattern are valid, but some of them have been overloaded to give 1450# a more natural TikZ syntax. 1451 1452# /tikz/patterns/bottom left=⟨point⟩ 1453# (no default) 1454 1455# Instead of a pgf name point, this key takes a TikZ point, e.g. (-.1,-.1). 1456 1457# /tikz/patterns/top right=⟨point⟩ 1458# (no default) 1459 1460# Instead of a pgf name point, this key takes a TikZ point, e.g. (3.1,3.1). 1461 1462# /tikz/patterns/tile size=⟨point⟩ 1463# (no default) 1464 1465# Instead of a pgf name point, this key takes a TikZ point, e.g. (3,3). 1466 1467# /tikz/patterns/tile transformation=⟨transformation⟩ 1468# (no default) 1469 1470# Instead of a pgf transformation, this key takes a list of keys and value and 1471# extracts the resulting transformation from them, e.g. rotate=30. 1472 1473# In addition to the overloaded keys, some new keys have been added. 1474 1475# /tikz/patterns/bounding box=⟨point⟩ and ⟨point⟩ 1476# (no default) 1477 1478# This is a shorthand to set the bounding box. It will assign the first point to 1479# bottom left and the second point to top right. 1480 1481# /tikz/patterns/infer tile bounding box=⟨dimension⟩ 1482# (default 0pt) 1483 1484# Instead of specifying the bounding box by hand, you can ask TikZ to infer the 1485# size of the bounding box for you. The ⟨dimension⟩ parameter is padding that is 1486# added around the bounding box. 1487 1488# Declare pattern example 1 1489# \usetikzlibrary {patterns.meta} 1490# \tikzdeclarepattern{ 1491# name=flower, 1492# type=colored, 1493# bottom left={(-.1pt,-.1pt)}, 1494# top right={(10.1pt,10.1pt)}, 1495# tile size={(10pt,10pt)}, 1496# code={ 1497# \tikzset{x=1pt,y=1pt} 1498# \path [draw=green] (5,2.5) -- (5, 7.5); 1499# \foreach \i in {0,60,...,300} 1500# \path [fill=pink, shift={(5,7.5)}, rotate=-\i] 1501# (0,0) .. controls ++(120:4) and ++(60:4) .. (0,0); 1502# \path [fill=red] (5,7.5) circle [radius=1]; 1503# \foreach \i in {-45,45} 1504# \path [fill=green, shift={(5,2.5)}, rotate=-\i] 1505# (0,0) .. controls ++(120:4) and ++(60:4) .. (0,0); 1506# } 1507# } 1508 1509# \tikz\draw [pattern=flower] circle [radius=1]; 1510 1511 1512# Declare pattern example 2 1513# \usetikzlibrary {patterns.meta} 1514# \tikzdeclarepattern{ 1515# name=mystars, 1516# type=uncolored, 1517# bounding box={(-5pt,-5pt) and (5pt,5pt)}, 1518# tile size={(\tikztilesize,\tikztilesize)}, 1519# parameters={\tikzstarpoints,\tikzstarradius,\tikzstarrotate,\tikztilesize}, 1520# tile transformation={rotate=\tikzstarrotate}, 1521# defaults={ 1522# points/.store in=\tikzstarpoints,points=5, 1523# radius/.store in=\tikzstarradius,radius=3pt, 1524# rotate/.store in=\tikzstarrotate,rotate=0, 1525# tile size/.store in=\tikztilesize,tile size=10pt, 1526# }, 1527# code={ 1528# \pgfmathparse{180/\tikzstarpoints}\let\a=\pgfmathresult 1529# \fill (90:\tikzstarradius) \foreach \i in {1,...,\tikzstarpoints}{ 1530# -- (90+2*\i*\a-\a:\tikzstarradius/2) -- (90+2*\i*\a:\tikzstarradius) 1531# } -- cycle; 1532# } 1533# } 1534 1535# \begin{tikzpicture} 1536# \draw[pattern=mystars,pattern color=blue] (0,0) rectangle +(2,2); 1537# \draw[pattern={mystars[points=7,tile size=15pt]}] (2,0) rectangle +(2,2); 1538# \draw[pattern={mystars[rotate=45]},pattern color=red] (0,2) rectangle +(2,2); 1539# \draw[pattern={mystars[rotate=30,points=4,radius=5pt]}] (2,2) rectangle +(2,2); 1540# \end{tikzpicture} 1541 1542# Declare pattern example 3 1543# \usetikzlibrary {patterns.meta} 1544# \tikzdeclarepattern{ 1545# name=mylines, 1546# parameters={ 1547# \pgfkeysvalueof{/pgf/pattern keys/size}, 1548# \pgfkeysvalueof{/pgf/pattern keys/angle}, 1549# \pgfkeysvalueof{/pgf/pattern keys/line width}, 1550# }, 1551# bounding box={ 1552# (0,-0.5*\pgfkeysvalueof{/pgf/pattern keys/line width}) and 1553# (\pgfkeysvalueof{/pgf/pattern keys/size}, 1554# 0.5*\pgfkeysvalueof{/pgf/pattern keys/line width})}, 1555# tile size={(\pgfkeysvalueof{/pgf/pattern keys/size}, 1556# \pgfkeysvalueof{/pgf/pattern keys/size})}, 1557# tile transformation={rotate=\pgfkeysvalueof{/pgf/pattern keys/angle}}, 1558# defaults={ 1559# size/.initial=5pt, 1560# angle/.initial=45, 1561# line width/.initial=.4pt, 1562# }, 1563# code={ 1564# \draw [line width=\pgfkeysvalueof{/pgf/pattern keys/line width}] 1565# (0,0) -- (\pgfkeysvalueof{/pgf/pattern keys/size},0); 1566# }, 1567# } 1568 1569# \begin{tikzpicture} 1570# \draw[pattern={mylines[size=10pt,line width=.8pt,angle=10]}, 1571# pattern color=red] (0,0) rectangle ++(2,2); 1572# \draw[pattern={mylines[size= 5pt,line width=.8pt,angle=40]}, 1573# pattern color=blue] (2,0) rectangle ++(2,2); 1574# \draw[pattern={mylines[size=10pt,line width=.4pt,angle=90]}, 1575# pattern color=green] (0,2) rectangle ++(2,2); 1576# \draw[pattern={mylines[size= 2pt,line width= 1pt,angle=70]}, 1577# pattern color=orange] (2,2) rectangle ++(2,2); 1578# \end{tikzpicture} 1579 1580 1581# style.line_style.color line_color 1582# style.line_style.alpha line_alpha 1583# style.line_style.width line_width 1584# style.line_style.dash_array line_dash_array 1585# style.line_style.dash_phase line_dash_phase 1586# style.line_style.cap line_cap 1587# style.line_style.join line_join 1588# style.line_style.miter_limit line_miter_limit 1589# style.line_style.fillet_radius fillet_radius 1590# style.line_style.smooth smooth 1591# style.line_style.stroke stroke 1592# style.line_style.draw_markers draw_markers 1593# style.line_style.draw_fillets draw_fillets 1594# style.line_style.markers_only markers_only 1595# style.line_style.double double 1596# style.line_style.double_distance double_distance 1597# style.fill_style.color fill_color 1598# style.fill_style.alpha fill_alpha 1599# style.fill_style.fill fill 1600# style.fill_style.back_style back_style 1601# style.fill_style.mode fill_mode 1602# style.line_style.marker_style.marker_type marker_type 1603# style.line_style.marker_style.size marker_size 1604# style.line_style.marker_style.color marker_color 1605# style.fill_style.pattern_style.pattern_type pattern_type 1606# style.fill_style.pattern_style.color pattern_color 1607# style.fill_style.pattern_style.distance pattern_distance 1608# style.fill_style.pattern_style.angle pattern_angle 1609# style.fill_style.pattern_style.x_shift pattern_x_shift 1610# style.fill_style.pattern_style.y_shift pattern_y_shift 1611# style.fill_style.pattern_style.line_width pattern_line_width 1612# style.fill_style.pattern_style.radius pattern_radius 1613# style.fill_style.pattern_style.points pattern_points 1614# style.fill_style.shade_style.top_color shade_top_color 1615# style.fill_style.shade_style.bottom_color shade_bottom_color 1616# style.fill_style.shade_style.left_color shade_left_color 1617# style.fill_style.shade_style.right_color shade_right_color 1618# style.fill_style.shade_style.middle_color shade_middle_color 1619# style.fill_style.shade_style.inner_color shade_inner_color 1620# style.fill_style.shade_style.outer_color shade_outer_color 1621# style.fill_style.shade_style.upper_left_color shade_upper_left_color 1622# style.fill_style.shade_style.upper_right_color shade_upper_right_color 1623# style.fill_style.shade_style.lower_left_color shade_lower_left_color 1624# style.fill_style.shade_style.lower_right_color shade_lower_right_color 1625# style.fill_style.shade_style.color_wheel shade_color_wheel 1626# style.fill_style.shade_style.color_wheel_black shade_color_wheel_black 1627# style.fill_style.shade_style.color_wheel_white shade_color_wheel_white 1628# style.fill_style.grid_style.line_color grid_line_color 1629# style.fill_style.grid_style.line_width grid_line_width 1630# style.fill_style.grid_style.alpha grid_alpha 1631# style.fill_style.grid_style.back_color grid_back_color 1632 1633 1634# style.font_style.font_family font_family 1635# style.font_style.color font_color 1636# style.font_style.family font_family 1637# style.font_style.size font_size 1638# style.font_style.bold bold 1639# style.font_style.italic italic 1640# style.font_style.small_caps small_caps 1641# style.font_style.old_style_nums old_style_nums 1642# style.font_style.overline overline 1643# style.font_style.strike_through strike_through 1644# style.font_style.underline underline 1645# style.font_style.alpha font_alpha 1646# style.frame_style.shape frame_shape 1647# style.frame_style.line_style line_style 1648# style.frame_style.fill_style fill_style 1649# style.frame_style.inner_sep frame_inner_sep 1650# style.frame_style.outer_sep frame_outer_sep 1651# style.frame_style.min_width frame_min_width 1652# style.frame_style.min_height frame_min_height 1653# style.frame_style.min_size frame_min_size 1654# style.frame_style.alpha frame_alpha 1655# style.frame_style.blend_mode frame_blend_mode 1656# style.frame_style.fill_style.color fill_color 1657# style.frame_style.fill_style.alpha fill_alpha 1658# style.frame_style.fill_style.fill fill 1659# style.frame_style.fill_style.back_style back_style 1660# style.frame_style.fill_style.mode fill_mode 1661# style.frame_style.fill_style.blend_mode fill_blend_mode 1662# style.frame_style.line_style.color line_color 1663# style.frame_style.line_style.alpha line_alpha 1664# style.frame_style.line_style.width line_width 1665# style.frame_style.line_style.dash_array line_dash_array 1666# style.frame_style.line_style.dash_phase line_dash_phase 1667# style.frame_style.line_style.cap line_cap 1668# style.frame_style.line_style.join line_join 1669# style.frame_style.line_style.miter_limit line_miter_limit 1670# style.frame_style.line_style.fillet_radius fillet_radius 1671# style.frame_style.line_style.smooth smooth 1672# style.frame_style.line_style.stroke stroke 1673# style.frame_style.line_style.blend_mode line_blend_mode 1674# style.frame_style.line_style.draw_markers draw_markers 1675# style.frame_style.line_style.draw_fillets draw_fillets 1676# style.frame_style.line_style.markers_only markers_only 1677# style.frame_style.line_style.double double
83@dataclass 84class FontStyle: 85 """FontStyle is used to set the font, color, and style of text. 86 87 Attributes: 88 font_family (str): The font family. 89 color (Color): The color of the font. 90 family (Union[FontFamily, str]): The font family. 91 size (Union[FontSize, float]): The size of the font. 92 bold (bool): Whether the font is bold. 93 italic (bool): Whether the font is italic. 94 small_caps (bool): Whether the font uses small caps. 95 old_style_nums (bool): Whether the font uses old style numbers. 96 overline (bool): Whether the font has an overline. 97 strike_through (bool): Whether the font has a strike through. 98 underline (bool): Whether the font is underlined. 99 blend_mode (BlendMode): The blend mode of the font. 100 alpha (float): The alpha value of the font. 101 """ 102 103 font_family: str = None 104 color: Color = None 105 family: Union[FontFamily, str] = None 106 size: Union[FontSize, float] = None 107 bold: bool = None 108 italic: bool = None 109 small_caps: bool = None 110 old_style_nums: bool = None 111 overline: bool = None 112 strike_through: bool = None 113 underline: bool = None 114 blend_mode: BlendMode = None 115 alpha: float = None 116 117 def __post_init__(self): 118 """Initialize the FontStyle object.""" 119 exact = [ 120 "bold", 121 "italic", 122 "small_caps", 123 "old_style_nums", 124 "overline", 125 "strike_through", 126 "underline", 127 "draw_frame", 128 "font_family", 129 ] 130 exclude = [] 131 132 _style_init( 133 self, 134 exact=exact, 135 exclude=exclude, 136 prefix="font", 137 subtype=Types.FONT_STYLE, 138 ) 139 self._exact = exact 140 self._exclude = exclude
FontStyle is used to set the font, color, and style of text.
Attributes:
- font_family (str): The font family.
- color (Color): The color of the font.
- family (Union[FontFamily, str]): The font family.
- size (Union[FontSize, float]): The size of the font.
- bold (bool): Whether the font is bold.
- italic (bool): Whether the font is italic.
- small_caps (bool): Whether the font uses small caps.
- old_style_nums (bool): Whether the font uses old style numbers.
- overline (bool): Whether the font has an overline.
- strike_through (bool): Whether the font has a strike through.
- underline (bool): Whether the font is underlined.
- blend_mode (BlendMode): The blend mode of the font.
- alpha (float): The alpha value of the font.
143@dataclass 144class GridStyle: 145 """GridStyle is used to set the grid color, alpha, width, and pattern. 146 147 Attributes: 148 line_color (Color): The color of the grid lines. 149 line_width (float): The width of the grid lines. 150 alpha (float): The alpha value of the grid. 151 back_color (Color): The background color of the grid. 152 """ 153 154 line_color: Color = None 155 line_width: float = None 156 alpha: float = None 157 # width: float = None 158 # height: float = None 159 back_color: Color = None 160 161 def __post_init__(self): 162 """Initialize the GridStyle object.""" 163 exact = [] 164 exclude = [] 165 166 _style_init( 167 self, 168 exact=exact, 169 exclude=exclude, 170 prefix="grid", 171 subtype=Types.GRID_STYLE, 172 ) 173 self._exact = exact 174 self._exclude = exclude 175 176 def __str__(self): 177 """Return a string representation of the GridStyle object.""" 178 return f"GridStyle: {self.id}" 179 180 def __repr__(self): 181 """Return a string representation of the GridStyle object.""" 182 return f"GridStyle: {self.id}" 183 184 def _get_attributes(self): 185 """Get the attributes of the GridStyle object.""" 186 attribs = [x for x in self.__dict__ if not x.startswith("_")] 187 res = [] 188 for attrib in attribs: 189 if attrib in self._exact: 190 res.append(attrib) 191 else: 192 res.append(f"grid_{attrib}")
GridStyle is used to set the grid color, alpha, width, and pattern.
Attributes:
- line_color (Color): The color of the grid lines.
- line_width (float): The width of the grid lines.
- alpha (float): The alpha value of the grid.
- back_color (Color): The background color of the grid.
195@dataclass 196class MarkerStyle: 197 """MarkerStyle is used to set the marker type, size, and color of a shape. 198 199 Attributes: 200 marker_type (MarkerType): The type of the marker. 201 size (float): The size of the marker. 202 color (Color): The color of the marker. 203 radius (float): The radius of the marker. 204 """ 205 206 marker_type: MarkerType = None 207 size: float = None 208 color: Color = None 209 radius: float = None 210 211 def __post_init__(self): 212 """Initialize the MarkerStyle object.""" 213 exact = ["marker_type"] 214 exclude = [] 215 _style_init( 216 self, 217 exact=exact, 218 exclude=exclude, 219 prefix="marker", 220 subtype=Types.MARKER_STYLE, 221 ) 222 self._exact = exact 223 self._exclude = exclude 224 225 def __str__(self): 226 """Return a string representation of the MarkerStyle object.""" 227 return f"Marker: {self.type}"
MarkerStyle is used to set the marker type, size, and color of a shape.
Attributes:
- marker_type (MarkerType): The type of the marker.
- size (float): The size of the marker.
- color (Color): The color of the marker.
- radius (float): The radius of the marker.
230@dataclass 231class LineStyle: 232 """LineStyle is used to set the line color, alpha, width, and pattern of a shape. 233 234 Attributes: 235 color (Color): The color of the line. 236 alpha (float): The alpha value of the line. 237 width (int): The width of the line. 238 dash_array (Optional[Sequence[float]]): The dash array of the line. 239 dash_phase (float): The dash phase of the line. 240 cap (LineCap): The cap style of the line. 241 join (LineJoin): The join style of the line. 242 miter_limit (float): The miter limit of the line. 243 fillet_radius (float): The fillet radius of the line. 244 marker_style (MarkerStyle): The marker style of the line. 245 smooth (bool): Whether the line is smooth. 246 stroke (bool): Whether the line is stroked. 247 draw_markers (bool): Whether to draw markers on the line. 248 draw_fillets (bool): Whether to draw fillets on the line. 249 markers_only (bool): Whether to draw only markers on the line. 250 double_lines (bool): Whether to draw double lines. 251 double_distance (float): The distance between double lines. 252 """ 253 254 # To do: Add support for arrows 255 color: Color = None 256 alpha: float = None 257 width: int = None 258 dash_array: Optional[Sequence[float]] = None 259 dash_phase: float = None 260 cap: LineCap = None 261 join: LineJoin = None 262 miter_limit: float = None 263 fillet_radius: float = None 264 marker_style: MarkerStyle = None 265 smooth: bool = None 266 stroke: bool = None 267 draw_markers: bool = None 268 draw_fillets: bool = None 269 markers_only: bool = None 270 double_lines: bool = None 271 double_distance: float = None 272 273 def __post_init__(self): 274 """Initialize the LineStyle object.""" 275 exact = [ 276 "smooth", 277 "stroke", 278 "fillet_radius", 279 "draw_fillets", 280 "draw_markers", 281 "markers_only", 282 "double", 283 "double_distance", 284 "double_lines", 285 ] 286 exclude = ["marker_style"] 287 _style_init( 288 self, exact, exclude, prefix="line", subtype=Types.LINE_STYLE 289 ) 290 self._exact = exact 291 self._exclude = exclude 292 self.marker_style = MarkerStyle() 293 294 def __str__(self): 295 """Return a string representation of the LineStyle object.""" 296 return f"LineStyle: {self.id}"
LineStyle is used to set the line color, alpha, width, and pattern of a shape.
Attributes:
- color (Color): The color of the line.
- alpha (float): The alpha value of the line.
- width (int): The width of the line.
- dash_array (Optional[Sequence[float]]): The dash array of the line.
- dash_phase (float): The dash phase of the line.
- cap (LineCap): The cap style of the line.
- join (LineJoin): The join style of the line.
- miter_limit (float): The miter limit of the line.
- fillet_radius (float): The fillet radius of the line.
- marker_style (MarkerStyle): The marker style of the line.
- smooth (bool): Whether the line is smooth.
- stroke (bool): Whether the line is stroked.
- draw_markers (bool): Whether to draw markers on the line.
- draw_fillets (bool): Whether to draw fillets on the line.
- markers_only (bool): Whether to draw only markers on the line.
- double_lines (bool): Whether to draw double lines.
- double_distance (float): The distance between double lines.
322@dataclass # used for creating patterns 323class PatternStyle: 324 """PatternStyle is used to set the pattern type, color, distance, angle, shift, line width, radius, and points. 325 326 Attributes: 327 pattern_type (PatternType): The type of the pattern. 328 color (Color): The color of the pattern. 329 distance (float): The distance between pattern elements. 330 angle (float): The angle of the pattern. 331 x_shift (float): The x-axis shift of the pattern. 332 y_shift (float): The y-axis shift of the pattern. 333 line_width (float): The line width of the pattern. 334 radius (float): The radius of the pattern elements. 335 points (int): The number of points in the pattern. 336 """ 337 338 pattern_type: PatternType = None # LINES, HATCH, DOTS, STARS 339 color: Color = None 340 distance: float = None 341 angle: float = None 342 x_shift: float = None 343 y_shift: float = None 344 line_width: float = None 345 radius: float = None # used for dots, stars 346 points: int = None # number of petals. Used for stars 347 348 def __post_init__(self): 349 """Initialize the PatternStyle object.""" 350 exact = ["stroke", "pattern_type"] 351 exclude = [] 352 _style_init( 353 self, 354 exact=exact, 355 exclude=exclude, 356 prefix="pattern", 357 subtype=Types.PATTERN_STYLE, 358 ) 359 self._exact = exact 360 self._exclude = exclude 361 362 def __str__(self): 363 """Return a string representation of the PatternStyle object.""" 364 return f"Pattern: {self.type}"
PatternStyle is used to set the pattern type, color, distance, angle, shift, line width, radius, and points.
Attributes:
- pattern_type (PatternType): The type of the pattern.
- color (Color): The color of the pattern.
- distance (float): The distance between pattern elements.
- angle (float): The angle of the pattern.
- x_shift (float): The x-axis shift of the pattern.
- y_shift (float): The y-axis shift of the pattern.
- line_width (float): The line width of the pattern.
- radius (float): The radius of the pattern elements.
- points (int): The number of points in the pattern.
368@dataclass 369class ShadeStyle: 370 """ShadeStyle uses TikZ shading library to create colors with gradients. 371 372 Attributes: 373 shade_type (ShadeType): The type of the shade. 374 axis_angle (float): The axis angle of the shade. 375 ball_color (Color): The color of the ball. 376 bottom_color (Color): The bottom color of the shade. 377 color_wheel (Color): The color wheel of the shade. 378 color_wheel_black (bool): Whether the color wheel includes black. 379 color_wheel_white (bool): Whether the color wheel includes white. 380 inner_color (Color): The inner color of the shade. 381 left_color (Color): The left color of the shade. 382 lower_left_color (Color): The lower left color of the shade. 383 lower_right_color (Color): The lower right color of the shade. 384 middle_color (Color): The middle color of the shade. 385 outer_color (Color): The outer color of the shade. 386 right_color (Color): The right color of the shade. 387 top_color (Color): The top color of the shade. 388 upper_left_color (Color): The upper left color of the shade. 389 upper_right_color (Color): The upper right color of the shade. 390 """ 391 392 shade_type: ShadeType = None 393 axis_angle: float = None 394 ball_color: Color = None 395 bottom_color: Color = None 396 color_wheel: Color = None 397 color_wheel_black: bool = None 398 color_wheel_white: bool = None 399 inner_color: Color = None 400 left_color: Color = None 401 lower_left_color: Color = None 402 lower_right_color: Color = None 403 middle_color: Color = None 404 outer_color: Color = None 405 right_color: Color = None 406 top_color: Color = None 407 upper_left_color: Color = None 408 upper_right_color: Color = None 409 410 def __post_init__(self): 411 """Initialize the ShadeStyle object.""" 412 exact = [ 413 "shade_type", 414 "axis_angle", 415 "color_wheel_black", 416 "color_wheel_white", 417 "top_color", 418 "bottom_color", 419 "left_color", 420 "right_color", 421 "middle_color", 422 "inner_color", 423 "outer_color", 424 "upper_left_color", 425 "upper_right_color", 426 "lower_left_color", 427 "lower_right_color", 428 "color_wheel", 429 ] 430 exact = ["shade_type"] 431 exclude = [] 432 _style_init( 433 self, 434 exact=exact, 435 exclude=exclude, 436 prefix="shade", 437 subtype=Types.SHADE_STYLE, 438 ) 439 self._exact = exact 440 self._exclude = exclude
ShadeStyle uses TikZ shading library to create colors with gradients.
Attributes:
- shade_type (ShadeType): The type of the shade.
- axis_angle (float): The axis angle of the shade.
- ball_color (Color): The color of the ball.
- bottom_color (Color): The bottom color of the shade.
- color_wheel (Color): The color wheel of the shade.
- color_wheel_black (bool): Whether the color wheel includes black.
- color_wheel_white (bool): Whether the color wheel includes white.
- inner_color (Color): The inner color of the shade.
- left_color (Color): The left color of the shade.
- lower_left_color (Color): The lower left color of the shade.
- lower_right_color (Color): The lower right color of the shade.
- middle_color (Color): The middle color of the shade.
- outer_color (Color): The outer color of the shade.
- right_color (Color): The right color of the shade.
- top_color (Color): The top color of the shade.
- upper_left_color (Color): The upper left color of the shade.
- upper_right_color (Color): The upper right color of the shade.
443@dataclass 444class FillStyle: 445 """FillStyle is used to set the fill color, alpha, and pattern of a shape. 446 447 Attributes: 448 color (Color): The fill color. 449 alpha (float): The alpha value of the fill. 450 fill (bool): Whether the shape is filled. 451 back_style (BackStyle): The back style of the fill. 452 mode (FillMode): The fill mode. 453 pattern_style (PatternStyle): The pattern style of the fill. 454 shade_style (ShadeStyle): The shade style of the fill. 455 grid_style (GridStyle): The grid style of the fill. 456 """ 457 458 color: Color = None 459 alpha: float = None 460 fill: bool = None 461 back_style: BackStyle = None 462 mode: FillMode = None 463 pattern_style: PatternStyle = None 464 shade_style: ShadeStyle = None 465 grid_style: GridStyle = None 466 467 def __post_init__(self): 468 """Initialize the FillStyle object.""" 469 self.shade_style = ShadeStyle() 470 self.grid_style = GridStyle() 471 self.pattern_style = PatternStyle() 472 exact = ["fill", "back_style"] 473 exclude = ["pattern_style", "shade_style", "grid_style"] 474 _style_init( 475 self, exact, exclude, prefix="fill", subtype=Types.FILL_STYLE 476 ) 477 self._exact = exact 478 self._exclude = exclude 479 480 def __str__(self): 481 """Return a string representation of the FillStyle object.""" 482 return f"FillStyle: {self.id}" 483 484 def __repr__(self): 485 """Return a string representation of the FillStyle object.""" 486 return f"FillStyle: {self.id}" 487 488 def _get_attributes(self): 489 """Get the attributes of the FillStyle object.""" 490 attribs = [x for x in self.__dict__ if not x.startswith("_")] 491 res = [] 492 for attrib in attribs: 493 if attrib in self._exact: 494 res.append(attrib) 495 else: 496 res.append(f"fill_{attrib}")
FillStyle is used to set the fill color, alpha, and pattern of a shape.
Attributes:
- color (Color): The fill color.
- alpha (float): The alpha value of the fill.
- fill (bool): Whether the shape is filled.
- back_style (BackStyle): The back style of the fill.
- mode (FillMode): The fill mode.
- pattern_style (PatternStyle): The pattern style of the fill.
- shade_style (ShadeStyle): The shade style of the fill.
- grid_style (GridStyle): The grid style of the fill.
499@dataclass 500class ShapeStyle: 501 """ShapeStyle is used to set the fill and line style of a shape. 502 503 Attributes: 504 line_style (LineStyle): The line style of the shape. 505 fill_style (FillStyle): The fill style of the shape. 506 alpha (float): The alpha value of the shape. 507 """ 508 509 line_style: LineStyle = None 510 fill_style: FillStyle = None 511 alpha: float = None 512 513 def __post_init__(self): 514 """Initialize the ShapeStyle object.""" 515 self.line_style = LineStyle() 516 self.fill_style = FillStyle() 517 self.marker_style = MarkerStyle() 518 self.alpha = defaults["alpha"] 519 exact = ["alpha"] 520 exclude = ["line_style", "fill_style"] 521 _style_init( 522 self, 523 exact=exact, 524 exclude=exclude, 525 prefix="", 526 subtype=Types.SHAPE_STYLE, 527 ) 528 self._exact = exact 529 self._exclude = exclude 530 531 def __str__(self): 532 """Return a string representation of the ShapeStyle object.""" 533 return f"ShapeStyle: {self.id}" 534 535 def __repr__(self): 536 """Return a string representation of the ShapeStyle object.""" 537 return f"ShapeStyle: {self.id}"
ShapeStyle is used to set the fill and line style of a shape.
Attributes:
- line_style (LineStyle): The line style of the shape.
- fill_style (FillStyle): The fill style of the shape.
- alpha (float): The alpha value of the shape.
540@dataclass 541class FrameStyle: 542 """FrameStyle is used to set the frame shape, line style, fill style, and size of a shape. 543 544 Attributes: 545 shape (FrameShape): The shape of the frame. 546 line_style (LineStyle): The line style of the frame. 547 fill_style (FillStyle): The fill style of the frame. 548 inner_sep (float): The inner separation of the frame. 549 inner_xsep (float): The inner x-axis separation of the frame. 550 inner_ysep (float): The inner y-axis separation of the frame. 551 outer_sep (float): The outer separation of the frame. 552 min_width (float): The minimum width of the frame. 553 min_height (float): The minimum height of the frame. 554 min_size (float): The minimum size of the frame. 555 alpha (float): The alpha value of the frame. 556 """ 557 558 shape: FrameShape = None 559 line_style: LineStyle = None 560 fill_style: FillStyle = None 561 inner_sep: float = None 562 inner_xsep: float = None 563 inner_ysep: float = None 564 outer_sep: float = None 565 min_width: float = None 566 min_height: float = None 567 min_size: float = None 568 alpha: float = None 569 570 def __post_init__(self): 571 """Initialize the FrameStyle object.""" 572 self.line_style = LineStyle() 573 self.fill_style = FillStyle() 574 exact = [] 575 exclude = ["line_style", "fill_style"] 576 _style_init( 577 self, 578 exact=exact, 579 exclude=exclude, 580 prefix="frame", 581 subtype=Types.FRAME_STYLE, 582 ) 583 self._exact = exact 584 self._exclude = exclude
FrameStyle is used to set the frame shape, line style, fill style, and size of a shape.
Attributes:
- shape (FrameShape): The shape of the frame.
- line_style (LineStyle): The line style of the frame.
- fill_style (FillStyle): The fill style of the frame.
- inner_sep (float): The inner separation of the frame.
- inner_xsep (float): The inner x-axis separation of the frame.
- inner_ysep (float): The inner y-axis separation of the frame.
- outer_sep (float): The outer separation of the frame.
- min_width (float): The minimum width of the frame.
- min_height (float): The minimum height of the frame.
- min_size (float): The minimum size of the frame.
- alpha (float): The alpha value of the frame.
587@dataclass 588class TagStyle: 589 """TagStyle is used to set the font, color, and style of tag objects. 590 591 Attributes: 592 align (Align): The alignment of the tag. 593 alpha (float): The alpha value of the tag. 594 bold (bool): Whether the tag is bold. 595 italic (bool): Whether the tag is italic. 596 anchor (Anchor): The anchor of the tag. 597 blend_mode (BlendMode): The blend mode of the tag. 598 draw_frame (bool): Whether to draw a frame around the tag. 599 font_style (FontStyle): The font style of the tag. 600 frame_style (FrameStyle): The frame style of the tag. 601 text_width (float): The text width of the tag. 602 """ 603 604 align: Align = None 605 alpha: float = None 606 bold: bool = None 607 italic: bool = None 608 anchor: Anchor = None 609 blend_mode: BlendMode = None 610 draw_frame: bool = None 611 font_style: FontStyle = None 612 frame_style: FrameStyle = None 613 text_width: float = None 614 615 def __post_init__(self): 616 """Initialize the TagStyle object.""" 617 self.font_style = FontStyle() 618 self.frame_style = FrameStyle() 619 self.alpha = defaults["tag_alpha"] 620 self.bold = defaults["bold"] 621 self.italic = defaults["italic"] 622 self.align = defaults["tag_align"] 623 self.blend_mode = defaults["tag_blend_mode"] 624 self.text_width = defaults["text_width"] 625 exact = [ 626 "alpha", 627 "blend_mode", 628 "draw_frame", 629 "anchor", 630 "bold", 631 "italic", 632 "text_width" 633 ] 634 exclude = ["font_style", "frame_style"] 635 636 _style_init( 637 self, 638 exact=exact, 639 exclude=exclude, 640 prefix="tag", 641 subtype=Types.TAG_STYLE, 642 ) 643 self._exact = exact 644 self._exclude = exclude 645 646 def __str__(self): 647 """Return a string representation of the TagStyle object.""" 648 return f"TagStyle: {self.id}" 649 650 def __repr__(self): 651 """Return a string representation of the TagStyle object.""" 652 return f"TagStyle: {self.id}"
TagStyle is used to set the font, color, and style of tag objects.
Attributes:
- align (Align): The alignment of the tag.
- alpha (float): The alpha value of the tag.
- bold (bool): Whether the tag is bold.
- italic (bool): Whether the tag is italic.
- anchor (Anchor): The anchor of the tag.
- blend_mode (BlendMode): The blend mode of the tag.
- draw_frame (bool): Whether to draw a frame around the tag.
- font_style (FontStyle): The font style of the tag.
- frame_style (FrameStyle): The frame style of the tag.
- text_width (float): The text width of the tag.