Skip to content

Commit b54181e

Browse files
committed
A wee bit o' code consolidation.
1 parent 0b93bee commit b54181e

3 files changed

Lines changed: 34 additions & 26 deletions

File tree

d3.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4068,15 +4068,18 @@ d3.svg.brush = function() {
40684068
: [];
40694069

40704070
g.each(function() {
4071-
var g = d3.select(this)
4072-
.style("pointer-events", "all")
4073-
.on("mousedown.brush", down)
4074-
.on("touchstart.brush", down),
4071+
var g = d3.select(this),
40754072
bg = g.selectAll(".background").data([0]),
40764073
fg = g.selectAll(".extent").data([0]),
40774074
tz = g.selectAll(".resize").data(resizes, String),
40784075
e;
40794076

4077+
// Prepare the brush container for events.
4078+
g
4079+
.style("pointer-events", "all")
4080+
.on("mousedown.brush", down)
4081+
.on("touchstart.brush", down);
4082+
40804083
// An invisible, mouseable area for starting a new brush.
40814084
bg.enter().append("rect")
40824085
.attr("class", "background")
@@ -4123,16 +4126,13 @@ d3.svg.brush = function() {
41234126

41244127
function down() {
41254128
var target = d3.select(d3.event.target),
4126-
touches = d3.event.changedTouches,
41274129
resize;
41284130

41294131
// Store some global state for the duration of the brush gesture.
41304132
d3_svg_brush = brush;
41314133
d3_svg_brushTarget = this;
41324134
d3_svg_brushExtent = extent;
4133-
d3_svg_brushPoint = touches
4134-
? d3.svg.touches(d3_svg_brushTarget, touches)[0]
4135-
: d3.svg.mouse(d3_svg_brushTarget);
4135+
d3_svg_brushPoint = d3_svg_brushMouse();
41364136

41374137
// If the extent was clicked on, drag rather than brush;
41384138
// store the point between the mouse and extent origin instead.
@@ -4266,6 +4266,13 @@ var d3_svg_brush,
42664266
d3_svg_brushPoint,
42674267
d3_svg_brushOffset;
42684268

4269+
function d3_svg_brushMouse() {
4270+
var touches = d3.event.changedTouches;
4271+
return touches
4272+
? d3.svg.touches(d3_svg_brushTarget, touches)[0]
4273+
: d3.svg.mouse(d3_svg_brushTarget);
4274+
}
4275+
42694276
function d3_svg_brushRedraw(g, extent) {
42704277
g.selectAll(".resize").attr("transform", function(d) {
42714278
return "translate(" + extent[+/e$/.test(d)][0] + "," + extent[+/^s/.test(d)][1] + ")";
@@ -4305,10 +4312,7 @@ function d3_svg_brushKeyup() {
43054312

43064313
function d3_svg_brushMove() {
43074314
if (d3_svg_brushPoint) {
4308-
var touches = d3.event.changedTouches,
4309-
mouse = touches
4310-
? d3.svg.touches(d3_svg_brushTarget, touches)[0]
4311-
: d3.svg.mouse(d3_svg_brushTarget),
4315+
var mouse = d3_svg_brushMouse(),
43124316
g = d3.select(d3_svg_brushTarget);
43134317

43144318
// Preserve the offset for thick resizers.

0 commit comments

Comments
 (0)