Skip to content

Commit

Permalink
Merge pull request #202 from t29mato/feature/add_global_types
Browse files Browse the repository at this point in the history
Add type to define manualMode, maskMode, pointMode
  • Loading branch information
yu-smc authored Sep 20, 2024
2 parents d7c192f + 4b2e4a2 commit 7e209d2
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src/@types/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { MANUAL_MODE, MASK_MODE, POINT_MODE } from "@/constants";

export type ManualMode = typeof MANUAL_MODE[keyof typeof MANUAL_MODE]
export type MaskMode = typeof MASK_MODE[keyof typeof MASK_MODE]
export type PointMode = typeof POINT_MODE[keyof typeof POINT_MODE]
11 changes: 6 additions & 5 deletions src/application/services/canvasHandler/canvasHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { CanvasHandlerInterface } from './canvasHandlerInterface'
import { Coord } from '../../../domain/models/dataset/datasetInterface'
import { HTMLCanvas } from '../../../presentation/dom/HTMLCanvas'
import { MANUAL_MODE, MASK_MODE } from '@/constants'
import { ManualMode, MaskMode } from '@/@types/types'
const colorThief = new ColorThief()

export class CanvasHandler implements CanvasHandlerInterface {
Expand All @@ -17,8 +18,8 @@ export class CanvasHandler implements CanvasHandlerInterface {
endX: 0,
endY: 0,
}
maskMode: number = MASK_MODE.UNSET
manualMode: number = MANUAL_MODE.UNSET
maskMode: MaskMode = MASK_MODE.UNSET
manualMode: ManualMode = MANUAL_MODE.UNSET
penToolSizePx = 50
eraserSizePx = 30
uploadImageUrl = ''
Expand Down Expand Up @@ -373,12 +374,12 @@ export class CanvasHandler implements CanvasHandlerInterface {
this.cursor = coord
}

setManualMode(mode: number) {
setManualMode(mode: ManualMode) {
this.manualMode = mode
this.maskMode = -1
this.maskMode = MASK_MODE.UNSET
}

setMaskMode(mode: number) {
setMaskMode(mode: MaskMode) {
this.maskMode = mode
this.manualMode = MANUAL_MODE.UNSET
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { ManualMode, MaskMode } from '@/@types/types'
import { Coord } from '@/domain/models/dataset/datasetInterface'

export interface CanvasHandlerInterface {
isDrawnMask: boolean
imageElement: HTMLImageElement
scale: number
cursor: Coord
manualMode: number
maskMode: number
manualMode: ManualMode
maskMode: MaskMode
rectangle: {
startX: number
startY: number
Expand Down
3 changes: 2 additions & 1 deletion src/domain/models/axisSet/axisSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Coord } from '@/domain/models/dataset/datasetInterface'
import { AxisSetInterface, Vector } from './axisSetInterface'
import { AxisInterface } from '@/domain/models/axis/axisInterface'
import { POINT_MODE } from '@/constants'
import { PointMode } from '@/@types/types'

export class AxisSet implements AxisSetInterface {
id: number
Expand All @@ -15,7 +16,7 @@ export class AxisSet implements AxisSetInterface {
xIsLogScale = false
yIsLogScale = false
activeAxisName = ''
pointMode = POINT_MODE.TWO_POINTS
pointMode: PointMode = POINT_MODE.TWO_POINTS
considerGraphTilt = false
isAdjusting = false
isVisible = true
Expand Down
3 changes: 2 additions & 1 deletion src/domain/models/axisSet/axisSetInterface.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Coord } from '../dataset/datasetInterface'
import { AxisInterface } from '../axis/axisInterface'
import { PointMode } from '@/@types/types'

// TODO: VectorはDatasetInterfaceでも利用しており共通Typeの場所を用意するべきか検討する
export type Vector = {
Expand All @@ -18,7 +19,7 @@ export interface AxisSetInterface {
xIsLogScale: boolean
yIsLogScale: boolean
activeAxisName: string
pointMode: number
pointMode: PointMode
considerGraphTilt: boolean
isAdjusting: boolean
isVisible: boolean
Expand Down

0 comments on commit 7e209d2

Please sign in to comment.