Skip to content

Commit

Permalink
Merge pull request #286 from multinet-app/network-variables
Browse files Browse the repository at this point in the history
Move network variables to store
gotdairyya authored Jul 1, 2021
2 parents 9255684 + 6214f82 commit ebf951e
Showing 4 changed files with 95 additions and 6 deletions.
11 changes: 6 additions & 5 deletions src/components/ConnectivityQuery.vue
Original file line number Diff line number Diff line change
@@ -87,8 +87,8 @@ export default {
const displayedHops = computed(() => 2 * selectedHops.value + 1);
const selectedVariables: Ref<string[]> = ref([]);
const nodeVariableItems = computed(() => (store.state.network ? Object.keys(store.state.network.nodes[0]) : ['No network']));
const edgeVariableItems = computed(() => (store.state.network ? Object.keys(store.state.network.edges[0]) : ['No network']));
const nodeVariableItems = computed(() => (store.state.network ? Object.keys(store.state.nodeAttributes) : ['No network']));
const edgeVariableItems = computed(() => (store.state.network ? Object.keys(store.state.edgeAttributes) : ['No network']));
const selectedQueryOptions: Ref<string[]> = ref([]);
const queryOptionItems = ['is (exact)', 'contains'];
@@ -106,9 +106,10 @@ export default {
watchEffect(() => {
selectedVariables.value.forEach((variable: string, i: number) => {
if (store.state.network !== null) {
const currentData = i % 2 ? store.state.network.edges : store.state.network.nodes;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
variableValueItems.value[i] = (currentData as any).map((d: any) => `${d[variable]}`).sort();
const currentData = i % 2 ? store.state.edgeAttributes : store.state.nodeAttributes;
if (variable) {
variableValueItems.value[i] = currentData[variable].map((value) => `${value}`);
}
}
});
});
57 changes: 56 additions & 1 deletion src/components/FilterOverlay.vue
Original file line number Diff line number Diff line change
@@ -57,7 +57,7 @@
<script lang="ts">
import Vue from 'vue';
import api from '@/api';
import { Network } from '@/types';
import { ArangoAttributes, Network } from '@/types';
import store from '@/store';
export default Vue.extend({
@@ -120,6 +120,61 @@ export default Vue.extend({
});
}
});
this.getAttributes();
}
},
getAttributes() {
const aqlQuery = `
let nodeValues = (FOR doc IN ${store.state.nodeTableNames}[**] RETURN VALUES(doc))
let edgeValues = (FOR doc IN ${store.state.edgeTableName} RETURN VALUES(doc))
let nodeAttr = (FOR doc IN ${store.state.nodeTableNames}[**] LIMIT 1 RETURN doc)
let edgeAttr = (FOR doc IN ${store.state.edgeTableName} LIMIT 1 RETURN doc)
RETURN {nodeAttributes: nodeAttr, nodeValues: nodeValues, edgeAttributes: edgeAttr, edgeValues: edgeValues}
`;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let nodeAndEdgeQuery: Promise<any[]> | undefined;
try {
nodeAndEdgeQuery = api.aql(store.state.workspaceName || '', aqlQuery);
} catch (error) {
// Add error message for user
if (error.status === 400) {
store.commit.setLoadError({
message: error.statusText,
href: 'https://multinet.app',
});
}
}
if (nodeAndEdgeQuery !== undefined) {
nodeAndEdgeQuery.then((promise) => {
const aqlResults = promise[0];
const nodeAttrDict: {[key: string]: number} = {};
const edgeAttrDict: {[key: string]: number} = {};
const nodeAttributes: ArangoAttributes = {};
const edgeAttributes: ArangoAttributes = {};
const getKeyByValue = (obj: {[key: string]: string | number | boolean }, value: string | number | boolean) => Object.keys(obj)[Object.values(obj).indexOf(value)];
Array(aqlResults.nodeValues[0].length).fill(1).forEach((_, i) => {
const attrKey: string = getKeyByValue(aqlResults.nodeAttributes[0], aqlResults.nodeValues[0][i]);
nodeAttrDict[attrKey] = i;
});
// eslint-disable-next-line no-restricted-syntax
for (const [key, value] of Object.entries(nodeAttrDict)) {
nodeAttributes[key] = [...new Set(aqlResults.nodeValues.map((vals: string[]) => `${vals[value]}`).sort())];
}
Array(aqlResults.edgeValues[0].length).fill(1).forEach((_, i) => {
const attrKey: string = getKeyByValue(aqlResults.edgeAttributes[0], aqlResults.edgeValues[0][i]);
edgeAttrDict[attrKey] = i;
});
// eslint-disable-next-line no-restricted-syntax
for (const [key, value] of Object.entries(edgeAttrDict)) {
edgeAttributes[key] = [...new Set(aqlResults.edgeValues.map((vals: string[]) => `${vals[value]}`).sort())];
}
store.commit.setLargeNetworkAttributeValues({ nodeAttributes, edgeAttributes });
});
}
},
},
27 changes: 27 additions & 0 deletions src/store/index.ts
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ import {
GraphSpec, RowsSpec, TableRow, UserSpec,
} from 'multinet';
import {
ArangoAttributes,
Cell,
Edge, LoadError, Network, Node, ProvenanceEventTypes, State,
} from '@/types';
@@ -57,6 +58,8 @@ const {
edgeTableName: null,
provenance: null,
showProvenanceVis: false,
nodeAttributes: {},
edgeAttributes: {},
} as State,

getters: {
@@ -234,6 +237,29 @@ const {
toggleShowProvenanceVis(state) {
state.showProvenanceVis = !state.showProvenanceVis;
},

setAttributeValues(state, network: Network) {
const allNodeKeys: Set<string> = new Set();
network.nodes.forEach((node: Node) => Object.keys(node).forEach((key) => allNodeKeys.add(key)));
const nodeKeys = [...allNodeKeys];
state.nodeAttributes = nodeKeys.reduce((ac, a) => ({ ...ac, [a]: [] }), {});
nodeKeys.forEach((key: string) => {
state.nodeAttributes[key] = [...new Set(network.nodes.map((n: Node) => `${n[key]}`).sort())];
});

const allEdgeKeys: Set<string> = new Set();
network.edges.forEach((edge: Edge) => Object.keys(edge).forEach((key) => allEdgeKeys.add(key)));
const edgeKeys = [...allEdgeKeys];
state.edgeAttributes = edgeKeys.reduce((ac, a) => ({ ...ac, [a]: [] }), {});
edgeKeys.forEach((key: string) => {
state.edgeAttributes[key] = [...new Set(network.edges.map((e: Edge) => `${e[key]}`).sort())];
});
},

setLargeNetworkAttributeValues(state: State, payload: { nodeAttributes: ArangoAttributes; edgeAttributes: ArangoAttributes }) {
state.nodeAttributes = payload.nodeAttributes;
state.edgeAttributes = payload.edgeAttributes;
},
},
actions: {
async fetchNetwork(context, { workspaceName, networkName }) {
@@ -326,6 +352,7 @@ const {
nodes: nodes as Node[],
edges: edges as Edge[],
};
commit.setAttributeValues(network);
dispatch.updateNetwork({ network });
},

6 changes: 6 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -40,6 +40,10 @@ export interface LoadError {
href: string;
}

export interface ArangoAttributes {
[key: string]: unknown[];
}

export interface State {
workspaceName: string | null;
networkName: string | null;
@@ -66,6 +70,8 @@ export interface State {
edgeTableName: string | null;
provenance: Provenance<State, ProvenanceEventTypes, unknown> | null;
showProvenanceVis: boolean;
nodeAttributes: ArangoAttributes;
edgeAttributes: ArangoAttributes;
}

export type ProvenanceEventTypes =

0 comments on commit ebf951e

Please sign in to comment.