Giter VIP home page Giter VIP logo

Comments (4)

jexp avatar jexp commented on May 18, 2024 1

I guess that's something you can figure out yourself. It's just javascript :)

from neo4j-3d-force-graph.

jexp avatar jexp commented on May 18, 2024

Thanks a lot,

I'm really just wrapping his amazing work. I think you saw the example for "text as nodes".

I saw you already raised an issue with him.

If you look at his code example I guess the easiest is to draw a background circle on the canvas instead of a rect here:

https://github.com/vasturiano/force-graph/blob/master/example/text-nodes/index.html#L26

from neo4j-3d-force-graph.

jexp avatar jexp commented on May 18, 2024

Please let me know how it goes.

from neo4j-3d-force-graph.

jexp avatar jexp commented on May 18, 2024

I just quickly took his demo and changed it a bit:

Looks like this now:

‎localhost_8000_caption-nodes_

<head>
  <style> body { margin: 0; } </style>

  <script src="//unpkg.com/force-graph"></script>
  <!--<script src="../../dist/force-graph.js"></script>-->
  <script src="//unpkg.com/d3-quadtree"></script>
  <script src="//unpkg.com/d3-force"></script>
  
</head>

<body>
  <div id="graph"></div>

  <script>
    fetch('../datasets/miserables.json').then(res => res.json()).then(data => {
      const Graph = ForceGraph()
      (document.getElementById('graph'))
        .graphData(data)
        .d3Force('collide', d3.forceCollide(50))
        .nodeId('id')
        .nodeAutoColorBy('group')
        .nodeCanvasObject((node, ctx, globalScale) => {
          const label = node.id;
          const fontSize = 12/globalScale;
          ctx.font = `${fontSize}px Sans-Serif`;
          const textWidth = ctx.measureText(label).width;
          const bckgDimensions = [textWidth, fontSize].map(n => n + fontSize * 0.2); // some padding

          ctx.fillStyle = node.color; // 'rgba(255, 255, 255, 0.8)';
          ctx.beginPath();
          const radius = Math.max(bckgDimensions[0],bckgDimensions[1])/2 + 2;
		  ctx.arc(node.x, node.y, radius, 0, 2 * Math.PI);
		  ctx.globalAlpha = 0.3;
		  ctx.fill();
		  ctx.stroke();
		  ctx.globalAlpha = 1;
//          ctx.fillRect(node.x - bckgDimensions[0] / 2, node.y - bckgDimensions[1] / 2, ...bckgDimensions);
          

          ctx.textAlign = 'center';
          ctx.textBaseline = 'middle';
          ctx.fillStyle = node.color;
          ctx.fillText(label, node.x, node.y);
        });
    });
  </script>
</body>

from neo4j-3d-force-graph.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.