Skip to content

Commit

Permalink
Merge pull request #90 from shefing/fixes-version-two
Browse files Browse the repository at this point in the history
rename - fix build
  • Loading branch information
RachelBra authored Nov 21, 2024
2 parents 238b2db + 975fa26 commit 94336fb
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
6 changes: 3 additions & 3 deletions library/math/numbersLine/src/components/ShowElements.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { unitAmount } from "@/type/ruler";

const ShowElements = () => {
const { windowSize, rulerType, unit, setUnit, dragElements, setIdDraggElementClick } = useNumbersLineContext();
const { rulerWidth, unitsAmount, rulerPosition } = useHelpers();
const { rulerWidth, unitsAmount, calcRulerPosition } = useHelpers();
const { updateDragElements } = useDraggableElementAction();
const [windowResizing, setWindowResizing] = useState(false);

Expand All @@ -26,9 +26,9 @@ const ShowElements = () => {
}
let translateY;
if (element.yRatio < 0) { // Element is below the ruler
translateY = (-1 * element.yRatio * (windowSize.height - rulerPosition())) + rulerPosition();
translateY = (-1 * element.yRatio * (windowSize.height - calcRulerPosition())) + calcRulerPosition();
} else {
translateY = element.yRatio * rulerPosition();
translateY = element.yRatio * calcRulerPosition();
}
const newTransform = `translate(${translateX.toFixed(2)}px, ${translateY.toFixed(2)}px)`;
let documentElement = document.getElementById(`dragElement-${element.id}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ interface IProps {
const MoveableElement = ({ moveableRef, element, dragging, setDragging }: IProps) => {
const { windowSize, rulerType, unit, leftPosition, idDraggElementClick, setIdDraggElementClick, color } = useNumbersLineContext();
const { deleteDragElement, duplicateDragJump, updateDragElements, updateDragElementsLayers } = useDraggableElementAction();
const { calculatScreenWidth, rulerPaddingSides, jumpHeightWithoutBase, calcYElementPosition, xAxisFactor, widthRatio, heightRatio, rulerPosition, xRatio, yRatio } = useHelpers();
const { calculatScreenWidth, rulerPaddingSides, jumpHeightWithoutBase, calcYElementPosition, xAxisFactor, widthRatio, heightRatio, calcRulerPosition, calcXRatio, calcYRatio } = useHelpers();
const [rightStartPosition, setRightStartPosition] = useState(0);
const [boundScale, setBoundScale] = useState(0);
const [changeDragState, setChangeDragState] = useState(false);
const [rulerPosition, setRulerPosition] = useState(rulerPosition());
const [rulerPosition, setRulerPosition] = useState(calcRulerPosition());

useEffect(() => {
setRulerPosition(rulerPosition());
setRulerPosition(calcRulerPosition());
}, [windowSize]);

const ableProps = {
Expand Down Expand Up @@ -65,8 +65,8 @@ const MoveableElement = ({ moveableRef, element, dragging, setDragging }: IProps

const onDragEnd = (e: OnDragEnd | OnResizeEnd, resizeElement?: IElement) => {
if (element.type == ActionTypes.text) {
const xRatio = xRatio(calcXTransform(e.target.style.transform));
const yRatio = yRatio(calcYTransform(e.target.style.transform));
const xRatio = calcXRatio(calcXTransform(e.target.style.transform));
const yRatio = calcYRatio(calcYTransform(e.target.style.transform));
updateDragElements(element.id, { ...element, transform: e.target.style.transform, xRatio, yRatio });
setDragging!(false);
setIdDraggElementClick("");
Expand All @@ -78,8 +78,8 @@ const MoveableElement = ({ moveableRef, element, dragging, setDragging }: IProps
if (Math.abs(rulerPosition - elementPsition) < DistanceRulerForUpdatePositioning) updateXLocation(e);
// Change the type of jump if its position has changed relative to the ruler.
if (!element?.jump) {
const xRatio = xRatio(calcXTransform(e.target.style.transform));
const yRatio = yRatio(calcYTransform(e.target.style.transform));
const xRatio = calcXRatio(calcXTransform(e.target.style.transform));
const yRatio = calcYRatio(calcYTransform(e.target.style.transform));
updateDragElements(element.id, { ...element, transform: e.target.style.transform, widthRatio: widthRatio(e.target.style.transform), heightRatio: heightRatio(e.target.style.transform), xRatio, yRatio });
return;
}
Expand All @@ -95,8 +95,8 @@ const MoveableElement = ({ moveableRef, element, dragging, setDragging }: IProps
}
e.target.style.transform = e.target.style.transform.replace(yTransform + "px)", newYPositionString);
}
const xRatio = xRatio(calcXTransform(e.target.style.transform));
const yRatio = yRatio(calcYTransform(e.target.style.transform));
const xRatio = calcXRatio(calcXTransform(e.target.style.transform));
const yRatio = calcYRatio(calcYTransform(e.target.style.transform));
updateDragElements(element.id, {
...element,
transform: e.target.style.transform,
Expand Down Expand Up @@ -173,7 +173,7 @@ const MoveableElement = ({ moveableRef, element, dragging, setDragging }: IProps
newTransform = e.target.style.transform.replace("(" + xPosition, newXPosition);
e.target.style.transform = newTransform;
}
const xRatio = xRatio(calcXTransform(e.target.style.transform));
const xRatio = calcXRatio(calcXTransform(e.target.style.transform));
updateDragElements(element.id, { ...element, transform: newTransform, widthRatio: widthRatio(e.target.style.transform), heightRatio: heightRatio(e.target.style.transform), jump: { ...element.jump, width: newWidth, value: newValue }, xRatio });
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ export const useDraggableElementAction = () => {
zIndexCounter,
setZIndexCounter,
} = useNumbersLineContext();
const { rulerWidth, unitsAmount, rulerPaddingSides, xRatio, yRatio } = useHelpers();
const { rulerWidth, unitsAmount, rulerPaddingSides, calcXRatio, calcYRatio } = useHelpers();

const addDraggableElement = (typeAction: ActionTypes, type?: NaviKeniIconsTypes) => {
const elementWidth = typeAction == ActionTypes.jump ? rulerWidth() / unitsAmount(): typeAction == ActionTypes.naviAndKeni? rulerWidth() / unitAmount.ten: textBoxWidth;
const xTranslate = (windowSize.width - elementWidth) / 2 + duplicateElementSpace;
const yTranslate = windowSize.height / 4 + duplicateElementSpace;
const xRatio = xRatio(xTranslate)
const yRatio = yRatio(yTranslate)
const xRatio = calcXRatio(xTranslate)
const yRatio = calcYRatio(yTranslate)
let newElement: IElement = {
id: uuidv4(),
type: typeAction,
Expand Down Expand Up @@ -93,7 +93,7 @@ export const useDraggableElementAction = () => {
setLeftPosition((prev) => Math.round((prev - outOfRange) / unit) * unit);
}
newTransform = element.transform.replace("(" + startPosition, "(" + newPosition);
const xRatio = xRatio(newPosition)
const xRatio = calcXRatio(newPosition)
const newElement = {
...element,
id,
Expand Down
18 changes: 9 additions & 9 deletions library/math/numbersLine/src/hooks/useHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,20 @@ export const useHelpers = () => {
return calcYTransform(transform)/windowSize.height;
};

const rulerPosition = (): number => {
const calcRulerPosition = (): number => {
return windowSize.height - (windowSize.height * rulerLocation) - ruleHeight;
};

const xRatio = (xPosition:number): number => {
const calcXRatio = (xPosition:number): number => {
if(unitsAmount() == unitAmount.twenty)
return (xPosition- 0.5*unit) / (windowSize.width - unit)
return (xPosition- RulerPaddingSides) / (windowSize.width - 2 * RulerPaddingSides)
};

const yRatio = (yPosition: number): number => {
if(rulerPosition() < yPosition)
return (yPosition - rulerPosition()) / (windowSize.height - rulerPosition()) * -1
return yPosition / rulerPosition()
const calcYRatio = (yPosition: number): number => {
if(calcRulerPosition() < yPosition)
return (yPosition - calcRulerPosition()) / (windowSize.height - calcRulerPosition()) * -1
return yPosition / calcRulerPosition()
};

const restart = () => {
Expand All @@ -96,10 +96,10 @@ export const useHelpers = () => {
widthRatio,
jumpHeightWithoutBase,
calcYElementPosition,
rulerPosition,
calcRulerPosition,
xAxisFactor,
xRatio,
yRatio,
calcXRatio,
calcYRatio,
restart,
};
};

0 comments on commit 94336fb

Please sign in to comment.