Skip to content

Commit

Permalink
Fine-tune multicolor wire PR
Browse files Browse the repository at this point in the history
- Remove modified background color -> should be discusses as a separate feature
- Render shields as thin tinned wire with black border, safer for b&w priting than single light-gray line
- Remove PE as color definition, since it is not, and should be called with GNYE
- Clean up minor things
  • Loading branch information
formatc1702 committed Jul 18, 2020
1 parent feee3c0 commit 8e680ee
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 46 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import os
from setuptools import setup, find_packages
Expand Down
8 changes: 3 additions & 5 deletions src/wireviz/Harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def create_graph(self) -> Graph:
font = 'arial'
dot.attr('graph', rankdir='LR',
ranksep='2',
bgcolor=wv_colors.default_bknd_color,
bgcolor='white',
nodesep='0.33',
fontname=font)
dot.attr('node', shape='record',
Expand Down Expand Up @@ -203,7 +203,6 @@ def create_graph(self) -> Graph:
html = f'{html}<td>{bla}</td>'
html = f'{html}</tr>'


bgcolors = ['#000000'] + get_color_hex(connection_color) + ['#000000']
html = f'{html}<tr><td colspan="{len(p)}" border="0" cellspacing="0" cellpadding="0" port="w{i}" height="{(2 * len(bgcolors))}"><table cellspacing="0" cellborder="0" border = "0">'
for j, bgcolor in enumerate(bgcolors[::-1]): # Reverse to match the curved wires when more than 2 colors
Expand All @@ -224,7 +223,6 @@ def create_graph(self) -> Graph:
for attrib in wireidentification:
html = f'{html}<td>{attrib}</td>'
html = f'{html}</tr></table></td></tr>'
# html = html + '</table></td></tr>'

if cable.shield:
p = ['<!-- s_in -->', 'Shield', '<!-- s_out -->']
Expand All @@ -251,8 +249,8 @@ def create_graph(self) -> Graph:
if isinstance(connection_color.via_port, int): # check if it's an actual wire and not a shield
dot.attr('edge', color=':'.join(['#000000'] + wv_colors.get_color_hex(cable.colors[connection_color.via_port - 1]) + ['#000000']))
else: # it's a shield connection
dot.attr('edge', color='#000000')

# shield is shown as a thin tinned wire
dot.attr('edge', color=':'.join(['#000000', wv_colors.get_color_hex('SN')[0], '#000000']))
if connection_color.from_port is not None: # connect to left
from_ferrule = self.connectors[connection_color.from_name].category == 'ferrule'
port = f':p{connection_color.from_port}r' if not from_ferrule else ''
Expand Down
57 changes: 16 additions & 41 deletions src/wireviz/wv_colors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

COLOR_CODES = {
Expand All @@ -22,15 +23,8 @@
'T568B': ['WHOG', 'OG', 'WHGN', 'BU', 'WHBU', 'GN', 'WHBN', 'BN'],
}

default_color = '#ffffff'

# default_bkgnd_color = '#ffffff' # white
default_bknd_color = '#fffbf8' # off-white beige-ish

# Convention: Color names should be 2 letters long, to allow for multicolored wires

shield_color = '#aaaaaa' # Tinned wire

_color_hex = {
'BK': '#000000',
'WH': '#ffffff',
Expand All @@ -45,16 +39,10 @@
'VT': '#8000ff',
'BN': '#895956',
'SL': '#708090',
# Faux-copper look, for bare CU wire
'CU': '#d6775e',
# Silvery look for tinned bare wire
'SN': '#aaaaaa',
# Darker silver for silvered wire
'AG': '#84878c',
# Golden color for gold
'AU': '#ffcf80',
# Yellow-green PE wire (matching actual wire colors, should prevent confusion with a yellow-green dual color wire
'PE': '#54aa85:#f7f854:#54aa85',
'CU': '#d6775e', # Faux-copper look, for bare CU wire
'SN': '#aaaaaa', # Silvery look for tinned bare wire
'AG': '#84878c', # Darker silver for silvered wire
'AU': '#ffcf80', # Golden color for gold
}

_color_full = {
Expand All @@ -75,10 +63,8 @@
'SN': 'tinned copper',
'AG': 'silver wire',
'AU': 'gold wire',
'PE': 'earth'
}

# TODO Help wanted: can someone check the german translation?
_color_ger = {
'BK': 'sw',
'WH': 'ws',
Expand All @@ -92,28 +78,20 @@
'BU': 'bl',
'VT': 'vi',
'BN': 'br',
# To the best of my ability, likely incorrect:

# Slate --> Schieferfarbe --> SI ??
'SL': 'si',
# Copper
'CU': 'cu',
# Tinned
'SN': 'sn',
# Silver
'AG': 'ag',
# Gold
'AU': 'au',
# Earth
'PE': 'pe'
'SL': 'si', # Slate/Schiefer?
'CU': 'ku', # Copper/Kupfer
'SN': 'vz', # Tinned/verzinkt
'AG': 'ag', # Silver
'AU': 'au', # Gold
}


color_default = '#ffffff'


def get_color_hex(input, pad=True):
if input is None or input == '':
# print('Unspecified color requested', file=sys.stderr)
return [default_color]
return [color_default]
if len(input) == 4: # give wires with EXACTLY 2 colors that striped/banded look
input = input + input[:2]
# hacky style fix: give single color wires a triple-up so that wires are the same size
Expand All @@ -122,16 +100,14 @@ def get_color_hex(input, pad=True):
try:
output = [_color_hex[input[i:i + 2]] for i in range(0, len(input), 2)]
except KeyError:
print("Unknown Color Specified", file=sys.stderr)
output = [default_color]
# raise Exception('Unknown Color Name')
print("Unknown color specified")
output = [color_default]
return output


def translate_color(input, color_mode):
if input == '' or input is None:
# print('Unspecified color requested', file=sys.stderr)
return default_color
return color_default
upper = color_mode.isupper()
if not (color_mode.isupper() or color_mode.islower()):
raise Exception('Unknown color mode capitalization')
Expand All @@ -151,4 +127,3 @@ def translate_color(input, color_mode):
return output.upper()
else:
return output.lower()

0 comments on commit 8e680ee

Please sign in to comment.