MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / _get_style_dict

Method _get_style_dict

lib/matplotlib/backends/backend_svg.py:570–613  ·  view source on GitHub ↗

Generate a style string from the GraphicsContext and rgbFace.

(self, gc, rgbFace)

Source from the content-addressed store, hash-verified

568 writer.end('defs')
569
570 def _get_style_dict(self, gc, rgbFace):
571 """Generate a style string from the GraphicsContext and rgbFace."""
572 attrib = {}
573
574 forced_alpha = gc.get_forced_alpha()
575
576 if gc.get_hatch() is not None:
577 attrib['fill'] = f"url(#{self._get_hatch(gc, rgbFace)})"
578 if (rgbFace is not None and len(rgbFace) == 4 and rgbFace[3] != 1.0
579 and not forced_alpha):
580 attrib['fill-opacity'] = _short_float_fmt(rgbFace[3])
581 else:
582 if rgbFace is None:
583 attrib['fill'] = 'none'
584 else:
585 if tuple(rgbFace[:3]) != (0, 0, 0):
586 attrib['fill'] = rgb2hex(rgbFace)
587 if (len(rgbFace) == 4 and rgbFace[3] != 1.0
588 and not forced_alpha):
589 attrib['fill-opacity'] = _short_float_fmt(rgbFace[3])
590
591 if forced_alpha and gc.get_alpha() != 1.0:
592 attrib['opacity'] = _short_float_fmt(gc.get_alpha())
593
594 offset, seq = gc.get_dashes()
595 if seq is not None:
596 attrib['stroke-dasharray'] = ','.join(
597 _short_float_fmt(val) for val in seq)
598 attrib['stroke-dashoffset'] = _short_float_fmt(float(offset))
599
600 linewidth = gc.get_linewidth()
601 if linewidth:
602 rgb = gc.get_rgb()
603 attrib['stroke'] = rgb2hex(rgb)
604 if not forced_alpha and rgb[3] != 1.0:
605 attrib['stroke-opacity'] = _short_float_fmt(rgb[3])
606 if linewidth != 1.0:
607 attrib['stroke-width'] = _short_float_fmt(linewidth)
608 if gc.get_joinstyle() != 'round':
609 attrib['stroke-linejoin'] = gc.get_joinstyle()
610 if gc.get_capstyle() != 'butt':
611 attrib['stroke-linecap'] = _capstyle_d[gc.get_capstyle()]
612
613 return attrib
614
615 def _get_style(self, gc, rgbFace):
616 return _generate_css(self._get_style_dict(gc, rgbFace))

Callers 2

_get_styleMethod · 0.95
draw_markersMethod · 0.95

Calls 11

_get_hatchMethod · 0.95
_short_float_fmtFunction · 0.85
get_forced_alphaMethod · 0.80
get_dashesMethod · 0.80
joinMethod · 0.80
get_hatchMethod · 0.45
get_alphaMethod · 0.45
get_linewidthMethod · 0.45
get_rgbMethod · 0.45
get_joinstyleMethod · 0.45
get_capstyleMethod · 0.45

Tested by

no test coverage detected