Style¶
Enum¶
Node Shape¶
The available point shapes (xgmml.utils.style_utils.NODE_SHAPES) are as follows:
| Enum | Example |
|---|---|
| ELLIPSE | |
| RECTANGLE | |
| HEXAGON | |
| OCTAGON | |
| DIAMOND | |
| TRIANGLE | |
| ROUNDED_RECTANGLE |
Line Type¶
The available line types (xgmml.utils.style_utils.LINE_TYPES) are as follows:
| Enum | Example |
|---|---|
| SOLID | |
| LONG_DASH | |
| DOT | |
| DASH_DOT | |
| EQUAL_DASH | |
| PARALLEL_LINES | |
| VERTICAL_SLASH | |
| FORWARD_SLASH | |
| BACKWARD_SLASH | |
| CONTIGUOUS_ARROW | |
| SEPARATE_ARROW | |
| SINEWAVE | |
| ZIGZAG |
Arrow Shape¶
The available arrow shapes (xgmml.utils.style_utils.ARROW_SHAPES) are as follows:
| Enum | Example |
|---|---|
| ARROW | |
| ARROW_SHORT | |
| CIRCLE | |
| CROSS_DELTA | |
| CROSS_OPEN_DELTA | |
| DELTA | |
| DELTA_SHORT_1 | |
| DELTA_SHORT_2 | |
| DIAMOND | |
| DIAMOND_SHORT_1 | |
| DIAMOND_SHORT_2 | |
| HALF_BOTTOM | |
| HALF_CIRCLE | |
| HALF_TOP | |
| NONE | |
| OPEN_CIRCLE | |
| OPEN_DELTA | |
| OPEN_DIAMOND | |
| OPEN_HALF_CIRCLE | |
| OPEN_SQUARE | |
| SQUARE | |
| T |
Color¶
The default discrete colors (xgmml.utils.style_utils.COLORS) are as follows:
| HEX | Example |
|---|---|
| #1783FF | |
| #00C9C9 | |
| #F0884D | |
| #D580FF | |
| #7863FF | |
| #60C42D | |
| #BD8F24 | |
| #FF80CA | |
| #2491B3 | |
| #17C76F |
The default continuous color is coolwarm in matplotlib, as shown below:

Mapper¶
Base mapper¶
The base mapper is the base class for all mappers:
class StyleMapper(ABC):
def __init__(self, values: list, **kwargs):
self._values = values
@abstractmethod
def map(self, value):
raise NotImplementedError()
The mapper maps style values via the map method. The kwargs in the write method of the XGMMLWriter object will be passed to the initialization method of the StyleMapper class.
Discrete mapper¶
The default discrete style mappers are:
- Point shape:
xgmml.style.style_mapper.StyleNodeShapeDefaultDiscreteMapper - Color:
xgmml.style.style_mapper.StyleColorDefaultDiscreteMapper - Line type:
xgmml.style.style_mapper.StyleLineTypeDefaultDiscreteMapper - Arrow shape:
xgmml.style.style_mapper.StyleArrowShapeDefaultDiscreteMapper
Custom discrete style mappers need to inherit from the xgmml.style.style_mapper.StyleDiscreteMapper class:
class StyleDiscreteMapper(StyleMapper):
def __init__(self, values: list, styles: list, **kwargs):
super(StyleDiscreteMapper, self).__init__(values)
self._styles = styles
self._categories = sorted(set(values), key=self._sort_key)
def _sort_key(self, value):
return value
def map(self, value):
category_idx = self._categories.index(value)
style_idx = category_idx % len(self._styles)
return self._styles[style_idx]
While, values is a list of discrete values, and styles is a list of corresponding styles.
Custom color discrete style mappers need to inherit from the xgmml.style.style_mapper.StyleColorDiscreteMapper class:
class StyleColorDiscreteMapper(StyleMapper):
def __init__(self, values: list, colormap: mpl.colors.ListedColormap, **kwargs):
super(StyleColorDiscreteMapper, self).__init__(values)
self._colors = colormap.colors
self._categories = sorted(set(values), key=self._sort_key)
def _sort_key(self, value):
return value
def map(self, value):
category_idx = self._categories.index(value)
color_idx = category_idx % len(self._colors)
return mpl.colors.to_hex(self._colors[color_idx])
While, values is a list of discrete values, and colormap is an instance of mpl.colors.ListedColormap of matplotlib.
All of the above can overload the _sort_key method, which is used for the sorting key of discrete values.
Continuous mapper¶
The default continuous style mappers are:
- Point size:
xgmml.style.style_mapper.StyleNodeSizeDefaultContinuousMapper - Font size:
xgmml.style.style_mapper.StyleFontSizeDefaultContinuousMapper
Custom continuous style mappers need to inherit from the xgmml.style.style_mapper.StyleContinuousMapper class:
class StyleContinuousMapper(StyleMapper):
def __init__(self, values: list, **kwargs):
super(StyleContinuousMapper, self).__init__(values)
self._min_value = min(self._values)
self._max_value = max(self._values)
def _transform_value(self, value) -> float:
if self._max_value - self._min_value == 0:
return 0.0
return (value - self._min_value) / (self._max_value - self._min_value)
def map(self, value):
return self._transform_value(value)
While, values is a list of continuous values. You can overload the _transform_value method, which is used to convert the original value to the mapped value.
Custom color discrete style mappers need to inherit from the xgmml.style.style_mapper.StyleColorContinuousMapper class:
class StyleColorContinuousMapper(StyleMapper):
def __init__(
self, values: list, colormap: mpl.colors.LinearSegmentedColormap, **kwargs
):
super(StyleColorContinuousMapper, self).__init__(values)
self._colormap = colormap
self._normalizer = mpl.colors.Normalize(vmin=min(values), vmax=max(values))
def map(self, value):
color = self._colormap(self._normalizer(value))
return mpl.colors.to_hex(color).upper()
Among them, values is a list of discrete values, and colormap is an instance of mpl.colors.ListedColormap of matplotlib.
Passthrough mapper¶
A passthrough mapper is a mapper that does not perform any mapping and directly returns the original value: