Skip to content

Commit c2f6e8c

Browse files
committed
feat: add CRT loop line/line badge connector and loop line style of basic station
1 parent 124a3c3 commit c2f6e8c

File tree

10 files changed

+224
-9
lines changed

10 files changed

+224
-9
lines changed

src/components/svgs/lines/lines.ts

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ import londonSandwich from './styles/london-sandwich';
3131
import londonLutonAirportDART from './styles/london-DART';
3232
import londonIFSCloudCableCar from './styles/london-ifs-could-cable-car';
3333
import guangdongIntercityRailway from './styles/guangdong-intercity-railway';
34+
import chongqingRTLoop from './styles/chongqingrt-loop';
35+
import chongqingRTLineBadge from './styles/chongqingrt-line-badge';
3436

3537
export const linePaths = {
3638
[LinePathType.Diagonal]: diagonalPath,
@@ -68,4 +70,6 @@ export const lineStyles = {
6870
[LineStyleType.LondonLutonAirportDART]: londonLutonAirportDART,
6971
[LineStyleType.LondonIFSCloudCableCar]: londonIFSCloudCableCar,
7072
[LineStyleType.GuangdongIntercityRailway]: guangdongIntercityRailway,
73+
[LineStyleType.ChongqingRTLoop]: chongqingRTLoop,
74+
[LineStyleType.ChongqingRTLineBadge]: chongqingRTLineBadge,
7175
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { RmgFields, RmgFieldsField } from '@railmapgen/rmg-components';
2+
import { MonoColour } from '@railmapgen/rmg-palette-resources';
3+
import React from 'react';
4+
import { useTranslation } from 'react-i18next';
5+
import { AttrsProps, CityCode } from '../../../../constants/constants';
6+
import {
7+
LinePathAttributes,
8+
LinePathType,
9+
LineStyle,
10+
LineStyleComponentProps,
11+
LineStyleType,
12+
} from '../../../../constants/lines';
13+
import { AttributesWithColor, ColorField } from '../../../panels/details/color-field';
14+
15+
const ChongqingRTLineBadge = (props: LineStyleComponentProps<ChongqingRTLineBadgeAttributes>) => {
16+
const { id, path, styleAttrs, newLine, handlePointerDown } = props;
17+
const { color = defaultChongqingRTLineBadgeAttributes.color } = styleAttrs ?? defaultChongqingRTLineBadgeAttributes;
18+
19+
const onPointerDown = React.useCallback(
20+
(e: React.PointerEvent<SVGElement>) => handlePointerDown(id, e),
21+
[id, handlePointerDown]
22+
);
23+
24+
return (
25+
<path
26+
id={id}
27+
d={path}
28+
fill="none"
29+
stroke={color[2]}
30+
strokeWidth="3"
31+
strokeLinecap="round"
32+
cursor="pointer"
33+
onPointerDown={newLine ? undefined : onPointerDown}
34+
pointerEvents={newLine ? 'none' : undefined}
35+
/>
36+
);
37+
};
38+
39+
/**
40+
* ChongqingRTLineBadge specific props.
41+
*/
42+
export interface ChongqingRTLineBadgeAttributes extends LinePathAttributes, AttributesWithColor {}
43+
44+
const defaultChongqingRTLineBadgeAttributes: ChongqingRTLineBadgeAttributes = {
45+
color: [CityCode.Chongqing, 'cq1', '#E4002B', MonoColour.white],
46+
};
47+
48+
const chongqingRTLineBadgeAttrsComponent = (props: AttrsProps<ChongqingRTLineBadgeAttributes>) => {
49+
const { t } = useTranslation();
50+
51+
const fields: RmgFieldsField[] = [
52+
{
53+
type: 'custom',
54+
label: t('color'),
55+
component: (
56+
<ColorField
57+
type={LineStyleType.ChongqingRTLineBadge}
58+
defaultTheme={defaultChongqingRTLineBadgeAttributes.color}
59+
/>
60+
),
61+
},
62+
];
63+
64+
return <RmgFields fields={fields} />;
65+
};
66+
67+
const chongqingRTLineBadge: LineStyle<ChongqingRTLineBadgeAttributes> = {
68+
component: ChongqingRTLineBadge,
69+
defaultAttrs: defaultChongqingRTLineBadgeAttributes,
70+
attrsComponent: chongqingRTLineBadgeAttrsComponent,
71+
metadata: {
72+
displayName: 'panel.details.lines.chongqingRTLineBadge.displayName',
73+
supportLinePathType: [LinePathType.Diagonal, LinePathType.Perpendicular, LinePathType.RotatePerpendicular],
74+
},
75+
};
76+
77+
export default chongqingRTLineBadge;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { RmgFields, RmgFieldsField } from '@railmapgen/rmg-components';
2+
import { MonoColour } from '@railmapgen/rmg-palette-resources';
3+
import React from 'react';
4+
import { useTranslation } from 'react-i18next';
5+
import { AttrsProps, CityCode } from '../../../../constants/constants';
6+
import {
7+
LinePathAttributes,
8+
LinePathType,
9+
LineStyle,
10+
LineStyleComponentProps,
11+
LineStyleType,
12+
} from '../../../../constants/lines';
13+
import { AttributesWithColor, ColorField } from '../../../panels/details/color-field';
14+
15+
const ChongqingRTLoop = (props: LineStyleComponentProps<ChongqingRTLoopAttributes>) => {
16+
const { id, path, styleAttrs, newLine, handlePointerDown } = props;
17+
const { color = defaultChongqingRTLoopAttributes.color } = styleAttrs ?? defaultChongqingRTLoopAttributes;
18+
19+
const onPointerDown = React.useCallback(
20+
(e: React.PointerEvent<SVGElement>) => handlePointerDown(id, e),
21+
[id, handlePointerDown]
22+
);
23+
24+
return (
25+
<path
26+
id={id}
27+
d={path}
28+
fill="none"
29+
stroke={color[2]}
30+
strokeWidth="8"
31+
strokeLinecap="round"
32+
cursor="pointer"
33+
onPointerDown={newLine ? undefined : onPointerDown}
34+
pointerEvents={newLine ? 'none' : undefined}
35+
/>
36+
);
37+
};
38+
39+
/**
40+
* ChongqingRTLoop specific props.
41+
*/
42+
export interface ChongqingRTLoopAttributes extends LinePathAttributes, AttributesWithColor {}
43+
44+
const defaultChongqingRTLoopAttributes: ChongqingRTLoopAttributes = {
45+
color: [CityCode.Chongqing, 'cq1', '#E4002B', MonoColour.white],
46+
};
47+
48+
const chongqingRTLoopAttrsComponent = (props: AttrsProps<ChongqingRTLoopAttributes>) => {
49+
const { t } = useTranslation();
50+
51+
const fields: RmgFieldsField[] = [
52+
{
53+
type: 'custom',
54+
label: t('color'),
55+
component: (
56+
<ColorField
57+
type={LineStyleType.ChongqingRTLoop}
58+
defaultTheme={defaultChongqingRTLoopAttributes.color}
59+
/>
60+
),
61+
},
62+
];
63+
64+
return <RmgFields fields={fields} />;
65+
};
66+
67+
const chongqingRTLoop: LineStyle<ChongqingRTLoopAttributes> = {
68+
component: ChongqingRTLoop,
69+
defaultAttrs: defaultChongqingRTLoopAttributes,
70+
attrsComponent: chongqingRTLoopAttrsComponent,
71+
metadata: {
72+
displayName: 'panel.details.lines.chongqingRTLoop.displayName',
73+
supportLinePathType: [LinePathType.Diagonal, LinePathType.Perpendicular, LinePathType.RotatePerpendicular],
74+
},
75+
};
76+
77+
export default chongqingRTLoop;

src/components/svgs/stations/chongqingrt-basic.tsx

+17-3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const ChongqingRTBasicStation = (props: StationComponentProps) => {
3030
nameOffsetX = defaultChongqingRTBasicStationAttributes.nameOffsetX,
3131
nameOffsetY = defaultChongqingRTBasicStationAttributes.nameOffsetY,
3232
color = defaultChongqingRTBasicStationAttributes.color,
33+
isLoop = defaultChongqingRTBasicStationAttributes.isLoop,
3334
} = attrs[StationType.ChongqingRTBasic] ?? defaultChongqingRTBasicStationAttributes;
3435

3536
const onPointerDown = React.useCallback(
@@ -59,9 +60,9 @@ const ChongqingRTBasicStation = (props: StationComponentProps) => {
5960
} else if (oX === 'right' && oY === 'bottom') {
6061
return [5, names[0].split('\n').length * LINE_HEIGHT[oY] + 3];
6162
} else if (oX === 'left' && oY === 'middle') {
62-
return [-5, 0];
63+
return [-5, 2];
6364
} else if (oX === 'right' && oY === 'middle') {
64-
return [5, 0];
65+
return [5, 2];
6566
} else return [0, 0];
6667
};
6768

@@ -72,7 +73,7 @@ const ChongqingRTBasicStation = (props: StationComponentProps) => {
7273
<g id={id} transform={`translate(${x}, ${y})`}>
7374
<circle
7475
id={`stn_core_${id}`}
75-
r="3"
76+
r={isLoop ? 4 : 3}
7677
stroke={color[2]}
7778
strokeWidth="1"
7879
fill="white"
@@ -109,13 +110,15 @@ const ChongqingRTBasicStation = (props: StationComponentProps) => {
109110
export interface ChongqingRTBasicStationAttributes extends StationAttributes, AttributesWithColor {
110111
nameOffsetX: NameOffsetX;
111112
nameOffsetY: NameOffsetY;
113+
isLoop: boolean;
112114
}
113115

114116
const defaultChongqingRTBasicStationAttributes: ChongqingRTBasicStationAttributes = {
115117
...defaultStationAttributes,
116118
color: [CityCode.Chongqing, 'cq1', '#e4002b', MonoColour.white],
117119
nameOffsetX: 'right',
118120
nameOffsetY: 'top',
121+
isLoop: false,
119122
};
120123

121124
const ChongqingRTBasicAttrsComponent = (props: AttrsProps<ChongqingRTBasicStationAttributes>) => {
@@ -176,6 +179,17 @@ const ChongqingRTBasicAttrsComponent = (props: AttrsProps<ChongqingRTBasicStatio
176179
/>
177180
),
178181
},
182+
{
183+
type: 'switch',
184+
label: t('panel.details.stations.chongqingRTBasic.isLoop'),
185+
isChecked: (attrs ?? defaultChongqingRTBasicStationAttributes).isLoop,
186+
onChange: val => {
187+
attrs.isLoop = val as boolean;
188+
handleAttrsUpdate(id, attrs);
189+
},
190+
minW: 'full',
191+
oneLine: true,
192+
},
179193
];
180194
return <RmgFields fields={fields} />;
181195
};

src/constants/lines.ts

+8
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ import { LondonLutonAirportDARTAttributes } from '../components/svgs/lines/style
3333
import { LondonIFSCloudCableCarAttributes } from '../components/svgs/lines/styles/london-ifs-could-cable-car';
3434
import { GuangdongIntercityRailwayAttributes } from '../components/svgs/lines/styles/guangdong-intercity-railway';
3535
import { GZMTRLoopAttributes } from '../components/svgs/lines/styles/gzmtr-loop';
36+
import { ChongqingRTLoopAttributes } from '../components/svgs/lines/styles/chongqingrt-loop';
37+
import { ChongqingRTLineBadgeAttributes } from '../components/svgs/lines/styles/chongqingrt-line-badge';
3638

3739
export enum LinePathType {
3840
Diagonal = 'diagonal',
@@ -77,6 +79,8 @@ export enum LineStyleType {
7779
LondonLutonAirportDART = 'london-DART',
7880
LondonIFSCloudCableCar = 'london-dangleway',
7981
GuangdongIntercityRailway = 'gd-intercity-rwy',
82+
ChongqingRTLoop = 'chongqingrt-loop',
83+
ChongqingRTLineBadge = 'chongqingrt-line-badge',
8084
}
8185

8286
export interface ExternalLineStyleAttributes {
@@ -108,6 +112,8 @@ export interface ExternalLineStyleAttributes {
108112
[LineStyleType.LondonLutonAirportDART]?: LondonLutonAirportDARTAttributes;
109113
[LineStyleType.LondonIFSCloudCableCar]?: LondonIFSCloudCableCarAttributes;
110114
[LineStyleType.GuangdongIntercityRailway]?: GuangdongIntercityRailwayAttributes;
115+
[LineStyleType.ChongqingRTLoop]?: ChongqingRTLoopAttributes;
116+
[LineStyleType.ChongqingRTLineBadge]?: ChongqingRTLineBadgeAttributes;
111117
}
112118

113119
export const LineStylesWithColor = new Set([
@@ -126,6 +132,8 @@ export const LineStylesWithColor = new Set([
126132
LineStyleType.LondonLutonAirportDART,
127133
LineStyleType.LondonIFSCloudCableCar,
128134
LineStyleType.GZMTRLoop,
135+
LineStyleType.ChongqingRTLoop,
136+
LineStyleType.ChongqingRTLineBadge,
129137
]);
130138

131139
/* ----- Below are core types for all lines, DO NOT TOUCH. ----- */

src/i18n/translations/en.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,8 @@
367367
"displayName": "Guangdong Intercity Railway station"
368368
},
369369
"chongqingRTBasic": {
370-
"displayName": "Chongqing Rail Transit basic station"
370+
"displayName": "Chongqing Rail Transit basic station",
371+
"isLoop": "Loop line station"
371372
},
372373
"chongqingRTInt": {
373374
"displayName": "Chongqing Rail Transit interchange station"
@@ -503,6 +504,12 @@
503504
},
504505
"guangdongIntercityRailway": {
505506
"displayName": "Guangdong Intercity Railway style"
507+
},
508+
"chongqingRTLineBadge": {
509+
"displayName": "Chongqing Rail Transit line badge style"
510+
},
511+
"chongqingRTLoop": {
512+
"displayName": "Chongqing Rail Transit loop line style"
506513
}
507514
},
508515
"edge": {},

src/i18n/translations/ja.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,8 @@
367367
"displayName": "広東省都市間鉄道駅"
368368
},
369369
"chongqingRTBasic": {
370-
"displayName": "重慶鉄道交通基本駅"
370+
"displayName": "重慶鉄道交通基本駅",
371+
"isLoop": "環状線駅"
371372
},
372373
"chongqingRTInt": {
373374
"displayName": "重慶鉄道交通乗り換え駅"
@@ -503,6 +504,12 @@
503504
},
504505
"guangdongIntercityRailway": {
505506
"displayName": "広東省都市間鉄道風格"
507+
},
508+
"chongqingRTLineBadge": {
509+
"displayName": "重慶鉄道交通路線標識接続線風格"
510+
},
511+
"chongqingRTLoop": {
512+
"displayName": "重慶鉄道交通環状線風格"
506513
}
507514
},
508515
"edges": {},

src/i18n/translations/ko.json

+9-2
Original file line numberDiff line numberDiff line change
@@ -367,13 +367,14 @@
367367
},
368368
"chongqingRTBasic": {
369369
"displayName": "충칭 궤도교통 기본역",
370-
"open": "개통여부"
370+
"isLoop": "순환역"
371371
},
372372
"chongqingRTInt": {
373373
"displayName": "충칭 궤도교통 환승역"
374374
},
375375
"chongqingRT2021Basic": {
376-
"displayName": "충칭 궤도교통 기본역(2021)"
376+
"displayName": "충칭 궤도교통 기본역(2021)",
377+
"open": "개통여부"
377378
},
378379
"chongqingRT2021Int": {
379380
"displayName": "충칭 도시철도 환승역 (2021)",
@@ -502,6 +503,12 @@
502503
},
503504
"guangdongIntercityRailway": {
504505
"displayName": "광동성 도시간 철도 스타일"
506+
},
507+
"chongqingRTLineBadge": {
508+
"displayName": "충칭 궤도교통 노선 표지 연결선 스타일"
509+
},
510+
"chongqingRTLoop": {
511+
"displayName": "충칭 궤도교통 순환선 스타일"
505512
}
506513
},
507514
"edges": {},

src/i18n/translations/zh-Hans.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,8 @@
366366
"displayName": "广东城际铁路车站"
367367
},
368368
"chongqingRTBasic": {
369-
"displayName": "重庆轨道交通基本车站"
369+
"displayName": "重庆轨道交通基本车站",
370+
"isLoop": "环线车站"
370371
},
371372
"chongqingRTInt": {
372373
"displayName": "重庆轨道交通换乘车站"
@@ -502,6 +503,12 @@
502503
},
503504
"guangdongIntercityRailway": {
504505
"displayName": "广东城际铁路样式"
506+
},
507+
"chongqingRTLineBadge": {
508+
"displayName": "重庆轨道交通线路标识连接线样式"
509+
},
510+
"chongqingRTLoop": {
511+
"displayName": "重庆轨道交通环线样式"
505512
}
506513
},
507514
"edges": {},

src/i18n/translations/zh-Hant.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,8 @@
366366
"displayName": "廣東城際鐵路車站"
367367
},
368368
"chongqingRTBasic": {
369-
"displayName": "重慶軌道交通基本車站"
369+
"displayName": "重慶軌道交通基本車站",
370+
"isLoop": "環線車站"
370371
},
371372
"chongqingRTInt": {
372373
"displayName": "重慶軌道交通換乘車站"
@@ -502,6 +503,12 @@
502503
},
503504
"guangdongIntercityRailway": {
504505
"displayName": "廣東城際鐵路樣式"
506+
},
507+
"chongqingRTLineBadge": {
508+
"displayName": "重慶軌道交通線路標識連接線樣式"
509+
},
510+
"chongqingRTLoop": {
511+
"displayName": "重慶軌道交通環線樣式"
505512
}
506513
},
507514
"edges": {},

0 commit comments

Comments
 (0)