-
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
723dcd9
commit 1d7ea2d
Showing
4 changed files
with
81 additions
and
87 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
This file was deleted.
Oops, something went wrong.
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,77 @@ | ||
import {AppState} from "../../store/appState/state"; | ||
import {Store} from "vuex"; | ||
import {GraphsAction} from "../../store/graphs/actions"; | ||
import {computed} from "vue"; | ||
|
||
export interface SelectVariablesMixin { | ||
startDrag: (evt: DragEvent, variable: string) => void; | ||
endDrag: () => void, | ||
onDrop: (evt: DragEvent) => void, | ||
removeVariable: (srcGraphIdx: number, variable: string) => void | ||
} | ||
|
||
export default ( | ||
store: Store<AppState>, | ||
emit: (event: string, ...args: any[]) => void, | ||
hiddenVariables: boolean, | ||
graphIndex?: number): SelectVariablesMixin => { | ||
|
||
const thisSrcGraph = hiddenVariables ? "hidden" : graphIndex!.toString(); | ||
|
||
const startDrag = (evt: DragEvent, variable: string) => { | ||
const { dataTransfer } = evt; | ||
dataTransfer!!.dropEffect = "move"; | ||
dataTransfer!!.effectAllowed = "move"; | ||
dataTransfer!!.setData("variable", variable); | ||
dataTransfer!!.setData("srcGraph", thisSrcGraph); | ||
|
||
emit("setDragging", true); | ||
}; | ||
|
||
const endDrag = () => { | ||
emit("setDragging", false); | ||
}; | ||
|
||
const updateSelectedVariables = (graphIndex: number, newVariables: string[]) => { | ||
store.dispatch(`graphs/${GraphsAction.UpdateSelectedVariables}`, { | ||
graphIndex, | ||
selectedVariables: newVariables | ||
}); | ||
}; | ||
|
||
// Remove variable from a given graph | ||
const removeVariable = (srcGraphIdx: number, variable: string) => { | ||
const srcVariables = [...store.state.graphs.config[srcGraphIdx].selectedVariables].filter( | ||
(v) => v !== variable | ||
); | ||
updateSelectedVariables(srcGraphIdx, srcVariables); | ||
}; | ||
|
||
const selectedVariables = computed<string[]>( | ||
() => hiddenVariables ? [] : store.state.graphs.config[graphIndex!].selectedVariables | ||
); | ||
|
||
const onDrop = (evt: DragEvent) => { | ||
const { dataTransfer } = evt; | ||
const variable = dataTransfer!!.getData("variable"); | ||
const srcGraph = dataTransfer!!.getData("srcGraph"); | ||
if (srcGraph !== thisSrcGraph) { | ||
// remove from source graph | ||
if (srcGraph !== "hidden") { | ||
removeVariable(parseInt(srcGraph), variable); | ||
} | ||
// add to this graph if necessary | ||
if (!hiddenVariables && !selectedVariables.value.includes(variable)) { | ||
const newVars = [...selectedVariables.value, variable]; | ||
updateSelectedVariables(graphIndex!, newVars); | ||
} | ||
} | ||
}; | ||
|
||
return { | ||
removeVariable, | ||
startDrag, | ||
endDrag, | ||
onDrop | ||
}; | ||
} |