Skip to content

Add axis domain references to shapes, annotations, and layout images #5014

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 117 commits into from
Oct 6, 2020

Conversation

nicholas-esterer
Copy link
Contributor

@nicholas-esterer nicholas-esterer commented Jul 22, 2020

Resolves #4958.

These elements can now be drawn relative to an axis's domain, so if this domain is updated, say, the element's position will update its position according to the new length and offset of the domain.
For example, to add a horizontal line that always spans the x axis and starts 25% of the way up the y axis, you would add such a shape to the layout:

{
          type: 'line',
          xref: 'x domain',
          yref: 'y domain',
          x0: 0,
          x1: 1,
          y0: 0.25,
          y1: 0.25,
}

You can see more examples of shapes by looking in test/domain_ref_tests.html. I've written a bunch of tests there that will eventually be made into jasmine tests (we can rebase out that file once that happens). I'll push some more tests (related to editing of shapes and annotations) as I make them.

This allows shapes and eventually annotations to refer to the length of
an axis, so if this length is changed, the shape changes accordingly.
For example for a shape, setting xref: "x2 domain", x0: 0, x1: 1 makes a
shape that spans exactly the width of xaxis2. When this axis changes
length (via the setting of its 'domain' attribute), then the shape will
span the new axis.
however there's a funny case when running
./test/image/mocks/sunburst_with-without_values.json where
xAx (local function) gets passed an array in
./src/components/shapes/defaults.js (it expects a string or undefined).
So we still need to solve this.
This is so that shapes, annotations and images can use the same
functions.

Still need to add the functionality for annotations and images.
However, when setting [xy]ref to "paper" and a sizex or sizey of 1, it
doesn't seem to fill the plotting area, is this a regression?
This is consistent with what 'paper' axis references does, which I think
is expected behaviour.
Still funny problem with log axes and shapes though.
before, set_convert was clipping coordinates to 0 if they were negative,
so we changed it so domain referenced shapes behave like paper
referenced shapes.
The curent paper axis reference has y = 0 at the bottom and y = 1 at
the top, so we also make this the case for domain axis references.
They are getting written in test/domain_ref_tests.html for now so they
can be debugged quickly. We can rebase this file out once moved to the
jasmine tests.
// xaxistype can be linear|log, only used if xref has type 'range' or 'domain',
// same for yaxistype and yref
function annotationTest(gd, layout, x0, y0, ax, ay, xref, yref, axref, ayref,
xaxistype, yaxistype, xid, yid) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Non-blocking:
When having several input arguments to a function like this

function annotationTest(gd, layout, x0, y0, ax, ay, xref, yref, axref, ayref,
    xaxistype, yaxistype, xid, yid) {

There is a chance to use wrong order in the caller(s).
It is possible to refactor it to use an object for last arguments.
Something like:

function annotationTest(gd, layout, opts) {
  var x0 = opts.x0;
  ...

Then change the caller to be

annotationTest(gd, layout, {
    x0: x0, 
    y0: y0, 
    ax: ax,
    ay: ay, 
    xref: xref, 
    yref: yref, 
    axref: axref,
    ayref: ayref
    xaxistype: xaxistype, 
    yaxistype: yaxistype, 
    xid: xid, 
    yid: yid
});



function imageTestCombos() {
var testCombos = Array.from(iterable.cartesianProduct(
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be non-blocking:
Array.from is not supported in some browsers namely IE11: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from

@@ -0,0 +1,3 @@
// module.exports can be set to a specific test number to run just a single
// test, otherwise if set to undefined, runs all the tests.
module.exports = undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry. I don't understand if we really need this to be a separate file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's there because jasmine can't read environment variables which would be handy to pin point a specific test that is not passing. So instead I made a file that you change. But I can remove this now because the tests pass.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, those are handy but in this case I had a for loop that generates many it(...) so if I changed it to fit(...) it would disable all the tests. Plus I personally don't like changing the source file, environment variables are more ephemeral and the risk of them getting committed is lower. But thanks for the tip!

var aroBBox = shapeToBBox(gd.layout, aro);
var ret = compareBBoxes(aroBBox, aroPathBBox);
console.log('aroBBox: ' + JSON.stringify(aroBBox));
console.log('aroPathBBox: ' + JSON.stringify(SVGTools.svgRectToObj(aroPathBBox)));
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove or comment these console.logs here and in other tests.

@nicolaskruchten
Copy link
Contributor

OK looks like all the checkboxes are in place, which is great! anything still blocking here @archmoj @alexcjohnson ?

@alexcjohnson
Copy link
Collaborator

@nicholas-esterer this is looking great, nice work! Just one blocking comment (endsWith) and a few style points, then it should be good to go from my standpoint.

@archmoj
Copy link
Contributor

archmoj commented Oct 6, 2020

💃 domain 💃
Looking great. The noCI tests are also passed on my machine.
@nicholas-esterer thanks very much for the big contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature something new
Projects
None yet
Development

Successfully merging this pull request may close these issues.

xref="x2 domain" type options for shape/annotation/image
4 participants