Styling Guide
Overview
momapy supports CSS-like stylesheets for customizing the appearance of molecular maps. Stylesheets allow you to control colors, fonts, strokes, and other visual properties of map elements without modifying the underlying map data.
Stylesheets are applied during rendering and can be used via the command line (-s flag) or the Python API.
Basic Syntax
Stylesheets follow a CSS-like syntax with rules, selectors, and declaration blocks:
A rule consists of:
- Selector: The element(s) to style (e.g.,
MacromoleculeLayout) - Declaration block: Properties and values inside
{ } - Properties: Visual attributes (e.g.,
fill,stroke-width) - Values: The setting for each property (e.g.,
royalblue,2.0)
Selectors
Type Selector
Matches elements by their exact class name:
This matches only MacromoleculeLayout elements, not subclasses.
Class Selector
Matches a class and all its subclasses (prefix with dot):
This matches Shape and any subclass like Rectangle, Ellipse, etc.
ID Selector
Matches an element by its id_ attribute:
Child Selector
Matches direct children only (use >):
Descendant Selector
Matches elements at any depth:
Or Selector
Matches any of multiple selectors (comma-separated):
Value Types
Numbers
- Floats:
2.0,10.5 - Integers:
42
Strings
Quoted strings for font names and other text values:
Colors
Color names or hex values:
Special Values
none: No value (e.g.,fill: none;)unset: Reset to default/inherited value
Lists
Comma-separated lists:
Filters
Drop shadow effect:
Parameters: drop-shadow(dx, dy, std_dev, opacity, color)
Common Properties
Drawing Properties
| Property | Description | Example |
|---|---|---|
fill |
Fill color | fill: royalblue; |
stroke |
Stroke/border color | stroke: black; |
stroke-width |
Stroke thickness | stroke-width: 2.0; |
stroke-dasharray |
Dash pattern | stroke-dasharray: 5, 5; |
opacity |
Opacity (0.0-1.0) | opacity: 0.8; |
filter |
Visual effects | filter: drop-shadow(2, 2, 3, 0.5, gray); |
Text Properties
| Property | Description | Example |
|---|---|---|
font-family |
Font name | font-family: "DejaVu Sans"; |
font-size |
Font size | font-size: 14.0; |
fill |
Text color | fill: white; |
font-style |
Font style | font-style: italic; |
font-weight |
Font weight | font-weight: bold; |
Shape Properties
| Property | Description | Example |
|---|---|---|
width |
Element width | width: 100.0; |
height |
Element height | height: 60.0; |
rounded-corners |
Corner radius | rounded-corners: 5.0; |
cut-corners |
Cut corner size | cut-corners: 10.0; |
Note: Some node and arc classes have specific attributes that define their shape geometry. For example, angle and offset are parameters used by certain shape types (like hexagons with specific corner angles) and are not rotation angles or position offsets. Refer to the specific node or arc class implementation to see which shape-specific properties are available.
Connector Properties
| Property | Description | Example |
|---|---|---|
left-connector-length |
Left connector size | left-connector-length: 10.0; |
left-connector-stroke |
Left connector color | left-connector-stroke: gray; |
right-connector-length |
Right connector size | right-connector-length: 10.0; |
right-connector-stroke |
Right connector color | right-connector-stroke: gray; |
Arrowhead Properties
| Property | Description | Example |
|---|---|---|
arrowhead-fill |
Arrowhead fill color | arrowhead-fill: black; |
arrowhead-stroke |
Arrowhead stroke color | arrowhead-stroke: gray; |
arrowhead-stroke-width |
Arrowhead stroke width | arrowhead-stroke-width: 1.5; |
Note: Not all arcs have arrowheads. For example, ConsumptionLayout is rendered as a simple line (polyline) without an arrowhead.
Path Properties
| Property | Description | Example |
|---|---|---|
path-stroke |
Path color | path-stroke: gray; |
path-stroke-width |
Path thickness | path-stroke-width: 1.5; |
end-shorten |
Shorten path at end | end-shorten: 1.0; |
Group Properties
Prefix with group- to style child elements collectively:
Imports
Stylesheets can import other stylesheets using the @import rule:
Imports are processed in order, with later rules overriding earlier ones.
Usage
Command Line
Apply a stylesheet when rendering:
Apply multiple stylesheets (applied in order):
Python API
Load from file:
Load from string:
Apply to a layout:
Or apply during rendering:
Complete Example
Here's a custom stylesheet for some layout elements of SBGN PD: