Skip to content

Commit

Permalink
Algorithm improvement: Compute maxHeight. Closes #7
Browse files Browse the repository at this point in the history
  • Loading branch information
curran committed Jul 29, 2017
1 parent 5394751 commit c0f2381
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/area-label.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ function areaLabel(area) {
// The minimum label bounding box height in pixels.
minHeight = 2,

// The maximum label bounding box height in pixels.
maxHeight = 1000,

// The tolerance within we wish to optimize the bounding box height.
epsilon = 0.01,

Expand Down Expand Up @@ -121,6 +118,11 @@ function areaLabel(area) {
// The aspect ratio of the text label bounding box.
var aspect = boxWidth / boxHeight;

// Compute maximum possible label bounding box height in pixels.
var maxHeight = d3.max(data, function (d) {
return y0(d) - y1(d);
});

// The test function for use in the bisection method.
var test = function (testHeight){
return fits(data, aspect, testHeight, true);
Expand Down Expand Up @@ -170,11 +172,6 @@ function areaLabel(area) {
return arguments.length ? (minHeight = +_, my) : minHeight;
};

// TODO compute this from the area, no need to have this constant.
my.maxHeight = function(_) {
return arguments.length ? (maxHeight = +_, my) : maxHeight;
};

my.epsilon = function(_) {
return arguments.length ? (epsilon = +_, my) : epsilon;
};
Expand Down

0 comments on commit c0f2381

Please sign in to comment.