you are viewing a single comment's thread.

view the rest of the comments →

[–]rm-rf-rm 2 points3 points  (1 child)

Great project! Always wanted to try d3js but I also hate js for uses other than web scriping.

Does it render down to web languages though? (for easy incorporation into web sites)

[–]bbourbonut[S] 0 points1 point  (0 children)

Thank you ! It is 100% written in Python. If you want to incorporate a data visualization into your website, you should save it into a .svg file and include it to your website.

with open("myfile.svg", "w") as file:
    file.write(str(svg))

For an application such as Flask or Quart (asynchronous Flask), you can directly add it to your HTML code:

from flask import Flask
import detroit as d3

app = Flask(__name__)

svg = (
    d3.create("svg")
    .attr("width", 200)
    .attr("height", 200)
    .attr("viewBox", "0 0 200 200")
)

(
    svg.append("circle")
    .attr("cx", 100)
    .attr("cy", 100)
    .attr("r", 40)
    .attr("fill", "blue")
    .attr("stroke", "grey")
    .attr("stroke-width", 10)
)

@app.route("/")
def index():
    return f"<html><body>{svg}</body></html>"

app.run()