vojtamolda / Plotly.swift

Interactive data visualization library for Swift
https://vojtamolda.github.io/Plotly.swift/
MIT License
82 stars 8 forks source link

Improve ColorScale with additional maps #6

Closed vojtamolda closed 4 years ago

vojtamolda commented 4 years ago

Implementation of the ColorScale enum currently lacks some of the options that are available in Python's plotly.express module. It would be nice to include these in the Swift version too.

Also since ColorScale is implemented as an enum it's not possible to write an extension that would define a new case. It would be better to transform it into a struct similar to OptionSet with static members. This achieves the same level of user convenience and is more flexible. This would also allow a new convinient constructor that would take an array of Colors and translate it into a map with equal distances between the colors.

For completeness here is the source code that holds the numeric values of the color-scales defined in the Python version:

https://github.com/plotly/plotly.py/blob/master/packages/python/plotly/_plotly_utils/colors/__init__.py https://github.com/plotly/plotly.py/blob/master/packages/python/plotly/_plotly_utils/colors/sequential.py

Another point worth considering is the support for categorical ColorScales. There's a nice discussion here.

vojtamolda commented 4 years ago

Color scales can be constructed from array or dict literals and there's a lot of new built-in color scales.

Sequential

Diverging

Ocean

Brewer

Carto

Plotly

vojtamolda commented 4 years ago

Categorical color scales will be implemented as ColorWay struct later. It doesn't fit the color scale paradigm that represents a smooth mapping.

Annoying angular and radial axes from the cyclical swatch can be removed only once #8 is fixed.

Cyclical