Skip to content

Instantly share code, notes, and snippets.

@larsvers
Last active July 24, 2018 20:05
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 larsvers/19345a59cf0a067cc69acf44c3cb0dda to your computer and use it in GitHub Desktop.
Save larsvers/19345a59cf0a067cc69acf44c3cb0dda to your computer and use it in GitHub Desktop.
Thin brushable line
license: mit
height: 500
border: no
*{box-sizing:border-box}
!function(n){function t(a){if(c[a])return c[a].exports;var e=c[a]={i:a,l:!1,exports:{}};return n[a].call(e.exports,e,e.exports,t),e.l=!0,e.exports}var c={};t.m=n,t.c=c,t.i=function(n){return n},t.d=function(n,c,a){t.o(n,c)||Object.defineProperty(n,c,{configurable:!1,enumerable:!0,get:a})},t.n=function(n){var c=n&&n.__esModule?function(){return n.default}:function(){return n};return t.d(c,"a",c),c},t.o=function(n,t){return Object.prototype.hasOwnProperty.call(n,t)},t.p="",t(t.s=0)}([function(module,exports,__webpack_require__){"use strict";eval("\n\nvar margin = { top: 0, right: 30, bottom: 0, left: 30 };\nvar width = 760 - margin.left - margin.right;\nvar height = 50 - margin.top - margin.bottom;\n\nvar svg = d3.select('body').append('svg').attr('width', width + margin.left + margin.right).attr('height', height + margin.top + margin.bottom).style('border', '1px solid grey');\n\nvar g = svg.append('g').attr('class', 'brush').attr('transform', 'translate(' + margin.left + ', ' + margin.top + ')');\n\nvar brush = d3.brushX().extent([[0, 0], [width, height]]).on('end', function () {\n return console.log(d3.event.selection);\n}).on('brush', function () {\n return brushing;\n});\n\ng.append('line').attr('x1', 0).attr('x2', width).attr('y1', height / 2).attr('y2', height / 2).style('stroke-width', 1).style('stroke', 'tomato');\n\ng.call(brush);\n\nfunction brushing() {\n\n d3.select('rect.selection').attr('y', height / 2 - 1).attr('height', 2);\n}//# sourceURL=[module]\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMC5qcyIsInNvdXJjZXMiOlsid2VicGFjazovLy9zY3J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rZS13aWR0aCcsIDEpXG4gIC5zdHlsZSgnc3Ryb2tlJywgJ3RvbWF0bycpXG5cbmcuY2FsbChicnVzaClcblxuXG5mdW5jdGlvbiBicnVzaGluZygpIHtcblxuICBkMy5zZWxlY3QoJ3JlY3Quc2VsZWN0aW9uJykuYXR0cigneScsIGhlaWdodC8yLTEpLmF0dHIoJ2hlaWdodCcsMilcbiAgXG59XG5cblxuXG4vLyBXRUJQQUNLIEZPT1RFUiAvL1xuLy8gc2NyaXB0LmpzIl0sIm1hcHBpbmdzIjoiOztBQUFBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQU1BO0FBQ0E7QUFJQTtBQUVBO0FBQUE7QUFDQTtBQUFBO0FBQ0E7QUFFQTtBQUNBO0FBT0E7QUFDQTtBQUVBO0FBQ0E7QUFDQTtBQUVBIiwic291cmNlUm9vdCI6IiJ9\n//# sourceURL=webpack-internal:///0\n")}]);
<!DOCTYPE html>
<title>blockup</title>
<link href='dist.css' rel='stylesheet' />
<body>
<script src='https://d3js.org/d3.v5.min.js'></script>
<script src='dist.js'></script>
</body>
{
"standard": {
"globals": [
"d3"
]
}
}
const margin = { top: 0, right: 30, bottom: 0, left: 30 };
const width = 760 - margin.left - margin.right;
const height = 50 - margin.top - margin.bottom;
const svg = d3
.select('body')
.append('svg')
.attr('width', width + margin.left + margin.right)
.attr('height', height + margin.top + margin.bottom)
.style('border', '1px solid grey');
const g = svg
.append('g')
.attr('class', 'brush')
.attr('transform', `translate(${margin.left}, ${margin.top})`);
const brush = d3.brushX()
.extent([[0, 0], [width, height]])
.on('end', () => console.log(d3.event.selection))
.on('brush', () => brushing);
g.append('line')
.attr('x1', 0)
.attr('x2', width)
.attr('y1', height/2)
.attr('y2', height/2)
.style('stroke-width', 1)
.style('stroke', 'tomato')
g.call(brush)
function brushing() {
d3.select('rect.selection').attr('y', height/2-1).attr('height',2)
}
*
box-sizing border-box
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment