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

Modebar aesthetic configurability #3063

Closed
jackparmer opened this issue Oct 1, 2018 · 31 comments · Fixed by #3068
Closed

Modebar aesthetic configurability #3063

jackparmer opened this issue Oct 1, 2018 · 31 comments · Fixed by #3068
Assignees
Labels
feature something new

Comments

@jackparmer
Copy link
Contributor

jackparmer commented Oct 1, 2018

Would like the modebar to have a few more programmatic options, especially for extremely styled Dash apps:

  1. Programmatic ability to set the modebar in a vertical orientation. Bokeh does a nice job with this:
    modebar_vertical

  2. Programmatic ability to set the background bar color, background bar opacity, and icon colors:
    modebar_plotly

  3. While we're at it, update the plotly logo in the modebar

Related:
#2171
https://github.com/plotly/streambed/issues/9699
(Perhaps we should create a plotly/plotly.js "modebar" label?)

@etpinard etpinard added the feature something new label Oct 1, 2018
@antoinerg
Copy link
Contributor

Good idea @jackparmer

I suggest we add the following config key:

    // mode bar style
    modeBarStyle: {
        orientation: 'h',
        backgroundColor: 'rgba(255 ,255 ,255 ,0.7)',
        iconColor: 'rgba(0, 31, 95, 0.3);'
    },

We should probably turn the icons into a font: it'll then be straightforward to change their color and opacity with CSS.

@etpinard, @alexcjohnson What do you think?

@alexcjohnson
Copy link
Collaborator

    modeBarStyle: {
        orientation: 'h',
        backgroundColor: 'rgba(255 ,255 ,255 ,0.7)',
        iconColor: 'rgba(0, 31, 95, 0.3);'
    },

I like it. I'd probably go for bgcolor just to match our usage in the regular schema. And there are two colors to consider: the logo and all other icons. So logoColor and iconColor? Also perhaps position: (top|middle|bottom) (left|center|right) like textposition, though that can be omitted for at least the first round, and added in later if someone is interested in it.

We should probably turn the icons into a font: it'll then be straightforward to change their color and opacity with CSS.

They were a font a long time ago... and in fact that's still how they're given to us when someone designs a new one. but we ditched that and instead just draw them as straight SVG (with a script to pull that out into js) so we have everything encapsulated in the one js bundle. Anyway this is still styled by css, we'll just need to make some pieces of that dynamic.

@antoinerg
Copy link
Contributor

antoinerg commented Oct 2, 2018

Thanks @alexcjohnson ! So I will go with the following for now:

  modeBarStyle: {
        orientation: 'h',
        bgcolor: 'rgba(255 ,255 ,255 ,0.7)',
        iconColor: 'rgba(0, 31, 95, 0.3)',
        logoColor: 'rgba(0, 31, 95, 0.3)',
        position: 'right'
    },

Let's keep the pipeline for icons the same for now. I guess I just need to crush the logo into a single path. A tool like this may do the job: https://www.enigmeta.com/svgcrush/ . Can you point me to the most up-to-date plot.ly logo in SVG?

Thank you again for the all the details :)

@nicolaskruchten
Copy link
Contributor

Just wanting to chime in here a bit and request that these be layout options and not config options if at all possible... :)

My rationale is that users will often want to control these settings alongside other layout options like the plot background colour and will likely want to drag along these settings in templates etc. If we make these options config-only then people will not be able to e.g. use the editor to style the modebar, and will not be able to make "dark theme" templates that can be reused within Chart Studio. Baking these in to layout will also likely make things easier for DDK...

/cc @chriddyp @wbrgss

@jackparmer
Copy link
Contributor Author

jackparmer commented Oct 3, 2018 via email

@alexcjohnson
Copy link
Collaborator

Thanks @nicolaskruchten, layout makes sense. I think we originally put these in config as that's where all the other modebar options go, but those are all about altering the functionality of the modebar, which may need to call out to other code on the page or something... whereas the new items are all about appearance and that's not something that depends on the display context so layout is better.

@antoinerg
Copy link
Contributor

Thank you for your input @nicolaskruchten!

@nicolaskruchten
Copy link
Contributor

Nice, thanks for the flexibility, sorry to give this feedback so late :)

Next ask: any way to make some of the behaviour automatic? especially with respect to the figure background? would be great to have the modebar either transparent or match the plot background by default, and to have the icon colours somehow maintain contrast... Even if that's hidden behind a flag I think it would be a nice option that would be turned on by default in the editor :)

@alexcjohnson
Copy link
Collaborator

Next ask: any way to make some of the behaviour automatic?

I think that would be fine, and I wouldn't consider that a breaking change as long as our solution is legible on any plot.

Ideal would be to have modebar.bgcolor match paper_bgcolor but add partial opacity, in case some component or subplot sneaks underneath the modebar. Then we just need to choose a default iconcolor (and active color) that is legible and looks good with the resulting (or explicit) bgcolor.

@antoinerg
Copy link
Contributor

I decided to wait before implementing the automatic behavior described above by @nicolaskruchten and @alexcjohnson. I definitely love the idea though. It could be applied to every bit of text on a figure: title, axes and so on. For example, as of right now, choosing "paper_bgcolor": "#444" makes all the text invisible! This sounds like a new feature to me and probably deserves its own issue.

@nicolaskruchten
Copy link
Contributor

@antoinerg I'd really like this default behaviour for the modebar background at least... Just because we can't do it everywhere doesn't mean we shouldn't do it in some places: we already do handle automatic contrasting text in places like hovertext, where the foreground color is automatically set based on the background :)

@antoinerg
Copy link
Contributor

Sure thing! I didn't know we already had the logic to do that in the codebase :)

@etpinard
Copy link
Contributor

etpinard commented Oct 5, 2018

Sure thing! I didn't know we already had the logic to do that in the codebase :)

It's here:

/*
* Create a color that contrasts with cstr.
*
* If cstr is a dark color, we lighten it; if it's light, we darken.
*
* If lightAmount / darkAmount are used, we adjust by these percentages,
* otherwise we go all the way to white or black.
*/
color.contrast = function(cstr, lightAmount, darkAmount) {
var tc = tinycolor(cstr);
if(tc.getAlpha() !== 1) tc = tinycolor(color.combine(cstr, background));
var newColor = tc.isDark() ?
(lightAmount ? tc.lighten(lightAmount) : background) :
(darkAmount ? tc.darken(darkAmount) : defaultLine);
return newColor.toString();
};

and see example for hover label text:

var commonBgColor = commonLabelOpts.bgcolor || Color.defaultLine;
var commonStroke = commonLabelOpts.bordercolor || Color.contrast(commonBgColor);
var contrastColor = Color.contrast(commonBgColor);
lpath.style({
fill: commonBgColor,
stroke: commonStroke
});
ltext.text(t0)
.call(Drawing.font,
commonLabelOpts.font.family || fontFamily,
commonLabelOpts.font.size || fontSize,
commonLabelOpts.font.color || contrastColor
)
.call(svgTextUtils.positionText, 0, 0)
.call(svgTextUtils.convertToTspans, gd);

@antoinerg
Copy link
Contributor

Thanks @etpinard ! @nicolaskruchten's request was super easy to implement with this 😊

Sorry @nicolaskruchten for not realizing how easy this was to do! I'm still learning 😄

@nicolaskruchten
Copy link
Contributor

There's never any need to apologize for learning :) Happy that it turned out to be easy!

@antoinerg
Copy link
Contributor

antoinerg commented Oct 5, 2018

For example, as of right now, choosing "paper_bgcolor": "#444" makes all the text invisible!

@nicolaskruchten Do you think we should now do the same for the title, axes and so on ie. provide a better font color by default ?

@etpinard
Copy link
Contributor

etpinard commented Oct 5, 2018

Do you think we should now do the same for the title, axes and so on ie

I'd call that a breaking change.

@zouhairm
Copy link
Contributor

Should I expect this to work with Dash ? I've tried passing it in the plotly config but doesn't seem to have an effect.

@antoinerg
Copy link
Contributor

antoinerg commented Feb 17, 2019

@zoohair It should work with Dash if you are using plotly.js version v.1.42.0 or newer!

For reference: https://github.com/plotly/plotly.js/releases/tag/v1.42.0

@zouhairm
Copy link
Contributor

zouhairm commented Mar 6, 2019

@antoinerg : I'm on Dash 0.39 which seems to be using plotly-1.45.0.min.js

But still no effect when passing modeBarStyle parameters (e.g. 'modeBarStyle':{'bgcolor': 'red', 'color':'rgba(0,0,0,1)'}) as part of the config to a dcc.Graph element in my layout.

Is there a codepen / minimum example somewhere that illustrates the proper use of modeBarStyle in conjunction with Dash?

@antoinerg
Copy link
Contributor

antoinerg commented Mar 6, 2019

@zoohair The style of the modebar is controlled by attribute layout.modebar. The following example has been tested to work properly

    dcc.Graph(
        id='example-graph',
        figure={
            'data': [
                {'x': [1, 2, 3], 'y': [4, 1, 2], 'type': 'bar', 'name': 'SF'},
                {'x': [1, 2, 3], 'y': [2, 4, 5], 'type': 'bar', 'name': u'Montréal'},
            ],
            'layout': {
                'title': 'Dash Data Visualization',
                'modebar': {
                    'orientation': 'v',
                    'bgcolor': 'rgba(0,0,0,0.5)'
                }
            }
        }
    )

@zouhairm
Copy link
Contributor

zouhairm commented Mar 7, 2019

Thanks @antoinerg : it is a bit confusing since this github issue mentions modeBarStyle, and other modebar configuration (visible icons, hover) is done through the dcc.Graph(config=...) not the layout.

I'm struggling though to find which setting makes it possible for the modebar to be transparent (both my paper_bgcolor and plot_bgcolor are set to rgba(0,0,0,0)). There is a gray background color (that I can't change despite setting modebar's bgcolor, color, or activecolor).

This issue only appeared in more recent Dash updates (likely due to an update to plotly.js - it worked on 1.42.2 but not working on 1.45.0). I remember seeing this reported as an issue in github somewhere but for the life of me I can't find it again 😞

screenshot

@nicolaskruchten
Copy link
Contributor

@antoinerg have we checked in the latest version of Dash that it's possible to set the modebar background to 100% transparent? I've been seeing a lot of semi-transparent modebar backgrounds in various Dash apps recently.

@antoinerg
Copy link
Contributor

@nicolaskruchten I confirm that it is possible to set the modebar background to 100% transparent by setting layout.modebar.bgcolor to rgba(0, 0, 0, 0).

@zoohair the fourth number in a rgba color is the opacity so setting it to 0 should make the modebar transparent. Can you send me the list of layout attributes you're using so I can assist you further?

@zouhairm
Copy link
Contributor

zouhairm commented Mar 8, 2019

@antoinerg : my apologies ; As I tried to put together a minimum working example I traced down the issue to a css that was included that was overriding the bgcolor using .js-plotly-plot .plotly .modebar { background-color: #f2f2f2 }

It's odd because I've had that there for a while, but things worked as expected (i.e. the background-color did not appear until the mdoebar was hovered on) but not in the new version of plotly.js.

@tcados
Copy link

tcados commented Mar 26, 2019

I'm still confused similarly to zoohair....
I am able to make the background transparent, but how and where do I change the color of the icons? and how about when I hover over the icons?

Thanks.

@etpinard
Copy link
Contributor

etpinard commented Mar 26, 2019

@tcados commenting on closed issues isn't the best way to ask for help for this project.

Please use https://community.plot.ly/c/plotly-js - that way other plotly.js users will be able to help out or be helped from your questions.

Thank you!

@kroim
Copy link

kroim commented Feb 19, 2020

How can I put watermark in plotly graph?

@kroim
Copy link

kroim commented Feb 19, 2020

image

@luggie
Copy link

luggie commented Feb 12, 2021

Any new thoughts on? :
'layout': {'modebar': { 'position': 'center' }

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

Successfully merging a pull request may close this issue.

9 participants