Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,22 @@
.DS_Store
temp/

.vscode/

.idea/


# IntelliJ Stuff
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/


# Windows
thumbs.db
desktop.ini
3 changes: 3 additions & 0 deletions examples/ex07.bom.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Item Qty Unit Designators
Connector, Stewart Connector SS-37000-002, male, 8 pins 2 X1, X2
Cable, 8 x 24 AWG 1 m W1
34 changes: 34 additions & 0 deletions examples/ex07.gv
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
graph {
// Graph generated by WireViz
// https://github.com/formatc1702/WireViz
graph [bgcolor="#fffbf8" fontname=arial nodesep=0.33 rankdir=LR ranksep=2]
node [fillcolor=white fontname=arial shape=record style=filled]
edge [fontname=arial style=bold]
X1 [label="X1|{Stewart Connector SS-37000-002|male|8-pin}|{{DA+|DA-|DB+|DC+|DC-|DB-|DD+|DD-}|{<p1r>1|<p2r>2|<p3r>3|<p4r>4|<p5r>5|<p6r>6|<p7r>7|<p8r>8}}"]
X2 [label="X2|{Stewart Connector SS-37000-002|male|8-pin}|{{<p1l>1|<p2l>2|<p3l>3|<p4l>4|<p5l>5|<p6l>6|<p7l>7|<p8l>8}|{DB+|DB-|DA+|DD+|DD-|DA-|DC+|DC-}}"]
edge [color="#000000:#ffffff:#00ff00:#ffffff:#000000"]
X1:p1r:e -- W1:w1:w
W1:w1:e -- X2:p3l:w
edge [color="#000000:#00ff00:#000000"]
X1:p2r:e -- W1:w2:w
W1:w2:e -- X2:p6l:w
edge [color="#000000:#ffffff:#ff8000:#ffffff:#000000"]
X1:p3r:e -- W1:w3:w
W1:w3:e -- X2:p1l:w
edge [color="#000000:#0066ff:#000000"]
X1:p4r:e -- W1:w4:w
W1:w4:e -- X2:p7l:w
edge [color="#000000:#ffffff:#0066ff:#ffffff:#000000"]
X1:p5r:e -- W1:w5:w
W1:w5:e -- X2:p8l:w
edge [color="#000000:#ff8000:#000000"]
X1:p6r:e -- W1:w6:w
W1:w6:e -- X2:p2l:w
edge [color="#000000:#ffffff:#a52a2a:#ffffff:#000000"]
X1:p7r:e -- W1:w7:w
W1:w7:e -- X2:p4l:w
edge [color="#000000:#a52a2a:#000000"]
X1:p8r:e -- W1:w8:w
W1:w8:e -- X2:p5l:w
W1 [label=<<table border="0" cellspacing="0" cellpadding="0"><tr><td><table border="0" cellspacing="0" cellpadding="3" cellborder="1"><tr><td colspan="3">W1</td></tr><tr><td>8x</td><td>24 AWG</td><td>1 m</td></tr></table></td></tr><tr><td>&nbsp;</td></tr><tr><td><table border="0" cellspacing="0" cellborder="0"><tr><td>X1:1</td><td>WHGN</td><td>X2:3</td></tr><tr><td colspan="3" cellpadding="0" height="6" bgcolor="#ffffff:#00ff00" border="2" sides="tb" port="w1"></td></tr><tr><td>X1:2</td><td>GN</td><td>X2:6</td></tr><tr><td colspan="3" cellpadding="0" height="6" bgcolor="#00ff00" border="2" sides="tb" port="w2"></td></tr><tr><td>X1:3</td><td>WHOG</td><td>X2:1</td></tr><tr><td colspan="3" cellpadding="0" height="6" bgcolor="#ffffff:#ff8000" border="2" sides="tb" port="w3"></td></tr><tr><td>X1:4</td><td>BU</td><td>X2:7</td></tr><tr><td colspan="3" cellpadding="0" height="6" bgcolor="#0066ff" border="2" sides="tb" port="w4"></td></tr><tr><td>X1:5</td><td>WHBU</td><td>X2:8</td></tr><tr><td colspan="3" cellpadding="0" height="6" bgcolor="#ffffff:#0066ff" border="2" sides="tb" port="w5"></td></tr><tr><td>X1:6</td><td>OG</td><td>X2:2</td></tr><tr><td colspan="3" cellpadding="0" height="6" bgcolor="#ff8000" border="2" sides="tb" port="w6"></td></tr><tr><td>X1:7</td><td>WHBN</td><td>X2:4</td></tr><tr><td colspan="3" cellpadding="0" height="6" bgcolor="#ffffff:#a52a2a" border="2" sides="tb" port="w7"></td></tr><tr><td>X1:8</td><td>BN</td><td>X2:5</td></tr><tr><td colspan="3" cellpadding="0" height="6" bgcolor="#a52a2a" border="2" sides="tb" port="w8"></td></tr><tr><td>&nbsp;</td></tr></table></td></tr></table>> fillcolor=white margin=0 shape=box style=""]
}
298 changes: 298 additions & 0 deletions examples/ex07.html

Large diffs are not rendered by default.

Binary file added examples/ex07.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
297 changes: 297 additions & 0 deletions examples/ex07.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions examples/ex07.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Example 7: Crossover Cable
connectors:
X1:
type: Stewart Connector SS-37000-002
subtype: male
pinout: [DA+,DA-,DB+,DC+,DC-,DB-,DD+,DD-] # pincount is implicit in pinout
X2:
type: Stewart Connector SS-37000-002
subtype: male
pinout: [DB+,DB-,DA+,DD+,DD-,DA-,DC+,DC-]

cables:
W1:
color_code: T568A # auto-color wires based on a standard
wirecount: 8 # need to specify number of wires explicitly when using a color code
gauge: 24 AWG # also accepts AWG as unit
length: 1 # length in m
shield: false
type: CAT5e

connections:
- - X1: [1-8]
- W1: [1-8]
- X2: [3,6,1,7,8,2,4,5] # crossover
4 changes: 4 additions & 0 deletions examples/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@

[Source](ex06.yml) - [Bill of Materials](ex06.bom.tsv)

## Example 07
![](ex07.png)

[Source](ex07.yml) - [Bill of Materials](ex07.bom.tsv)

14 changes: 8 additions & 6 deletions src/wireviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ def create_graph(self):
dot.body.append('// Graph generated by WireViz')
dot.body.append('// https://github.com/formatc1702/WireViz')
font = 'arial'
bgcolor = wv_colors.default_bknd_color
dot.attr('graph', rankdir='LR',
ranksep='2',
bgcolor='white',
bgcolor=bgcolor,
nodesep='0.33',
fontname=font)
dot.attr('node', shape='record',
Expand Down Expand Up @@ -141,7 +142,7 @@ def create_graph(self):
for bla in p:
html = html + '<td>{}</td>'.format(bla)
html = html + '</tr>'
bgcolor = wv_colors.translate_color(x, 'hex')
bgcolor = ":".join(wv_colors.translate_color(x, 'hex').split(':')[:2])
html = html + '<tr><td colspan="{colspan}" cellpadding="0" height="6" bgcolor="{bgcolor}" border="2" sides="tb" port="{port}"></td></tr>'.format(colspan=len(p), bgcolor=bgcolor if bgcolor != '' else '#ffffff', port='w{}'.format(i))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest changing height="6" to height="10" for two-colored wires to match the extra thickness of the connecting curved wires. The thickness seems to be 2x the number of color stripes (black edge + base color + stripe color + base color + black edge).

Copy link
Collaborator

@kvid kvid Jun 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An even better improvement (to avoid the color gradient) is to build the striped wire using multiple HTML rows with the port attribute only present in the middle row for each wire. See this excerpt from the upper wire in ex07.gv where the black edges are separated rows:

<tr><td colspan="3" cellpadding="0" height="2" bgcolor="#000000" border="0" sides="tb"></td></tr>
<tr><td colspan="3" cellpadding="0" height="6" color="#ffffff" bgcolor="#00ff00" border="2" sides="tb" port="w1">
<tr><td colspan="3" cellpadding="0" height="2" bgcolor="#000000" border="0" sides="tb"></td></tr>

It might be easier to to use one row (with no border) for each color in the generic case with multiple stripes.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SVG provides dashes ( https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dasharray ) which provide a simple and clean way to add this. Draw a solid wire then a dashed wire.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just saw your changes, if you are able to, please check out my solution and let me knnow if you have any comments. I will try to review your pull request shortly.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just created this PR: aakatz3#4 with my suggested implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@njhurst While it would be nice to do this, there is a problem: Graphviz does not support this properly. When drawing dashed lines, you cannot specify an alternate color, and you can't seem to overlay them properly. One COULD modify the SVG after the fact, but it breaks compatibility with GraphViz


if c.shield:
Expand All @@ -168,10 +169,10 @@ def create_graph(self):
for x in c.connections:
if isinstance(x.via_port, int): # check if it's an actual wire and not a shield
search_color = c.colors[x.via_port-1]
if search_color in wv_colors.color_hex:
dot.attr('edge',color='#000000:{wire_color}:#000000'.format(wire_color=wv_colors.color_hex[search_color]))
else: # color name not found
dot.attr('edge',color='#000000:#ffffff:#000000')
# if search_color in wv_colors.color_hex:
dot.attr('edge',color='#000000:{wire_color}:#000000'.format(wire_color=wv_colors.get_color_hex(search_color)))
# else: # color name not found
# dot.attr('edge',color='#000000:#ffffff:#000000')
else: # it's a shield connection
dot.attr('edge',color='#000000')

Expand Down Expand Up @@ -230,6 +231,7 @@ def output(self, filename, directory='_output', view=False, cleanup=True, format

file.write('</body></html>')

# TODO: add support for types of cables / Part Numbers
def bom(self):
bom = []
bom_connectors = []
Expand Down
132 changes: 89 additions & 43 deletions src/wv_colors.py
Original file line number Diff line number Diff line change
@@ -1,54 +1,100 @@
COLOR_CODES = {
'DIN': ['WH','BN','GN','YE','GY','PK','BU','RD','BK','VT'], # ,'GYPK','RDBU','WHGN','BNGN','WHYE','YEBN','WHGY','GYBN','WHPK','PKBN'],
'IEC': ['BN','RD','OG','YE','GN','BU','VT','GY','WH','BK'],
'BW': ['BK','WH']
}
'DIN': ['WH', 'BN', 'GN', 'YE', 'GY', 'PK', 'BU', 'RD', 'BK', 'VT', 'GYPK', 'RDBU', 'WHGN', 'BNGN', 'WHYE', 'YEBN',
'WHGY', 'GYBN', 'WHPK', 'PKBN', 'WHBU', 'BNBU', 'WHRD', 'BNRD', 'WHBK', 'BNBK', 'GYGN', 'YEGY', 'PKGN',
'YEPK', 'GNBU', 'YEBU', 'GNRD', 'YERD', 'GNBK', 'YEBK', 'GYBU', 'PKBU', 'GYRD', 'PKRD', 'GYBK', 'PKBK',
'BUBK', 'RDBK', 'WHBNBK', 'YEGNBK', 'GYPKBK', 'RDBUBK', 'WHGNBK', 'BNGNBK', 'WHYEBK', 'YEBNBK', 'WHGYBK',
'GYBNBK', 'WHPKBK', 'PKBNBK', 'WHBUBK', 'BNBUBK', 'WHRDBK', 'BNRDBK'],
'IEC': ['BN', 'RD', 'OG', 'YE', 'GN', 'BU', 'VT', 'GY', 'WH', 'BK'],
'BW': ['BK', 'WH'],
'TEL': ['BUWH', 'WHBU', 'OGWH', 'WHOG', 'GNWH', 'WHGN', 'BNWH', 'WHBN', 'SLWH', 'WHSL', 'BURD', 'RDBU', 'OGRD',
'RDOG', 'GNRD', 'RDGN', 'BNRD', 'RDBN', 'SLRD', 'RDSL', 'BUBK', 'BKBU', 'OGBK', 'BKOG', 'GNBK', 'BKGN',
'BNBK', 'BKBN', 'SLBK', 'BKSL', 'BUYW', 'YWBU', 'OGYW', 'YWOG', 'GNYW', 'YWGN', 'BNYW', 'YWBN', 'SLYW',
'YWSL', 'BUVT', 'VTBU', 'OGVT', 'VTOG', 'GNVT', 'VTGN', 'BNVT', 'VTBN', 'SLVT', 'VTSL'],
'TELALT': ['WHBU', 'BU', 'WHOG', 'OG', 'WHGN', 'GN', 'WHBN', 'BN', 'WHSL', 'SL', 'RDBU', 'BURD', 'RDOG', 'OGRD',
'RDGN', 'GNRD', 'RDBN', 'BNRD', 'RDSL', 'SLRD', 'BKBU', 'BUBK', 'BKOG', 'OGBK', 'BKGN', 'GNBK', 'BKBN',
'BNBK', 'BKSL', 'SLBK', 'YWBU', 'BUYW', 'YWOG', 'OGYW', 'YWGN', 'GNYW', 'YWBN', 'BNYW', 'YWSL', 'SLYW',
'VTBU', 'BUVT', 'VTOG', 'OGVT', 'VTGN', 'GNVT', 'VTBN', 'BNVT', 'VTSL', 'SLVT'],
'T568A': ['WHGN', 'GN', 'WHOG', 'BU', 'WHBU', 'OG', 'WHBN', 'BN'],
'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

color_hex = {
'BK': '#000000',
'WH': '#ffffff',
'GY': '#999999',
'PK': '#ff66cc',
'RD': '#ff0000',
'OG': '#ff8000',
'YE': '#ffff00',
'GN': '#00ff00',
'TQ': '#00ffff',
'BU': '#0066ff',
'VT': '#8000ff',
'BN': '#666600',
}
'BK': '#000000',
'WH': '#ffffff',
'GY': '#999999',
'PK': '#ff66cc',
'RD': '#ff0000',
'OG': '#ff8000',
'YE': '#ffff00',
'GN': '#00ff00',
'TQ': '#00ffff',
'BU': '#0066ff',
'VT': '#8000ff',
'BN': '#a52a2a',
'SL': '#708090',
# Faux-copper look, for bare CU wire
'CU': '#d6775e:#895956',
# Silvery look for tinned bare wire
'TI': '#aaaaaa:#84878c',
# Yellow-green PE wire
'PE': '#54aa85:#f7f854:#54aa85',
}

# TODO: Add a helper method for this, that can deal with banded wires
color_full = {
'BK': 'black',
'WH': 'white',
'GY': 'grey',
'PK': 'pink',
'RD': 'red',
'OG': 'orange',
'YE': 'yellow',
'GN': 'green',
'TQ': 'turquoise',
'BU': 'blue',
'VT': 'violet',
'BN': 'brown',
'BK': 'black',
'WH': 'white',
'GY': 'grey',
'PK': 'pink',
'RD': 'red',
'OG': 'orange',
'YE': 'yellow',
'GN': 'green',
'TQ': 'turquoise',
'BU': 'blue',
'VT': 'violet',
'BN': 'brown',
'SL': 'slate',
'CU': 'bare copper',
'TI': 'tinned copper',
}

# TODO Help wanted! Need help translating colors/banded colors to german shortcodes
color_ger = {
'BK': 'sw',
'WH': 'ws',
'GY': 'gr',
'PK': 'rs',
'RD': 'rt',
'OG': 'or',
'YE': 'ge',
'GN': 'gn',
'TQ': 'tk',
'BU': 'bl',
'VT': 'vi',
'BN': 'br',
'BK': 'sw',
'WH': 'ws',
'GY': 'gr',
'PK': 'rs',
'RD': 'rt',
'OG': 'or',
'YE': 'ge',
'GN': 'gn',
'TQ': 'tk',
'BU': 'bl',
'VT': 'vi',
'BN': 'br',
}


def get_color_hex(input):
if len(input) == 4: # give wires with EXACTLY 2 colors that striped/banded look
input = input + input[:2]
output = ''
for i in range(0, len(input), 2): # Split into 2 letter chunks
if input[i:i + 2] in color_hex:
output += color_hex[input[i:i + 2]]
if i + 2 != len(input):
output += ':'
if output == '':
output = _default_color
return output


def translate_color(input, color_mode):
if input == '':
output = ''
Expand All @@ -58,9 +104,9 @@ def translate_color(input, color_mode):
elif color_mode == 'FULL':
output = color_full[input].upper()
elif color_mode == 'hex':
output = color_hex[input].lower()
output = get_color_hex(input).lower()
elif color_mode == 'HEX':
output = color_hex[input].upper()
output = get_color_hex(input).upper()
elif color_mode == 'ger':
output = color_ger[input].lower()
elif color_mode == 'GER':
Expand Down