Skip to content
This repository has been archived by the owner on Apr 23, 2024. It is now read-only.

Commit

Permalink
fix: limit animation (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
haxxmaxx committed Feb 12, 2020
1 parent 69a9e4e commit da275da
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 27 deletions.
23 changes: 18 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ export default function supernova(env) {
};
}, []);

const setStateCallback = newNode => {
setExpandedState(newNode);
const setStateCallback = newState => {
newState.useTransitions = true;
setExpandedState(newState);
};

/*
Expand All @@ -98,7 +99,6 @@ export default function supernova(env) {
return treeTransform({ layout, model }).then(transformed => {
setDataTree(transformed);
setStyling(stylingUtils.cardStyling({ Theme, layout }));
setExpandedState(null);
});
}
return Promise.resolve();
Expand All @@ -122,9 +122,22 @@ export default function supernova(env) {

useEffect(() => {
if (objectData && expandedState && styling) {
paintTree({ objectData, expandedState, styling, setStateCallback, selectionsAPI, linked });
paintTree({ objectData, expandedState, styling, setStateCallback, selectionsAPI });
}
}, [expandedState, objectData, selState]);
}, [objectData, selState]);

useEffect(() => {
if (objectData && expandedState && styling) {
paintTree({
objectData,
expandedState,
styling,
setStateCallback,
selectionsAPI,
useTransitions: expandedState.useTransitions,
});
}
}, [expandedState]);
},
ext: ext(env),
};
Expand Down
22 changes: 4 additions & 18 deletions src/tree/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,8 @@ import createPaths from './path';
import transform from './transform';
import '../treeCss.css';

const filterTree = ({ topId, isExpanded, expandedChildren }, nodeTree, setStateCallback) => {
const topNode = topId ? nodeTree.descendants().find(node => node.data.id === topId) : null;
if (!topNode) {
setStateCallback({
topId: nodeTree.data.id,
isExpanded: true,
expandedChildren: [],
});
return [];
}
const filterTree = ({ topId, isExpanded, expandedChildren }, nodeTree) => {
const topNode = nodeTree.descendants().find(node => node.data.id === topId) || nodeTree;
const subTree = [];
subTree.push(topNode); // self
if (isExpanded && topNode.children) {
Expand All @@ -31,13 +23,7 @@ const filterTree = ({ topId, isExpanded, expandedChildren }, nodeTree, setStateC
return subTree;
};

export const paintTree = ({
objectData,
expandedState,
styling,
setStateCallback,
selectionsAPI,
}) => {
export const paintTree = ({ objectData, expandedState, styling, setStateCallback, selectionsAPI, useTransitions }) => {
const { svg, divBox, allNodes, positioning, width, height } = objectData;
divBox.selectAll('.node-rect').remove();
svg.selectAll('g').remove();
Expand All @@ -55,7 +41,7 @@ export const paintTree = ({
// Create the lines (links) between the nodes
createPaths(node, positioning, expandedState.topId);
// Scale and translate
transform(nodes, width, height, svg, divBox);
transform(nodes, width, height, svg, divBox, useTransitions);
};

export const getSize = ({ error, warn }, element) => {
Expand Down
8 changes: 4 additions & 4 deletions src/tree/transform.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import constants from './size-constants';

const getBBoxOfNodes = (nodes) => {
const getBBoxOfNodes = nodes => {
const { cardWidth, cardHeight, buttonHeight, buttonMargin } = constants;
const bbox = {
left: Infinity,
Expand All @@ -22,7 +22,7 @@ const getBBoxOfNodes = (nodes) => {
};
};

export default function transform(nodes, width, height, svg, divBox) {
export default function transform(nodes, width, height, svg, divBox, useTransitions) {
// Zooming and positioning of the tree
const bBox = getBBoxOfNodes(nodes);
const scaleToWidhth = bBox.width / width > bBox.height / height;
Expand All @@ -44,8 +44,8 @@ export default function transform(nodes, width, height, svg, divBox) {
} else {
// Transition using css, does not work in IE11
svg.attr('style', `transform: scale(${1 / scaleFactor}) translate(${translation});`);
divBox.classed('org-disable-transition', false);
svg.classed('org-disable-transition', false);
divBox.classed('org-disable-transition', !useTransitions);
svg.classed('org-disable-transition', !useTransitions);
}

divBox.attr(
Expand Down

0 comments on commit da275da

Please sign in to comment.