Skip to content

Set global defaults that apply to all graphs within a project #152

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
bluppfisk opened this issue Mar 2, 2021 · 6 comments · Fixed by #240
Closed

Set global defaults that apply to all graphs within a project #152

bluppfisk opened this issue Mar 2, 2021 · 6 comments · Fixed by #240
Assignees
Labels
enhancement New feature or request

Comments

@bluppfisk
Copy link

Is it possible to set global defaults, e.g. the default layout.colorway property so that every graph I instantiate in a project obeys that setting? I can't seem to find how to do this.

@andrefarzat
Copy link
Collaborator

Hello, @bluppfisk . Unfortunately, there isn't a way to do this as the code is. What I can recomend, as a quick fix, is creating a service which you can get the default. E.g.:

@Injectable
export class DefaultLayoutService {
    private defaultLayoutObject = { /* the default data */ };

    public getDefaultLayoutObject(layout: object): object {
        return Object.assign({}, this.defaultLayoutObject, layout);
    }
}

then use it in the controller

@Component()
export class MyComponent {

    public layout: object = {};

    constructor(public layoutService: DefaultLayoutService) {
        this.layout = layoutService.getDefaultLayoutObject({ /* data which will overwrite the default */});
    }
}

@andrefarzat
Copy link
Collaborator

Now, regarding the "global defaults". Do you have an idea in how it could be implemented? Like, declaring a theme globally?

@bluppfisk
Copy link
Author

Thanks for the quick response.
Global defaults: yes, a theme would be nice. My application uses plotly graphs in nearly every component and so I have to tell plotly to use my colourway in every component. Your workaround will probably work, but being able to override globals sounds even more attractive.

I'm no expert on Plotly nor Angular, and it's a little opaque to me as to how the angular wrapper for plotly works, but maybe this works:

Wherever you import the module, you could provide some defaults. In Python, Plotly is retrieved through the PlotlyService. I don't know if something like this happens at all under the hood, but the PlotlyService sounds like a good point to set global configs.

Is that something?

@andrefarzat
Copy link
Collaborator

I know in other languages (i.e.: python) there are themes: https://plotly.com/python/templates/
I will look to see if we can add it to JS

@andrefarzat andrefarzat self-assigned this Mar 2, 2021
@andrefarzat andrefarzat added the enhancement New feature or request label Mar 2, 2021
@kiranatious
Copy link

is this resolved?

@bluppfisk
Copy link
Author

Not as far as I know; I still use the service to get an object with the default config. It's a workaround but it works.

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

Successfully merging a pull request may close this issue.

3 participants