mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-28 17:51:21 +00:00
Added edge arrows
This commit is contained in:
@@ -14,19 +14,35 @@ class Edge extends React.Component {
|
||||
}
|
||||
|
||||
render() {
|
||||
const { id, path, highlighted, blurred, focused, scale, contrastMode } = this.props;
|
||||
const {
|
||||
id,
|
||||
path,
|
||||
highlighted,
|
||||
blurred,
|
||||
focused,
|
||||
scale,
|
||||
source,
|
||||
target
|
||||
} = this.props;
|
||||
const className = classNames('edge', { highlighted, blurred, focused });
|
||||
const thickness = scale * (contrastMode ? 0.02 : 0.01) * NODE_BASE_SIZE;
|
||||
|
||||
const thickness = (scale * 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>
|
||||
);
|
||||
}
|
||||
|
||||
18
client/app/scripts/charts/marker.js
Normal file
18
client/app/scripts/charts/marker.js
Normal file
@@ -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>
|
||||
);
|
||||
}
|
||||
@@ -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' : '40';
|
||||
const markerSize = this.props.selectedNodeId ? '10' : '30';
|
||||
|
||||
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>
|
||||
|
||||
@@ -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';
|
||||
@@ -72,5 +72,5 @@ export const graphEdgesSelector = createSelector(
|
||||
[
|
||||
graphLayoutSelector,
|
||||
],
|
||||
graph => collapseMultiEdges(graph.edges)
|
||||
graph => graph.edges
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user