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 20afb64
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 15 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}) {
return (
<marker
className="edge-marker"
id={id}
viewBox="1 0 10 10"
refX={offset}
refY="3.5"
markerWidth={size}
markerHeight={size}
orient="auto"
>
{children}
</marker>
);
}
1 change: 1 addition & 0 deletions client/app/scripts/charts/nodes-chart-edges.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class NodesChartEdges extends React.Component {
blurred={edge.get('blurred')}
scale={edge.get('scale')}
isAnimated={isAnimated}
bidirectional={edge.get('bidirectional')}
/>
))}
</g>
Expand Down
22 changes: 21 additions & 1 deletion client/app/scripts/charts/nodes-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { clickBackground, cacheZoomState } from '../actions/app-actions';
import { activeLayoutZoomSelector } from '../selectors/nodes-chart-zoom';
import { activeTopologyZoomCacheKeyPathSelector } from '../selectors/topology';
import { ZOOM_CACHE_DEBOUNCE_INTERVAL } from '../constants/timer';
import Marker from './marker';


const ZOOM_CACHE_FIELDS = [
Expand Down Expand Up @@ -84,12 +85,31 @@ 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 ? '45' : '60';
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
id="end-arrow"
offset={markerOffset}
size={markerSize}
>
<polygon className="link" points="0 0, 10 3.5, 0 7" />
</Marker>
<Marker
id="start-arrow"
offset={markerOffset}
size={markerSize}
>
<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
);
4 changes: 4 additions & 0 deletions client/app/styles/_base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,10 @@
stroke-width: $node-border-stroke-width * 0.8;
}

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

.matched-results {
Expand Down
14 changes: 7 additions & 7 deletions client/webpack.local.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ module.exports = {
path.resolve(__dirname, 'app/scripts', 'app/styles')
],

preLoaders: [
{
test: /\.js$/,
exclude: /node_modules|vendor/,
loader: 'eslint-loader'
}
],
// preLoaders: [
// {
// test: /\.js$/,
// exclude: /node_modules|vendor/,
// loader: 'eslint-loader'
// }
// ],
loaders: [
{
test: /\.json$/,
Expand Down

0 comments on commit 20afb64

Please sign in to comment.