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

Commit

Permalink
fix: comments
Browse files Browse the repository at this point in the history
  • Loading branch information
eliseeborn committed Feb 17, 2020
1 parent 02e2e1b commit 2de96fc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
26 changes: 13 additions & 13 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,34 +48,34 @@ export default function supernova(env) {
const [opts] = useState(options);
const selectionsAPI = useSelections();
const constraints = useConstraints();
const [selections] = useState({ api: selectionsAPI, setState: setSelectionState, linked: false, zoom: {} });
const [selectionsAndZoom] = useState({ api: selectionsAPI, setState: setSelectionState, linked: false, transform: {} });

const resetSelections = () => {
setSelectionState([]);
};
useEffect(() => {
if (!selections.api) {
if (!selectionsAndZoom.api) {
return () => {};
}
selections.api = selectionsAPI;
selections.api.on('canceled', resetSelections);
selections.api.on('cleared', resetSelections);
selectionsAndZoom.api = selectionsAPI;
selectionsAndZoom.api.on('canceled', resetSelections);
selectionsAndZoom.api.on('cleared', resetSelections);
// Return function called on unmount
return () => {
selections.api.removeListener('deactivated', resetSelections);
selections.api.removeListener('canceled', resetSelections);
selections.api.removeListener('cleared', resetSelections);
selectionsAndZoom.api.removeListener('deactivated', resetSelections);
selectionsAndZoom.api.removeListener('canceled', resetSelections);
selectionsAndZoom.api.removeListener('cleared', resetSelections);
};
}, [selectionsAPI]);

useEffect(() => {
selections.zoom = zoomState;
selectionsAndZoom.transform = zoomState;
}, [zoomState]);

useAction(
() => ({
action() {
selections.linked = !linked;
selectionsAndZoom.linked = !linked;
setLinked(!linked);
},
icon: {
Expand All @@ -90,14 +90,14 @@ export default function supernova(env) {
useEffect(() => {
const addKeyPress = event => {
if (event.key === 'Shift') {
selections.linked = true;
selectionsAndZoom.linked = true;
setLinked(true);
}
};

const removeKeyPress = event => {
if (event.key === 'Shift') {
selections.linked = false;
selectionsAndZoom.linked = false;
setLinked(false);
}
};
Expand Down Expand Up @@ -164,7 +164,7 @@ export default function supernova(env) {
expandedState,
styling,
setStateCallback,
selections,
selections: selectionsAndZoom,
selectionState,
constraints,
useTransitions: expandedState.useTransitions,
Expand Down
6 changes: 3 additions & 3 deletions src/tree/box.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default function box(
sel,
allowInteractions
) {
const { cardWidth, cardHeight, buttonWidth, buttonHeight, buttonMargin, rootDiameter } = constants;
const { cardWidth, cardHeight, buttonWidth, buttonHeight, buttonMargin, rootDiameter, tooltipWidth, tooltipHeight } = constants;
const { topId, isExpanded } = expandedState;

// dummy root
Expand All @@ -77,8 +77,8 @@ export default function box(

function getTooltipStyle(d) {
const halfCardWidth = cardWidth / 2;
const halfTooltipWidth = 240 / 2;
return `top:${(y(d)) * sel.zoom.zoom + sel.zoom.y - 85}px;left:${x(d) * sel.zoom.zoom + sel.zoom.x - (halfTooltipWidth - (halfCardWidth * sel.zoom.zoom))}px;visibility: visible;opacity: 0.9;`;
const halfTooltipWidth = tooltipWidth / 2;
return `top:${(y(d)) * sel.transform.zoom + sel.transform.y - tooltipHeight - 25}px;left:${x(d) * sel.transform.zoom + sel.transform.x - (halfTooltipWidth - (halfCardWidth * sel.transform.zoom))}px;visibility: visible;opacity: 0.9;`;
}

// cards
Expand Down
2 changes: 2 additions & 0 deletions src/tree/size-constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const constants = {
buttonHeight,
rootDiameter: 20,
r: 4,
tooltipWidth: 240,
tooltipHeight: 60,
};

export default constants;

0 comments on commit 2de96fc

Please sign in to comment.