-
Notifications
You must be signed in to change notification settings - Fork 44
#1329 Improvement of Beijing subway stations #1330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import { RmgFields, RmgFieldsField } from '@railmapgen/rmg-components'; | ||
| import { RmgButtonGroup, RmgFields, RmgFieldsField } from '@railmapgen/rmg-components'; | ||
| import React from 'react'; | ||
| import { useTranslation } from 'react-i18next'; | ||
| import { AttrsProps, CanvasType, CategoriesType, CityCode } from '../../../constants/constants'; | ||
|
|
@@ -31,6 +31,8 @@ const BjsubwayBasicStation = (props: StationComponentProps) => { | |
| open = defaultBjsubwayBasicStationAttributes.open, | ||
| construction = defaultBjsubwayBasicStationAttributes.construction, | ||
| scale = defaultBjsubwayBasicStationAttributes.scale, | ||
| minorOffsetX = defaultBjsubwayBasicStationAttributes.minorOffsetX, | ||
| minorOffsetY = defaultBjsubwayBasicStationAttributes.minorOffsetY, | ||
| } = attrs[StationType.BjsubwayBasic] ?? defaultBjsubwayBasicStationAttributes; | ||
|
|
||
| const onPointerDown = React.useCallback( | ||
|
|
@@ -71,6 +73,17 @@ const BjsubwayBasicStation = (props: StationComponentProps) => { | |
| const [textX, textY] = getTextOffset(nameOffsetX, nameOffsetY); | ||
| const textAnchor = nameOffsetX === 'left' ? 'end' : nameOffsetX === 'right' ? 'start' : 'middle'; | ||
|
|
||
| const getMinorTextOffset = (offset: '-2' | '-1' | '0' | '1' | '2') => { | ||
| if (offset === '-2') return -8; | ||
| else if (offset === '-1') return -2.5; | ||
| else if (offset === '0') return 0; | ||
| else if (offset === '1') return 2.5; | ||
| else if (offset === '2') return 8; | ||
| else return 0; | ||
| }; | ||
| const minorTextX = getMinorTextOffset(minorOffsetX); | ||
| const minorTextY = getMinorTextOffset(minorOffsetY); | ||
|
|
||
| return ( | ||
| <g id={id} transform={`translate(${x}, ${y})`}> | ||
| <circle | ||
|
|
@@ -85,7 +98,7 @@ const BjsubwayBasicStation = (props: StationComponentProps) => { | |
| onPointerUp={onPointerUp} | ||
| style={{ cursor: 'move' }} | ||
| /> | ||
| <g transform={`translate(${textX}, ${textY})`} textAnchor={textAnchor}> | ||
| <g transform={`translate(${textX + minorTextX}, ${textY + minorTextY})`} textAnchor={textAnchor}> | ||
| <MultilineText | ||
| text={names[0].split('\n')} | ||
| fontSize={LINE_HEIGHT.zh} | ||
|
|
@@ -131,6 +144,8 @@ export interface BjsubwayBasicStationAttributes extends StationAttributes { | |
| open: boolean; | ||
| construction: boolean; | ||
| scale: number; | ||
| minorOffsetX: '-2' | '-1' | '0' | '1' | '2'; | ||
| minorOffsetY: '-2' | '-1' | '0' | '1' | '2'; | ||
| } | ||
|
|
||
| const defaultBjsubwayBasicStationAttributes: BjsubwayBasicStationAttributes = { | ||
|
|
@@ -140,6 +155,8 @@ const defaultBjsubwayBasicStationAttributes: BjsubwayBasicStationAttributes = { | |
| open: true, | ||
| construction: false, | ||
| scale: 1, | ||
| minorOffsetX: '0', | ||
| minorOffsetY: '0', | ||
| }; | ||
|
|
||
| const BJSubwayBasicAttrsComponent = (props: AttrsProps<BjsubwayBasicStationAttributes>) => { | ||
|
|
@@ -236,6 +253,72 @@ const BJSubwayBasicAttrsComponent = (props: AttrsProps<BjsubwayBasicStationAttri | |
| }, | ||
| minW: 'full', | ||
| }, | ||
| { | ||
| type: 'custom', | ||
| label: t('panel.details.stations.bjsubwayBasic.minorOffset.labelX'), | ||
| component: ( | ||
| <RmgButtonGroup | ||
| selections={[ | ||
| { | ||
| label: t('panel.details.stations.bjsubwayBasic.minorOffset.-2'), | ||
| value: '-2', | ||
| }, | ||
| { | ||
| label: t('panel.details.stations.bjsubwayBasic.minorOffset.-1'), | ||
| value: '-1', | ||
| }, | ||
| { | ||
| label: t('panel.details.stations.bjsubwayBasic.minorOffset.0'), | ||
| value: '0', | ||
| }, | ||
| { | ||
| label: t('panel.details.stations.bjsubwayBasic.minorOffset.1'), | ||
| value: '1', | ||
| }, | ||
| { | ||
| label: t('panel.details.stations.bjsubwayBasic.minorOffset.2'), | ||
| value: '2', | ||
| }, | ||
| ]} | ||
| defaultValue={attrs.minorOffsetX ?? defaultBjsubwayBasicStationAttributes.minorOffsetX} | ||
| onChange={val => { | ||
| attrs.minorOffsetX = val as '-2' | '-1' | '0' | '1' | '2'; | ||
| handleAttrsUpdate(id, attrs); | ||
| }} | ||
| multiSelect={false} | ||
| /> | ||
| ), | ||
| minW: 'full', | ||
| }, | ||
| { | ||
| type: 'custom', | ||
| label: t('panel.details.stations.bjsubwayBasic.minorOffset.labelY'), | ||
| component: ( | ||
| <RmgButtonGroup | ||
| selections={[ | ||
| { | ||
| label: t('panel.details.stations.bjsubwayBasic.minorOffset.-1'), | ||
| value: '-1', | ||
| }, | ||
| { | ||
| label: t('panel.details.stations.bjsubwayBasic.minorOffset.0'), | ||
| value: '0', | ||
| }, | ||
| { | ||
| label: t('panel.details.stations.bjsubwayBasic.minorOffset.1'), | ||
| value: '1', | ||
| }, | ||
| ]} | ||
|
Comment on lines
+298
to
+311
|
||
| defaultValue={attrs.minorOffsetY ?? defaultBjsubwayBasicStationAttributes.minorOffsetY} | ||
| onChange={val => { | ||
| attrs.minorOffsetY = val as '-2' | '-1' | '0' | '1' | '2'; | ||
| handleAttrsUpdate(id, attrs); | ||
| }} | ||
| multiSelect={false} | ||
| /> | ||
| ), | ||
| minW: 'full', | ||
| }, | ||
| ]; | ||
|
|
||
| return <RmgFields fields={fields} />; | ||
|
|
||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -57,7 +57,7 @@ export interface RMPSave { | |||||||||||||||||||||||||||||||||||||||||
| images?: { id: string; base64: string }[]; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| export const CURRENT_VERSION = 68; | ||||||||||||||||||||||||||||||||||||||||||
| export const CURRENT_VERSION = 69; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||
| * Parse the version from a save string without fully validating the save. | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -906,4 +906,29 @@ export const UPGRADE_COLLECTION: { [version: number]: (param: string) => string | |||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||
| return JSON.stringify({ ...p, version: 68, graph: graph.export() }); | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| 68: param => { | ||||||||||||||||||||||||||||||||||||||||||
| // Bump save version to add minorOffset to beijing subway basic and interchange stations. | ||||||||||||||||||||||||||||||||||||||||||
| const p = JSON.parse(param); | ||||||||||||||||||||||||||||||||||||||||||
| const graph = new MultiDirectedGraph() as MultiDirectedGraph<NodeAttributes, EdgeAttributes, GraphAttributes>; | ||||||||||||||||||||||||||||||||||||||||||
| graph.import(p?.graph); | ||||||||||||||||||||||||||||||||||||||||||
| graph | ||||||||||||||||||||||||||||||||||||||||||
| .filterNodes( | ||||||||||||||||||||||||||||||||||||||||||
| (node, attr) => | ||||||||||||||||||||||||||||||||||||||||||
| node.startsWith('stn') && | ||||||||||||||||||||||||||||||||||||||||||
| (attr.type === StationType.BjsubwayBasic || attr.type === StationType.BjsubwayInt) | ||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||
| .forEach(node => { | ||||||||||||||||||||||||||||||||||||||||||
| const type = graph.getNodeAttribute(node, 'type'); | ||||||||||||||||||||||||||||||||||||||||||
| const attr = graph.getNodeAttribute(node, type) as any; | ||||||||||||||||||||||||||||||||||||||||||
| if (typeof attr.minorOffsetX !== 'number') { | ||||||||||||||||||||||||||||||||||||||||||
| attr.minorOffsetX = '0'; | ||||||||||||||||||||||||||||||||||||||||||
| graph.mergeNodeAttributes(node, { [type]: attr }); | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| if (typeof attr.minorOffsetY !== 'number') { | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+923
to
+927
|
||||||||||||||||||||||||||||||||||||||||||
| if (typeof attr.minorOffsetX !== 'number') { | |
| attr.minorOffsetX = '0'; | |
| graph.mergeNodeAttributes(node, { [type]: attr }); | |
| } | |
| if (typeof attr.minorOffsetY !== 'number') { | |
| if (typeof attr.minorOffsetX !== 'string') { | |
| attr.minorOffsetX = '0'; | |
| graph.mergeNodeAttributes(node, { [type]: attr }); | |
| } | |
| if (typeof attr.minorOffsetY !== 'string') { |
Copilot
AI
Feb 12, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same type mismatch issue as with minorOffsetX. The code sets minorOffsetY to the string '0' but checks if the type is NOT 'number'. According to the TypeScript interface, minorOffsetY should be of type '-2' | '-1' | '0' | '1' | '2' (a string union type), not a number. The condition should check typeof attr.minorOffsetY !== 'string' or check if the attribute is undefined.
| if (typeof attr.minorOffsetX !== 'number') { | |
| attr.minorOffsetX = '0'; | |
| graph.mergeNodeAttributes(node, { [type]: attr }); | |
| } | |
| if (typeof attr.minorOffsetY !== 'number') { | |
| if (typeof attr.minorOffsetX !== 'string') { | |
| attr.minorOffsetX = '0'; | |
| graph.mergeNodeAttributes(node, { [type]: attr }); | |
| } | |
| if (typeof attr.minorOffsetY !== 'string') { |
Uh oh!
There was an error while loading. Please reload this page.