# ScaleBar
[Video tutorial](https://www.bilibili.com/video/BV1WHuo6oEAC/?vd_source=26b97f3813c282e1420c2304f2e2efd2)
ScaleBar is a Cytoscape desktop app that overlays coordinate rulers on the
active network view. It draws a horizontal ruler at the top of the drawing area
and a vertical ruler on the left. Tick marks extend into the canvas as a dashed
grid, making it easier to inspect node positions and spatial relationships in
the current network view.
The ruler labels are calculated from the current Cytoscape network view center
and zoom factor, so the coordinate display updates as you pan and zoom.
## Features
- Top and left coordinate rulers for the active network view.
- Dashed grid lines extended from ruler tick marks.
- Adaptive tick spacing based on the current zoom level.
- Transparent overlay that does not block normal Cytoscape canvas interaction.
- Toggle support from both the Cytoscape Apps menu and a keyboard shortcut.
- Support for both docked and detached network views.
- Vector PDF export that follows the current ruler visibility state.
## Usage
Open a network view in Cytoscape, then toggle the rulers from:
```text
Apps > ScaleBar > Show Coordinate Rulers
```
You can also use the keyboard shortcut:
```text
Command + G on macOS
Ctrl + G on Windows/Linux
```
Use the same menu item or shortcut again to hide the rulers and grid.
To export a vector PDF, use:
```text
Apps > ScaleBar > Export View With Rulers to PDF...
```
Cytoscape's built-in image export exports the network rendering canvas only, so
it does not include this app's Swing overlay. Use the ScaleBar export command
when you want export behavior that follows the current ScaleBar state.
The ScaleBar PDF export writes through a vector PDF graphics context. If
ScaleBar is visible when you export, the PDF includes the rulers and grid. If
ScaleBar is hidden, the PDF exports the network view without the overlay.
## Commands
ScaleBar also registers Cytoscape Commands under the `scalebar` namespace for
automation from the Cytoscape Command Tool, RCy3, py4cytoscape, and CyREST-based
workflows.
Available commands:
```text
scalebar show
scalebar hide
scalebar toggle
scalebar status
scalebar export_pdf outputFile="/absolute/path/to/scalebar-view.pdf"
scalebar export_png outputFile="/absolute/path/to/scalebar-view.png"
```
Examples:
```text
scalebar show
scalebar export_pdf outputFile="/absolute/path/to/network-with-scalebar.pdf"
scalebar export_png outputFile="/absolute/path/to/network-with-scalebar.png"
```
RCy3 example:
```r
commandsRun("scalebar show")
commandsRun('scalebar export_pdf outputFile="/absolute/path/to/network-with-scalebar.pdf"')
commandsRun('scalebar export_png outputFile="/absolute/path/to/network-with-scalebar.png"')
```
py4cytoscape example:
```python
import py4cytoscape as p4c
p4c.commands_run("scalebar show")
p4c.commands_run('scalebar export_pdf outputFile="/absolute/path/to/network-with-scalebar.pdf"')
p4c.commands_run('scalebar export_png outputFile="/absolute/path/to/network-with-scalebar.png"')
```
Use an absolute `outputFile` value for `scalebar export_pdf` and
`scalebar export_png`, especially when calling commands from RCy3 or
py4cytoscape. Both export commands follow the current ScaleBar visibility state.
## Build
```bash
mvn package
```
The app bundle is generated at:
```text
target/scalebar-1.0.1.jar
```
## Install in Cytoscape
Open Cytoscape, then use:
```text
Apps > App Manager > Install from File...
```
Choose `target/scalebar-1.0.1.jar`.
## Notes
- Coordinates are calculated from `NETWORK_CENTER_X_LOCATION`,
`NETWORK_CENTER_Y_LOCATION`, and `NETWORK_SCALE_FACTOR`.
- If no network view is open, the app will show a message instead of drawing
the overlay.
## Author
zhangjing