-
Notifications
You must be signed in to change notification settings - Fork 265
Description
Example
The following YAML input:
cables:
W1:
gauge: 0.25 mm2
length: 0.2
colors: [tomato, ge, 00FF00, BU]should be valid, and produce the following output:
Yes, tomato should be an accepted color because it's part of the official HTML color names 🍅
Motivation
Currently, wv_colors.py includes list of german color codes (e.g. ge for gelb=yellow), as well as full english color names, but there is no direct way to use them. It would be nice if German users could directly use the german color codes; the direct HTML color and hex options give unlimited flexibility to anybody who needs it; anybody who does not like abbreviations is not forced to use them, or see them in the output.
My proposal is to allow the following inputs:
- English color codes (RD)
- German color codes (rt)
- HTML color entities (red)
- Hex colors (FF0000)
I've chosen to exclude the # in the hex colors because YAML treats it as a comment delimiter, and \#FF0000 is less readable
The HTML color entities do not cause extra work because GraphViz understands them natively.
Implementation
The implementation should be quite straightforward.
In addition to a cable's colors list, a second htmlcolors list (or similar) is needed. Then, a simple parsing function parses the user's input, checking whether it's included in one of the color codes, and setting the appropriate htmlcolor, i.e. mapping RD to #ff0000 and ge to #ffff00, adding the missing # if a hex color was specified, and simply passing the input if it is neither of these (tomato). If the input is a completely unknown color, it will be rendered black (default GraphViz behavior) but the label will still show the input.
This means that the color parsing would happen in the cable's __post_init__() function, and all the GraphViz code generation would no longer use the translate_color() function, but read straight from the htmlcolors list.
Multicolor wires should be easy to include as well:
Keep allowing four- and six- letter combinations as input (GNYE, gnge, and possibly even 00FF00/FFFF00 and green/yellow) and expand them to a list while parsing.
The rendering code would check if the respective item in htmlcolors is a string (single color) or list (multicolor) and react accordingly.
cables:
W1:
gauge: 0.25 mm2
length: 0.2
colors: [GNYE, gnge, green/yellow, 00FF00/FFFF00, MysteryColor]
