Skip to content

Instantly share code, notes, and snippets.

@quantbo
Last active December 23, 2016 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quantbo/45b98a10e42aa6656d0aa3aaaaf1a971 to your computer and use it in GitHub Desktop.
Save quantbo/45b98a10e42aa6656d0aa3aaaaf1a971 to your computer and use it in GitHub Desktop.
D3: In 'enter' sequence 'selectAll' accepts any non-empty string.
<!--
Adapted from Thinking with Joins:
https://bost.ocks.org/mike/join/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<style>
circle {
fill-opacity: 0.5;
}
</style>
</head>
<body>
<svg height='200px', width='400px'></svg>
</body>
<script>
'use strict';
const myData = [
{x: 100, y: 100, r: 100},
{x: 200, y: 100, r: 100},
{x: 300, y: 100, r: 100}
];
let svg = d3.select('svg');
//A curious property of D3 is that in the sequence below
//any non-empty string will serve within the selectAll method.
svg.selectAll('i think therefore i am')
.data(myData)
.enter().append('circle')
.attr('cx', (d) => {return d.x;})
.attr('cy', (d) => {return d.y;})
.attr('r', (d) => {return d.r;});
</script>
</html>
@quantbo
Copy link
Author

quantbo commented Dec 23, 2016

A curious property of D3 is that in an enter sequence the selectAll method will accept any non-empty string. This is illustrated in the accompanying code. This suggests that a separate method, with an empty signature, might be appropriate for use in an enter sequence. Alternatively, and perhaps more parsimoniously, it might be possible to eliminate the selectAll.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment