Skip to content

Commit 61c4363

Browse files
committed
support virtual node and master station
1 parent 0903b48 commit 61c4363

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

src/components/svg-canvas-graph.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ import {
1919
setSelected,
2020
} from '../redux/runtime/runtime-slice';
2121
import { getMousePosition, pointerPosToSVGCoord, roundToNearestN } from '../util/helpers';
22+
import { getNearestPolyline, getPolylineDistance, isNodeSupportPolyline } from '../util/graph';
2223
import { makeParallelIndex } from '../util/parallel';
2324
import { getLines, getNodes } from '../util/process-elements';
2425
import SvgLayer from './svg-layer';
2526
import { linePaths } from './svgs/lines/lines';
2627
import singleColor from './svgs/lines/styles/single-color';
2728
import miscNodes from './svgs/nodes/misc-nodes';
2829
import { default as stations } from './svgs/stations/stations';
29-
import { getNearestPolyline, getPolylineDistance } from '../util/graph';
3030

3131
const connectableNodesType = [
3232
...Object.values(StationType),
@@ -112,7 +112,7 @@ const SvgCanvas = () => {
112112
let newX = toX;
113113
let newY = toY;
114114

115-
if (node.startsWith('stn')) {
115+
if (isNodeSupportPolyline(node, graph.current)) {
116116
if (activePolylines.length !== 0) {
117117
Object.values(activePolylines).forEach(p => {
118118
const d = getPolylineDistance(p, toX, toY);

src/redux/runtime/runtime-slice.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import { MAX_MASTER_NODE_FREE, MAX_MASTER_NODE_PRO } from '../../constants/maste
77
import { MiscNodeType } from '../../constants/nodes';
88
import i18n from '../../i18n/config';
99
import { countParallelLines, MAX_PARALLEL_LINES_FREE, MAX_PARALLEL_LINES_PRO } from '../../util/parallel';
10+
import { getPolylines } from '../../util/graph';
1011
import { setAutoParallel } from '../app/app-slice';
1112
import { redoAction, undoAction } from '../param/param-slice';
12-
import { getPolylines } from '../../util/graph';
1313

1414
/**
1515
* RuntimeState contains all the data that do not require any persistence.

src/util/graph.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,16 @@ export const getMasterNodeTypes = (graph: MultiDirectedGraph<NodeAttributes, Edg
113113
return newList;
114114
};
115115

116+
export const isNodeSupportPolyline = (
117+
node: StnId | MiscNodeId,
118+
graph: MultiDirectedGraph<NodeAttributes, EdgeAttributes, GraphAttributes>
119+
) =>
120+
node.startsWith('stn') ||
121+
(node.startsWith('misc_node') && graph.getNodeAttribute(node, 'type') === MiscNodeType.Virtual) ||
122+
(node.startsWith('misc_node') &&
123+
graph.getNodeAttribute(node, 'type') === MiscNodeType.Master &&
124+
graph.getNodeAttributes(node)[MiscNodeType.Master]!.nodeType === 'Station');
125+
116126
export const getPolylines = (graph: MultiDirectedGraph<NodeAttributes, EdgeAttributes, GraphAttributes>): Polylines => {
117127
const polylinesX: Polyline[] = [];
118128
const polylinesY: Polyline[] = [];
@@ -122,7 +132,7 @@ export const getPolylines = (graph: MultiDirectedGraph<NodeAttributes, EdgeAttri
122132
// const sortFunc = (x: Polyline, y: Polyline) => y.c - x.c;
123133

124134
graph
125-
.filterNodes(node => node.startsWith('stn'))
135+
.filterNodes(node => isNodeSupportPolyline(node as StnId | MiscNodeId, graph))
126136
.forEach(node => {
127137
const x = graph.getNodeAttribute(node, 'x');
128138
const y = graph.getNodeAttribute(node, 'y');

0 commit comments

Comments
 (0)