toyplot.style module

Functionality for working with CSS style information.

class toyplot.style.allowed[source]

Bases: object

Defines groups of allowable CSS property names.

fill = {'fill', 'fill-opacity', 'opacity', 'stroke', 'stroke-dasharray', 'stroke-opacity', 'stroke-width'}

Allowable CSS property names for filling areas.

line = {'opacity', 'stroke', 'stroke-dasharray', 'stroke-linecap', 'stroke-opacity', 'stroke-width'}

Allowable CSS property names for stroking lines.

marker = {'fill', 'fill-opacity', 'opacity', 'stroke', 'stroke-opacity', 'stroke-width'}

Allowable CSS property names for Markers.

text = {'-toyplot-anchor-shift', '-toyplot-text-layout-box-visibility', '-toyplot-text-layout-line-visibility', '-toyplot-text-layout-visibility', '-toyplot-vertical-align', 'alignment-baseline', 'baseline-shift', 'fill', 'fill-opacity', 'font-family', 'font-size', 'font-weight', 'line-height', 'opacity', 'stroke', 'stroke-opacity', 'stroke-width', 'text-anchor', 'text-decoration-line', 'text-shadow'}

Allowable CSS property names for text.

toyplot.style.combine(*styles)[source]

Combine multiple style specifications into one.

Parameters:styles (sequence of dict instances) – A collection of dicts containing CSS-compatible name-value pairs.
Returns:styles
Return type:dict containing CSS-compatible name-value pairs.
toyplot.style.parse(css)[source]

Parse a CSS style into a dict.

toyplot.style.require(css, allowed)[source]

Validate that an object is usable as CSS style information.

Parameters:
  • css (dict or None) – The style dictionary to be validated. An exception will be raised if it is not a valid style dictionary or None.
  • allowed (sequence of strings) – The set of allowed style properties. An exception will be raised if css contains any keys that aren’t in this sequence.
Returns:

style – The validated style dictionary.

Return type:

dict

toyplot.style.to_css(*styles)[source]

Convert one-or-more dicts containing CSS properties into a single CSS string.