diff --git a/ea-scripts/Normalize Selected Arrows.md b/ea-scripts/Normalize Selected Arrows.md new file mode 100644 index 0000000..bdf2f64 --- /dev/null +++ b/ea-scripts/Normalize Selected Arrows.md @@ -0,0 +1,79 @@ +/* +![](https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/images/scripts-download-raw.jpg) + +Download this file and save to your Obsidian Vault including the first line, or open it in "Raw" and copy the entire contents to Obsidian. + +![](https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/images/scripts-normalize-selected-arrows.png) + +This script will reset the start and end positions of the selected arrows. The arrow will point to the center of the connected box and will have a gap of 8px from the box. + +See documentation for more details: +https://zsviczian.github.io/obsidian-excalidraw-plugin/ExcalidrawScriptsEngine.html + +```javascript +*/ +const selectedIndividualArrows = ea.getMaximumGroups(ea.getViewSelectedElements()) + .reduce((result, group) => (group.length === 1 && (group[0].type === 'arrow' || group[0].type === 'line')) ? + [...result, group[0]] : result, []); + +const allElements = ea.getViewElements(); +for(const arrow of selectedIndividualArrows) { + const startBindingEl = allElements.filter(el => el.id === (arrow.startBinding||{}).elementId)[0]; + const endBindingEl = allElements.filter(el => el.id === (arrow.endBinding||{}).elementId)[0]; + + if(startBindingEl) { + recalculateStartPointOfLine(arrow, startBindingEl, endBindingEl); + } + if(endBindingEl) { + recalculateEndPointOfLine(arrow, endBindingEl, startBindingEl); + } +} + +ea.copyViewElementsToEAforEditing(selectedIndividualArrows); +ea.addElementsToView(); + +function recalculateStartPointOfLine(line, el, elB) { + const aX = el.x + el.width/2; + const bX = (line.points.length <=2 && elB) ? elB.x + elB.width/2 : line.x + line.points[1][0]; + const aY = el.y + el.height/2; + const bY = (line.points.length <=2 && elB) ? elB.y + elB.height/2 : line.y + line.points[1][1]; + + line.startBinding.gap = 8; + line.startBinding.focus = 0; + const intersectA = ea.intersectElementWithLine( + el, + [bX, bY], + [aX, aY], + line.startBinding.gap + ); + + if(intersectA.length > 0) { + line.points[0] = [0, 0]; + for(var i = 1; i 0) { + line.points[line.points.length - 1] = [intersectA[0][0] - line.x, intersectA[0][1] - line.y]; + } +} \ No newline at end of file diff --git a/ea-scripts/README.md b/ea-scripts/README.md index 6e1b8a7..833ab1c 100644 --- a/ea-scripts/README.md +++ b/ea-scripts/README.md @@ -35,6 +35,7 @@ Open the script you are interested in and save it to your Obsidian Vault includi |[Lighten background color](Lighten%20background%20color.md)|This script lightens the background color of the selected element by 2% at a time. You can use this script several times until you are satisfied. It is recommended to set a shortcut key for this script so that you can quickly try to DARKEN and LIGHTEN the color effect.In contrast to the `Modify background color opacity` script, the advantage is that the background color of the element is not affected by the canvas color, and the color value does not appear in a strange rgba() form.|![](https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/images/darken-lighten-background-color.png)|[@1-2-3](https://github.com/1-2-3)| |[Modify background color opacity](Modify%20background%20color%20opacity.md)|This script changes the opacity of the background color of the selected boxes. The default background color in Excalidraw is so dark that the text is hard to read. You can lighten the color a bit by setting transparency. And you can tweak the transparency over and over again until you're happy with it. Although excalidraw has the opacity option in its native property Settings, it also changes the transparency of the border. Use this script to change only the opacity of the background color without affecting the border.|![](https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/images/scripts-modify-background-color-opacity.png)|[@1-2-3](https://github.com/1-2-3)| |[Modify stroke width of selected elements](Modify%20stroke%20width%20of%20selected%20elements.md)|This script will set the stroke width of selected elements. This is helpful, for example, when you scale freedraw sketches and want to reduce or increase their line width.|![](https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/images/scripts-stroke-width.jpg)|[@zsviczian](https://github.com/zsviczian)| +|[Normalize Selected Arrows](Normalize%20Selected%20Arrows.md)|This script will reset the start and end positions of the selected arrows. The arrow will point to the center of the connected box and will have a gap of 8px from the box.|![](https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/images/scripts-normalize-selected-arrows.png)|[@1-2-3](https://github.com/1-2-3)| |[OCR - Optical Character Recognition](OCR%20-%20Optical%20Character%20Recognition.md)|The script will 1) send the selected image file to [taskbone.com](https://taskbone.com) to exctract the text from the image, and 2) will add the text to your drawing as a text element.|![](https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/images/scripts-ocr.jpg)|[@zsviczian](https://github.com/zsviczian)| |[Reverse arrows](Reverse%20arrows.md)|Reverse the direction of **arrows** within the scope of selected elements.|![](https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/images/scripts-reverse-arrow.jpg)|[@zsviczian](https://github.com/zsviczian)| |[Set Link Alias](Set20%Link20%Alias.md)|Iterates all of the links in the selected TextElements and prompts the user to set or modify the alias for each link found.|![](https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/images/scripts-set-link-alias.jpg)|[@zsviczian](https://github.com/zsviczian)| diff --git a/ea-scripts/index.md b/ea-scripts/index.md index 9aff4e0..97cf54f 100644 --- a/ea-scripts/index.md +++ b/ea-scripts/index.md @@ -46,6 +46,7 @@ I would love to include your contribution in the script library. If you have a s - [[#Lighten background color]] - [[#Modify background color opacity]] - [[#Modify stroke width of selected elements]] +- [[#Normalize Selected Arrows]] - [[#OCR - Optical Character Recognition]] - [[#Reverse arrows]] - [[#Set Link Alias]] @@ -180,6 +181,12 @@ https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea ```
Author@zsviczian
SourceFile on GitHub
DescriptionThis script will set the stroke width of selected elements. This is helpful, for example, when you scale freedraw sketches and want to reduce or increase their line width.
+## Normalize Selected Arrows +```excalidraw-script-install +https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Normalize%20Selected%20Arrows +``` +
Author@1-2-3
SourceFile on GitHub
DescriptionThis script will reset the start and end positions of the selected arrows. The arrow will point to the center of the connected box and will have a gap of 8px from the box.
+ ## OCR - Optical Character Recognition ```excalidraw-script-install https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/OCR%20-%20Optical%20Character%20Recognition.md diff --git a/images/scripts-normalize-selected-arrows.png b/images/scripts-normalize-selected-arrows.png new file mode 100644 index 0000000..85f23c3 Binary files /dev/null and b/images/scripts-normalize-selected-arrows.png differ