Code Monkey home page Code Monkey logo

Comments (10)

benfred avatar benfred commented on August 17, 2024 1

This appends an extra tspan below each label with the size of the area

function annotateSizes() {
    d3.select(this).select("text")
        .append("tspan")
        .text(function(d) { return "size " + d.size; })
        .attr("x", function() { return d3.select(this.parentNode).attr("x"); })
        .attr("dy", "1.5em")
        .style("fill", "#666")
        .style("font-size", "10px");
}
div.selectAll("g").transition("venn").each("end", annotateSizes).duration(0);

There might be an easier way of doing this, the 'transition' thing is a bit of a hack. Appending to the 'examples/venn_venn.html' file produces this output:
screen shot 2015-10-01 at 12 34 56 pm

from venn.js.

ben-pr-p avatar ben-pr-p commented on August 17, 2024

It works until the circles start moving – after that, the tspan element gets removed. It happens on some timeout – I'll try to get more information.

I could always wait until the circles on done moving to render the text, but that's not preferable.

from venn.js.

benfred avatar benfred commented on August 17, 2024

I added an example with transitions for this: http://benfred.github.io/venn.js/examples/sublabels.html

This required making some minor changes to the library (a13bab7) so you'll need to get the latest version if you want to go this route. hope this helps =)

from venn.js.

ben-pr-p avatar ben-pr-p commented on August 17, 2024

Thanks! I've got the sublabels working exactly as desired now.

However, is there something in the latest commit that would've changed the way hover on intersection works? Even when not including the new sublabels feature, my old hover on intersection code is not working like it was before.

from venn.js.

ben-pr-p avatar ben-pr-p commented on August 17, 2024

It seems as if the svg path element on venn-intersection is not being created correctly – the text is added in the right place, however.

Take a look:

screen shot 2015-10-05 at 12 02 57 pm

from venn.js.

ben-pr-p avatar ben-pr-p commented on August 17, 2024

I double checked and this issue was not present in 050d9ad

from venn.js.

ben-pr-p avatar ben-pr-p commented on August 17, 2024

I put some debugger statements in and found that venn.intersectionAreaPath is not being called on the initial circle creation in a13bab7 but is in 050d9ad

from venn.js.

ben-pr-p avatar ben-pr-p commented on August 17, 2024

Figured it out – a simple change – https://github.com/benfred/venn.js/blob/master/src/diagram.js#L92 should read
update.select("path") instead of update.select(".venn-circle path").

Was there a reason you made that change? The label rendering still works properly with path only.

from venn.js.

benfred avatar benfred commented on August 17, 2024

sorry about that - didn't mean to check that in =( the indentation level changed, so I didn't spot it in the diff.

thanks for fixing!

from venn.js.

ben-pr-p avatar ben-pr-p commented on August 17, 2024

Sublabels work better when you "retext" the labels on update – they refresh if the sizes have changed. For example:

// move existing
    layout.update
        .select(".sublabel")
        .text(function(d) { 
          if (d.size == 0.9) return "0 opinions"; 
          else return (d.size) + ' opinions'; }) // 0.9 is the marker for 0
        .style("font-size", "10px")
        .attr("dy", "18")
        .attr("x", function(d) {
            return Math.floor(textCentres[d.sets].x);
        })
        .attr("y", function(d) {
            return Math.floor(textCentres[d.sets].y);
        });

from venn.js.

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.