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 = set(['opacity', 'stroke-opacity', 'fill-opacity', 'stroke', 'stroke-dasharray', 'stroke-width', 'fill'])

Allowable CSS property names for filling areas.

line = set(['opacity', 'stroke-opacity', 'stroke', 'stroke-linecap', 'stroke-dasharray', 'stroke-width'])

Allowable CSS property names for stroking lines.

marker = set(['opacity', 'stroke-opacity', 'fill-opacity', 'stroke', 'stroke-width', 'fill'])

Allowable CSS property names for Markers.

text = set(['opacity', 'font-size', 'font-weight', 'baseline-shift', 'stroke-opacity', 'fill-opacity', '-toyplot-text-layout-visibility', '-toyplot-anchor-shift', '-toyplot-text-layout-line-visibility', '-toyplot-vertical-align', 'text-anchor', '-toyplot-text-layout-box-visibility', 'text-shadow', 'stroke', 'stroke-width', 'alignment-baseline', 'font-family', 'line-height', 'fill'])

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.