Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

emilianbold
Copy link
Contributor

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.

@emilianbold
Copy link
Contributor Author

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.

@benmccann
Copy link
Collaborator

I've never been involved with any of the jsplot stuff, so I'll leave this one to you and Larry

@emilianbold
Copy link
Contributor Author

@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.

@benmccann
Copy link
Collaborator

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

@lwhite1
Copy link
Collaborator

lwhite1 commented Nov 13, 2019

@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

Copy link
Collaborator

@ryancerf ryancerf left a 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;
Copy link
Collaborator

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("['")
Copy link
Collaborator

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(")
Copy link
Collaborator

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) {
Copy link
Collaborator

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?

@ryancerf
Copy link
Collaborator

@emilianbold

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.

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"
Copy link
Collaborator

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

Copy link
Contributor Author

@emilianbold emilianbold Feb 4, 2020

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");
Copy link
Collaborator

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

@benmccann benmccann force-pushed the master branch 2 times, most recently from 6baaa1c to 23716aa Compare January 13, 2020 02:51
x.asJavascript()
.contains(
"colorscale: [\n"
+ "['0.0', 'rgb(255,0,0)'],\n"
Copy link
Contributor

@larshelge larshelge Feb 16, 2020

Choose a reason for hiding this comment

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

@lwhite1
Copy link
Collaborator

lwhite1 commented Feb 21, 2020

Does this project have a mailing list or some other way to talk among developers / users?

We have always just used issues and pull requests for conversations. Are they inadequate for some reason?

@emilianbold
Copy link
Contributor Author

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.

@benmccann
Copy link
Collaborator

@emilianbold is this PR something that you're going to come back to?

@emilianbold
Copy link
Contributor Author

emilianbold commented Dec 19, 2020 via email

@benmccann
Copy link
Collaborator

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!

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

Successfully merging this pull request may close these issues.

5 participants