From 44e4394da42bd4df378067427a2db7333f07dbb8 Mon Sep 17 00:00:00 2001 From: grey-cat-1908 Date: Thu, 21 Mar 2024 21:03:02 +0300 Subject: [PATCH] window settings --- package.json | 1 + src/App.vue | 108 +++++++++++++++++++++-- src/models/map.ts | 45 ++++++---- src/models/{ => map}/branch.ts | 0 src/models/{ => map}/connectedStation.ts | 0 src/models/{ => map}/extraBranch.ts | 0 src/models/{ => map}/station.ts | 2 +- src/models/settings.ts | 19 ++++ src/style.css | 12 +++ 9 files changed, 159 insertions(+), 28 deletions(-) rename src/models/{ => map}/branch.ts (100%) rename src/models/{ => map}/connectedStation.ts (100%) rename src/models/{ => map}/extraBranch.ts (100%) rename src/models/{ => map}/station.ts (91%) create mode 100644 src/models/settings.ts diff --git a/package.json b/package.json index 08b7d47..c514512 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ }, "dependencies": { "@svgdotjs/svg.js": "^3.2.0", + "@vueuse/core": "^10.9.0", "vue": "^3.3.11", "vuetify": "^3.5.9" }, diff --git a/src/App.vue b/src/App.vue index 7d263c1..46c76bc 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,12 +1,42 @@ diff --git a/src/models/map.ts b/src/models/map.ts index 79fdcce..7e73157 100644 --- a/src/models/map.ts +++ b/src/models/map.ts @@ -1,35 +1,43 @@ // @ts-ignore import { SVG } from '@svgdotjs/svg.js' -import {Branch} from "./branch.ts"; -import {Station} from "./station.ts"; -import {ConnectedStation} from "./connectedStation.ts"; - -const yMax = (window.innerHeight-50) / 4; +import {Branch} from "./map/branch.ts"; +import {Station} from "./map/station.ts"; +import {ConnectedStation} from "./map/connectedStation.ts"; +import {Settings} from "./settings.ts"; export interface MetroMap { branch: Branch; + settings: Settings } export class Map implements MetroMap { branch: Branch; + settings: Settings + private yMax: number; private draw; - public constructor(branch: Branch) { + public constructor(branch: Branch, settings: Settings) { this.draw = SVG().addTo('#map') this.branch = branch + this.settings = settings + this.yMax = (this.settings.height - 50) / 4 } public setBranch(branch: Branch) { this.branch = branch } + public setSettings(settings: Settings) { + this.settings = settings + } + private getTextPosition(up: boolean): number { if (up) { - return yMax - 60; + return this.yMax - 60; } else { - return yMax + 60; + return this.yMax + 60; } } @@ -41,6 +49,7 @@ export class Map implements MetroMap { } else { cy = scy - (i + 1) * 50 } + this.draw.circle(40).fill(stations[i].branch.color).cx(cx).cy(cy) let text = this.draw.text(stations[i].branch.number.toString()).fill('white').font({ size: 28}).cx(cx).cy(cy); @@ -65,12 +74,12 @@ export class Map implements MetroMap { for (let i = 0; i < stations.length; i++) { let cx = last + stations[i].step; if (stations[i].connectedStations.length > 0) { - this.draw.circle(50).fill(this.branch.color).cx(cx).cy(yMax) - this.draw.circle(25).fill('white').cx(cx).cy(yMax) + this.draw.circle(50).fill(this.branch.color).cx(cx).cy(this.yMax) + this.draw.circle(25).fill('white').cx(cx).cy(this.yMax) - this.drawConnectedStations(stations[i].connectedStations, stations[i].up, cx, yMax); + this.drawConnectedStations(stations[i].connectedStations, stations[i].up, cx, this.yMax); } else { - this.draw.rect(15, 50).fill(this.branch.color).cx(cx).cy(yMax) + this.draw.rect(15, 50).fill(this.branch.color).cx(cx).cy(this.yMax) } let textPosition: number = this.getTextPosition(stations[i].up) @@ -84,7 +93,10 @@ export class Map implements MetroMap { } public build() { - this.draw = this.draw.size(window.innerWidth, (window.innerHeight-50) / 2); + const lineMax = this.settings.width - 200; + this.yMax = (this.settings.height - 50) / 4 + + this.draw = this.draw.size(this.settings.width, this.yMax * 2); this.draw.clear(); this.draw.circle(50).fill(this.branch.color).cx(50).cy(50) @@ -96,16 +108,13 @@ export class Map implements MetroMap { }) let naming = this.draw.text(this.branch.name).font({ size: 35}); - naming.cx(50 + 40 + (naming.bbox().width / 2)).cy(50); + naming.cx(90 + (naming.bbox().width / 2)).cy(50); naming.font({ family: 'NTSomic', weight: '750', }) - const lineMax = window.innerWidth - 200; - const yMax = (window.innerHeight-50) / 4; - - let line = this.draw.line(200, yMax, lineMax, yMax) + let line = this.draw.line(200, this.yMax, lineMax, this.yMax) line.stroke({ color: this.branch.color, width: 16}) this.drawStations(this.branch.stations) diff --git a/src/models/branch.ts b/src/models/map/branch.ts similarity index 100% rename from src/models/branch.ts rename to src/models/map/branch.ts diff --git a/src/models/connectedStation.ts b/src/models/map/connectedStation.ts similarity index 100% rename from src/models/connectedStation.ts rename to src/models/map/connectedStation.ts diff --git a/src/models/extraBranch.ts b/src/models/map/extraBranch.ts similarity index 100% rename from src/models/extraBranch.ts rename to src/models/map/extraBranch.ts diff --git a/src/models/station.ts b/src/models/map/station.ts similarity index 91% rename from src/models/station.ts rename to src/models/map/station.ts index 7149d37..c18101a 100644 --- a/src/models/station.ts +++ b/src/models/map/station.ts @@ -7,7 +7,7 @@ export interface StationInterface { step: number; } -export class Station implements StationInterface { +export class Station implements StationInterface { name: string; up: boolean; connectedStations: Array diff --git a/src/models/settings.ts b/src/models/settings.ts new file mode 100644 index 0000000..3ac447d --- /dev/null +++ b/src/models/settings.ts @@ -0,0 +1,19 @@ +export interface BaseSettings { + height: number; + width: number; +} + +export class Settings implements BaseSettings { + height: number; + width: number; + + constructor(width?: number, height?: number) { + this.width = width || window.innerWidth; + this.height = (height || (window.innerHeight / 2)) * 2; + } + + public setValues(width?: number, height?: number) { + this.width = width || this.width; + this.height = height || this.height; + } +} \ No newline at end of file diff --git a/src/style.css b/src/style.css index 85dc0d6..096f3f0 100644 --- a/src/style.css +++ b/src/style.css @@ -4,3 +4,15 @@ font-family: NTSomic; src: url(./assets/NTSomic-Bold.ttf); } + +*, .settings { + overflow: hidden; +} + +.map, svg { + overflow-x: auto; +} + +.v-btn { + margin-bottom: 1em; +} \ No newline at end of file