chiasm-charts
Advanced tools
Comparing version 0.1.4 to 0.1.5
{ | ||
"name": "chiasm-charts", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "Reusable data visualization components.", | ||
@@ -5,0 +5,0 @@ "repository": "git://github.com/chiasm-project/chiasm-charts.git", |
@@ -11,29 +11,39 @@ var d3 = require("d3"); | ||
var data = [ "left", "right", "top", "bottom" ]; | ||
my.addPublicProperty("marginEditor", [ "left", "right", "top", "bottom" ]); | ||
var handles = svg.selectAll(".margin-handle").data(data); | ||
handles.enter().append("rect") | ||
.attr("class", "margin-handle") | ||
.style("fill", "none") | ||
.style("pointer-events", "all") | ||
var drag = d3.behavior.drag(); | ||
var drag = d3.behavior.drag().on("drag", function (d) { | ||
// Update the margin based on the side being dragged. | ||
// "d" is one of "left", "right", "top", "bottom". | ||
my.margin = set(my.margin, d, { | ||
left: d3.event.x, | ||
right: -d3.event.x, | ||
top: d3.event.y, | ||
bottom: -d3.event.y, | ||
}[d]); | ||
my.when("marginEditor", function (sides){ | ||
var handles = svg.selectAll(".margin-handle").data(sides); | ||
handles.enter().append("rect"); | ||
handles.exit().remove(); | ||
handles | ||
.attr("class", "margin-handle") | ||
.style("fill", "none") | ||
.style("pointer-events", "all") | ||
handles.call(drag); | ||
// Hide the handles during drag. | ||
handles.style("fill", "none"); | ||
my.handles = handles; | ||
}); | ||
handles.call(drag); | ||
my.when(["margin", "handles"], function (margin, handles){ | ||
drag.on("drag", function (d) { | ||
// Update the margin based on the side being dragged. | ||
// "d" is one of "left", "right", "top", "bottom". | ||
my.margin = set(margin, d, { | ||
left: d3.event.x, | ||
right: -d3.event.x, | ||
top: d3.event.y, | ||
bottom: -d3.event.y, | ||
}[d]); | ||
// Hide the handles during drag. | ||
handles.style("fill", "none"); | ||
}); | ||
}); | ||
// Fill in the handles on hover. | ||
my.when("marginEditorFill", function (marginEditorFill){ | ||
my.when(["marginEditorFill", "handles"], function (marginEditorFill, handles){ | ||
handles | ||
@@ -65,4 +75,4 @@ .on("mouseenter", function (){ | ||
// Render the handles | ||
my.when(["margin", "marginEditorWidth", "width", "height"], | ||
function (margin, marginEditorWidth, width, height){ | ||
my.when(["handles", "margin", "marginEditorWidth", "width", "height"], | ||
function (handles, margin, marginEditorWidth, width, height){ | ||
@@ -69,0 +79,0 @@ var x = { |
@@ -84,3 +84,6 @@ var Chiasm = require("chiasm"); | ||
"yAxisLabelTextOffset": yAxisLabelTextOffset, | ||
"margin": margin | ||
"margin": margin, | ||
// This tests that it is possible to specify a set of sides for the editor. | ||
"marginEditor": ["left"] | ||
} | ||
@@ -87,0 +90,0 @@ }, |
52824
1089