Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
67e2b71
docs: update README.md
wmakerjun Dec 15, 2020
2db71fe
add: add .gitignore
sunhpark42 Dec 19, 2020
c43e5da
add: set Eslint
sunhpark42 Dec 19, 2020
0895467
add: create README.md
sunhpark42 Dec 19, 2020
1143333
feat: create init data of Stations and Lines
sunhpark42 Dec 19, 2020
625595e
feat: connect main module of subway-path with html
sunhpark42 Dec 19, 2020
f99f71d
feat: add StationPathView module
sunhpark42 Dec 19, 2020
a99ea81
docs: updata README.md
sunhpark42 Dec 19, 2020
aa01728
docs: updata README.md
sunhpark42 Dec 19, 2020
31f6f40
feat: rename subwyas to stations
sunhpark42 Dec 19, 2020
5fbee3b
feat: rename subwyas to stations
sunhpark42 Dec 19, 2020
b95a04f
feat: add GetUserInput and check validation
sunhpark42 Dec 19, 2020
f27ebc8
feat: add Error Constant for error distinction
sunhpark42 Dec 19, 2020
82904af
docs: update README.md
sunhpark42 Dec 19, 2020
0752690
feat: return error num for error distinction
sunhpark42 Dec 19, 2020
503552a
feat: change error num to avoid confusion with bool
sunhpark42 Dec 19, 2020
a1b89b5
feat: add StationPathController module and add EventHandler for click
sunhpark42 Dec 19, 2020
9fb9238
feat: set radio option default by shortest distance
sunhpark42 Dec 19, 2020
7392182
feat: get user input when search-button clicked
sunhpark42 Dec 19, 2020
efdc87f
fix: fix error condition that isInstations cannot check station included
sunhpark42 Dec 19, 2020
ef4a6ef
feat: add StationPathModel module
sunhpark42 Dec 19, 2020
8896683
feat: find sections by line name
sunhpark42 Dec 19, 2020
0953316
feat: get shortest distance path between departure, arrival
sunhpark42 Dec 19, 2020
10b394b
refactor: separate method to make graph from getShortestDistancePath
sunhpark42 Dec 19, 2020
8d50419
feat: find lines that include departure and arrival stations
sunhpark42 Dec 19, 2020
ab02528
feat: edit getShortestDistancePath method for multiple lines
sunhpark42 Dec 19, 2020
9cbbc11
feat: calculate time from path
sunhpark42 Dec 19, 2020
4d4499d
feat: calculate distance from path
sunhpark42 Dec 19, 2020
641d591
docs: update README.md
sunhpark42 Dec 19, 2020
fa54fe4
feat: get shortest time between departure and arrival
sunhpark42 Dec 19, 2020
0aadc85
docs: update README.md
sunhpark42 Dec 19, 2020
a7725fc
fix: correct method name in eventHandler
sunhpark42 Dec 19, 2020
e0652e7
fix: fix isInstations method that cannot given station is in stations…
sunhpark42 Dec 19, 2020
3121069
feat: get shortest path, time, distance when search button clicked
sunhpark42 Dec 19, 2020
75909cd
feat, fix: add variable to resultView, rename radio name to search-type
sunhpark42 Dec 19, 2020
3fdf136
feat: get Options from radio input
sunhpark42 Dec 19, 2020
b33f341
feat: show result when search button clicked
sunhpark42 Dec 19, 2020
9c1ab92
feat: show path in result and delet resultView from view method
sunhpark42 Dec 19, 2020
faf787e
feat: set main module with StationPathController and StationPathView
sunhpark42 Dec 19, 2020
879780c
docs: update README.md
sunhpark42 Dec 19, 2020
2100f15
feat: add error messages
sunhpark42 Dec 19, 2020
ac421c7
docs: update README.md
sunhpark42 Dec 19, 2020
b0ab7d4
feat: alert error msg
sunhpark42 Dec 19, 2020
a1370ab
docs: update README.md
sunhpark42 Dec 19, 2020
138dd00
feat: get result when line transfer
sunhpark42 Dec 19, 2020
a5f30df
Merge branch 'sunhpark42' into transferLine
sunhpark42 Dec 19, 2020
2e18087
Merge pull request #1 from sunhpark42/transferLine
sunhpark42 Dec 19, 2020
cd7082a
style: delete consol log message
sunhpark42 Dec 19, 2020
4ee7761
feat: alert error when stations are not linked
sunhpark42 Dec 19, 2020
d4b9fc4
feat: reload view when error
sunhpark42 Dec 19, 2020
e3d8336
refactor: get ShortestPath by options to redule lines
sunhpark42 Dec 19, 2020
13f8b58
refactor: add ShortestPath includes ShortestTimePath and ShortestDist…
sunhpark42 Dec 19, 2020
34af0ec
feat: add error when input is not in stations
sunhpark42 Dec 19, 2020
95f4898
refactor: add calculate module to reduce indent depth
sunhpark42 Dec 19, 2020
1601503
docs: update README.md
sunhpark42 Dec 19, 2020
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
13 changes: 13 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
"env": {
"browser": true,
"es2021": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module"
},
"rules": {
}
};
151 changes: 151 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
# Created by https://www.toptal.com/developers/gitignore/api/macos,node,vscode
# Edit at https://www.toptal.com/developers/gitignore?templates=macos,node,vscode

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test
.env*.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

### vscode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace

# End of https://www.toptal.com/developers/gitignore/api/macos,node,vscode
147 changes: 146 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,146 @@
# javascript-subway-final
# 🚇 지하철 노선도 경로 조회 미션
- 등록된 지하철 노선도에서 경로를 조회하는 기능을 구현한다.

## 🚀 기능 요구사항
> 프리코스 3주차 미션에서 사용한 코드를 참고해도 무관하다.

### 초기 설정
- 프로그램 시작 시 역, 노선, 구간 데이터를 초기 설정 해야 한다.
- 거리와 소요 시간은 양의 정수이며 단위는 km와 분을 의미한다.
- 아래의 사전 등록 정보로 반드시 초기 설정을 한다.

```
1. 지하철역으로 교대, 강남, 역삼, 남부터미널, 양재, 양재시민의숲, 매봉 역 정보가 등록되어 있다.
2. 지하철 노선으로 2호선, 3호선, 신분당선이 등록되어 있다.
3. 노선에 역이 아래와 같이 등록되어 있다.(왼쪽 끝이 상행 종점)
- 2호선: 교대 - ( 2km / 3분 ) - 강남 - ( 2km / 3분 ) - 역삼
- 3호선: 교대 - ( 3km / 2분 ) - 남부터미널 - ( 6km / 5분 ) - 양재 - ( 1km / 1분 ) - 매봉
- 신분당선: 강남 - ( 2km / 8분 ) - 양재 - ( 10km / 3분 ) - 양재시민의숲
```

### 경로 조회 기능
<img src="/images/path_result.jpg" width="100%">

- 출발역과 도착역을 입력받아 경로를 조회한다.
- 경로 조회 시 총 거리, 총 소요 시간을 함께 출력한다.
- 경로 조회 시 `최단 거리` 또는 `최소 시간` 옵션을 선택할 수 있다.

### 예외 처리
- 출발역과 도착역은 2글자 이상이어야 한다.
- 존재하지 않는 역을 출발역 또는 도착역으로 입력할 수 없다.
- 경로 조회 시 출발역과 도착역이 같을 수 없다.
- 경로 조회 시 출발역과 도착역이 연결되지 않으면 경로를 조회할 수 없다.
- 그 외 정상적으로 프로그램이 수행되지 않은 경우 `alert`으로 에러를 출력한다.

<br>

## 💻 프로그래밍 실행 결과
### 경로 조회
<img src="/images/path_result.gif" width="100%">


## ✅ 프로그래밍 요구사항
### 길찾기 관련 기능
- 출발역을 입력하는 input 태그는 `departure-station-name-input` id 속성값을 가진다.
- 도착역을 입력하는 input 태그는 `arrival-station-name-input` id 속성값을 가진다.
- 최단거리, 최소시간을 선택하는 radio는 `search-type` name 속성값을 가진다.
- **radio option의 default 값은 최단거리이다.**
- 길찾기 버튼은 `search-button` id 속성값을 가진다.
- 📝 결과는 `table`을 이용하여 보여준다.

## ❗️힌트
## 데이터 초기화
자바스크립트에서 데이터를 초기화하는 방법 중에 하나는 아래와 같이 data를 `export`하고, `import`하는 것이다.

```javascript
export const users = [
{
name: 'Alt'
},
{
name: 'Jamie'
},
{
name: 'Sony'
}
]

export const courses = [
{
name: 'frontend',
},
{
name: 'backend',
},
{
name: 'iOS',
},
{
name: 'Android',
}
]

```
위와 같이 데이터를 `export`하면 아래와 같이 데이터를 `import` 하여 사용할 수 있다.
```javascript
import { users, courses } from './data.js'

function App() {
this.users = users
this.courses = courses
}
```

## 최단 경로 라이브러리
- `utils/Dijkstra.js` 라이브러리를 활용하면 간편하게 최단거리를 조회할 수 있다.
- 정점(Vertex)과 간선(Edge), 그리고 가중치 개념을 이용
- 정점: 지하철역
- 간선: 지하철역 연결정보
- 가중치: 거리 or 소요 시간
- 최단 거리 기준 조회 시 가중치를 거리로 설정
- 최소 시간 기준 조회 시 가중치를 시간으로 설정

```javascript
import Dijkstra from "./utils/Dijkstra.js";
const dijkstra = new Dijkstra()

//dijkstra.addEdge("출발역", "도착역", 거리 또는 시간);
dijkstra.addEdge("V1", "V2", 2);
dijkstra.addEdge("V2", "V3", 2);
dijkstra.addEdge("V1", "V3", 100);

const result = dijkstra.findShortestPath("V1", "V3");
// result = ["V1", "V2", "V3"]
```

#### 테스트설명
<img src="/images/dijkstra_example.png" width="400">

- 역 사이의 거리를 고려하지 않는 경우 V1->V3 경로가 최단 경로
- 역 사이의 거리를 고려할 경우 V1->V3 경로의 거리는 100km, V1->V2->V3 경로의 거리는 4km이므로 최단 경로는 V1->V2->V3

<br>

### 요구사항
- 사용자가 잘못된 입력 값을 작성한 경우 `alert`을 이용해 메시지를 보여주고, 재입력할 수 있게 한다.
- 외부 라이브러리(jQuery, Lodash 등)를 사용하지 않고, 순수 Vanilla JS로만 구현한다.
- **자바스크립트 코드 컨벤션을 지키면서 프로그래밍** 한다
- [https://google.github.io/styleguide/jsguide.html](https://google.github.io/styleguide/jsguide.html)
- [https://ui.toast.com/fe-guide/ko_CODING-CONVENSION/](https://ui.toast.com/fe-guide/ko_CODING-CONVENTION)
- **indent(인덴트, 들여쓰기) depth를 3이 넘지 않도록 구현한다. 2까지만 허용**한다.
- 예를 들어 while문 안에 if문이 있으면 들여쓰기는 2이다.
- 힌트: indent(인덴트, 들여쓰기) depth를 줄이는 좋은 방법은 함수(또는 메소드)를 분리하면 된다.
- **함수(또는 메소드)의 길이가 15라인을 넘어가지 않도록 구현한다.**
- 함수(또는 메소드)가 한 가지 일만 잘 하도록 구현한다.
- 변수 선언시 [var](https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Statements/var) 를 사용하지 않는다. [const](https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Statements/const) 와 [let](https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Statements/let) 을 사용한다.
- [import](https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Statements/import) 문을 이용해 스크립트를 모듈화하고 불러올 수 있게 만든다.
- [template literal](https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Template_literals)을 이용해 데이터와 html string을 가독성 좋게 표현한다.

<br/>

## 📝 미션 저장소 및 진행 요구사항

- 미션은 [https://github.com/woowacourse/javascript-subway-path-precourse](https://github.com/woowacourse/javascript-subway-path-precourse) 저장소를 fork/clone해 시작한다.
- **기능을 구현하기 전에 javascript-subway-path-precourse/docs/README.md 파일에 구현할 기능 목록**을 정리해 추가한다.
- **git의 commit 단위는 앞 단계에서 README.md 파일에 정리한 기능 목록 단위로 추가**한다.
- [프리코스 과제 제출](https://github.com/woowacourse/woowacourse-docs/tree/master/precourse) 문서 절차를 따라 미션을 제출한다.
22 changes: 22 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 지하철 길 찾기 미션

## 기능 목록
0. 출발역, 도착역에 대한 초기 설정 [o]
1. 지하철 길찾기 입력 화면을 출력한다. [o]
1-1. 지하철 길찾기 결과 화면을 출력한다.
- 초기 세팅 [o]
- 데이터를 활용해 추후 수정 예정
2. 출발역, 도착역, 최단거리/최소시간을 입력 받는다. [o]
3. 입력 받은 값의 유효성을 검사한다. [o]
- 출발역과 도착역의 이름은 2글자 이상 [o]
- 출발역, 도착역이 역에 존재하는지 확인한다. [o]
- 출발역, 도착역이 서로 같은지 확인한다. [o]
4. 출발역, 도착역의 최단 거리를 구한다. [o]
- 출발역, 도착역이 포함된 노선은 2개 이상일 수 있다. [o]
- 해당 노선에 포함된 모든 역을 작성해서 넣어주어야 한다.
5. 출발역, 도착역의 최소 시간을 구한다.[o]
6. 최단 경로를 이용하여 시간 합계를 구한다. [o]
7. 최단 경로를 이용하여 거리 합계를 구한다. [o]
8. 출발역, 도착역이 연결되어 있지 않다면 경고 메세지를 출력한다.[o]

9. 환승을 고려하여 로직 수정[o]
Binary file added images/dijkstra_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/path_result.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/path_result.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>지하철 길찾기</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="src/index.js"></script>
</body>
</html>
Loading