-
Notifications
You must be signed in to change notification settings - Fork 648
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 Figure.setLayout and Figure.setConfig #690
Conversation
I have not had time to look at this yet, but the API code is really just
intended for quick-and-dirty exploratory plots. It's not even very good
for that.
Some kind of concise builder pattern would probably be best but I haven't
had time for that. Also, it would probably be wise to look at the Plot.ly
python enhancements (not directly implemented in the JS) that make it easy
to create more sophisticated plot types.
…On Wed, Oct 23, 2019 at 3:49 PM Emilian Bold ***@***.***> wrote:
Thanks for contributing.
- Tick to sign-off your agreement to the Developer Certificate of
Origin (DCO) 1.1 <https://developercertificate.org>
Description
The jsplot APIs don't allow a whole lot of UI flexibility. Allowing
callers to send a Layout instance would help a lot with UI
customizations. The most basic customization being changing the chart
width/height.
This PR adds some simple methods to accomplish this for VerticalBarPlot
and HorizontalBarPlot.
I am open to suggestions on this.
I see that the api package is supposed to create an API boundary so I'm
not certain making Layout public API is the best solution. It doesn't
seem such a bad solution though since the APIs already expose
tech.tablesaw.plotly.components.Figure and Layout.BarMode so the
components package isn't entirely hidden.
One idea would be to create a separate
tech.tablesaw.plotly.api.LayoutOptions of sorts but it would more or less
be a copy paste of what components.Layout has and in the end we would
just add all the options into the main Layout instance.
If this idea is good (or we settle on something else) I can go through the
other plot classes (api.LinePlot, etc.) and add methods with Layout.
Testing
Manually tested.
------------------------------
You can view, comment on, or merge this pull request online at:
#690
Commit Summary
- Allows Layout argument to Vertical- and HorizontalBarPlot
File Changes
- *M* jsplot/src/main/java/tech/tablesaw/plotly/api/BarPlot.java
<https://github.com/jtablesaw/tablesaw/pull/690/files#diff-0> (20)
- *M*
jsplot/src/main/java/tech/tablesaw/plotly/api/HorizontalBarPlot.java
<https://github.com/jtablesaw/tablesaw/pull/690/files#diff-1> (10)
- *M*
jsplot/src/main/java/tech/tablesaw/plotly/api/VerticalBarPlot.java
<https://github.com/jtablesaw/tablesaw/pull/690/files#diff-2> (10)
Patch Links:
- https://github.com/jtablesaw/tablesaw/pull/690.patch
- https://github.com/jtablesaw/tablesaw/pull/690.diff
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#690?email_source=notifications&email_token=AA2FPAWO2EMJONLG7E474L3QQCTGLA5CNFSM4JEIRU7KYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HT5NKKA>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA2FPAWJU2VVL6OTFENCK6LQQCTGLANCNFSM4JEIRU7A>
.
|
So far the API seems sufficient to nicely display data. But the 1st change is to make it look good or fit somewhere which means I don't need (yet?) to change how any of the Note that all the If we add I don't understand how the Plotly python enhancements would help. Do you mean I should copy the API style? If I look at a bar plot: px.bar(tips, x="sex", y="total_bill", color='smoker', barmode='group', height=400) they seem to use Python named arguments. I guess we could add another method to |
I noticed that although not part of the So, I think allowing |
I will try to cover some of the design considerations here and then look at the code specifics.
Yeah, part of the problem (as you suggested elsewhere) is that api is not really a good description of the intended functionality here. It should probably have been eda (exploratory data analysis) or something like that. The goal was to make it easy to do one-liners for interactive analysis. The theory was that you wouldn't worry too much about height and width, etc.
Absolutely. My experience as a Tablesaw user, even doing interactive analysis, is exactly that. OTOH, when I recently worked on a project where I made hundreds of plots, I ended up writing code to wrap the builders, providing certain defaults, and making it easier to construct more complex graphs. For example: I frequently wanted to make scatter plots of more than two variables. With Tablesaw, you can do up to 5 numeric variables and two categorical variables: (a 3D bubble chart (x, y, z, plus bubble size, with color spectrum for the fifth numeric variable, plus shape and 'conditioning' (i.e., making separate plots for each item in a category) for two categorical variables). Or you could do 4 numeric and three categorical, or whatever. A problem with the current implementation is that doing any of this involves heavy use of the builders. While they're easy, they're not concise. This is what led me to believe that a different API was desirable. It should be possible to change the dimensions and create a 2D scatter with color or shape categories without digging into the marker builder. And it should be easy to specify "use color for the category" in one plot and "use shape for the category" in another.
That's true, but you will double the size of the API by doing that (or break the existing api) because you can't add an optional argument in java. The API is already pretty large and not very elegant (in the sense of providing a lot of power through a few, uniformly applied constructs). [Sorry. Have to break this off at this point as i need to be driving. Will come back to it as time allows] |
You thought about this much more than me, clearly. What you are saying makes sense: the plotly configuration is too low level, even if we wrap it in nice fluent builders. We could offer another high-level API where users can customize their charts without getting into the plotly implementation details. I don't have a feeling about how that could look though. If you give me some pointers I can think about it and get back to you. Seems like it might depend on chart type, as in, determine some usual chart "templates"/use-cases which we could support. Speaking of APIs, what you want would be a 3rd API package since we can't remove the existing As for the In a way what I'm trying to avoid with the |
There are a few different perspectives that might be worth looking at. Let me give it a little thought/research and get back to you.
True, but I would deprecate the current API if we had something better. Having the low-level stuff accessible via builders is fine, I think, because someone will always want to create something that leverages all the flexibility you get in Plot.ly. We just don't want to make people build everything from the ground up if they just want to plot X by Y.
I was thinking more about adding layout to, say, the BoxPlot class. BoxPlot looks like this:
To add a custom layout you'd need a new method here. You're suggesting adding a layout to Plot, but that seems a little awkward (although easier to implement). If I were looking for a shortcut here, I would make Figure have a layout setter that overrides the default layout and leave Plot the way it is.
I would be ok with a PR that lets you create a plot with the existing API classes like BoxPlot and override the Layout as described above. What do you think of that option? |
just wanted to add that one model for a simpler api might be the "plotly express" code |
That was an idea I also had then I saw the |
I've changed this branch to only add
I'll look into this. |
Actually, there's no need for |
6baaa1c
to
23716aa
Compare
sorry for the huge delay. |
Thanks for contributing.
Description
The jsplot APIs don't allow a whole lot of UI flexibility. Allowing callers to send a
Layout
instance would help a lot with UI customizations. The most basic customization being changing the chart width/height.This PR adds some simple methods to accomplish this for
VerticalBarPlot
andHorizontalBarPlot
.I am open to suggestions on this.
I see that the
api
package is supposed to create an API boundary so I'm not certain makingLayout
public API is the best solution. It doesn't seem such a bad solution though since the APIs already exposetech.tablesaw.plotly.components.Figure
andLayout.BarMode
so thecomponents
package isn't entirely hidden.One idea would be to create a separate
tech.tablesaw.plotly.api.LayoutOptions
of sorts but it would more or less be a copy paste of whatcomponents.Layout
has and in the end we would just add all the options into the mainLayout
instance.If this idea is good (or we settle on something else) I can go through the other plot classes (
api.LinePlot
, etc.) and add methods withLayout
.Testing
Manually tested.