Component Drag-and-Drop & Connections
Applies to: CoModel cloud modeling & simulation platform (v1.7+) Related articles: Canvas & Component Browser, Parameters & Model Validation
1. Overview
In CoModel, the core modeling actions are dragging components from the browser onto the canvas and then connecting their ports with connections. The platform automatically generates the corresponding ModelingToolkit (MTK) Julia code from the diagram; conversely, comments in the code can restore the diagram. This chapter describes the complete drag-and-drop and connection workflow.

2. Dragging Components In
2.1 Placing Components
- Find the target component in the Component Browser on the left.
- Hold the left mouse button and drag the component into the canvas in the middle (while dragging, the cursor carries a default drag image of the component entry).
- Release the mouse at the target position; the system creates a component instance node there.
Every new node automatically:
- Generates a unique instance ID, such as
inst_a1b2c3d4. - Renders ports according to the component definition (see port types below).
- Initializes parameters to the component defaults.
- Triggers automatic regeneration of the model code; switch to the Code tab to see the corresponding
@namedinstantiation statements.
2.2 Port Types and Visual Styles
CoModel ports fall into three classes by connection semantics:
| Port type | Semantics |
|---|---|
| Physical port (acausal) | A physical-domain connection, such as a mechanical flange or an electrical pin; supports multiple connections |
| Signal input (input) | Receives control signals; only one incoming connection allowed |
| Signal output (output) | Sends control signals; can fan out to multiple inputs |
All ports share a circular style (10px diameter, 2.5px stroke): unconnected ports are white with a domain-colored stroke; connected ports are filled with the domain color. While drawing a connection, the originating port shows a blue halo, compatible ports highlight green, and incompatible ports gray out. Hover over a port to see its name, type, and physical domain.
Port colors are encoded by physical domain:
| Physical domain | Color |
|---|---|
| Mechanical · translational (mechanical_translational) | Orange (#F5A623) |
| Mechanical · rotational (mechanical_rotational) | Dark orange (#E8601C) |
| Electrical (electrical) | Yellow-green (#AFCC2A) |
| Thermal (thermal) | Red (#E8282B) |
| Hydraulic (hydraulic) | Blue (#3D7ABF) |
| Signal (signal) | Dark gray (#555555) |
Unrecognized domains display as neutral gray (#999999). A matching color means the same physical domain—connection validation requires both ends to belong to exactly the same domain, so only ports of the same color can connect, and ports of different colors never can.

2.3 Basic Node Operations
| Action | Method | Effect |
|---|---|---|
| Select | Click the node | The node border highlights and the parameter panel appears on the right |
| Move | Drag the node | Connections reroute automatically to follow the ports |
| Rotate | Context menu → Rotate, or press R |
The node rotates 90° clockwise and port positions rotate with it |
| Flip horizontal | Context menu → Flip Horizontal | Mirrors left-right; ports swap left and right |
| Flip vertical | Context menu → Flip Vertical | Mirrors top-bottom; ports swap top and bottom |
| Resize | Drag the corner handles | Minimum size 40×40 px; aspect ratio locked by default |
| Edit instance name | Double-click the node label | Must be a valid Julia variable name |
| Delete | Select, then press Delete |
Prompts for confirmation when connections exist |
| Copy / paste | Ctrl + C / Ctrl + V |
New nodes get new instance IDs; connections are not copied |
3. Drawing Connections
3.1 Connection Steps
- Hover over the source port; the cursor becomes a crosshair and the tooltip shows the port name, type, and physical domain.
- Hold the left mouse button and drag out from the port; a rubber-band preview line appears (the connection created on release is an orthogonal polyline). You can also click the source port and then click the target port to complete the connection.
- Drag to the target port: compatible ports highlight green to indicate that connecting is allowed; incompatible ports gray out (the cursor shows a not-allowed icon).
- Release the mouse to finish the connection. The connection is recorded in the diagram data, and the generated
connect(...)statement is visible on the Code tab.
Tip: If the mouse is released off a valid port, the connection is canceled automatically. In click-to-connect mode (click the source port, then click the target port), press
Escto cancel the pending connection.
3.2 Connection Semantics Rules
| Source port | Target port | Allowed | MTK semantics |
|---|---|---|---|
| Physical port (same domain) | Physical port (same domain) | ✅ | connect(a.flange, b.flange) |
| Signal output | Signal input | ✅ | connect(a.output, b.input) |
| Physical port | Signal port | ❌ | Incompatible types |
| Signal input | Signal input | ❌ | Two inputs cannot be interconnected |
| Signal output | Multiple signal inputs | ✅ | Fan-out |
The equation semantics of physical connections are derived automatically by MTK: the same physical connection generates two classes of equations—equal potential variables and conservation of flow variables (Kirchhoff's law).
# Electrical example: two resistors in series
@named r1 = Resistor(R=1.0)
@named r2 = Resistor(R=2.0)
# A physical connection generates potential-equality and Kirchhoff current equations
connect(r1.n, r2.p)
3.3 Port Connection States
- Unconnected port: keeps its original color, with a small circle indicating it can be connected.
- Connected physical port: filled solid; physical ports support multiple connections (Kirchhoff node).
- Connected signal input: filled solid; a signal input allows only one incoming connection.
- Connected signal output: filled solid; a signal output can fan out to multiple inputs.
4. Modifying and Deleting Connections
4.1 Adjusting the Path
- Click a connection to select it; it highlights and shows path edit points.
- Drag the "+" insert point on a segment to add a waypoint anywhere and adjust the orthogonal polyline path.
- Existing waypoints appear as dots: drag to move them, double-click to remove them. You can also click Reset waypoints in the properties panel on the right to restore automatic routing.
- Path changes are saved to the diagram's
waypointsfield and restored on the next load.

4.2 Deleting Connections
- Select the connection and press
Delete. - After deletion, the corresponding
connect(...)statement is removed from both the diagram data and the regenerated MTK code (visible on the Code tab).
4.3 Connection Labels and Colors
After selecting a connection, the Connection section of the properties panel on the right lets you set the label text and stroke color, and view or reset the path waypoints. Labels do not affect code generation; they are stored as visual annotations in the diagram metadata.
5. Worked Modeling Example
The following is a simplified spring-mass-damper system demonstrating the MTK code generated by dragging and connecting (the complete code generated by the platform is wrapped in @component function ModelName(; name), and each canvas connection corresponds to one connect statement):
using ModelingToolkit
using ModelingToolkit: t_nounits as t, D_nounits as D
using ModelingToolkitStandardLibrary.Mechanical.Translational: Mass, Spring, Damper, Fixed
@component function SpringMassDamper(; name)
pars = Num[]
@named mass = Mass(m=1.0)
@named spring = Spring(k=1000.0)
@named damper = Damper(d=10.0)
@named fixed = Fixed()
eqs = [
connect(mass.flange, spring.flange_a),
connect(mass.flange, damper.flange_a),
connect(spring.flange_b, fixed.flange),
connect(damper.flange_b, fixed.flange),
]
return System(eqs, t, [], pars; systems=[mass, spring, damper, fixed], name=name)
end
On the CoModel canvas, the code above corresponds to:
- Drag
Mass,Spring,Damper, andFixedfrom the mechanical library. - Connect the same-side ports of
SpringandDampertoMassandFixedrespectively. - The platform automatically checks domain consistency and generates the correct
connectstatements.
6. FAQ
Why can't two ports of the same color be connected?
A matching color means the same physical domain, but the connection direction rules must also hold: two signal inputs cannot be interconnected, and neither can two signal outputs. For example, two dark-gray signal ports cannot be connected if both are inputs. While drawing a connection, compatible ports highlight green and incompatible ports gray out; hover over a port to see its name, type, and physical domain.
Can one signal output connect to multiple inputs?
Yes. Signal outputs support fan-out: one output port can connect to multiple input ports.
The Code tab does not show updates after a connection is made?
Diagram operations regenerate the Julia code automatically with a debounce interval of about 800ms. If you just finished a connection, wait a moment before switching to the Code tab. For the sync rules between diagram and code, see Code ↔ Diagram Two-Way Sync.