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

Feature request: make tech.tablesaw.plotly.Plot members public #860

Closed
hmf opened this issue Jan 14, 2021 · 8 comments
Closed

Feature request: make tech.tablesaw.plotly.Plot members public #860

hmf opened this issue Jan 14, 2021 · 8 comments
Labels

Comments

@hmf
Copy link

hmf commented Jan 14, 2021

Would it be possible to make the class have its private members public. This way I can extend the plot class for additional functionality. It would also be great to refactor the show to use a show(String html, File outputFile) that saves the HTML to a file, so that it can be reused for other page set-ups.

@benmccann
Copy link
Collaborator

You just need them to be protected and not public then, right?

@hmf
Copy link
Author

hmf commented Jan 14, 2021

Yes, that is correct.

@lwhite1
Copy link
Collaborator

lwhite1 commented Jan 24, 2021

The private methods are now protected (on master. not sure when they'll be in a release version). Not sure what you mean by

It would also be great to refactor the show to use a show(String html, File outputFile) that saves the HTML to a file, so that it can be reused for other page set-ups.

It takes a file now for the output. What is it you would like to see changed.

@hmf
Copy link
Author

hmf commented Jan 25, 2021

@lwhite1 Thank you.

Currently you have:

public static void show(Figure figure, String divName, File outputFile) {
...
}

which creates the HTML page for a single figure with the divName.
I create an HTML page with several figures and would like to show that.
So it is not possible for me to take that HTML and show it. However if you
had a protected member:

  public static void show(String HTML, File outputFile) {
...
}

I could use that. Note that I said refactor because I
think that that call can be reused by your own class:

  public static void show(output: String, File outputFile) {
    try {
      try (Writer writer =
          new OutputStreamWriter(new FileOutputStream(outputFile), StandardCharsets.UTF_8)) {
        writer.write(output);
      }
      new Browser().browse(outputFile);
    } catch (IOException e) {
      throw new UncheckedIOException(e);
    }
  }

  public static void show(Figure figure, String divName, File outputFile) {
    Page page = Page.pageBuilder(figure, divName).build();
    String output = page.asJavascript();
    show(output, outputFile);
  }

Ofcourse I don't know if this fits in ok with what you have planned here,
but I don't think it will affect the current API.

@lwhite1
Copy link
Collaborator

lwhite1 commented Jan 25, 2021 via email

@hmf
Copy link
Author

hmf commented Jan 25, 2021

I understand. I have used that for my own code so:

    val page = HTMLPlot.makePage(List(figure1, figure2), List(funcInfo.divName, gradInfo.divName))
    HTMLPlot.show(page, HTMLPlot.withName(funcInfo.divName))

I had to code my own HTMLPlot.show with source that I copy & pasted from your Plot because there is no show that take in a String/HTML.

Not a big issues. But it will save people from explicitly adding code to save the HTML to a file and then opening a browser to load that file.

As I said, no biggy. Please feel free to close this issue.

Thank you

@lwhite1
Copy link
Collaborator

lwhite1 commented Jan 25, 2021

i will take a look when i have some time.

@lwhite1 lwhite1 added the plot.ly label May 5, 2021
lwhite1 added a commit that referenced this issue May 26, 2021
* implementation of enhancement issue #860

* make constants protected so they can be accessed from a subclass
@lwhite1
Copy link
Collaborator

lwhite1 commented May 26, 2021

implemented.

@lwhite1 lwhite1 closed this as completed May 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants