Giter Club home page Giter Club logo

Comments (6)

JobJob avatar JobJob commented on July 20, 2024

So here's an example. It's not that pretty, or efficient, but it works - if you move the slider, one of the bars will move up and down. It uses the @manipulate macro from Interact.jl. Note in the dataset the $i interpolated into the data array.

using Interact
@manipulate for i in 1:30
    d3code = """
        <g></g>

        <style>
        element {
            height: 25px;
        }
        div.bar {
            display: inline-block;
            width: 20px;
            height: 75px;
            margin-right: 2px;
            background-color: teal;
        }
        </style>

        <script>
        var dataset = [ 5, 10, 13, 19, 21, $i, 22, 18, 15, 13,
                        11, 12, 15, 20, 18, 17, 16, 18, 23, 25 ];

        d3.select("g").selectAll("div")
            .data(dataset)
            .enter()
            .append("div")
            .attr("class", "bar")
            .style("height", function(d) {
                var barHeight = d * 5;
                return barHeight + "px";
            });
        </script>
    """
    IJulia.clear_output()
    @d3_str d3code
end;

Anyway, at some point I will likely improve this, so we can leave this open for now.

from d3magic.jl.

JobJob avatar JobJob commented on July 20, 2024

n.b. you'll need to update to the latest version.

from d3magic.jl.

zahachtah avatar zahachtah commented on July 20, 2024

Thanks!

from d3magic.jl.

xiaohk avatar xiaohk commented on July 20, 2024

Is it possible to implement tooltip using D3Magic? Like this example . I am having some troubles to implement it, since it seems we cannot select body in the JS code.

from d3magic.jl.

xiaohk avatar xiaohk commented on July 20, 2024

It seems IJulia.clear_output() now also clears the slider. Any workaround?

from d3magic.jl.

JobJob avatar JobJob commented on July 20, 2024

@xiaohk I've added an example of how to use Interact/InteractNext in the README.

On the latest master (Pkg.update() should get you there), I've added d3._select and d3._selectAll that allow you to select things outside the "sandbox" that D3Magic creates. So you can select <body> with d3._select("body").

The example below should work, let me know how you go.

d3"""
<div class="example_div"></div>
<script>
var tooltip = d3._select("body")
    .append("div")
    .attr("class", "jjtooltip")
	.style("position", "absolute")
	.style("z-index", "10")
	.style("visibility", "hidden")
	.text("a simple tooltip");
	
var sampleSVG = d3.select(".example_div")
	.append("svg:svg")
	.attr("class", "sample")
	.attr("width", 300)
	.attr("height", 300);    
	
d3.select(".example_div svg")
	.append("svg:circle")
	.attr("stroke", "black")
	.attr("fill", "aliceblue")
	.attr("r", 50)
	.attr("cx", 52)
	.attr("cy", 52)
	.on("mouseover", function(){
        return tooltip.style("visibility", "visible");
    })
	.on("mousemove", function(){
        // debugger
        return tooltip.style("top", (event.y-10)+"px").style("left",(event.x+10)+"px");
    })
	.on("mouseout", function(){return tooltip.style("visibility", "hidden");});
</script>
"""

from d3magic.jl.

Related Issues (3)

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.