-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
da2cddb
commit d1f17fd
Showing
4 changed files
with
125 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<template> | ||
<div class="selected-variables-panel m-2" @drop="onDrop($event)" @dragover.prevent @dragenter.prevent> | ||
<h5>Hidden variables</h5> | ||
<template v-for="variable in hiddenVariables" :key="variable"> | ||
<span | ||
class="badge variable me-2 mb-2" | ||
:style="getStyle(variable)" | ||
draggable="true" | ||
@dragstart="startDrag($event, variable)" | ||
> | ||
{{ variable }} | ||
</span> | ||
</template> | ||
<div v-if="!hiddenVariables.length" style="height: 3rem; background-color: #eee" class="p-2 me-4"> | ||
Drag variables here to hide them on all graphs. | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { computed, defineComponent } from "vue"; | ||
import { useStore } from "vuex"; | ||
import { ModelAction } from "../../store/model/actions"; | ||
import VueFeather from "vue-feather"; | ||
import tooltip from "../../directives/tooltip"; | ||
import { ModelMutation } from "../../store/model/mutations"; | ||
import { ModelGetter } from "../../store/model/getters"; | ||
export default defineComponent({ | ||
name: "SelectedVariables", | ||
computed: { | ||
tooltip() { | ||
return tooltip; | ||
} | ||
}, | ||
components: { VueFeather }, | ||
setup(props) { | ||
const store = useStore(); | ||
const hiddenVariables = computed<string[]>(() => store.getters[`model/${ModelGetter.unselectedVariables}`]); | ||
const palette = computed(() => store.state.model.paletteModel!); | ||
const getStyle = (variable: string) => { | ||
const bgcolor = palette.value ? palette.value[variable] : "#eee"; | ||
return { "background-color": bgcolor }; | ||
}; | ||
const startDrag = (evt: DragEvent, variable: string) => { | ||
console.log(`started dragging ${variable}`); | ||
const { dataTransfer } = evt; | ||
dataTransfer!!.dropEffect = "move"; | ||
dataTransfer!!.effectAllowed = "move"; | ||
dataTransfer!!.setData("variable", variable); | ||
dataTransfer!!.setData("srcGraph", "hidden"); | ||
}; | ||
const onDrop = (evt: DragEvent) => { | ||
const { dataTransfer } = evt; | ||
const variable = dataTransfer!!.getData("variable"); | ||
const srcGraph = dataTransfer!!.getData("srcGraph"); | ||
if (srcGraph !== "hidden") { | ||
// remove from source graph | ||
const srcVariables = [...store.state.model.graphs[srcGraph].selectedVariables].filter( | ||
(v) => v !== variable | ||
); | ||
store.dispatch(`model/${ModelAction.UpdateSelectedVariables}`, { | ||
key: srcGraph, | ||
selectedVariables: srcVariables | ||
}); | ||
} | ||
}; | ||
return { | ||
hiddenVariables, | ||
getStyle, | ||
startDrag, | ||
onDrop | ||
}; | ||
} | ||
}); | ||
</script> | ||
|
||
<style scoped lang="scss"> | ||
.selected-variables-panel { | ||
width: 100%; | ||
.variable { | ||
font-size: large; | ||
cursor: pointer; | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters