Added port numbers to port labels. Still needs fine tuning, but good enough for the demo.
Showing
2 changed files
with
44 additions
and
10 deletions
... | @@ -89,9 +89,9 @@ | ... | @@ -89,9 +89,9 @@ |
89 | marginLR: 3, | 89 | marginLR: 3, |
90 | marginTB: 2, | 90 | marginTB: 2, |
91 | port: { | 91 | port: { |
92 | - gap: 2, | 92 | + gap: 3, |
93 | - width: 12, | 93 | + width: 18, |
94 | - height: 12 | 94 | + height: 14 |
95 | } | 95 | } |
96 | }, | 96 | }, |
97 | icons: { | 97 | icons: { |
... | @@ -315,6 +315,7 @@ | ... | @@ -315,6 +315,7 @@ |
315 | portLabelsOn = !portLabelsOn; | 315 | portLabelsOn = !portLabelsOn; |
316 | var portVis = portLabelsOn ? 'visible' : 'hidden'; | 316 | var portVis = portLabelsOn ? 'visible' : 'hidden'; |
317 | d3.selectAll('.port').style('visibility', portVis); | 317 | d3.selectAll('.port').style('visibility', portVis); |
318 | + d3.selectAll('.portText').style('visibility', portVis); | ||
318 | } | 319 | } |
319 | 320 | ||
320 | function unpin() { | 321 | function unpin() { |
... | @@ -577,30 +578,46 @@ | ... | @@ -577,30 +578,46 @@ |
577 | class: 'portLayer' | 578 | class: 'portLayer' |
578 | }); | 579 | }); |
579 | 580 | ||
580 | - var portVis = portLabelsOn ? 'visible' : 'hidden'; | 581 | + var portVis = portLabelsOn ? 'visible' : 'hidden', |
582 | + pw = config.labels.port.width, | ||
583 | + ph = config.labels.port.height; | ||
581 | 584 | ||
582 | network.link.filter('.infra').each(function(d, i) { | 585 | network.link.filter('.infra').each(function(d, i) { |
583 | network.linkSrcPort.append('rect').attr({ | 586 | network.linkSrcPort.append('rect').attr({ |
584 | id: 'srcPort-' + d.id, | 587 | id: 'srcPort-' + d.id, |
585 | class: 'port', | 588 | class: 'port', |
586 | - width: 12, | 589 | + width: pw, |
587 | - height: 12, | 590 | + height: ph, |
588 | x: i * 20, | 591 | x: i * 20, |
589 | y: 0 | 592 | y: 0 |
590 | }) | 593 | }) |
591 | - .style('visibility', portVis) | 594 | + .style('visibility', portVis); |
592 | - .append('text').text(d.srcPort); | ||
593 | 595 | ||
594 | network.linkTgtPort.append('rect').attr({ | 596 | network.linkTgtPort.append('rect').attr({ |
595 | id: 'tgtPort-' + d.id, | 597 | id: 'tgtPort-' + d.id, |
596 | class: 'port', | 598 | class: 'port', |
597 | - width: 12, | 599 | + width: pw, |
598 | - height: 12, | 600 | + height: ph, |
599 | x: i * 20, | 601 | x: i * 20, |
600 | y: 20 | 602 | y: 20 |
601 | }) | 603 | }) |
602 | .style('visibility', portVis); | 604 | .style('visibility', portVis); |
603 | 605 | ||
606 | + network.linkSrcPort.append('text').attr({ | ||
607 | + id: 'srcText-' + d.id, | ||
608 | + class: 'portText', | ||
609 | + x: i * 20, | ||
610 | + y:0 | ||
611 | + }).text(d.srcPort) | ||
612 | + .style('visibility', portVis); | ||
613 | + | ||
614 | + network.linkTgtPort.append('text').attr({ | ||
615 | + id: 'tgtText-' + d.id, | ||
616 | + class: 'portText', | ||
617 | + x: i * 20, | ||
618 | + y:20 | ||
619 | + }).text(d.tgtPort) | ||
620 | + .style('visibility', portVis); | ||
604 | }); | 621 | }); |
605 | 622 | ||
606 | // ............................................................... | 623 | // ............................................................... |
... | @@ -982,6 +999,15 @@ | ... | @@ -982,6 +999,15 @@ |
982 | .attr('x', pxt - portHalfW) | 999 | .attr('x', pxt - portHalfW) |
983 | .attr('y', pyt - portHalfH); | 1000 | .attr('y', pyt - portHalfH); |
984 | 1001 | ||
1002 | + // TODO: fit label rect to size of port number. | ||
1003 | + d3.select('#srcText-' + d.id) | ||
1004 | + .attr('x', pxs - 5) | ||
1005 | + .attr('y', pys + 3); | ||
1006 | + | ||
1007 | + d3.select('#tgtText-' + d.id) | ||
1008 | + .attr('x', pxt - 5) | ||
1009 | + .attr('y', pyt + 3); | ||
1010 | + | ||
985 | }); | 1011 | }); |
986 | 1012 | ||
987 | // position each node by translating the node (group) by x,y | 1013 | // position each node by translating the node (group) by x,y | ... | ... |
... | @@ -112,6 +112,14 @@ svg g.portLayer rect.port { | ... | @@ -112,6 +112,14 @@ svg g.portLayer rect.port { |
112 | fill: white; | 112 | fill: white; |
113 | } | 113 | } |
114 | 114 | ||
115 | +svg g.portLayer text { | ||
116 | + stroke: #888; | ||
117 | + font-size: 8pt; | ||
118 | + text-align: center; | ||
119 | + font-weight: normal; | ||
120 | + pointer-events: none; | ||
121 | +} | ||
122 | + | ||
115 | svg .node.device rect { | 123 | svg .node.device rect { |
116 | stroke-width: 1.5px; | 124 | stroke-width: 1.5px; |
117 | 125 | ... | ... |
-
Please register or login to post a comment