Skip to content

Commit

Permalink
Added edge arrows
Browse files Browse the repository at this point in the history
  • Loading branch information
jpellizzari committed Mar 10, 2017
1 parent 456ac0b commit 2bcfef1
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 10 deletions.
27 changes: 22 additions & 5 deletions client/app/scripts/charts/edge.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,36 @@ class Edge extends React.Component {
}

render() {
const { id, path, highlighted, blurred, focused, scale, contrastMode } = this.props;
const {
id,
path,
highlighted,
blurred,
focused,
scale,
contrastMode,
source,
target
} = this.props;
const className = classNames('edge', { highlighted, blurred, focused });
const thickness = scale * (contrastMode ? 0.02 : 0.01) * NODE_BASE_SIZE;

const strokeWidth = focused ? thickness * 3 : thickness;
const shouldRenderMarker = (focused || highlighted) && (source !== target);
// Draws the edge so that its thickness reflects the zoom scale.
// Edge shadow is always made 10x thicker than the edge itself.
return (
<g
id={id} className={className}
onMouseEnter={this.handleMouseEnter}
onMouseLeave={this.handleMouseLeave}>
<path className="shadow" d={path} style={{ strokeWidth: 10 * thickness }} />
<path className="link" d={path} style={{ strokeWidth: thickness }} />
onMouseLeave={this.handleMouseLeave}
>
<path className="shadow" d={path} style={{ strokeWidth: 10 * strokeWidth }} />
<path
className="link"
d={path}
markerEnd={shouldRenderMarker ? 'url(#end-arrow)' : null}
style={{ strokeWidth }}
/>
</g>
);
}
Expand Down
18 changes: 18 additions & 0 deletions client/app/scripts/charts/marker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';

export default function Marker({id, offset, size, children, viewBox}) {
return (
<marker
className="edge-marker"
id={id}
viewBox={viewBox}
refX={offset}
refY="3.5"
markerWidth={size}
markerHeight={size}
orient="auto"
>
{children}
</marker>
);
}
19 changes: 18 additions & 1 deletion client/app/scripts/charts/nodes-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,29 @@ class NodesChart extends React.Component {
const { panTranslateX, panTranslateY, zoomScale } = this.state;
const transform = `translate(${panTranslateX}, ${panTranslateY}) scale(${zoomScale})`;
const svgClassNames = this.props.isEmpty ? 'hide' : '';
const markerOffset = this.props.selectedNodeId ? '35' : '50';
const markerSize = this.props.selectedNodeId ? '10' : '20';

return (
<div className="nodes-chart">
<svg
width="100%" height="100%" id="nodes-chart-canvas"
className={svgClassNames} onClick={this.handleMouseClick}>
className={svgClassNames} onClick={this.handleMouseClick}
>
<defs>
<marker
className="edge-marker"
id="end-arrow"
viewBox="1 0 10 10"
refX={markerOffset}
refY="3.5"
markerWidth={markerSize}
markerHeight={markerSize}
orient="auto"
>
<polygon className="link" points="0 0, 10 3.5, 0 7" />
</marker>
</defs>
<g transform="translate(24,24) scale(0.25)">
<Logo />
</g>
Expand Down
4 changes: 2 additions & 2 deletions client/app/scripts/selectors/nodes-chart-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createSelector, createStructuredSelector } from 'reselect';
import { Map as makeMap } from 'immutable';
import timely from 'timely';

import { initEdgesFromNodes, collapseMultiEdges } from '../utils/layouter-utils';
import { initEdgesFromNodes } from '../utils/layouter-utils';
import { viewportWidthSelector, viewportHeightSelector } from './canvas-viewport';
import { activeTopologyOptionsSelector } from './topology';
import { shownNodesSelector } from './node-filters';
Expand Down Expand Up @@ -72,5 +72,5 @@ export const graphEdgesSelector = createSelector(
[
graphLayoutSelector,
],
graph => collapseMultiEdges(graph.edges)
graph => graph.edges
);
7 changes: 5 additions & 2 deletions client/app/styles/_base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,7 @@

.link {
fill: none;
stroke: $text-secondary-color;
stroke-opacity: $edge-opacity;
stroke: $edge-color;
}
.shadow {
fill: none;
Expand Down Expand Up @@ -494,6 +493,10 @@
stroke-width: $node-border-stroke-width * 0.8;
}

.edge-marker {
color: $edge-color;
fill: $edge-color;
}
}

.matched-results {
Expand Down
1 change: 1 addition & 0 deletions client/app/styles/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ $node-text-scale: 2;
$edge-highlight-opacity: 0.1;
$edge-opacity-blurred: 0.2;
$edge-opacity: 0.5;
$edge-color: rgb(110, 110, 156);

$btn-opacity-default: 0.7;
$btn-opacity-hover: 1;
Expand Down

0 comments on commit 2bcfef1

Please sign in to comment.