diff --git a/ea-scripts/Grid Selected Images.md b/ea-scripts/Grid Selected Images.md index 7b89988..d858f58 100644 --- a/ea-scripts/Grid Selected Images.md +++ b/ea-scripts/Grid Selected Images.md @@ -1,67 +1,67 @@ -/* -![](https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/images/grid-selected-images.png) - -This script arranges selected images into compact grid view, removing gaps in-between, resizing when necessary and breaking into multiple rows/columns. - -```javascript -*/ - -try { - let els = ea.getViewSelectedElements().filter(el => el.type == 'image'); - - new Notice(els.length); - - if (els.length == 0) throw new Error('No image elements selected'); - - const bounds = ea.getBoundingBox(els); - const { topX, topY, width, height } = bounds; - - els.sort((a, b) => a.x + a.y < b.x + b.y); - - const areaAvailable = width * height; - - let elWidth = els[0].width; - let elHeight = els[0].height; - - if (elWidth * elHeight > areaAvailable) { - while (elWidth * elHeight > areaAvailable) { - elWidth /= 1.1; - elHeight /= 1.1; - } - } else if (elWidth * elHeight < areaAvailable) { - while (elWidth * elHeight > areaAvailable) { - elWidth *= 1.1; - elHeight *= 1.1; - } - } - - const rows = (width - elWidth) / elWidth; - - let row = 0, column = 0; - for (const element of els) { - element.x = topX + (elWidth * row); - element.y = topY + (elHeight * column); - - if (element.width > elWidth) { - while (element.width >= elWidth) { - element.width /= 1.1; - element.height /= 1.1; - } - } else if (element.width < elWidth) { - while (element.width <= elWidth) { - element.width *= 1.1; - element.height *= 1.1; - } - } - - row++; - if (row > rows) { - row = 0; - column++; - } - } - - ea.addElementsToView(false, true, true); -} catch (err) { - _ = new Notice(err.toString()) +/* +![](https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/images/scripts-grid-selected-images.png) + +This script arranges selected images into compact grid view, removing gaps in-between, resizing when necessary and breaking into multiple rows/columns. + +```javascript +*/ + +try { + let els = ea.getViewSelectedElements().filter(el => el.type == 'image'); + + new Notice(els.length); + + if (els.length == 0) throw new Error('No image elements selected'); + + const bounds = ea.getBoundingBox(els); + const { topX, topY, width, height } = bounds; + + els.sort((a, b) => a.x + a.y < b.x + b.y); + + const areaAvailable = width * height; + + let elWidth = els[0].width; + let elHeight = els[0].height; + + if (elWidth * elHeight > areaAvailable) { + while (elWidth * elHeight > areaAvailable) { + elWidth /= 1.1; + elHeight /= 1.1; + } + } else if (elWidth * elHeight < areaAvailable) { + while (elWidth * elHeight > areaAvailable) { + elWidth *= 1.1; + elHeight *= 1.1; + } + } + + const rows = (width - elWidth) / elWidth; + + let row = 0, column = 0; + for (const element of els) { + element.x = topX + (elWidth * row); + element.y = topY + (elHeight * column); + + if (element.width > elWidth) { + while (element.width >= elWidth) { + element.width /= 1.1; + element.height /= 1.1; + } + } else if (element.width < elWidth) { + while (element.width <= elWidth) { + element.width *= 1.1; + element.height *= 1.1; + } + } + + row++; + if (row > rows) { + row = 0; + column++; + } + } + + ea.addElementsToView(false, true, true); +} catch (err) { + _ = new Notice(err.toString()) } \ No newline at end of file diff --git a/ea-scripts/directory-info.json b/ea-scripts/directory-info.json index 13a271f..03ca6f7 100644 --- a/ea-scripts/directory-info.json +++ b/ea-scripts/directory-info.json @@ -1 +1 @@ -[{"fname":"Mindmap connector.md","mtime":1658686599427},{"fname":"Mindmap connector.svg","mtime":1658686599427},{"fname":"Add Connector Point.md","mtime":1645305706000},{"fname":"Add Connector Point.svg","mtime":1645944722000},{"fname":"Add Link to Existing File and Open.md","mtime":1647807918345},{"fname":"Add Link to Existing File and Open.svg","mtime":1645964261000},{"fname":"Add Link to New Page and Open.md","mtime":1654168862138},{"fname":"Add Link to New Page and Open.svg","mtime":1645960639000},{"fname":"Add Next Step in Process.md","mtime":1645305706000},{"fname":"Add Next Step in Process.svg","mtime":1645960639000},{"fname":"Box Each Selected Groups.md","mtime":1645305706000},{"fname":"Box Each Selected Groups.svg","mtime":1645967510000},{"fname":"Box Selected Elements.md","mtime":1645305706000},{"fname":"Box Selected Elements.svg","mtime":1645960639000},{"fname":"Change shape of selected elements.md","mtime":1652701169236},{"fname":"Change shape of selected elements.svg","mtime":1645960775000},{"fname":"Connect elements.md","mtime":1645305706000},{"fname":"Connect elements.svg","mtime":1645960639000},{"fname":"Convert freedraw to line.md","mtime":1645305706000},{"fname":"Convert freedraw to line.svg","mtime":1645960639000},{"fname":"Convert selected text elements to sticky notes.md","mtime":1645620104000},{"fname":"Convert selected text elements to sticky notes.svg","mtime":1645960639000},{"fname":"Convert text to link with folder and alias.md","mtime":1641639819000},{"fname":"Convert text to link with folder and alias.svg","mtime":1645960639000},{"fname":"Copy Selected Element Styles to Global.md","mtime":1642232088000},{"fname":"Copy Selected Element Styles to Global.svg","mtime":1645960639000},{"fname":"Create new markdown file and embed into active drawing.md","mtime":1640866935000},{"fname":"Create new markdown file and embed into active drawing.svg","mtime":1645960639000},{"fname":"Darken background color.md","mtime":1644924415000},{"fname":"Darken background color.svg","mtime":1645960639000},{"fname":"Elbow connectors.md","mtime":1645305706000},{"fname":"Elbow connectors.svg","mtime":1645960639000},{"fname":"Expand rectangles horizontally keep text centered.md","mtime":1646563692000},{"fname":"Expand rectangles horizontally keep text centered.svg","mtime":1645967510000},{"fname":"Expand rectangles horizontally.md","mtime":1644950235000},{"fname":"Expand rectangles horizontally.svg","mtime":1645967510000},{"fname":"Expand rectangles vertically keep text centered.md","mtime":1646563692000},{"fname":"Expand rectangles vertically keep text centered.svg","mtime":1645967510000},{"fname":"Expand rectangles vertically.md","mtime":1658686599427},{"fname":"Expand rectangles vertically.svg","mtime":1645967510000},{"fname":"Fixed horizontal distance between centers.md","mtime":1646743234000},{"fname":"Fixed horizontal distance between centers.svg","mtime":1645960639000},{"fname":"Fixed inner distance.md","mtime":1646743234000},{"fname":"Fixed inner distance.svg","mtime":1645960639000},{"fname":"Fixed spacing.md","mtime":1646743234000},{"fname":"Fixed spacing.svg","mtime":1645967510000},{"fname":"Fixed vertical distance between centers.md","mtime":1646743234000},{"fname":"Fixed vertical distance between centers.svg","mtime":1645967510000},{"fname":"Fixed vertical distance.md","mtime":1646743234000},{"fname":"Fixed vertical distance.svg","mtime":1645967510000},{"fname":"Lighten background color.md","mtime":1644924415000},{"fname":"Lighten background color.svg","mtime":1645959546000},{"fname":"Modify background color opacity.md","mtime":1644924415000},{"fname":"Modify background color opacity.svg","mtime":1645944722000},{"fname":"Normalize Selected Arrows.md","mtime":1647607808346},{"fname":"Normalize Selected Arrows.svg","mtime":1645960639000},{"fname":"OCR - Optical Character Recognition.md","mtime":1643462434000},{"fname":"OCR - Optical Character Recognition.svg","mtime":1645959546000},{"fname":"Organic Line.md","mtime":1645297209000},{"fname":"Organic Line.svg","mtime":1645964261000},{"fname":"README.md","mtime":1645175700000},{"fname":"Repeat Elements.md","mtime":1645619546000},{"fname":"Repeat Elements.svg","mtime":1645960639000},{"fname":"Reverse arrows.md","mtime":1645305706000},{"fname":"Reverse arrows.svg","mtime":1645960639000},{"fname":"Scribble Helper.md","mtime":1645305706000},{"fname":"Scribble Helper.svg","mtime":1645944722000},{"fname":"Select Elements of Type.md","mtime":1643464321000},{"fname":"Select Elements of Type.svg","mtime":1645960639000},{"fname":"Set Dimensions.md","mtime":1645305706000},{"fname":"Set Dimensions.svg","mtime":1645944722000},{"fname":"Set Font Family.md","mtime":1645305706000},{"fname":"Set Font Family.svg","mtime":1645944722000},{"fname":"Set Grid.md","mtime":1642877297000},{"fname":"Set Grid.svg","mtime":1645960639000},{"fname":"Set Link Alias.md","mtime":1645305706000},{"fname":"Set Link Alias.svg","mtime":1645960639000},{"fname":"Set Stroke Width of Selected Elements.md","mtime":1645305706000},{"fname":"Set Stroke Width of Selected Elements.svg","mtime":1645960639000},{"fname":"Set Text Alignment.md","mtime":1645305706000},{"fname":"Set Text Alignment.svg","mtime":1645960639000},{"fname":"Set background color of unclosed line object by adding a shadow clone.md","mtime":1645305706000},{"fname":"Set background color of unclosed line object by adding a shadow clone.svg","mtime":1645960639000},{"fname":"Split text by lines.md","mtime":1645305706000},{"fname":"Split text by lines.svg","mtime":1645944722000},{"fname":"Transfer TextElements to Excalidraw markdown metadata.md","mtime":1641056885000},{"fname":"Transfer TextElements to Excalidraw markdown metadata.svg","mtime":1645959546000},{"fname":"Zoom to Fit Selected Elements.md","mtime":1640770602000},{"fname":"Zoom to Fit Selected Elements.svg","mtime":1645960639000},{"fname":"directory-info.json","mtime":1646583437000},{"fname":"index-new.md","mtime":1645986149000},{"fname":"index.md","mtime":1645175700000},{"fname":"TheBrain-navigation.md","mtime":1650216837464},{"fname":"TheBrain-navigation.svg","mtime":1649614401982}] +[{"fname":"Mindmap connector.md","mtime":1658686599427},{"fname":"Mindmap connector.svg","mtime":1658686599427},{"fname":"Add Connector Point.md","mtime":1645305706000},{"fname":"Add Connector Point.svg","mtime":1645944722000},{"fname":"Add Link to Existing File and Open.md","mtime":1647807918345},{"fname":"Add Link to Existing File and Open.svg","mtime":1645964261000},{"fname":"Add Link to New Page and Open.md","mtime":1654168862138},{"fname":"Add Link to New Page and Open.svg","mtime":1645960639000},{"fname":"Add Next Step in Process.md","mtime":1645305706000},{"fname":"Add Next Step in Process.svg","mtime":1645960639000},{"fname":"Box Each Selected Groups.md","mtime":1645305706000},{"fname":"Box Each Selected Groups.svg","mtime":1645967510000},{"fname":"Box Selected Elements.md","mtime":1645305706000},{"fname":"Box Selected Elements.svg","mtime":1645960639000},{"fname":"Change shape of selected elements.md","mtime":1652701169236},{"fname":"Change shape of selected elements.svg","mtime":1645960775000},{"fname":"Connect elements.md","mtime":1645305706000},{"fname":"Connect elements.svg","mtime":1645960639000},{"fname":"Convert freedraw to line.md","mtime":1645305706000},{"fname":"Convert freedraw to line.svg","mtime":1645960639000},{"fname":"Convert selected text elements to sticky notes.md","mtime":1645620104000},{"fname":"Convert selected text elements to sticky notes.svg","mtime":1645960639000},{"fname":"Convert text to link with folder and alias.md","mtime":1641639819000},{"fname":"Convert text to link with folder and alias.svg","mtime":1645960639000},{"fname":"Copy Selected Element Styles to Global.md","mtime":1642232088000},{"fname":"Copy Selected Element Styles to Global.svg","mtime":1645960639000},{"fname":"Create new markdown file and embed into active drawing.md","mtime":1640866935000},{"fname":"Create new markdown file and embed into active drawing.svg","mtime":1645960639000},{"fname":"Darken background color.md","mtime":1644924415000},{"fname":"Darken background color.svg","mtime":1645960639000},{"fname":"Elbow connectors.md","mtime":1645305706000},{"fname":"Elbow connectors.svg","mtime":1645960639000},{"fname":"Expand rectangles horizontally keep text centered.md","mtime":1646563692000},{"fname":"Expand rectangles horizontally keep text centered.svg","mtime":1645967510000},{"fname":"Expand rectangles horizontally.md","mtime":1644950235000},{"fname":"Expand rectangles horizontally.svg","mtime":1645967510000},{"fname":"Expand rectangles vertically keep text centered.md","mtime":1646563692000},{"fname":"Expand rectangles vertically keep text centered.svg","mtime":1645967510000},{"fname":"Expand rectangles vertically.md","mtime":1658686599427},{"fname":"Expand rectangles vertically.svg","mtime":1645967510000},{"fname":"Fixed horizontal distance between centers.md","mtime":1646743234000},{"fname":"Fixed horizontal distance between centers.svg","mtime":1645960639000},{"fname":"Fixed inner distance.md","mtime":1646743234000},{"fname":"Fixed inner distance.svg","mtime":1645960639000},{"fname":"Fixed spacing.md","mtime":1646743234000},{"fname":"Fixed spacing.svg","mtime":1645967510000},{"fname":"Fixed vertical distance between centers.md","mtime":1646743234000},{"fname":"Fixed vertical distance between centers.svg","mtime":1645967510000},{"fname":"Fixed vertical distance.md","mtime":1646743234000},{"fname":"Fixed vertical distance.svg","mtime":1645967510000},{"fname":"Lighten background color.md","mtime":1644924415000},{"fname":"Lighten background color.svg","mtime":1645959546000},{"fname":"Modify background color opacity.md","mtime":1644924415000},{"fname":"Modify background color opacity.svg","mtime":1645944722000},{"fname":"Normalize Selected Arrows.md","mtime":1647607808346},{"fname":"Normalize Selected Arrows.svg","mtime":1645960639000},{"fname":"OCR - Optical Character Recognition.md","mtime":1643462434000},{"fname":"OCR - Optical Character Recognition.svg","mtime":1645959546000},{"fname":"Organic Line.md","mtime":1645297209000},{"fname":"Organic Line.svg","mtime":1645964261000},{"fname":"README.md","mtime":1645175700000},{"fname":"Repeat Elements.md","mtime":1645619546000},{"fname":"Repeat Elements.svg","mtime":1645960639000},{"fname":"Reverse arrows.md","mtime":1645305706000},{"fname":"Reverse arrows.svg","mtime":1645960639000},{"fname":"Scribble Helper.md","mtime":1645305706000},{"fname":"Scribble Helper.svg","mtime":1645944722000},{"fname":"Select Elements of Type.md","mtime":1643464321000},{"fname":"Select Elements of Type.svg","mtime":1645960639000},{"fname":"Set Dimensions.md","mtime":1645305706000},{"fname":"Set Dimensions.svg","mtime":1645944722000},{"fname":"Set Font Family.md","mtime":1645305706000},{"fname":"Set Font Family.svg","mtime":1645944722000},{"fname":"Set Grid.md","mtime":1642877297000},{"fname":"Set Grid.svg","mtime":1645960639000},{"fname":"Set Link Alias.md","mtime":1645305706000},{"fname":"Set Link Alias.svg","mtime":1645960639000},{"fname":"Set Stroke Width of Selected Elements.md","mtime":1645305706000},{"fname":"Set Stroke Width of Selected Elements.svg","mtime":1645960639000},{"fname":"Set Text Alignment.md","mtime":1645305706000},{"fname":"Set Text Alignment.svg","mtime":1645960639000},{"fname":"Set background color of unclosed line object by adding a shadow clone.md","mtime":1645305706000},{"fname":"Set background color of unclosed line object by adding a shadow clone.svg","mtime":1645960639000},{"fname":"Split text by lines.md","mtime":1645305706000},{"fname":"Split text by lines.svg","mtime":1645944722000},{"fname":"Transfer TextElements to Excalidraw markdown metadata.md","mtime":1641056885000},{"fname":"Transfer TextElements to Excalidraw markdown metadata.svg","mtime":1645959546000},{"fname":"Zoom to Fit Selected Elements.md","mtime":1640770602000},{"fname":"Zoom to Fit Selected Elements.svg","mtime":1645960639000},{"fname":"directory-info.json","mtime":1646583437000},{"fname":"index-new.md","mtime":1645986149000},{"fname":"index.md","mtime":1645175700000},{"fname":"TheBrain-navigation.md","mtime":1650216837464},{"fname":"TheBrain-navigation.svg","mtime":1649614401982},{"fname":"Grid Selected Images.md","mtime":1649614401982},{"fname":"Grid Selected Images.svg","mtime":1649614401982}] diff --git a/ea-scripts/index-new.md b/ea-scripts/index-new.md index 71c4f10..fca3cf9 100644 --- a/ea-scripts/index-new.md +++ b/ea-scripts/index-new.md @@ -51,6 +51,7 @@ I would love to include your contribution in the script library. If you have a s |
|[[#Fixed spacing]]| |
|[[#Fixed vertical distance between centers]]| |
|[[#Fixed vertical distance]]| +|
|[[#Grid Selected Images]]| |
|[[#Lighten background color]]| |
|[[#Mindmap connector]]| |
|[[#Modify background color opacity]]| @@ -216,6 +217,12 @@ https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea ```
Author@1-2-3
SourceFile on GitHub
DescriptionThe script arranges the selected elements vertically with a fixed spacing. When we create an architecture diagram or mind map, we often need to arrange a large number of elements in a fixed spacing. `Fixed spacing` and `Fixed vertical Distance` scripts can save us a lot of time.
+## Grid selected images +```excalidraw-script-install +https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Grid%20Selected%20Images.md +``` +
Author@7flash
SourceFile on GitHub
DescriptionThis script arranges selected images into compact grid view, removing gaps in-between, resizing when necessary and breaking into multiple rows/columns.
+ ## Lighten background color ```excalidraw-script-install https://raw.githubusercontent.com/zsviczian/obsidian-excalidraw-plugin/master/ea-scripts/Lighten%20background%20color.md diff --git a/images/scripts-grid-selected-images.png b/images/scripts-grid-selected-images.png index 23a4d56..1af898b 100644 Binary files a/images/scripts-grid-selected-images.png and b/images/scripts-grid-selected-images.png differ