-
Notifications
You must be signed in to change notification settings - Fork 642
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
Adds custom color scale to Marker #710
base: master
Are you sure you want to change the base?
Conversation
Does this project have a mailing list or some other way to talk among developers / users? This commit seems fine to me and I would merge it myself but it's unclear to me if you are fine with this approach. |
I've never been involved with any of the jsplot stuff, so I'll leave this one to you and Larry |
@benmccann I'm a committer now so if it was up to me I'd just push these changes. I just want to make sure you guys are OK with me doing this by myself? I will be careful, of course, not to break existing APIs, etc. and ask for confirmations if it looks complicated. For many smaller things though it would seem faster to just commit. I just realized GitHub offers no way for committer to talk among eachother. There's no chat, no mailing list. It's only the discussions in the PRs. Surprising, now that I've noticed it. |
I'll usually review commits to the core library. I'd ask @lwhite1 what he prefers for the jsplot library since he's been the one maintaining this one |
@emilianbold It will be weeks-to-months before I'm able to devote any time to this. If @benmccann and @ryancerf are unavailable, I would say use your judgement |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not super familiar with the Plotly stuff either, but I did my best to give a meaningful review.
@@ -155,6 +163,39 @@ public String asJavascript() { | |||
return context; | |||
} | |||
|
|||
static class Color { | |||
|
|||
final int r, g, b; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about adding the colorScaleCustomRange value to the Color class? It looks like colors and values are always added at the same time.
That will allow you to only add one field to the MarkerBuilder (not two).
if (i != 0) { | ||
sb.append(",\n"); | ||
} | ||
sb.append("['") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you add value to the color class as mentioned above you could factor this out into a separate method that takes no parameters.
} | ||
sb.append("['") | ||
.append(values.get(i)) | ||
.append("', 'rgb(") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be more concise with String.format. Something like.
String.format("[r(%d,%d,%d)]", c.r, c.g, c.b)
@@ -129,7 +135,9 @@ public String asJavascript() { | |||
Map<String, Object> context = new HashMap<>(); | |||
context.put("size", size.length == 1 ? size[0] : Utils.dataAsString(size)); | |||
if (colorScalePalette != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If colorScalePalette always takes precedence over colorScaleCustomRange should we mention that in the javadoc somewhere?
In core (where I have done my work) we generally try to give each other a bit of time to review before submitting(1-2 days). For changes with little API impact in the plotly stuff I think it is fine to take more leeway especially if we are slowing you down and we have already discussed the issue. For non trivial changes in core please wait for Larry or Ben to review. |
assertTrue( | ||
x.asJavascript() | ||
.contains( | ||
"colorscale: [\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test seems a little brittle since it's sensitive to formatting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've had this PR in my inbox for many days since these minor remarks are, to me, a mountain of work.
I wonder if it's something obvious I'm not seeing about how to make this test less brittle (there are other existing tests sensitive to formatting) or how Jackson would simplify that little method?
The way I see it, to test the output in a non-brittle way would mean to basically parse that generated JS. Which isn't obvious how (Jackson, you say, but note we don't have JSON, we have Javascript there) and it would make the test much more complex.
As for introducing Jackson that's a good idea, but, again, nothing easy to hook into. I have not one but two branches where I try to see how Jackson might look for the JS/JSON output.
This one https://github.com/emilianbold/tablesaw/commits/emi/jackson is from late last year and I was trying to use whole objects to serialize via Jackson. Not bad, but a lot of work.
This other one https://github.com/emilianbold/tablesaw/commits/jackson is from today and I'm using the easier way of writing the Map<String,Object>
via Jackson. This seems better, but, of course, there's a lot of work to migrate everything to Jackson.
In conclusion, I don't know how to move this PR forward. I'll make a PR for the Jackson branch but for this one I don't know how to make it better and the code is starting to become stale. I guess I should just drop the PR.
|
||
private static String asColorScaleString(List<Double> values, List<Color> colors) { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append("[\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it might be cleaner to use a JSON library like Jackson for this
6baaa1c
to
23716aa
Compare
x.asJavascript() | ||
.contains( | ||
"colorscale: [\n" | ||
+ "['0.0', 'rgb(255,0,0)'],\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might want to look into JSONassert:
We have always just used issues and pull requests for conversations. Are they inadequate for some reason? |
As a new committer is seemed slow to use issue / PRs as a way to ask global questions about the project. Such as, how do you usually do merges? Or, who generally "owns" which chunk and which areas need a PR from a committer and which areas would allow me to do a commit directly? Basic on-boarding questions so to say. |
@emilianbold is this PR something that you're going to come back to? |
I rather forgot what was going on in this PR but from my long comment I see
there the cost/benefit are quite slim on finishing it, unless you
introduced some nicer helpers for the kind of testing(?) that was not
proper in the PR.
I do wish to resume contributing to open source next year...
Hope everything is well with you and Happy Holidays.
…--emi
On Fri, Dec 18, 2020 at 8:30 PM Ben McCann ***@***.***> wrote:
@emilianbold <https://github.com/emilianbold> is this PR something that
you're going to come back to?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#710 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAHSCQSV6IT73LEOSTR4OLTSVONTFANCNFSM4JIS4MMQ>
.
|
I liked the suggestion of using https://github.com/skyscreamer/JSONassert as a helper for testing. That seems quite straightforward and wouldn't require you to make many changes besides just including and calling the library Hope all is well with you and happy holidays to you too! |
Thanks for contributing.
Description
Adds
MarkerBuilder.addColorScale(double value, int r, int g, int b)
and related JS generation code which allows custom (non-palette) color scales.Testing
Yes.