Add option to keep null values in generated options
See original GitHub issueDespite the big effort made in pyecharts, it normal to find ECharts options unavailable using pyecharts classes. This is where the _option
attribute becomes helpful (is there a better way?). Sometimes an ECharts option needs to be set to null
as in the example below when setting a candlestick chart.
itemStyle: {
normal: {
color: '#06B800',
color0: '#FA0000',
borderColor: null,
borderColor0: null
}
}
When adding these keys to _option
, the keys whose value is None
are removes from the generated options because of the following code in the Base
class:
@property
def options(self):
return utils.remove_key_with_none_value(self._option)
Also this makes it harder when there’s a lot of work needs to be done with _option
as the removed keys need to be recreated first. For example, in the example above itemStyle
needed to be created first, then the dictionary value assigned ({'normal' : { 'color': ...} }
) assigned instead of accessing individual keys.
Is there a way to handle this? if not, I suggest adding an option to preserve null
values in the generated options such as:
bar = Bar(remove_none_options=True)
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (3 by maintainers)
Top GitHub Comments
OK. Just checked the options documentation, if pyecharts omits both options,
borderColor
defaults to #c23531 andborderColor0
defaults to #314656.So I would propose that pyecharts provides ‘NULL’ definition to signal that the key should be present and with value ‘null’ in js/html. In this way, remove_key_with_none_value() will ignore
NULL
ed keys.Great. What do you think the best value that
NOT_SET
should take? I think NumPy’s way of usingnan
is good if there’s no other safe value in mind. As show in numpy.nan’s documentation, it is “IEEE 754 floating point representation of Not a Number (NaN)”. In this case,is_not_set()
could be the equivalent of NumPy’sisnan()
to test for unassigned options.