graph.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. "use strict";
  2. import { tabulate } from './d3table.js';
  3. import { drawGraph } from './d3graph.js';
  4. import { drawTree } from './d3tree.js';
  5. // import { treeTable } from './d3treetable.js';
  6. import { data } from './results.js';
  7. // import * as d3 from "https://cdn.jsdelivr.net/npm/d3@7/+esm";
  8. // const div = d3.selectAll("div");
  9. // tabulate(data, "#figure1");
  10. // drawGraph(data, "#figure2", 1280, 650);
  11. // drawTree(data, "#figure3", "root", false, 1280, 650, 150);
  12. // treeTable(data, "#figure4");
  13. class GraphPlugin {
  14. priority = 10;
  15. hideFromSelection = false;
  16. constructor(yasr) {
  17. this.yasr = yasr;
  18. }
  19. draw() {
  20. const el = document.createElement("div");
  21. console.log(this.yasr.results);
  22. this.yasr.resultsEl.style.width = "100%";
  23. drawGraph(this.yasr.results.json, this.yasr.resultsEl, this.yasr.resultsEl.offsetWidth, 650);
  24. }
  25. canHandleResults() {
  26. return true;
  27. return (
  28. this.yasr.results.getBoolean &&
  29. (this.yasr.results.getBoolean() === true || this.yasr.results.getBoolean() == false)
  30. );
  31. }
  32. getIcon() {
  33. const tabElement = document.createElement("div");
  34. tabElement.classList.add("svgImg");
  35. tabElement.innerHTML = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 512 512\" aria-hidden=\"true\"><path fill=\"currentColor\" d=\"M464 32H48C21.49 32 0 53.49 0 80v352c0 26.51 21.49 48 48 48h416c26.51 0 48-21.49 48-48V80c0-26.51-21.49-48-48-48zM224 416H64v-96h160v96zm0-160H64v-96h160v96zm224 160H288v-96h160v96zm0-160H288v-96h160v96z\"></path></svg>"
  36. return tabElement;
  37. }
  38. }
  39. Yasr.registerPlugin("Graph", GraphPlugin);
  40. Yasqe.defaults.value = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" +
  41. "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" +
  42. "SELECT * WHERE {\n" +
  43. " ?sub ?pred ?obj .\n" +
  44. "} LIMIT 10";
  45. // https://triply.cc/docs/yasgui-api/
  46. const url = "https://fuseki.rys.app/example/";
  47. const yasgui = new Yasgui(document.getElementById("yasgui"), {
  48. requestConfig: {endpoint: url, copyEndpointOnNewTab: false},
  49. });
  50. // let tab = yasgui.getTab();
  51. yasgui.on("queryResponse", (instance, tab) => {
  52. console.log(instance);
  53. console.log(tab);
  54. });