Files
weave-scope/client/app/scripts/charts/node-networks-overlay.js
Simon Howe 55bed7b7b6 A couple more tweaks to the network-bar position.
- Center it vertically properly.
2016-07-12 18:29:15 +02:00

56 lines
1.4 KiB
JavaScript

import React from 'react';
import d3 from 'd3';
import { List as makeList } from 'immutable';
import { getNetworkColor } from '../utils/color-utils';
import { isContrastMode } from '../utils/contrast-utils';
// Gap size between bar segments.
const minBarHeight = 3;
const padding = 0.05;
const rx = 1;
const ry = rx;
const x = d3.scale.ordinal();
function NodeNetworksOverlay({offset, size, stack, networks = makeList()}) {
// Min size is about a quarter of the width, feels about right.
const minBarWidth = (size / 4);
const barWidth = Math.max(size, minBarWidth * networks.size);
const barHeight = Math.max(size * 0.085, minBarHeight);
// Update singleton scale.
x.domain(networks.map((n, i) => i).toJS());
x.rangeBands([barWidth * -0.5, barWidth * 0.5], padding, 0);
const bars = networks.map((n, i) => (
<rect
x={x(i)}
y={offset - barHeight * 0.5}
width={x.rangeBand()}
height={barHeight}
rx={rx}
ry={ry}
className="node-network"
style={{
fill: getNetworkColor(n.get('colorKey', n.get('id')))
}}
key={n.get('id')}
/>
));
let transform = '';
if (stack) {
const contrastMode = isContrastMode();
const [dx, dy] = contrastMode ? [0, 8] : [0, 0];
transform = `translate(${dx}, ${dy * -1.5})`;
}
return (
<g transform={transform}>
{bars.toJS()}
</g>
);
}
export default NodeNetworksOverlay;