Giter VIP home page Giter VIP logo

Comments (2)

anvaka avatar anvaka commented on May 13, 2024

To put a border around image you should follow SVG rules. I'm not sure which way is the best one, but usually I go with a grouping element g and put elements inside the group to achieve required UI. E.g. for image with border I would create a rectangle and then put image above it:

graphics.node(function(node) {
  var ui = Viva.Graph.svg('g'),
      rect = Viva.Graph.svg('rect')
         .attr('stroke-width', 10)
         .attr('stroke', 'blue')
         .attr('width', node.data.size)
         .attr('height', node.data.size),
      img = Viva.Graph.svg('image')
         .attr('width', node.data.size)
         .attr('height', node.data.size)
         .link(node.data.url);

  ui.append(rect); 
  ui.append(img);
  ui.myCustomSize = node.data.size; // we'll talk about this later

  return ui;    
});

Moving groups around the screen is a bit harder than plain images though. Groups don't have 'x' and 'y' properties, but can be moved with svg:transform attribute:

graphics.placeNode(function(nodeUI, pos){
    var half = nodeUI.myCustomSize/2; // myCustomSize is here!
    nodeUI.attr('transform', 
                'translate(' + 
                      (pos.x - half) + ',' + 
                      (pos.y - half) + 
                ')'); // and not so elegant syntax for transforms
});

As for the size - you can pass arbitrary attribute to the object returned from 'node()' callback. Exactly the same object you'll get as nodeUI in the 'placeNode()' callback. I'm using this fact in the code above to specify custom attribute called 'myCustomSize'.

I also made this fiddle for you to show complete example.

Hope this helps :).

from vivagraphjs.

eljeffeg avatar eljeffeg commented on May 13, 2024

Perfect!

from vivagraphjs.

Related Issues (20)

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.