From af3f18b933e63a33d9c5b4de25cb99049e3f07b3 Mon Sep 17 00:00:00 2001 From: Simon Howe Date: Tue, 10 May 2016 22:26:54 +0200 Subject: [PATCH] Don't draw svg labels when we don't need them. Having the DOM nodes w/ display:none is still expensive. We only need them briefly for svg export. --- client/app/scripts/actions/app-actions.js | 4 +- client/app/scripts/charts/node.js | 55 ++++++++++++-------- client/app/scripts/constants/action-types.js | 3 +- client/app/scripts/reducers/root.js | 7 ++- client/app/styles/main.less | 4 +- 5 files changed, 47 insertions(+), 26 deletions(-) diff --git a/client/app/scripts/actions/app-actions.js b/client/app/scripts/actions/app-actions.js index 85a6246eb..d5eaa6191 100644 --- a/client/app/scripts/actions/app-actions.js +++ b/client/app/scripts/actions/app-actions.js @@ -143,8 +143,10 @@ export function clickCloseTerminal(pipeId, closePipe) { } export function clickDownloadGraph() { - return () => { + return (dispatch) => { + dispatch({ type: ActionTypes.SET_EXPORTING_GRAPH, exporting: true }); saveGraph(); + dispatch({ type: ActionTypes.SET_EXPORTING_GRAPH, exporting: false }); }; } diff --git a/client/app/scripts/charts/node.js b/client/app/scripts/charts/node.js index 76c517b7d..f28f52719 100644 --- a/client/app/scripts/charts/node.js +++ b/client/app/scripts/charts/node.js @@ -37,6 +37,17 @@ function getNodeShape({ shape, stack }) { return stack ? stackedShape(nodeShape) : nodeShape; } +function svgLabels(label, subLabel, labelClassName, subLabelClassName, labelOffsetY) { + return ( + + {label} + + {subLabel} + + + ); +} + class Node extends React.Component { constructor(props, context) { @@ -65,7 +76,7 @@ class Node extends React.Component { render() { const { blurred, focused, highlighted, label, matches = makeMap(), - pseudo, rank, subLabel, scaleFactor, transform, zoomScale } = this.props; + pseudo, rank, subLabel, scaleFactor, transform, zoomScale, exportingGraph } = this.props; const { hovered, matched } = this.state; const nodeScale = focused ? this.props.selectedNodeScale : this.props.nodeScale; @@ -88,30 +99,29 @@ class Node extends React.Component { const subLabelClassName = classnames('node-sublabel', { truncate }); const NodeShapeType = getNodeShape(this.props); + const useSvgLabels = exportingGraph; return ( - {/* For browser */} - -
-
- + + {useSvgLabels ? + + svgLabels(label, subLabel, labelClassName, subLabelClassName, labelOffsetY) : + + +
+
+ +
+
+ +
+ {!blurred && }
-
- -
- {!blurred && } -
- - {/* For SVG export */} - - {label} - - {subLabel} - - + } + ({ searchQuery: state.get('searchQuery') }), + state => ({ + searchQuery: state.get('searchQuery'), + exportingGraph: state.get('exportingGraph') + }), { clickNode, enterNode, leaveNode } )(Node); diff --git a/client/app/scripts/constants/action-types.js b/client/app/scripts/constants/action-types.js index 18e42a69f..5d2b85277 100644 --- a/client/app/scripts/constants/action-types.js +++ b/client/app/scripts/constants/action-types.js @@ -46,7 +46,8 @@ const ACTION_TYPES = [ 'RECEIVE_ERROR', 'ROUTE_TOPOLOGY', 'SELECT_METRIC', - 'SHOW_HELP' + 'SHOW_HELP', + 'SET_EXPORTING_GRAPH' ]; export default _.zipObject(ACTION_TYPES, ACTION_TYPES); diff --git a/client/app/scripts/reducers/root.js b/client/app/scripts/reducers/root.js index 3f0349802..de3669641 100644 --- a/client/app/scripts/reducers/root.js +++ b/client/app/scripts/reducers/root.js @@ -70,7 +70,8 @@ export const initialState = makeMap({ updatePausedAt: null, // Date version: '...', versionUpdate: null, - websocketClosed: true + websocketClosed: true, + exportingGraph: false }); // adds ID field to topology (based on last part of URL path) and save urls in @@ -169,6 +170,10 @@ export function rootReducer(state = initialState, action) { return state; } + case ActionTypes.SET_EXPORTING_GRAPH: { + return state.set('exportingGraph', action.exporting); + } + case ActionTypes.CLEAR_CONTROL_ERROR: { return state.removeIn(['controlStatus', action.nodeId, 'error']); } diff --git a/client/app/styles/main.less b/client/app/styles/main.less index 434fdf4f4..1ead30216 100644 --- a/client/app/styles/main.less +++ b/client/app/styles/main.less @@ -322,12 +322,12 @@ h2 { top: 0px; } - .logo, .node-label-svg { + .logo { display: none; } svg.exported { - .logo, .node-label-svg { + .logo { display: inline; } }