8000 Contour line labels by alexcjohnson · Pull Request #1815 · plotly/plotly.js · GitHub
[go: up one dir, main page]

Skip to content

Contour line labels #1815

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 39 commits into from
Jun 30, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
468ef5d
put all contour lines into one group (so we can clip it later)
alexcjohnson Jun 21, 2017
88cc33c
collect contour clipPath in the main <defs>
alexcjohnson Jun 21, 2017
ee7a839
more standard format for contour constants
alexcjohnson Jun 22, 2017
b56f4ea
move lineIntersect -> Lib.geometry2d
alexcjohnson Jun 22, 2017
d534fb2
segmentDistance and tests of geometry2d
alexcjohnson Jun 22, 2017
d1e3448
contour line label basic functionality
alexcjohnson Jun 22, 2017
b8c75c0
better test of alternate Drawing.font syntax
alexcjohnson Jun 23, 2017
2f3a712
use contour/attributes in contourcarpet/attributes
alexcjohnson Jun 23, 2017
6299303
pull path measurement routines out into Lib
alexcjohnson Jun 23, 2017
99f39f8
allow contour labels even without lines
alexcjohnson Jun 23, 2017
d518c83
simple contour label position optimization
alexcjohnson Jun 23, 2017
27f8cfe
use axis formatting for contour labels
alexcjohnson Jun 23, 2017
221b124
include label attrs in contourcarpet to avoid errors but they're noops
alexcjohnson Jun 23, 2017
ca1cced
location -> loc (window global potential confusion)
alexcjohnson Jun 26, 2017
d52cfba
scale min path length for contour labels to width + height
alexcjohnson Jun 26, 2017
0f37648
:cow2: remove obsolete regexp
alexcjohnson Jun 26, 2017
62156dd
:hocho: long-obsolete cache object
alexcjohnson Jun 27, 2017
539ca22
Drawing.bBox "inTester" mode for quicker testing of dummy elements
alexcjohnson Jun 27, 2017
2116a12
contours.font -> contours.labelfont
alexcjohnson Jun 27, 2017
e1880c1
more permissive Drawing.bBox test
alexcjohnson Jun 27, 2017
14c832e
image tests of contour labels
alexcjohnson Jun 27, 2017
1bbdf59
contour line-colored label test
alexcjohnson Jun 27, 2017
e5a2f91
use `editTypes` for contour/contourcarpet-specific attributes
alexcjohnson Jun 27, 2017
cbdf795
no editType nesting - just docalc on editing full containers
alexcjohnson Jun 27, 2017
4db549c
:hocho: obsolete import
alexcjohnson Jun 27, 2017
fb4b690
refactor contour/plot for smaller functions
alexcjohnson Jun 29, 2017
b0f9bb2
updated contour_edge_cases baseline
alexcjohnson Jun 29, 2017
e1caa9e
unify contour.style and contourcarpet.style
alexcjohnson Jun 29, 2017
0ff2dc4
cover contour edge cases with contourcarpet
alexcjohnson Jun 29, 2017
f5873f1
fix contour style when coloring=none
alexcjohnson Jun 29, 2017
b5a674f
a little more stuff contourcarpet can inherit from contour
alexcjohnson Jun 29, 2017
1f85a6f
fix carpet plot clip path
alexcjohnson Jun 30, 2017
6c2043e
:hocho: some obsolete code in carpet/plot
alexcjohnson Jun 30, 2017
bbb9574
update histogram2dcontour for contour.plot API change
alexcjohnson Jun 30, 2017
9495dee
nest scattercontour lines inside a contourlines group
alexcjohnson Jun 30, 2017
7f086e0
fixup font->labelfont in contourcarpet
alexcjohnson Jun 30, 2017
49b8141
labels on contourcarpet
alexcjohnson Jun 30, 2017
8934038
update comment on contourcarpet label bounds
alexcjohnson Jun 30, 2017
dbeecd0
update baselines for findBestTextLocation bugfix
alexcjohnson Jun 30, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Drawing.bBox "inTester" mode for quicker testing of dummy elements
  • Loading branch information
alexcjohnson committed Jun 27, 2017
commit 539ca224de5d350373782eec85a726a6818fe716
41 changes: 31 additions & 10 deletions src/components/drawing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -604,15 +604,31 @@ drawing.makeTester = function() {

/*
* use our offscreen tester to get a clientRect for an element,
* in a reference frame where it isn't translated and its anchor
* point is at (0,0)
* in a reference frame where it isn't translated (or transformed) and
* its anchor point is at (0,0)
* always returns a copy of the bbox, so the caller can modify it safely
*
* @param {SVGElement} node: the element to measure. If possible this should be
* a <text> or MathJax <g> element that's already passed through
* `convertToTspans` because in that case we can cache the results, but it's
* possible to pass in any svg element.
*
* @param {boolean} inTester: is this element already in `drawing.tester`?
* If you are measuring a dummy element, rather than one you really intend
* to use on the plot, making it in `drawing.tester` in the first place
* allows us to test faster because it cuts out cloning and appending it.
*
* @param {string} hash: for internal use only, if we already know the cache key
* for this element beforehand.
*
* @return {object}: a plain object containing the width, height, left, right,
* top, and bottom of `node`
8000
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️ 📚

*/
drawing.savedBBoxes = {};
var savedBBoxesCount = 0;
var maxSavedBBoxes = 10000;

drawing.bBox = function(node, hash) {
drawing.bBox = function(node, inTester, hash) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 technically an internal API used elsewhere, but a quick grep I can't find any cases where the argument signature change is invalid.

/*
* Cache elements we've already measured so we don't have to
* remeasure the same thing many times
Expand Down Expand Up @@ -645,7 +661,7 @@ drawing.bBox = function(node, hash) {
if(!transform) {
// in this case, just varying x and y, don't bother caching
// the final bBox because the alteration is quick.
var innerBB = drawing.bBox(innerNode, hash);
var innerBB = drawing.bBox(innerNode, false, hash);
if(x) {
innerBB.left += x;
innerBB.right += x;
Expand All @@ -672,12 +688,17 @@ drawing.bBox = function(node, hash) {
if(out) return Lib.extendFlat({}, out);
}
}
var testNode, tester;
if(inTester) {
testNode = node;
}
else {
tester = drawing.tester.node();

var tester = drawing.tester.node();

// copy the node to test into the tester
var testNode = node.cloneNode(true);
tester.appendChild(testNode);
// copy the node to test into the tester
testNode = node.cloneNode(true);
tester.appendChild(testNode);
}

// standardize its position (and newline tspans if any)
d3.select(testNode)
Expand All @@ -689,7 +710,7 @@ drawing.bBox = function(node, hash) {
.node()
.getBoundingClientRect();

tester.removeChild(testNode);
if(!inTester) tester.removeChild(testNode);

var bb = {
height: testRect.height,
Expand Down
4 changes: 2 additions & 2 deletions src/traces/contour/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ function makeLinesAndLabels(plotgroup, pathinfo, gd, cd0, contours, perimeter) {
};
}

var dummyText = defs.append('text')
var dummyText = Drawing.tester.append('text')
.attr('data-notex', 1)
.call(Drawing.font, contours.font);

Expand Down Expand Up @@ -397,7 +397,7 @@ function makeLinesAndLabels(plotgroup, pathinfo, gd, cd0, contours, perimeter) {
var text = contourFormat(d.level);
dummyText.text(text)
.call(svgTextUtils.convertToTspans, gd);
var bBox = Drawing.bBox(dummyText.node());
var bBox = Drawing.bBox(dummyText.node(), true);
var textWidth = bBox.width;
var textHeight = bBox.height;
var dy = (bBox.top + bBox.bottom) / 2;
Expand Down
23 changes: 23 additions & 0 deletions test/jasmine/tests/drawing_test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var d3 = require('d3');
var Plotly = require('@lib/index');
var Drawing = require('@src/components/drawing');
var svgTextUtils = require('@src/lib/svg_text_utils');
var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');
var fail = require('../assets/fail_test');
Expand Down Expand Up @@ -422,6 +423,28 @@ describe('Drawing', function() {
.catch(fail)
.then(done);
});

it('works with dummy nodes created in Drawing.tester', function() {
var node = Drawing.tester.append('text')
.text('bananas')
.call(Drawing.font, '"Open Sans", verdana, arial, sans-serif', 19)
.call(svgTextUtils.convertToTspans).node();

expect(node.parentNode).toBe(Drawing.tester.node());

assertBBox(Drawing.bBox(node), {
height: 21,
width: 80,
left: 0,
top: -17,
right: 80,
bottom: 4
});

expect(node.parentNode).toBe(Drawing.tester.node());

node.parentNode.removeChild(node);
});
});
});

Expand Down
0