Skip to content

Commit

Permalink
Update graph styles
Browse files Browse the repository at this point in the history
- Increase item height to 30px
- Increase icon size to 20px
- Update colours of edges, arrows, and default text / outlines
- Update spacing of elements in node labels
- Avoid duplicating the marker (arrow) definition
- Update arrow definition to produce a cleaner shape when zoomed
- Set fixed width for nodes at 200px
- Switch to center truncation on long labels
  • Loading branch information
AlanGreene committed Dec 6, 2019
1 parent 0ea273a commit 8a5948f
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 45 deletions.
32 changes: 17 additions & 15 deletions packages/components/src/components/Graph/Graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default class Graph extends Component {
'org.eclipse.elk.layered.spacing.nodeNodeBetweenLayers': isSubGraph
? 0
: 40,
'org.eclipse.elk.padding': '[top=26,left=0,bottom=1,right=0]',
'org.eclipse.elk.padding': '[top=30,left=0,bottom=1,right=0]',
'org.eclipse.elk.separateConnectedComponents': false,
'org.eclipse.elk.spacing.nodeNode': isSubGraph ? 0 : 40
}
Expand Down Expand Up @@ -83,20 +83,22 @@ export default class Graph extends Component {
viewBox={`0 0 ${width} ${height}`}
preserveAspectRatio="xMidYMin meet"
>
<defs>
<marker
id="edge-arrow"
viewBox="0 -5 10 10"
markerUnits="strokeWidth"
markerWidth="8.4"
markerHeight="14"
orient="auto"
refY="0"
refX="10"
>
<path d="M0,-5L10,0L0,5" />
</marker>
</defs>
{!isSubGraph && (
<defs>
<marker
id="edge-arrow"
viewBox="0 0 100 100"
markerUnits="strokeWidth"
markerWidth="10"
markerHeight="14"
orient="auto"
refY="50"
refX="86"
>
<path d="M 0 0 L100 50 L 0 100" />
</marker>
</defs>
)}
<VXGraph
graph={{ links, nodes }}
nodeComponent={c => (
Expand Down
10 changes: 5 additions & 5 deletions packages/components/src/components/Graph/Graph.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

$edge-color: #979797;
$edge-color: #8d8d8d;

.graph {
#edge-arrow path {
Expand All @@ -27,19 +27,19 @@ $edge-color: #979797;
.Task {
rect {
fill: #FFFFFF;
stroke: #979797;
stroke: #8d8d8d;
}

.label-hitbox {
stroke: transparent;
}

text {
fill: #6F6F6F;
fill: #8d8d8d;
}

.chevron {
fill: #565656;
.chevron, .status-icon {
fill: #8d8d8d;
}
}

Expand Down
6 changes: 3 additions & 3 deletions packages/components/src/components/Graph/Graph.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const taskProps = {
type: 'Task',
label: 'build-and-push',
width: 160,
height: 26
height: 30
};

const expandedProps = {
Expand All @@ -51,14 +51,14 @@ const expandedProps = {
id: '__step_build-and-push__build-image',
label: 'build-image',
width: 160,
height: 26
height: 30
},
{
type: 'Step',
id: '__step_build-and-push__push-image',
label: 'push-image',
width: 160,
height: 26
height: 30
}
],
edges: [],
Expand Down
27 changes: 16 additions & 11 deletions packages/components/src/components/Graph/Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ limitations under the License.
import React, { Component } from 'react';
import classNames from 'classnames';

import CheckmarkFilled from '@carbon/icons-react/lib/checkmark--filled/16';
import ChevronDown from '@carbon/icons-react/lib/chevron--down/16';
import ChevronUp from '@carbon/icons-react/lib/chevron--up/16';
import CloseFilled from '@carbon/icons-react/lib/close--filled/16';
import Undefined from '@carbon/icons-react/lib/undefined/16';
import CheckmarkFilled from '@carbon/icons-react/lib/checkmark--filled/20';
import ChevronDown from '@carbon/icons-react/lib/chevron--down/20';
import ChevronUp from '@carbon/icons-react/lib/chevron--up/20';
import CloseFilled from '@carbon/icons-react/lib/close--filled/20';
import Undefined from '@carbon/icons-react/lib/undefined/20';

import Graph from './Graph'; // eslint-disable-line import/no-cycle
import InlineLoading from './InlineLoading';
Expand Down Expand Up @@ -66,16 +66,21 @@ export default class Node extends Component {
StatusIcon = <StatusIcon className="status-icon" x="8" y="5" />;
}

const maxLabelLength = 24;
const maxLabelLength = 19;
let labelText = label;
if (label.length > maxLabelLength) {
labelText = `${label.substring(0, maxLabelLength)}\u2026`;
const charDisplay = maxLabelLength - 1;
const labelStart = label.substring(0, Math.ceil(charDisplay / 2));
const labelEnd = label.substring(
label.length - Math.floor(charDisplay / 2)
);
labelText = `${labelStart}\u2026${labelEnd}`;
}

let labelPosition = {
textAnchor: 'start',
x: 30,
y: 18
x: 36,
y: 20
};

if (type === 'Start' || type === 'End') {
Expand All @@ -91,7 +96,7 @@ export default class Node extends Component {
x: isSelected ? 0 : 1,
y: isSelected ? 0 : 1,
width: isSelected ? width : width - 2,
height: isSelected ? 26 : 24
height: isSelected ? 30 : 28
};

const Chevron = children ? ChevronUp : ChevronDown;
Expand Down Expand Up @@ -120,7 +125,7 @@ export default class Node extends Component {
{StatusIcon}
<text {...labelPosition}>{labelText}</text>
{type === 'Task' && (
<Chevron className="chevron" x={width - 22} y="5" />
<Chevron className="chevron" x={width - 28} y="5" />
)}
</g>
{children && (
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/components/Graph/NodeLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const NodeLink = ({ link }) => {
path.moveTo(startX, startY);
path.lineTo(startX, startY + (targetY - startY) * percent);
path.lineTo(targetX, startY + (targetY - startY) * percent);
path.lineTo(targetX, targetY);
path.lineTo(targetX, targetY - 1); // stop short to prevent it showing around the arrow tip

return (
<path strokeWidth={1} fill="none" strokeOpacity={1} d={path.toString()} />
Expand Down
14 changes: 4 additions & 10 deletions packages/utils/src/utils/buildGraphData.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ limitations under the License.
/* istanbul ignore file */
import { getStatus } from './status';

const defaultHeight = 26;
const defaultCharWidth = 9;
const defaultHeight = 30;
const defaultWidth = 200;

function getBaseNodes() {
const graph = {
Expand Down Expand Up @@ -149,20 +149,14 @@ function addNodes({ expanded, graph, pipeline, pipelineRun, tasks }) {
task.spec.steps &&
task.spec.steps.length > 0
) {
const parentWidth = taskRef.name.length * defaultCharWidth + 40;
const subgraph = {
id: taskRef.name,
label: taskRef.name,
children: task.spec.steps.map(step => {
let stepWidth = step.name.length * defaultCharWidth + 40;
if (stepWidth < parentWidth) {
stepWidth = parentWidth;
}

const stepNode = {
id: `__step__${taskRef.name}__${step.name}`,
label: step.name,
width: stepWidth,
width: defaultWidth,
height: defaultHeight,
nChildren: 0,
nParents: 0,
Expand Down Expand Up @@ -190,7 +184,7 @@ function addNodes({ expanded, graph, pipeline, pipelineRun, tasks }) {
node = {
id: taskRef.name,
label: taskRef.name,
width: taskRef.name.length * defaultCharWidth + 40,
width: defaultWidth,
height: defaultHeight,
nChildren: 0,
nParents: 0,
Expand Down

0 comments on commit 8a5948f

Please sign in to comment.