8000 REVERT: Do not expose JoinStyle/CapStyle at all · matplotlib/matplotlib@56f37c3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 56f37c3

Browse files
committed
REVERT: Do not expose JoinStyle/CapStyle at all
1 parent d2de8a2 commit 56f37c3

File tree

12 files changed

+59
-92
lines changed

12 files changed

+59
-92
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ def get_antialiased(self):
821821

822822
def get_capstyle(self):
823823
"""Return the `.CapStyle`."""
824-
return self._capstyle
824+
return self._capstyle.name
825825

826826
def get_clip_rectangle(self):
827827
"""
@@ -866,7 +866,7 @@ def get_forced_alpha(self):
866866

867867
def get_joinstyle(self):
868868
"""Return the `.JoinStyle`."""
869-
return self._joinstyle
869+
return self._joinstyle.name
870870

871871
def get_linewidth(self):
872872
"""Return the line width in points."""

lib/matplotlib/backends/backend_cairo.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
from matplotlib.mathtext import MathTextParser
3333
from matplotlib.path import Path
3434
from matplotlib.transforms import Affine2D
35-
from matplotlib._types import JoinStyle, CapStyle
3635

3736

3837
backend_version = cairo.version
@@ -322,15 +321,15 @@ def points_to_pixels(self, points):
322321

323322
class GraphicsContextCairo(GraphicsContextBase):
324323
_joind = {
325-
JoinStyle.bevel: cairo.LINE_JOIN_BEVEL,
326-
JoinStyle.miter: cairo.LINE_JOIN_MITER,
327-
JoinStyle.round: cairo.LINE_JOIN_ROUND,
324+
'bevel': cairo.LINE_JOIN_BEVEL,
325+
'miter': cairo.LINE_JOIN_MITER,
326+
'round': cairo.LINE_JOIN_ROUND,
328327
}
329328

330329
_capd = {
331-
CapStyle.butt: cairo.LINE_CAP_BUTT,
332-
CapStyle.projecting: cairo.LINE_CAP_SQUARE,
333-
CapStyle.round: cairo.LINE_CAP_ROUND,
330+
'butt': cairo.LINE_CAP_BUTT,
331+
'projecting': cairo.LINE_CAP_SQUARE,
332+
'round': cairo.LINE_CAP_ROUND,
334333
}
335334

336335
def __init__(self, renderer):
@@ -354,8 +353,8 @@ def set_alpha(self, alpha):
354353
# one for False.
355354

356355
1356 def set_capstyle(self, cs):
357-
super().set_capstyle(cs)
358-
self.ctx.set_line_cap(self._capd[self.get_capstyle()])
356+
s F438 elf.ctx.set_line_cap(_api.check_getitem(self._capd, capstyle=cs))
357+
self._capstyle = cs
359358

360359
def set_clip_rectangle(self, rectangle):
361360
if not rectangle:
@@ -397,8 +396,8 @@ def get_rgb(self):
397396
return self.ctx.get_source().get_rgba()[:3]
398397

399398
def set_joinstyle(self, js):
400-
super().set_joinstyle(js)
401-
self.ctx.set_line_join(self._joind[self.get_joinstyle()])
399+
self.ctx.set_line_join(_api.check_getitem(self._joind, joinstyle=js))
400+
self._joinstyle = js
402401

403402
def set_linewidth(self, w):
404403
self._linewidth = float(w)

lib/matplotlib/backends/backend_pdf.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,22 @@
2626
import matplotlib as mpl
2727
from matplotlib import _api, _text_layout, cbook
2828
from matplotlib._pylab_helpers import Gcf
29-
from matplotlib.afm import AFM
3029
from matplotlib.backend_bases import (
3130
_Backend, _check_savefig_extra_args, FigureCanvasBase, FigureManagerBase,
3231
GraphicsContextBase, RendererBase)
3332
from matplotlib.backends.backend_mixed import MixedModeRenderer
34-
from matplotlib.dates import UTC
35-
import matplotlib.dviread as dviread
3633
from matplotlib.figure import Figure
3734
from matplotlib.font_manager import findfont, get_font
35+
from matplotlib.afm import AFM
36+
import matplotlib.type1font as type1font
37+
import matplotlib.dviread as dviread
3838
from matplotlib.ft2font import (FIXED_WIDTH, ITALIC, LOAD_NO_SCALE,
3939
LOAD_NO_HINTING, KERNING_UNFITTED)
4040
from matplotlib.mathtext import MathTextParser
41-
from matplotlib import _path
42-
from matplotlib.path import Path
43-
from matplotlib._types import JoinStyle, CapStyle
44-
import matplotlib.type1font as type1font
4541
from matplotlib.transforms import Affine2D, BboxBase
42+
from matplotlib.path import Path
43+
from matplotlib.dates import UTC
44+
from matplotlib import _path
4645
from . import _backend_pdf_ps
4746

4847
_log = logging.getLogger(__name__)
@@ -747,8 +746,7 @@ def newPage(self, width, height):
747746
self.reserveObject('length of content stream'))
748747
# Initialize the pdf graphics state to match the default mpl
749748
# graphics context: currently only the join style needs to be set
750-
self.output(GraphicsContextPdf.joinstyles[JoinStyle.round],
751-
Op.setlinejoin)
749+
self.output(GraphicsContextPdf.joinstyles['round'], Op.setlinejoin)
752750

753751
# Clear the list of annotations for the next page
754752
self.pageAnnotations = []
@@ -2416,8 +2414,8 @@ def paint(self):
24162414
"""
24172415
return Op.paint_path(self.fill(), self.stroke())
24182416

2419-
capstyles = {CapStyle.butt: 0, CapStyle.round: 1, CapStyle.projecting: 2}
2420-
joinstyles = {JoinStyle.miter: 0, JoinStyle.round: 1, JoinStyle.bevel: 2}
2417+
capstyles = {'butt': 0, 'round': 1, 'projecting': 2}
2418+
joinstyles = {'miter': 0, 'round': 1, 'bevel': 2}
24212419

24222420
def capstyle_cmd(self, style):
24232421
return [self.capstyles[style], Op.setlinecap]

lib/matplotlib/backends/backend_pgf.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
from matplotlib.path import Path
2727
from matplotlib.figure import Figure
2828
from matplotlib._pylab_helpers import Gcf
29-
from matplotlib._types import JoinStyle, CapStyle
3029

3130
_log = logging.getLogger(__name__)
3231

@@ -516,15 +515,15 @@ def _print_pgf_clip(self, gc):
516515

517516
def _print_pgf_path_styles(self, gc, rgbFace):
518517
# cap style
519-
capstyles = {CapStyle.butt: r"\pgfsetbuttcap",
520-
CapStyle.round: r"\pgfsetroundcap",
521-
CapStyle.projecting: r"\pgfsetrectcap"}
518+
capstyles = {"butt": r"\pgfsetbuttcap",
519+
"round": r"\pgfsetroundcap",
520+
"projecting": r"\pgfsetrectcap"}
522521
writeln(self.fh, capstyles[gc.get_capstyle()])
523522

524523
# join style
525-
joinstyles = {JoinStyle.miter: r"\pgfsetmiterjoin",
526-
JoinStyle.round: r"\pgfsetroundjoin",
527-
JoinStyle.bevel: r"\pgfsetbeveljoin"}
524+
joinstyles = {"miter": r"\pgfsetmiterjoin",
525+
"round": r"\pgfsetroundjoin",
526+
"bevel": r"\pgfsetbeveljoin"}
528527
writeln(self.fh, joinstyles[gc.get_joinstyle()])
529528

530529
# filling

lib/matplotlib/backends/backend_ps.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,16 @@
2424
from matplotlib.backend_bases import (
2525
_Backend, _check_savefig_extra_args, FigureCanvasBase, FigureManagerBase,
2626
GraphicsContextBase, RendererBase)
27-
from matplotlib.backends.backend_mixed import MixedModeRenderer
2827
from matplotlib.cbook import is_writable_file_like, file_requires_unicode
2928
from matplotlib.font_manager import get_font
3029
from matplotlib.ft2font import LOAD_NO_HINTING, LOAD_NO_SCALE
3130
from matplotlib._ttconv import convert_ttf_to_ps
3231
from matplotlib.mathtext import MathTextParser
3332
from matplotlib._mathtext_data import uni2type1
3433
from matplotlib.path import Path
35-
from matplotlib._types import JoinStyle, CapStyle
3634
from matplotlib.texmanager import TexManager
3735
from matplotlib.transforms import Affine2D
36+
from matplotlib.backends.backend_mixed import MixedModeRenderer
3837
from . import _backend_pdf_ps
3938

4039
_log = logging.getLogger(__name__)
@@ -802,16 +801,11 @@ def _is_transparent(rgb_or_rgba):
802801

803802
@_api.deprecated("3.4", alternative="GraphicsContextBase")
804803
class GraphicsContextPS(GraphicsContextBase):
805-
806-
_capstyles = {CapStyle.butt: 0, CapStyle.round: 1, CapStyle.projecting: 2}
807-
808804
def get_capstyle(self):
809-
return self._capstyles[super().get_capstyle()]
810-
811-
_joinstyles = {JoinStyle.miter: 0, JoinStyle.round: 1, JoinStyle.bevel: 2}
805+
return {'butt': 0, 'round': 1, 'projecting': 2}[super().get_capstyle()]
812806

813807
def get_joinstyle(self):
814-
return self._joinstyles[super().get_joinstyle()]
808+
return {'miter': 0, 'round': 1, 'bevel': 2}[super().get_joinstyle()]
815809

816810

817811
class _Orientation(Enum):

lib/matplotlib/backends/backend_svg.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
from matplotlib.path import Path
2828
from matplotlib import _path
2929
from matplotlib.transforms import Affine2D, Affine2DBase
30-
from matplotlib._types import JoinStyle, CapStyle
3130

3231
_log = logging.getLogger(__name__)
3332

@@ -572,10 +571,10 @@ def _get_style_dict(self, gc, rgbFace):
572571
attrib['stroke-opacity'] = short_float_fmt(rgb[3])
573572
if linewidth != 1.0:
574573
attrib['stroke-width'] = short_float_fmt(linewidth)
575-
if gc.get_joinstyle() != JoinStyle.round:
576-
attrib['stroke-linejoin'] = gc.get_joinstyle().name
577-
if gc.get_capstyle() != CapStyle.butt:
578-
attrib['stroke-linecap'] = _capstyle_d[gc.get_capstyle().name]
574+
if gc.get_joinstyle() != 'round':
575+
attrib['stroke-linejoin'] = gc.get_joinstyle()
576+
if gc.get_capstyle() != 'butt':
577+
attrib['stroke-linecap'] = _capstyle_d[gc.get_capstyle()]
579578

580579
return attrib
581580

lib/matplotlib/backends/backend_wx.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
from matplotlib.figure import Figure
2929
from matplotlib.path import Path
3030
from matplotlib.transforms import Affine2D
31-
from matplotlib._types import JoinStyle, CapStyle
3231
from matplotlib.widgets import SubplotTool
3332

3433
import wx
@@ -327,13 +326,13 @@ class GraphicsContextWx(GraphicsContextBase):
327326
since wxPython colour management is rather simple, I have not chosen
328327
to implement a separate colour manager class.
329328
"""
330-
_capd = {CapStyle.butt: wx.CAP_BUTT,
331-
CapStyle.projecting: wx.CAP_PROJECTING,
332-
CapStyle.round: wx.CAP_ROUND}
329+
_capd = {'butt': wx.CAP_BUTT,
330+
'projecting': wx.CAP_PROJECTING,
331+
'round': wx.CAP_ROUND}
333332

334-
_joind = {JoinStyle.bevel: wx.JOIN_BEVEL,
335-
JoinStyle.miter: wx.JOIN_MITER,
336-
JoinStyle.round: wx.JOIN_ROUND}
333+
_joind = {'bevel': wx.JOIN_BEVEL,
334+
'miter': wx.JOIN_MITER,
335+
'round': wx.JOIN_ROUND}
337336

338337
_cache = weakref.WeakKeyDictionary()
339338

lib/matplotlib/collections.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -659,12 +659,11 @@ def set_capstyle(self, cs):
659659
Parameters
660660
----------
661661
cs : `.CapStyle` or {'butt', 'round', 'projecting'}
662-
The capstyle.
663662
"""
664663
self._capstyle = CapStyle(cs)
665664

666665
def get_capstyle(self):
667-
return self._capstyle
666+
return self._capstyle.name
668667

669668
def set_joinstyle(self, js):
670669
"""
@@ -673,12 +672,11 @@ def set_joinstyle(self, js):
673672
Parameters
674673
----------
675674
js : `.JoinStyle` or {'miter', 'round', 'bevel'}
676-
The joinstyle.
677675
"""
678676
self._joinstyle = JoinStyle(js)
679677

680678
def get_joinstyle(self):
681-
return self._joinstyle
679+
return self._joinstyle.name
682680

683681
@staticmethod
684682
def _bcast_lwls(linewidths, dashes):

lib/matplotlib/lines.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,12 +254,12 @@ class Line2D(Artist):
254254
@_api.deprecated("3.4")
255255
@_api.classproperty
256256
def validCap(cls):
257-
return ('butt', 'round', 'projecting')
257+
return tuple(cs.value for cs in CapStyle)
258258

259259
@_api.deprecated("3.4")
260260
@_api.classproperty
261261
def validJoin(cls):
262-
return ('miter', 'round', 'bevel')
262+
return tuple(js.value for js in JoinStyle)
263263

264264
def __str__(self):
265265
if self._label != "":
@@ -1344,15 +1344,15 @@ def get_dash_joinstyle(self):
13441344
13451345
See also `~.Line2D.set_dash_joinstyle`.
13461346
"""
1347-
return self._dashjoinstyle
1347+
return self._dashjoinstyle.name
13481348

13491349
def get_solid_joinstyle(self):
13501350
"""
13511351
Return the `.JoinStyle` for solid lines.
13521352
13531353
See also `~.Line2D.set_solid_joinstyle`.
13541354
"""
1355-
return self._solidjoinstyle
1355+
return self._solidjoinstyle.name
13561356

13571357
def set_dash_capstyle(self, s):
13581358
"""
@@ -1386,15 +1386,15 @@ def get_dash_capstyle(self):
13861386
13871387
See also `~.Line2D.set_dash_capstyle`.
13881388
"""
1389-
return self._dashcapstyle
1389+
return self._dashcapstyle.name
13901390

13911391
def get_solid_capstyle(self):
13921392
"""
13931393
Return the `.CapStyle` for solid lines.
13941394
13951395
See also `~.Line2D.set_solid_capstyle`.
13961396
"""
1397-
return self._solidcapstyle
1397+
return self._solidcapstyle.name
13981398

13991399
def is_dashed(self):
14001400
"""

lib/matplotlib/tests/test_collections.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
import pytest
77

88
i 10000 mport matplotlib as mpl
9+
import matplotlib.pyplot as plt
910
import matplotlib.collections as mcollections
11+
import matplotlib.transforms as mtransforms
1012
from matplotlib.collections import (Collection, LineCollection,
1113
EventCollection, PolyCollection)
1214
import matplotlib.pyplot as plt
13-
from matplotlib._types import JoinStyle, CapStyle
1415
from matplotlib.testing.decorators import check_figures_equal, image_comparison
1516
import matplotlib.transforms as mtransforms
1617

@@ -530,17 +531,17 @@ def test_lslw_bcast():
530531
@pytest.mark.style('default')
531532
def test_capstyle():
532533
col = mcollections.PathCollection([], capstyle='round')
533-
assert col.get_capstyle() == CapStyle.round
534+
assert col.get_capstyle() == 'round'
534535
col.set_capstyle('butt')
535-
assert col.get_capstyle() == CapStyle.butt
536+
assert col.get_capstyle() == 'butt'
536537

537538

538539
@pytest.mark.style('default')
539540
def test_joinstyle():
540541
col = mcollections.PathCollection([], joinstyle='round')
541-
assert col.get_joinstyle() == JoinStyle.round
542+
assert col.get_joinstyle() == 'round'
542543
col.set_joinstyle('miter')
543-
assert col.get_joinstyle() == JoinStyle.miter
544+
assert col.get_joinstyle() == 'miter'
544545

545546

546547
@image_comparison(['cap_and_joinstyle.png'])

lib/matplotlib/tests/test_patches.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
import pytest
77

88
from matplotlib.patches import Patch, Polygon, Rectangle, FancyArrowPatch
9-
import matplotlib.pyplot as plt
109
from matplotlib.testing.decorators import image_comparison, check_figures_equal
1110
from matplotlib.transforms import Bbox
12-
from matplotlib._types import JoinStyle, CapStyle
11+
import matplotlib.pyplot as plt
1312
from matplotlib import (
1413
collections as mcollections, colors as mcolors, patches as mpatches,
1514
path as mpath, style as mstyle, transforms as mtransforms, rcParams)
@@ -621,9 +620,9 @@ def test_default_linestyle():
621620

622621
def test_default_capstyle():
623622
patch = Patch()
624-
assert patch.get_capstyle() == CapStyle.butt
623+
assert patch.get_capstyle() == 'butt'
625624

626625

627626
def test_default_joinstyle():
628627
patch = Patch()
629-
assert patch.get_joinstyle() == JoinStyle.miter
628+
assert patch.get_joinstyle() == 'miter'

0 commit comments

Comments
 (0)
0