|
| 1 | +from typing import Optional |
| 2 | + |
| 3 | +from validator_collection import validators |
| 4 | + |
| 5 | +from highcharts_core import errors |
1 | 6 | from highcharts_core.options.plot_options.dependencywheel import DependencyWheelOptions |
2 | 7 |
|
3 | 8 |
|
@@ -28,4 +33,108 @@ class SankeyOptions(DependencyWheelOptions): |
28 | 33 | :align: center |
29 | 34 |
|
30 | 35 | """ |
31 | | - pass |
| 36 | + def __init__(self, **kwargs): |
| 37 | + self._link_color_mode = None |
| 38 | + |
| 39 | + self.link_color_mode = kwargs.get('link_color_mode', None) |
| 40 | + |
| 41 | + super().__init__(**kwargs) |
| 42 | + |
| 43 | + @property |
| 44 | + def link_color_mode(self) -> Optional[str]: |
| 45 | + """Determines color mode for sankey links. |
| 46 | + |
| 47 | + Available options: |
| 48 | + |
| 49 | + * ``'from'`` - color of the sankey link will be the same as the ``.from`` node |
| 50 | + * ``'gradient'`` - color of the sankey link will be set to gradient between |
| 51 | + colors of the ``.from`` node and the ``.to`` node |
| 52 | + * ``'to'`` - color of the sankey link will be same as the ``.to`` |
| 53 | + |
| 54 | + Defaults to ``'from'``. |
| 55 | + |
| 56 | + :rtype: :class:`str <python:str>` or :obj:`None <python:None>` |
| 57 | + """ |
| 58 | + return self._link_color_mode |
| 59 | + |
| 60 | + @link_color_mode.setter |
| 61 | + def link_color_mode(self, value): |
| 62 | + if not value: |
| 63 | + self._link_color_mode = None |
| 64 | + else: |
| 65 | + value = validators.string(value) |
| 66 | + value = value.lower() |
| 67 | + if value not in ['from', 'gradient', 'to']: |
| 68 | + raise errors.HighchartsValueError( |
| 69 | + f'link_color_mode expects a value of either "from", ' |
| 70 | + f'"gradient", or "to". Received "{value}"') |
| 71 | + self._link_color_mode = value |
| 72 | + |
| 73 | + @classmethod |
| 74 | + def _get_kwargs_from_dict(cls, as_dict): |
| 75 | + kwargs = { |
| 76 | + 'accessibility': as_dict.get('accessibility', None), |
| 77 | + 'allow_point_select': as_dict.get('allowPointSelect', None), |
| 78 | + 'animation': as_dict.get('animation', None), |
| 79 | + 'class_name': as_dict.get('className', None), |
| 80 | + 'clip': as_dict.get('clip', None), |
| 81 | + 'color': as_dict.get('color', None), |
| 82 | + 'cursor': as_dict.get('cursor', None), |
| 83 | + 'custom': as_dict.get('custom', None), |
| 84 | + 'dash_style': as_dict.get('dashStyle', None), |
| 85 | + 'data_labels': as_dict.get('dataLabels', None), |
| 86 | + 'description': as_dict.get('description', None), |
| 87 | + 'enable_mouse_tracking': as_dict.get('enableMouseTracking', None), |
| 88 | + 'events': as_dict.get('events', None), |
| 89 | + 'include_in_data_export': as_dict.get('includeInDataExport', None), |
| 90 | + 'keys': as_dict.get('keys', None), |
| 91 | + 'label': as_dict.get('label', None), |
| 92 | + 'legend_symbol': as_dict.get('legendSymbol', None), |
| 93 | + 'linked_to': as_dict.get('linkedTo', None), |
| 94 | + 'marker': as_dict.get('marker', None), |
| 95 | + 'on_point': as_dict.get('onPoint', None), |
| 96 | + 'opacity': as_dict.get('opacity', None), |
| 97 | + 'point': as_dict.get('point', None), |
| 98 | + 'point_description_formatter': as_dict.get('pointDescriptionFormatter', None), |
| 99 | + 'selected': as_dict.get('selected', None), |
| 100 | + 'show_checkbox': as_dict.get('showCheckbox', None), |
| 101 | + 'show_in_legend': as_dict.get('showInLegend', None), |
| 102 | + 'skip_keyboard_navigation': as_dict.get('skipKeyboardNavigation', None), |
| 103 | + 'sonification': as_dict.get('sonification', None), |
| 104 | + 'states': as_dict.get('states', None), |
| 105 | + 'sticky_tracking': as_dict.get('stickyTracking', None), |
| 106 | + 'threshold': as_dict.get('threshold', None), |
| 107 | + 'tooltip': as_dict.get('tooltip', None), |
| 108 | + 'turbo_threshold': as_dict.get('turboThreshold', None), |
| 109 | + 'visible': as_dict.get('visible', None), |
| 110 | + |
| 111 | + 'border_color': as_dict.get('borderColor', None), |
| 112 | + 'border_width': as_dict.get('borderWidth', None), |
| 113 | + 'center': as_dict.get('center', None), |
| 114 | + 'center_in_category': as_dict.get('centerInCategory', None), |
| 115 | + 'color_by_point': as_dict.get('colorByPoint', None), |
| 116 | + 'color_index': as_dict.get('colorIndex', None), |
| 117 | + 'colors': as_dict.get('colors', None), |
| 118 | + 'curve_factor': as_dict.get('curveFactor', None), |
| 119 | + 'levels': as_dict.get('levels', None), |
| 120 | + 'link_opacity': as_dict.get('linkOpacity', None), |
| 121 | + 'min_link_width': as_dict.get('minLinkWidth', None), |
| 122 | + 'node_padding': as_dict.get('nodePadding', None), |
| 123 | + 'node_width': as_dict.get('nodeWidth', None), |
| 124 | + 'start_angle': as_dict.get('startAngle', None), |
| 125 | + |
| 126 | + 'link_color_mode': as_dict.get('linkColorMode', None), |
| 127 | + } |
| 128 | + |
| 129 | + return kwargs |
| 130 | + |
| 131 | + def _to_untrimmed_dict(self, in_cls = None) -> dict: |
| 132 | + untrimmed = { |
| 133 | + 'linkColorMode': self.link_color_mode, |
| 134 | + } |
| 135 | + parent_as_dict = super()._to_untrimmed_dict(in_cls = in_cls) |
| 136 | + |
| 137 | + for key in parent_as_dict: |
| 138 | + untrimmed[key] = parent_as_dict[key] |
| 139 | + |
| 140 | + return untrimmed |
0 commit comments