import { OctopusArms, baseHeight } from './util/OctopusArms.jsx';
import { displayName, metricToFormatter } from './util/Utils.js';
import Card from '@material-ui/core/Card';
import CardContent from '@material-ui/core/CardContent';
import Grid from '@material-ui/core/Grid';
import PropTypes from 'prop-types';
import React from 'react';
import { StyledProgress } from './util/Progress.jsx';
import Table from '@material-ui/core/Table';
import TableBody from '@material-ui/core/TableBody';
import TableCell from '@material-ui/core/TableCell';
import TableRow from '@material-ui/core/TableRow';
import Typography from '@material-ui/core/Typography';
import _ceil from 'lodash/ceil';
import _floor from 'lodash/floor';
import _get from 'lodash/get';
import _isEmpty from 'lodash/isEmpty';
import _isNil from 'lodash/isNil';
import _orderBy from 'lodash/orderBy';
import _size from 'lodash/size';
import _slice from 'lodash/slice';
import _take from 'lodash/take';
import _times from 'lodash/times';
import { getSuccessRateClassification } from './util/MetricUtils.jsx' ;
import { withStyles } from "@material-ui/core/styles";
const maxNumNeighbors = 6; // max number of neighbor nodes to show in the octopus graph
const styles = () => ({
graphContainer: {
overflowX: "scroll",
padding: "16px 0"
},
graph: {
maxWidth: "974px",
minWidth: "974px",
marginLeft: "auto",
marginRight: "auto"
},
centerNode: {
width: "244px"
},
neighborNode: {
width: "220px"
}
});
class Octopus extends React.Component {
static defaultProps = {
neighbors: {},
resource: {},
unmeshedSources: []
}
static propTypes = {
classes: PropTypes.shape({}).isRequired,
neighbors: PropTypes.shape({}),
resource: PropTypes.shape({}),
unmeshedSources: PropTypes.arrayOf(PropTypes.shape({})),
}
getNeighborDisplayData = neighbors => {
// only display maxNumNeighbors neighboring nodes in the octopus graph,
// otherwise it will be really tall
let upstreams = _orderBy(neighbors.upstream, n => n.successRate);
let downstreams = _orderBy(neighbors.downstream, n => n.successRate);
let display = {
upstreams: {
displayed: upstreams,
collapsed: []
},
downstreams: {
displayed: downstreams,
collapsed: []
}
};
if (_size(upstreams) > maxNumNeighbors) {
display.upstreams.displayed = _take(upstreams, maxNumNeighbors);
display.upstreams.collapsed = _slice(upstreams, maxNumNeighbors, _size(upstreams));
}
if (_size(downstreams) > maxNumNeighbors) {
display.downstreams.displayed = _take(downstreams, maxNumNeighbors);
display.downstreams.collapsed = _slice(downstreams, maxNumNeighbors, _size(downstreams));
}
return display;
}
linkedResourceTitle = (resource, display) => {
return _isNil(resource.namespace) ? display :