-
Notifications
You must be signed in to change notification settings - Fork 712
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1105 from weaveworks/metrics-on-canvas
Metrics on canvas
- Loading branch information
Showing
24 changed files
with
890 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,27 @@ | ||
import React from 'react'; | ||
import classNames from 'classnames'; | ||
import {getMetricValue, getMetricColor, getClipPathDefinition} from '../utils/metric-utils.js'; | ||
import {CANVAS_METRIC_FONT_SIZE} from '../constants/styles.js'; | ||
|
||
export default function NodeShapeCircle({onlyHighlight, highlighted, size, color}) { | ||
const hightlightNode = <circle r={size * 0.7} className="highlighted" />; | ||
|
||
if (onlyHighlight) { | ||
return ( | ||
<g className="shape"> | ||
{highlighted && hightlightNode} | ||
</g> | ||
); | ||
} | ||
export default function NodeShapeCircle({id, highlighted, size, color, metric}) { | ||
const clipId = `mask-${id}`; | ||
const {height, hasMetric, formattedValue} = getMetricValue(metric, size); | ||
const metricStyle = { fill: getMetricColor(metric) }; | ||
const className = classNames('shape', { metrics: hasMetric }); | ||
const fontSize = size * CANVAS_METRIC_FONT_SIZE; | ||
|
||
return ( | ||
<g className="shape"> | ||
{highlighted && hightlightNode} | ||
<g className={className}> | ||
{hasMetric && getClipPathDefinition(clipId, size, height)} | ||
{highlighted && <circle r={size * 0.7} className="highlighted" />} | ||
<circle r={size * 0.5} className="border" stroke={color} /> | ||
<circle r={size * 0.45} className="shadow" /> | ||
<circle r={Math.max(2, size * 0.125)} className="node" /> | ||
{hasMetric && <circle r={size * 0.45} className="metric-fill" style={metricStyle} | ||
clipPath={`url(#${clipId})`} />} | ||
{highlighted && hasMetric ? | ||
<text style={{fontSize}}>{formattedValue}</text> : | ||
<circle className="node" r={Math.max(2, (size * 0.125))} />} | ||
</g> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,40 @@ | ||
import React from 'react'; | ||
import classNames from 'classnames'; | ||
import {getMetricValue, getMetricColor, getClipPathDefinition} from '../utils/metric-utils.js'; | ||
import {CANVAS_METRIC_FONT_SIZE} from '../constants/styles.js'; | ||
|
||
export default function NodeShapeSquare({onlyHighlight, highlighted, size, color, rx = 0, ry = 0}) { | ||
const rectProps = v => ({ | ||
width: v * size * 2, | ||
height: v * size * 2, | ||
rx: v * size * rx, | ||
ry: v * size * ry, | ||
transform: `translate(-${size * v}, -${size * v})` | ||
}); | ||
|
||
const hightlightNode = <rect className="highlighted" {...rectProps(0.7)} />; | ||
export default function NodeShapeSquare({ | ||
id, highlighted, size, color, rx = 0, ry = 0, metric | ||
}) { | ||
const rectProps = (scale, radiusScale) => ({ | ||
width: scale * size * 2, | ||
height: scale * size * 2, | ||
rx: (radiusScale || scale) * size * rx, | ||
ry: (radiusScale || scale) * size * ry, | ||
x: -size * scale, | ||
y: -size * scale | ||
}); | ||
|
||
if (onlyHighlight) { | ||
return ( | ||
<g className="shape"> | ||
{highlighted && hightlightNode} | ||
</g> | ||
); | ||
} | ||
const clipId = `mask-${id}`; | ||
const {height, hasMetric, formattedValue} = getMetricValue(metric, size); | ||
const metricStyle = { fill: getMetricColor(metric) }; | ||
const className = classNames('shape', { metrics: hasMetric }); | ||
const fontSize = size * CANVAS_METRIC_FONT_SIZE; | ||
|
||
return ( | ||
<g className="shape"> | ||
{highlighted && hightlightNode} | ||
<rect className="border" stroke={color} {...rectProps(0.5)} /> | ||
<rect className="shadow" {...rectProps(0.45)} /> | ||
<circle className="node" r={Math.max(2, (size * 0.125))} /> | ||
<g className={className}> | ||
{hasMetric && getClipPathDefinition(clipId, size, height)} | ||
{highlighted && <rect className="highlighted" {...rectProps(0.7)} />} | ||
<rect className="border" stroke={color} {...rectProps(0.5, 0.5)} /> | ||
<rect className="shadow" {...rectProps(0.45, 0.39)} /> | ||
{hasMetric && <rect className="metric-fill" style={metricStyle} | ||
clipPath={`url(#${clipId})`} {...rectProps(0.45, 0.39)} />} | ||
{highlighted && hasMetric ? | ||
<text style={{fontSize}}> | ||
{formattedValue} | ||
</text> : | ||
<circle className="node" r={Math.max(2, (size * 0.125))} />} | ||
</g> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.