mirror of
https://github.com/ansible/awx.git
synced 2026-05-18 06:47:41 -02:30
Use 100% height.
This commit is contained in:
@@ -13,6 +13,8 @@ import {
|
|||||||
renderNodeType,
|
renderNodeType,
|
||||||
renderNodeIcon,
|
renderNodeIcon,
|
||||||
redirectToDetailsPage,
|
redirectToDetailsPage,
|
||||||
|
getHeight,
|
||||||
|
getWidth,
|
||||||
// generateRandomNodes,
|
// generateRandomNodes,
|
||||||
// getRandomInt,
|
// getRandomInt,
|
||||||
} from './utils/helpers';
|
} from './utils/helpers';
|
||||||
@@ -23,9 +25,7 @@ import {
|
|||||||
DEFAULT_NODE_HIGHLIGHT_COLOR,
|
DEFAULT_NODE_HIGHLIGHT_COLOR,
|
||||||
DEFAULT_NODE_LABEL_TEXT_COLOR,
|
DEFAULT_NODE_LABEL_TEXT_COLOR,
|
||||||
DEFAULT_FONT_SIZE,
|
DEFAULT_FONT_SIZE,
|
||||||
MARGIN,
|
SELECTOR,
|
||||||
HEIGHT,
|
|
||||||
FALLBACK_WIDTH,
|
|
||||||
} from './constants';
|
} from './constants';
|
||||||
|
|
||||||
const Loader = styled(ContentLoading)`
|
const Loader = styled(ContentLoading)`
|
||||||
@@ -43,22 +43,8 @@ function MeshGraph({ data, showLegend, zoom }) {
|
|||||||
|
|
||||||
// const data = generateRandomNodes(getRandomInt(4, 50));
|
// const data = generateRandomNodes(getRandomInt(4, 50));
|
||||||
const draw = () => {
|
const draw = () => {
|
||||||
const getWidth = () => {
|
const width = getWidth(SELECTOR);
|
||||||
let width;
|
const height = getHeight(SELECTOR);
|
||||||
// This is in an a try/catch due to an error from jest.
|
|
||||||
// Even though the d3.select returns a valid selector with
|
|
||||||
// style function, it says it is null in the test
|
|
||||||
try {
|
|
||||||
width =
|
|
||||||
parseInt(d3.select(`#chart`).style('width'), 10) - MARGIN ||
|
|
||||||
FALLBACK_WIDTH;
|
|
||||||
} catch (error) {
|
|
||||||
width = FALLBACK_WIDTH;
|
|
||||||
}
|
|
||||||
|
|
||||||
return width;
|
|
||||||
};
|
|
||||||
const width = getWidth();
|
|
||||||
|
|
||||||
/* Add SVG */
|
/* Add SVG */
|
||||||
d3.selectAll(`#chart > svg`).remove();
|
d3.selectAll(`#chart > svg`).remove();
|
||||||
@@ -66,13 +52,9 @@ function MeshGraph({ data, showLegend, zoom }) {
|
|||||||
.select('#chart')
|
.select('#chart')
|
||||||
.append('svg')
|
.append('svg')
|
||||||
.attr('class', 'mesh-svg')
|
.attr('class', 'mesh-svg')
|
||||||
.attr('width', `${width + MARGIN}px`)
|
.attr('width', `${width}px`)
|
||||||
.attr('height', `${HEIGHT + MARGIN}px`)
|
.attr('height', `100%`);
|
||||||
.attr('viewBox', [0, 0, width, HEIGHT]);
|
const mesh = svg.append('g').attr('class', 'mesh');
|
||||||
const mesh = svg
|
|
||||||
.append('g')
|
|
||||||
.attr('class', 'mesh')
|
|
||||||
.attr('transform', `translate(${MARGIN}, ${MARGIN})`);
|
|
||||||
|
|
||||||
const graph = data;
|
const graph = data;
|
||||||
|
|
||||||
@@ -94,7 +76,7 @@ function MeshGraph({ data, showLegend, zoom }) {
|
|||||||
)
|
)
|
||||||
.force('forceX', d3.forceX(MESH_FORCE_LAYOUT.defaultForceX))
|
.force('forceX', d3.forceX(MESH_FORCE_LAYOUT.defaultForceX))
|
||||||
.force('forceY', d3.forceY(MESH_FORCE_LAYOUT.defaultForceY))
|
.force('forceY', d3.forceY(MESH_FORCE_LAYOUT.defaultForceY))
|
||||||
.force('center', d3.forceCenter(width / 2, HEIGHT / 2));
|
.force('center', d3.forceCenter(width / 2, height / 2));
|
||||||
|
|
||||||
const link = mesh
|
const link = mesh
|
||||||
.append('g')
|
.append('g')
|
||||||
@@ -274,7 +256,7 @@ function MeshGraph({ data, showLegend, zoom }) {
|
|||||||
}, []); // eslint-disable-line react-hooks/exhaustive-deps
|
}, []); // eslint-disable-line react-hooks/exhaustive-deps
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div id="chart" style={{ position: 'relative' }}>
|
<div id="chart" style={{ position: 'relative', height: '100%' }}>
|
||||||
{showLegend && <Legend />}
|
{showLegend && <Legend />}
|
||||||
<Tooltip
|
<Tooltip
|
||||||
isNodeSelected={isNodeSelected}
|
isNodeSelected={isNodeSelected}
|
||||||
|
|||||||
@@ -37,9 +37,9 @@ function TopologyView() {
|
|||||||
d3.select('.mesh-svg').transition().call(zoom.scaleBy, 0.5);
|
d3.select('.mesh-svg').transition().call(zoom.scaleBy, 0.5);
|
||||||
};
|
};
|
||||||
const resetZoom = () => {
|
const resetZoom = () => {
|
||||||
const margin = 15;
|
const parent = d3.select('.mesh').node().parentElement;
|
||||||
const height = 600;
|
const width = parent.clientWidth;
|
||||||
const width = parseInt(d3.select(`#chart`).style('width'), 10) - margin;
|
const height = parent.clientHeight;
|
||||||
d3.select('.mesh-svg')
|
d3.select('.mesh-svg')
|
||||||
.transition()
|
.transition()
|
||||||
.duration(750)
|
.duration(750)
|
||||||
@@ -85,7 +85,7 @@ function TopologyView() {
|
|||||||
resetZoom={resetZoom}
|
resetZoom={resetZoom}
|
||||||
/>
|
/>
|
||||||
<PageSection>
|
<PageSection>
|
||||||
<Card>
|
<Card style={{ height: '100%' }}>
|
||||||
<CardBody>
|
<CardBody>
|
||||||
{!isLoading && (
|
{!isLoading && (
|
||||||
<MeshGraph data={meshData} showLegend={showLegend} zoom={zoom} />
|
<MeshGraph data={meshData} showLegend={showLegend} zoom={zoom} />
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
/* eslint-disable-next-line import/prefer-default-export */
|
/* eslint-disable-next-line import/prefer-default-export */
|
||||||
|
export const SELECTOR = '#chart';
|
||||||
export const MESH_FORCE_LAYOUT = {
|
export const MESH_FORCE_LAYOUT = {
|
||||||
defaultCollisionFactor: 80,
|
defaultCollisionFactor: 80,
|
||||||
defaultForceStrength: -100,
|
defaultForceStrength: -100,
|
||||||
@@ -15,7 +16,6 @@ export const DEFAULT_FONT_SIZE = '12px';
|
|||||||
export const LABEL_TEXT_MAX_LENGTH = 15;
|
export const LABEL_TEXT_MAX_LENGTH = 15;
|
||||||
|
|
||||||
export const MARGIN = 15;
|
export const MARGIN = 15;
|
||||||
export const HEIGHT = 600;
|
|
||||||
export const FALLBACK_WIDTH = 700;
|
export const FALLBACK_WIDTH = 700;
|
||||||
|
|
||||||
export const NODE_STATE_COLOR_KEY = {
|
export const NODE_STATE_COLOR_KEY = {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import * as d3 from 'd3';
|
||||||
import { InstancesAPI } from 'api';
|
import { InstancesAPI } from 'api';
|
||||||
import { truncateString } from '../../../util/strings';
|
import { truncateString } from '../../../util/strings';
|
||||||
|
|
||||||
@@ -84,3 +85,11 @@ export const generateRandomNodes = (n) => {
|
|||||||
}
|
}
|
||||||
return generateRandomLinks(nodes, getRandomInt(1, n - 1));
|
return generateRandomLinks(nodes, getRandomInt(1, n - 1));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export function getWidth(selector) {
|
||||||
|
return selector ? d3.select(selector).node().clientWidth : 700;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getHeight(selector) {
|
||||||
|
return selector !== null ? d3.select(selector).node().clientHeight : 600;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user