D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
boneskull
Full window
Github gist
fiddling w snapsvg
Built with
blockbuilder.org
<!DOCTYPE html> <head> <meta charset="utf-8"> <script src="https://d3js.org/d3.v4.min.js"></script> <script src="https://unpkg.com/snapsvg@0.5.1"></script> <style> body { padding: 2em; font-family: sans-serif; } .wrapper { display: flex; flex-flow: row; } .wrapper > * { padding: 10px; } main { background: #f6f6f6; } aside { background: #f3f3f3; border-right: 4px solid #ececec; } main { flex: 4 1 auto; order: 2; } aside { flex: 1 6 140px; order: 1; } </style> </head> <body> <div class="wrapper"> <aside> </aside> <main><p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. </p></main> </div> <script> const nodes = { 'Bodkin': '#63BA9B', 'Hoos-Foos': '#98C9C3', 'Snimm': '#F2DDBD', 'Hot-Shot': '#D8C3A7', 'Jim': '#DD6985' } function createPalette () { const aside = d3.select('aside'); Object.keys(nodes).forEach(name => { const svg = Snap(aside.append('svg') .attr('width', 140) .attr('height', 60) .attr('id', name) .node()); const node = svg.rect(10, 10, 120, 40, 4, 4) .attr({ stroke: '#555', strokeWidth: 2, fill: nodes[name] }); const text = svg.text('50%', '50%', name).attr('text-anchor', 'middle').attr('alignment-baseline', 'middle').attr('fill', '#333'); }); } createPalette(); // const s = Snap('#foo'); // s.rect(10, 10, 100, 40, 4, 4).attr({stroke: 'black', strokeWidth: 3, fill: '#63BA9B'}); // Feel free to change or delete any of the code you see in this editor! // var svg = d3.select("main").append("svg") // .attr("width", 960) // .attr("height", 500) // svg.append("text") // .text("Edit the code below to change me!") // .attr("y", 200) // .attr("x", 120) // .style("font-size", 36) // .style("font-family", "monospace") </script> </body>
https://d3js.org/d3.v4.min.js
https://unpkg.com/snapsvg@0.5.1