Skip to content

Commit

Permalink
🐛 showObjects/Regions/Skeleton/Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidZhang73 committed Feb 27, 2022
1 parent b0a6182 commit 22b469e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 43 deletions.
22 changes: 11 additions & 11 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ const mode_dict = {
}
if (mode) {
if (mode in mode_dict) {
if (mode_dict[mode].toLowerCase() !== 'false') {
if (mode_dict[mode]?.toLowerCase() !== 'false') {
annotationStore.mode = mode
}
}
Expand All @@ -191,44 +191,44 @@ if (sensitivity) {
preferenceStore.sensitivity = sensitivity
}
}
if (!annotation && defaultFps) {
if (defaultFps) {
const fps = parseInt(defaultFps, 10)
if (fps >= 1 && fps <= 60 && fps % 1 === 0) {
preferenceStore.defaultFps = fps
}
}
if (!annotation && defaultFpk) {
if (defaultFpk) {
const fpk = parseInt(defaultFpk, 10)
if (fpk >= 1 && fpk % 1 === 0) {
preferenceStore.defaultFpk = fpk
}
}
if (showObjects) {
if (showObjects.toLowerCase() === 'true') {
preferenceStore.showObjects = true
preferenceStore.objects = true
} else if (showObjects.toLowerCase() === 'false') {
preferenceStore.showObjects(false)
preferenceStore.objects = false
}
}
if (showRegions) {
if (showRegions.toLowerCase() === 'true') {
preferenceStore.showRegions = true
preferenceStore.regions = true
} else if (showRegions.toLowerCase() === 'false') {
preferenceStore.showRegions = false
preferenceStore.regions = false
}
}
if (showSkeletons) {
if (showSkeletons.toLowerCase() === 'true') {
preferenceStore.showSkeletons = true
preferenceStore.skeletons = true
} else if (showSkeletons.toLowerCase() === 'false') {
preferenceStore.showSkeletons = false
preferenceStore.skeletons = false
}
}
if (showActions) {
if (showActions.toLowerCase() === 'true') {
preferenceStore.showActions = true
preferenceStore.actions = true
} else if (showActions.toLowerCase() === 'false') {
preferenceStore.showActions = false
preferenceStore.actions = false
}
}
if (muted) {
Expand Down
6 changes: 3 additions & 3 deletions src/libs/annotationlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
* Library for annotations
*/

import deepClone from 'lodash.clonedeep'
import { useAnnotationStore } from '~/store/annotation.js'
import { useConfigurationStore } from '~/store/configuration.js'
import { usePreferenceStore } from '~/store/preference.js'
import utils from './utils.js'

class Annotation {
constructor (instance = null, score = null) {
Expand Down Expand Up @@ -449,7 +449,7 @@ class RegionAnnotation extends Annotation {
*/
clone () {
return new RegionAnnotation(
utils.deepClone(this.pointList),
deepClone(this.pointList),
this.labelId,
this.color,
this.instance,
Expand Down Expand Up @@ -679,7 +679,7 @@ class SkeletonAnnotation extends Annotation {
this.score
)
skeletonAnnotation._ratio = this._ratio
skeletonAnnotation.pointList = utils.deepClone(this.pointList)
skeletonAnnotation.pointList = deepClone(this.pointList)
return skeletonAnnotation
}

Expand Down
20 changes: 1 addition & 19 deletions src/libs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default {
* @param timeout
* @returns
*/
notify (message, color = 'positive', timeout=5000) {
notify (message, color = 'positive', timeout = 5000) {
return Notify.create({
message: message,
color: color,
Expand Down Expand Up @@ -141,23 +141,5 @@ export default {
randomColor () {
return `#${('000000' + (Math.random() * 16777216 | 0).toString(16)).slice(
-6)}`
},
/**
* DeepClone
* @param object
* @returns {Object}
*/
deepClone (object) {
let newObject = new object.constructor
if (object === null) return object
if (typeof object == 'function') return new Function(
'return ' + object.toString())()
if (typeof object != 'object') return object
if (object instanceof RegExp) return new RegExp(object)
if (object instanceof Date) return new Date(object)
for (let i in object) {
newObject[i] = this.deepClone(object[i])
}
return newObject
}
}
15 changes: 5 additions & 10 deletions src/store/preference.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,21 @@ const DEFAULT_PREFERENCE = {
showPopup: true
}

function getPreferenceData () {
const ret = deepClone(DEFAULT_PREFERENCE)
export const usePreferenceStore = defineStore('preference', () => {
const defaultPreference = deepClone(DEFAULT_PREFERENCE)
const state = reactive(DEFAULT_PREFERENCE)
const ls = JSON.parse(localStorage.getItem(LS_KEY))
if (ls) {
for (const key in ret) {
for (const key in state) {
if (ls.hasOwnProperty(key)) {
ret[key] = ls[key]
state[key] = ls[key]
}
}
}
return ret
}

export const usePreferenceStore = defineStore('preference', () => {
const state = reactive(getPreferenceData())
watch(state, (newValue) => {
localStorage.setItem(LS_KEY, JSON.stringify(newValue))
})
const reset = () => {
const defaultPreference = deepClone(DEFAULT_PREFERENCE)
Object.keys(state).map(key => state[key] = defaultPreference[key])
}
return { ...toRefs(state), reset }
Expand Down

0 comments on commit 22b469e

Please sign in to comment.