Skip to content

Commit

Permalink
delete graph
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmaLRussell committed Jul 1, 2024
1 parent 3ce85fa commit f49637b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
30 changes: 28 additions & 2 deletions app/static/src/app/components/graphConfig/GraphConfig.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
<template>
<div class="graph-config-panel m-2" @drop="onDrop($event)" @dragover.prevent @dragenter.prevent>
<h5>Graph {{ graphIndex + 1 }}</h5>
<h5>
Graph {{ graphIndex + 1 }}
<button
type="button"
class="btn btn-light mx-2"
v-if="canDelete"
@click="deleteGraph"
v-tooltip="'Delete Graph'"
>
<vue-feather
class="inline-icon clickable ms-2"
type="trash-2"
></vue-feather>
</button>
</h5>
<div class="drop-zone" :class="dragging ? 'drop-zone-active' : 'drop-zone-inactive'">
<template v-for="variable in selectedVariables" :key="variable">
<span
Expand All @@ -24,12 +38,17 @@
</template>

<script lang="ts">
import VueFeather from "vue-feather";
import { computed, defineComponent } from "vue";
import { useStore } from "vuex";
import SelectVariables from "../mixins/selectVariables";
import {GraphsMutation} from "../../store/graphs/mutations";
export default defineComponent({
name: "GraphConfig",
components: {
VueFeather
},
props: {
dragging: {
type: Boolean,
Expand All @@ -46,6 +65,7 @@ export default defineComponent({
const selectedVariables = computed<string[]>(
() => store.state.graphs.config[props.graphIndex].selectedVariables
);
const canDelete = computed(() => store.state.graphs.config.length > 1);
const palette = computed(() => store.state.model.paletteModel!);
const getStyle = (variable: string) => {
Expand All @@ -56,13 +76,19 @@ export default defineComponent({
return { "background-color": bgcolor };
};
const deleteGraph = () => {
store.commit(`graphs/${GraphsMutation.DeleteGraph}`, props.graphIndex);
};
return {
selectedVariables,
canDelete,
removeVariable,
getStyle,
startDrag,
endDrag,
onDrop
onDrop,
deleteGraph
};
}
});
Expand Down
5 changes: 5 additions & 0 deletions app/static/src/app/store/graphs/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export enum GraphsMutation {
SetLockYAxis = "SetLockYAxis",
SetYAxisRange = "SetYAxisRange",
AddGraph = "AddGraph",
DeleteGraph = "DeleteGraph",
SetSelectedVariables = "SetSelectedVariables"
}

Expand Down Expand Up @@ -36,5 +37,9 @@ export const mutations: MutationTree<GraphsState> = {

[GraphsMutation.AddGraph](state: GraphsState, payload: GraphConfig) {
state.config.push(payload);
},

[GraphsMutation.DeleteGraph](state: GraphsState, payload: number) {
state.config.splice(payload, 1);
}
};

0 comments on commit f49637b

Please sign in to comment.