Skip to content
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

#220 Shanghai Metro Style Station Number #291

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions public/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@
"sh": "Default",
"sh2020": "2020 (Beta)"
},
"stationNumber":"Show Station Number",
"stationNumberRailmap":"Show Station Number in Railmap",
"autoNum": {
"button": "Station Auto-numbering",
"title": "Warning",
Expand Down
2 changes: 2 additions & 0 deletions public/locale/zh-HK.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@
"sh": "默認樣式",
"sh2020": "2020年新樣式(測試版)"
},
"stationNumber":"显示車站號",
"stationNumberRailmap":"在路線圖上显示車站號",
"autoNum": {
"button": "車站自動編碼",
"title": "警告",
Expand Down
2 changes: 2 additions & 0 deletions public/locale/zh-Hans.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@
"sh": "默认样式",
"sh2020": "2020年样式(测试版)"
},
"stationNumber":"显示车站号",
"stationNumberRailmap":"在线路图中显示车站号",
"autoNum": {
"button": "车站自动编码",
"title": "警告",
Expand Down
4 changes: 4 additions & 0 deletions public/styles/share_shmetro.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
.rmg-name__en {
font-family: Arial, sans-serif;
}
.rmg-station-name {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we said before, no need for another class style, .rmg-name__en would be fine for numbers.

font-family: Arial, sans-serif;
}


:root {
--rmg-black: black;
Expand Down
8 changes: 8 additions & 0 deletions src/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,14 @@ export interface RMGParam {
theme: Theme;
line_name: Name;
current_stn_idx: keyof StationDict;
/**
* Display the station number or not.
*/
showStationNumber: boolean;
/**
* Display the station number in railmap or not.
*/
showStationNumberRailmap: boolean;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to distinguish between two scenarios? For stations that only display station number at runin canvas, I believe that is just an obsolete image at will be replaced soon.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like the resolve of Disney Icon. There're some person reason in it (For my Minecraft server), sorry.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you need the station number on only one canvas, why not download one canvas and switch the station number button and then download another canvas?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because now numbers in railmap were replaced, but at Xinjiangwancheng - Hangzhong Road/Hongqiao Railway Station the station numbers on runin also there.(Xinjiangwancheng removed.)

/**
* Key-value pairs of the information of each station.
*/
Expand Down
126 changes: 110 additions & 16 deletions src/panels/design/list-shmetro.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
import React, { ChangeEvent, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { ListItem, ListItemIcon, Icon, ListItemText, Divider, Select } from '@material-ui/core';
import {
Switch,
ListItem,
ListItemIcon,
Icon,
ListItemText,
Divider,
Select,
makeStyles,
createStyles,
ListItemSecondaryAction,
Collapse,
List,
TextField,
} from '@material-ui/core';
import { PanelTypeShmetro } from '../../constants/constants';
import { useAppDispatch, useAppSelector } from '../../redux';
import { setPanelType } from '../../redux/param/action';
import { setPanelType, setLineNum, setShowStationNumber, setShowStationNumberRailmap } from '../../redux/param/action';

const DesignListShmetro = () => {
return (
Expand All @@ -27,30 +41,110 @@ const DesignListShmetro = () => {

export default DesignListShmetro;

const useStyles = makeStyles(theme =>
createStyles({
dividerVertical: {
margin: theme.spacing(0, 2),
},
nestedList: {
paddingLeft: theme.spacing(5),
},
})
);

const StationNumberSHMetroLi = () => {
const { t } = useTranslation();
const classes = useStyles();
const dispatch = useAppDispatch();

const station_number = useAppSelector(store => store.param.showStationNumber);
const station_number_railmap = useAppSelector(store => store.param.showStationNumberRailmap);
const line_number = useAppSelector(store => store.param.line_num);

return useMemo(() => {
const handleSwitch = (_: React.ChangeEvent<HTMLInputElement>, checked: boolean) => {
if (checked) {
dispatch(setShowStationNumber(true));
} else {
dispatch(setShowStationNumber(false));
}
};

const handleSwitchSecondary = (_: React.ChangeEvent<HTMLInputElement>, checked: boolean) => {
if (checked) {
dispatch(setShowStationNumberRailmap(true));
} else {
dispatch(setShowStationNumberRailmap(false));
}
};

const handleChange = ({ target: { value } }: ChangeEvent<HTMLInputElement>) => {
dispatch(setLineNum(value));
};

return (
<>
<ListItem>
<ListItemIcon>
<Icon>account_balance_wallet</Icon>
</ListItemIcon>
<ListItemText primary={t('design.stationNumber')} />
<ListItemSecondaryAction>
<Switch color="primary" checked={station_number !== false} onChange={handleSwitch} />
</ListItemSecondaryAction>
</ListItem>
<Collapse in={station_number !== false} unmountOnExit>
<List component="div" disablePadding className={classes.nestedList}>
<ListItem>
<ListItemText primary={t('design.stationNumberRailmap')} />
<ListItemSecondaryAction>
<Switch
color="primary"
checked={station_number_railmap !== false}
onChange={handleSwitchSecondary}
/>
</ListItemSecondaryAction>
</ListItem>
<ListItem>
<TextField
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will you put a label before the line num? Just like what GTMTR did https://github.com/wongchito/RailMapGenerator/blob/rmg-3.12.3/src/panels/design/list-gzmtr.tsx#L63

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

....I forget to do it because there are only one field in part 1.

placeholder={t('design.lineNum')}
defaultValue={line_number}
onChange={handleChange}
/>
</ListItem>
</List>
</Collapse>
</>
);
}, [line_number, station_number, station_number_railmap]);
};

const PanelTypeLi = () => {
const { t } = useTranslation();
const dispatch = useAppDispatch();

const panelType = useAppSelector(store => store.param.info_panel_type);

return useMemo(() => {
const handleChange = ({ target: { value } }: ChangeEvent<{ name?: string; value: unknown }>) => {
dispatch(setPanelType(value as PanelTypeShmetro));
};
return (
<ListItem>
<ListItemIcon>
<Icon style={{ transform: 'rotate(180deg)' }}>credit_card</Icon>
</ListItemIcon>
<ListItemText primary={t('design.panelType.button')} />
<Select native value={panelType} onChange={handleChange} style={{ width: 166 }}>
{Object.values(PanelTypeShmetro).map(type => (
<option key={type} value={type}>
{t('design.panelType.' + type)}
</option>
))}
</Select>
</ListItem>
<>
<StationNumberSHMetroLi />
<ListItem>
<ListItemIcon>
<Icon style={{ transform: 'rotate(180deg)' }}>credit_card</Icon>
</ListItemIcon>
<ListItemText primary={t('design.panelType.button')} />
<Select native value={panelType} onChange={handleChange} style={{ width: 166 }}>
{Object.values(PanelTypeShmetro).map(type => (
<option key={type} value={type}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tested default info_panel_type sh? It looks a bit weird on my browser.
image

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! Sorry my test template is using sh2020.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just find a problem: Shanghai Line 10 removed all station number on railmap in the 2012 style (which is the current style (without platform number version) that RMG uses) update although the station number still remain on Running-in):
Screen Shot 2022-05-23 at 4 26 41 PM

Which now looks like this (the 2020 style also used the normal railmap without station number) (source: https://zhuanlan.zhihu.com/p/57368457)
v2-2051eed404e47fd73ca2d14b0dadc1f8_720w

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@52PD Yes, this is the reason why station number in shmetro has a lower priority. And since this PR is targeted for V3, we may need a rewrite for this part.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am going to rewrite it for v5. Thinks that we can make stationNumberRailmap option hidden and we only can edit it in json.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still insisting that stationNumberRailmap is not needed. Users can hide the station number if showStationNumber is set. They can download one canvas, switch the control, and download another canvas.

{t('design.panelType.' + type)}
</option>
))}
</Select>
</ListItem>
</>
);
}, [panelType, t, dispatch]);
};
5 changes: 4 additions & 1 deletion src/panels/stations/edit-diag/name-tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ interface Props {

const NameTab = (props: Props) => {
const rmgStyle = useAppSelector(store => store.param.style);
const showStationNumber = useAppSelector(store => store.param.showStationNumber);

return (
<List component="div">
{rmgStyle === RmgStyle.GZMTR && <NumInput {...props} />}
{(rmgStyle === RmgStyle.GZMTR || (rmgStyle === RmgStyle.SHMetro && showStationNumber)) && (
<NumInput {...props} />
)}
<NameInput {...props} />
{rmgStyle === RmgStyle.GZMTR && <SecondaryNameInput {...props} />}
</List>
Expand Down
5 changes: 4 additions & 1 deletion src/panels/stations/station-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const StationEntry = (props: { stnId: string; isSelected: boolean; onAction: (ac

const rmgStyle = useAppSelector(store => store.param.style);
const stationInfo = useAppSelector(store => store.param.stn_list[stnId]);
const stn_number = useAppSelector(store => store.param.showStationNumber);

const name = stationInfo?.name || ['', ''];
const num = stationInfo?.num || '00';
Expand All @@ -94,7 +95,9 @@ const StationEntry = (props: { stnId: string; isSelected: boolean; onAction: (ac

return (
<ListItem className={isSelected ? classes.selectedItem : ''}>
{rmgStyle === RmgStyle.GZMTR && <Typography className={classes.listItemNum}>{num}</Typography>}
{(rmgStyle === RmgStyle.GZMTR || (rmgStyle === RmgStyle.SHMetro && stn_number)) && (
<Typography className={classes.listItemNum}>{num}</Typography>
)}
<ListItemText primary={name[0]} secondary={name[1].replace('\\', ' ')} className={classes.listItemText} />
<ListItemSecondaryAction>
<IconButton size="small" onClick={e => setToggleEl(e.currentTarget)}>
Expand Down
20 changes: 20 additions & 0 deletions src/redux/param/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export const SET_PLATFORM = 'SET_PLATFORM';
export const SET_LINE_NUM = 'SET_LINE_NUM';
export const SET_PSD_NUM = 'SET_PSD_NUM';
export const SET_PANEL_TYPE = 'SET_PANEL_TYPE';
export const SET_SHOW_STATION_NUMBER = 'SET_SHOW_STATION_NUMBER';
export const SET_SHOW_STATION_NUMBER_RAILMAP = 'SET_SHOW_STATION_NUMBER_RAILMAP';
export const SET_NOTES = 'SET_NOTES';
export const SET_NAME_POSITION = 'SET_NAME_POSITION';
export const SET_CUSTOMISED_MTR_DESTINATION = 'SET_CUSTOMISED_MTR_DESTINATION';
Expand Down Expand Up @@ -131,6 +133,16 @@ export interface setPanelTypeAction {
panelType: PanelTypeGZMTR | PanelTypeShmetro;
}

export interface setShowStationNumberAction {
type: typeof SET_SHOW_STATION_NUMBER;
showStationNumber: RMGParam['showStationNumber'];
}

export interface setShowStationNumberRailmapAction {
type: typeof SET_SHOW_STATION_NUMBER_RAILMAP;
showStationNumberRailmap: RMGParam['showStationNumberRailmap'];
}

export interface setNotesAction {
type: typeof SET_NOTES;
notes: Note[];
Expand Down Expand Up @@ -234,6 +246,14 @@ export const setPanelType = (panelType: PanelTypeShmetro | PanelTypeGZMTR): setP
return { type: SET_PANEL_TYPE, panelType };
};

export const setShowStationNumber = (showStationNumber: boolean): setShowStationNumberAction => {
return { type: SET_SHOW_STATION_NUMBER, showStationNumber };
};

export const setShowStationNumberRailmap = (showStationNumberRailmap: boolean): setShowStationNumberRailmapAction => {
return { type: SET_SHOW_STATION_NUMBER_RAILMAP, showStationNumberRailmap };
};

const setNotes = (notes: Note[]): setNotesAction => {
return { type: SET_NOTES, notes };
};
Expand Down
14 changes: 14 additions & 0 deletions src/redux/param/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
SET_THEME,
SET_Y_PERCENTAGE,
SET_STYLE,
SET_SHOW_STATION_NUMBER,
setBranchSpacingAction,
setCurrentStationAction,
setCustomisedMtrDestinationAction,
Expand All @@ -45,6 +46,9 @@ import {
setThemeAction,
setYPercentageAction,
setStyleAction,
setShowStationNumberAction,
setShowStationNumberRailmapAction,
SET_SHOW_STATION_NUMBER_RAILMAP,
} from './action';

const initialState: RMGParam = {
Expand All @@ -64,6 +68,8 @@ const initialState: RMGParam = {
theme: [CityCode.Hongkong, 'twl', '#E2231A', MonoColour.white],
line_name: ['線', 'line'],
current_stn_idx: '',
showStationNumber: false,
showStationNumberRailmap: true,
stn_list: {},
namePosMTR: {
isStagger: true,
Expand Down Expand Up @@ -106,6 +112,8 @@ export default function ParamReducer(
| setCurrentStationAction
| setStationAction
| setStationsBulkAction
| setShowStationNumberAction
| setShowStationNumberRailmapAction
) {
switch (action.type) {
case SET_FULL_PARAM:
Expand Down Expand Up @@ -173,6 +181,12 @@ export default function ParamReducer(
case SET_STATIONS_BULK:
state.stn_list = action.stations;
break;
case SET_SHOW_STATION_NUMBER:
state.showStationNumber = action.showStationNumber;
break;
case SET_SHOW_STATION_NUMBER_RAILMAP:
state.showStationNumberRailmap = action.showStationNumberRailmap;
break;
default:
break;
}
Expand Down
31 changes: 28 additions & 3 deletions src/svgs/railmap/main/main-shmetro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,34 @@ const StationGroup = (props: StationGroupProps) => {
.filter(stnId => !['linestart', 'lineend'].includes(stnId))
.filter(stnId => param.stn_list[stnId].services.length !== 0)
.map(stnId => (
<g key={stnId} transform={`translate(${props.xs[stnId]},${props.ys[stnId]})`}>
<StationSHMetro stnId={stnId} stnState={props.stnStates[stnId]} />
</g>
<>
<g key={stnId} transform={`translate(${props.xs[stnId]},${props.ys[stnId]})`}>
{param.showStationNumberRailmap && param.showStationNumber ? (
<g>
<circle
cx="0"
cy="0"
r="20"
stroke={props.stnStates[stnId] === -1 ? 'gray' : 'var(--rmg-theme-colour)'}
strokeWidth="5"
fill="white"
></circle>
<line x1="-18" y1="0" x2="18" y2="0" stroke="rgb(0,0,0)" strokeWidth="2" />
<g textAnchor="middle">
<text className="rmg-station-name" fontSize={15} dy={-3}>
{param.line_num}
</text>
<text className="rmg-station-name" fontSize={15} dy={15}>
{param.stn_list[stnId].num}
</text>
</g>
</g>
) : (
<></>
)}
<StationSHMetro stnId={stnId} stnState={props.stnStates[stnId]} />
</g>
</>
))}
</g>
);
Expand Down
12 changes: 8 additions & 4 deletions src/svgs/railmap/main/station/station-shmetro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@ const StationSHMetro = (props: Props) => {

return (
<>
<use
xlinkHref={`#${stationIconStyle}`}
{...stationIconColor} // different styles use either `fill` or `stroke`
/>
{!(param.showStationNumberRailmap && param.showStationNumber) ? (
<use
xlinkHref={`#${stationIconStyle}`}
{...stationIconColor} // different styles use either `fill` or `stroke`
/>
) : (
<></>
)}
<g transform={`translate(${branchNameDX},0)`}>
<StationNameGElement
name={stnInfo.name}
Expand Down
Loading