Skip to content

Reduce plot size #501

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

Closed
wants to merge 3 commits into from
Closed

Reduce plot size #501

wants to merge 3 commits into from

Conversation

fu
Copy link

@fu fu commented Jun 9, 2016

Hi,

I added a kwarg outsource_plotly, that allows the plotly.js to be separated from the actual plot. The code just adds a separate file containing the plotly.min.js into the plot folder. While it is not so convenient for a single plot (two files vs one file), it is very good if one creates many plots in one folder, since all plots share the same js.library and thus the overall plotting size is reduced significantly.

Cheers

.c

fu added 2 commits June 9, 2016 15:04
…ng, i.e. regular plotly with 1.2MB javascript in each plot, or having plotly.min.js in a seperate file
@theengineear
Copy link
Contributor

@chriddyp , did you ever take a peek at this one? I think @fu makes a good point here. Right now we're just copying in the entire script where we could just be linking it as suggested. Is there a use-case that I'm not considering?

This is more complex (as was suggested, we need to make sure the src in the script points to the proper place), but I'd be willing to consider if it provides a large reduction in file size.

One alternate route would be to allow users to use a flag like:

plotly.offline.outsource_plotly()

That can set a module-level flag to change the behavior of get_plotlyjs(). Then, the default behavior is not changed for now.

@chriddyp
Copy link
Member

chriddyp commented Feb 2, 2017

plotly.offline.outsource_plotly()

Yeah, that makes sense. Perhaps something like plotly.offline.serve_plotlyjs_from_directory()?

@theengineear
Copy link
Contributor

^^ yah, definitely something more specific than outsource_plotly, I was just using the name from the line changes.

The other thing I don't want to do is have a million hard-to-discover functions. We could alternatively keep this in config?

{
    "offline_serve_plotlyjs_from_directory": True
}

We can name-space offline config with offline_*. Then we'd allow users to keep using:

session.sign_in

... which should really have an alias like:

def update_session(**kwargs):
    # blah blah

I like the idea of having a central place where all the current options can be sorted out. Really I'm ok with either option though since we can just deprecate it later...

@fu, can you change this so that the user has to manually call a function or set some config to get this to happen?

@fu
Copy link
Author

fu commented Feb 2, 2017

Hi Guys,

thanks for picking this one up! I would happily go back and adapt my pull request to have it in the config or use a function call. Personally, I would go for the config solution, would that be ok?

Cheers

.c

@theengineear
Copy link
Contributor

Personally, I would go for the config solution, would that be ok?

Yup that's fine by me! Let me know if you have any questions. Thanks @fu!

@fu
Copy link
Author

fu commented Feb 6, 2017

Hi again,

second thought, setting the config file seems not straight forward in the current implementation, or maybe I could not find the obvious way :)

Form my understanding, I would have to adjust set_config_file to accept my "offline_serve_plotlyjs_from_directory", and for all following parts this would need to be adjusted as well. Adding just a **kwargs might be a way but sort of defeats all your checking in set_config_file.

Therefore, I opted for the second option: adding serve_plotlyjs_from_directory() that sets a global variable.

Pull request on its way

Cheers and thank you for the great plotly lib - keep up the good work!

.c

@theengineear
Copy link
Contributor

second thought, setting the config file seems not straight forward in the current implementation

Yah, it's definitely not straightforward because there are three levels of settings that you can set:

  1. file-level
  2. session-level
  3. function-call-level

The function call is fine for now, can always just change the function implementation later such that it updates the session config down the road.

Thanks for the update :)

@fu fu closed this Feb 6, 2017
This was referenced Feb 6, 2017
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.

3 participants