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

Commit

Permalink
fix: limit zooming and keep state
Browse files Browse the repository at this point in the history
  • Loading branch information
niekvanstaveren committed Feb 12, 2020
1 parent 978596e commit 294cb49
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 24 deletions.
37 changes: 19 additions & 18 deletions src/extension/ext-raw.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ const colorOptions = [
{ value: 'byExpression', translation: 'properties.colorMode.byExpression' },
];

const navigationOptions = [
{ value: 'regular', translation: '$Unlimited sizing' },
{ value: 'scroll', translation: '$SCroll thing' },
{ value: 'free', translation: '$Free pan and zoom' },
];
// Navigation options only needed when adding new option
// const navigationOptions = [
// { value: 'regular', translation: '$Unlimited sizing' },
// { value: 'scroll', translation: '$SCroll thing' },
// { value: 'free', translation: '$Free pan and zoom' },
// ];

export default {
definition: {
Expand Down Expand Up @@ -107,19 +108,19 @@ export default {
backgroundColor: {
type: 'items',
items: {
navigation: {
type: 'items',
items: {
navigtaionMode: {
ref: 'navigationMode',
type: 'string',
translation: '$Navigationmode',
component: 'dropdown',
default: 'scroll',
options: navigationOptions,
},
},
},
// Dropdown for navigation options. Should only be activated when adding new options
// navigation: {
// type: 'items',
// items: {
// navigtaionMode: {
// ref: 'navigationMode',
// type: 'string',
// translation: '$Navigationmode',
// component: 'dropdown',
// options: navigationOptions,
// },
// },
// },
useColorExpression: {
ref: 'style.backgroundColor.colorType',
type: 'string',
Expand Down
4 changes: 1 addition & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
useEffect,
useElement,
useModel,
useRect,
useState,
usePromise,
useTheme,
Expand Down Expand Up @@ -34,7 +33,6 @@ export default function supernova(env) {
const layout = useStaleLayout();
const model = useModel();
const element = useElement();
const rect = useRect()[0];
const Theme = useTheme();
const selectionsAPI = useSelections();
selectionsAPI.refreshSelectionState = setSelState;
Expand Down Expand Up @@ -115,7 +113,7 @@ export default function supernova(env) {
});
}
}
}, [element, dataTree, rect]);
}, [element, dataTree]);

useEffect(() => {
if (objectData && expandedState && styling) {
Expand Down
2 changes: 1 addition & 1 deletion src/tree/position.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function position(orientation, nodeSize, element) {
? d.parent[axis] + nodeMargin / 2
: d.parent[axis] + (d.data.childNumber - (d.parent.children.length - 1) / 2) * widthSpacing;
} else if (!d.children) {
d[axis] = 0;
d[axis] = (element.clientWidth - nodeSize.width) / 2;
} else {
// In case of zoom mode we need to have the tree moved to the right from the start
const neededWidth = (nodeSize.width + nodeMargin) * d.children.length - nodeMargin;
Expand Down
7 changes: 5 additions & 2 deletions src/tree/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ export function applyTransform(eventTransform, svg, divBox, width, height) {

export function setZooming(objectData) {
const { svg, divBox, width, height, element, allNodes } = objectData;
const scaleFactor = allNodes.zoomFactor;
const maxZoom = 6;
const minZoom = 0.2;
const scaleFactor = Math.max(Math.min(maxZoom, allNodes.zoomFactor), minZoom);

const zoomed = () => {
applyTransform(
Expand All @@ -57,13 +59,14 @@ export function setZooming(objectData) {
height
);
};

select(element).call(
zoom()
.extent([
[0, 0],
[width, height],
])
.scaleExtent([0.05, 8])
.scaleExtent([minZoom, maxZoom])
.on('zoom', zoomed)
);

Expand Down

0 comments on commit 294cb49

Please sign in to comment.