Skip to content

Commit

Permalink
init tagGraph 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
stg-annon committed May 26, 2024
1 parent 865d777 commit a5cad9e
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 0 deletions.
7 changes: 7 additions & 0 deletions plugins/tagGraph/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Tag Graph psuedo-plugin

## This renders a graph with physics in realtime, it is not lightweight

This plugin does not run in stash, but instead runs in your browser

To view, go to `http://localhost:9999/plugin/tag-graph/assets/graph/`
15 changes: 15 additions & 0 deletions plugins/tagGraph/graph/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
margin: 0
}
#taggraph {
background-color: #202b33;
}
</style>
<script src="./vis.min.js"></script>
<script src="./parse.js"></script>
<body onload="draw()">
<div id="taggraph"></div>
</body>
81 changes: 81 additions & 0 deletions plugins/tagGraph/graph/parse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
function parse(source) {
const nodes = []
const edges = []
for (const tag of source.data.findTags.tags) {
nodes.push({
id: tag.id,
shape: "circularImage", // could also just use "image" here
image: tag.image_path,
label: tag.name
})
for (const child of tag.children) {
edges.push({from:tag.id, to:child.id})
}
}
return { nodes, edges }
}

async function getTags() {

const query = `query FindTags($filter: FindFilterType, $tag_filter: TagFilterType) {
findTags(filter: $filter, tag_filter: $tag_filter) {
count
tags {
id
name
image_path
parents { id }
children { id }
}
}
}`
const variables = {
"tag_filter": {
"child_count": {"modifier": "GREATER_THAN", "value": 0},
"OR": {"parent_count": {"modifier": "GREATER_THAN", "value": 0}},
},
"filter": {"q": "", "per_page": -1},
}
const source = await fetch("/graphql", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ query:query, variables:variables })
}).then(r => r.json())
console.log(`Found ${source.data.findTags.count} tags with parents/children`)
return parse(source)

}
var network = null;

async function draw() {

var container = document.getElementById("taggraph");
var data = await getTags();

console.log(data)

var options = {
autoResize: true,
height: `${window.screen.height}px`, //100% does not seem to work here
width: "100%",
configure: { enabled: false }, //set to true to enable config options
nodes: {
color: {
border: "#adb5bd",
background: "#394b59",
highlight: {
border: "#137cbd",
background: "#FFFFFF"
}
},
font: { color: "white" },
},
edges: {
color: "#FFFFFF"
},
layout: {
improvedLayout: false
}
};
network = new vis.Network(container, data, options);
}
34 changes: 34 additions & 0 deletions plugins/tagGraph/graph/vis.min.js

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions plugins/tagGraph/tag-graph.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: tag-graph
description: Interactive tag graph with vis.js
version: 2.0
url: https://github.com/stg-annon/StashScripts/tree/main/plugins/tagGraph
ui:
assets:
/: .

0 comments on commit a5cad9e

Please sign in to comment.