[ Launch: simple bar code ] 6559357 by enjalot
[ Launch: simple bar ] 6559330 by enjalot
-
-
Save enjalot/6559357 to your computer and use it in GitHub Desktop.
simple bar code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"description":"simple bar code","endpoint":"","display":"div","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"style.css":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"pingpong","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"thumbnail":"http://i.imgur.com/efXGs0F.png"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var data = [5, 9, 12, 15, 2, 6]; | |
var xscale = d3.scale.ordinal() | |
//.domain(d3.range(data.length)) | |
.domain([0, 1, 2, 3, 4, 5]) | |
.rangeBands([0, 400]); | |
var min = d3.min(data); | |
var max = d3.max(data); | |
var yscale = d3.scale.linear() | |
//.domain([min, max]) | |
.domain([0, 15]) | |
.range([400, 0]); | |
var x = 50; | |
var y = 50; | |
var display = d3.select("#display") | |
var svg = display.append("svg").classed("tributary_svg", true); | |
var bg = svg.append("rect").classed("bg", true) | |
.attr({ | |
x: x, | |
y: y, | |
width: 400, | |
height: 400, | |
fill: "#fefefe", | |
stroke: "#722C2C" | |
}) | |
var circle = svg.append("circle") | |
.attr({ | |
cx: x, | |
cy: x, | |
r: 5 | |
}) | |
var drag = d3.behavior.drag() | |
.on("drag", function(d,i) { | |
console.log("evt", d3.event); | |
data[i] += d3.event.dy; | |
d3.select(this) | |
.attr({ | |
y: function(d,i) { return y + yscale(d) }, | |
height: function(d,i) { return 400 - yscale(d) } | |
}) | |
}) | |
svg.selectAll("rect.bar") | |
.data(data) | |
.enter() | |
.append("rect") | |
.classed("bar", true) | |
.attr({ | |
x: function(d,i) { return x + xscale(i) }, | |
width: 30, | |
y: function(d,i) { return y + yscale(d) }, | |
height: function(d,i) { return 400 - yscale(d) } | |
}) | |
.call(drag); | |
var options = { | |
mode: 'javascript', | |
lineNumbers: true, | |
viewportMargin: Infinity, | |
theme: 'vibrant-ink' | |
} | |
var editor = display.append("div").classed("editor", true) | |
.classed("test-editor", true); | |
var cm = CodeMirror(editor.node(), options); | |
cm.setValue("var x = 5\nconsole.log(\"x\",x);\nx = 1337;\nconsole.log(\"x\", x, x+42);") | |
bg.on("mousemove", function() { | |
var x = d3.mouse(this)[0]; | |
var y = d3.mouse(this)[1]; | |
circle | |
.transition() | |
.duration(35) | |
.attr({ | |
cx: x, | |
cy: y | |
}) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.test-editor { | |
width: 400px; | |
height: 400px; | |
} | |
.test-editor .CodeMirror { | |
width: 100%; | |
height: 100%; | |
overflow-x: scroll; | |
} | |
.tributary_svg { | |
width: 500px; | |
height: 500px; | |
} | |
#display { | |
overflow:scroll; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment