Files
weave-scope/client/app/scripts/charts/node-shape-square.js
Simon Howe a104962aa2 Simple metric selection clicking!
Locks onto a metric after you mouseout.
2016-04-04 17:48:40 +02:00

41 lines
1.2 KiB
JavaScript

import React from 'react';
import {getMetricValue} from '../utils/data-utils.js';
export default function NodeShapeSquare({
highlighted, size, color, rx = 0, ry = 0, metric
}) {
const rectProps = v => ({
width: v * size * 2,
height: v * size * 2,
rx: v * size * rx,
ry: v * size * ry,
x: -size * v,
y: -size * v
});
const clipId = `mask-${Math.random()}`;
const {height, formattedValue} = getMetricValue(metric, size);
return (
<g className="shape">
<defs>
<clipPath id={clipId}>
<rect
width={size}
height={size}
x={-size * 0.5}
y={size * 0.5 - height}
/>
</clipPath>
</defs>
{highlighted && <rect className="highlighted" {...rectProps(0.7)} />}
<rect className="border" stroke={color} {...rectProps(0.5)} />
<rect className="shadow" {...rectProps(0.45)} />
<rect className="metric-fill" clipPath={`url(#${clipId})`} {...rectProps(0.45)} />
{highlighted ?
<text dy="0.35em" style={{'textAnchor': 'middle'}}>{formattedValue}</text> :
<circle className="node" r={Math.max(2, (size * 0.125))} />}
</g>
);
}