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

How to hide the legends for GraduatedCircleViz? #181

Open
xchen0326 opened this issue Nov 16, 2020 · 1 comment
Open

How to hide the legends for GraduatedCircleViz? #181

xchen0326 opened this issue Nov 16, 2020 · 1 comment
Labels

Comments

@xchen0326
Copy link

I tried legend=False but it does not work. I wanted to assign the radius and the color of the circles based on two properties, but it leads to a problem that there creates two legends which either overlap each other or overlap the map. How can I fix that?

@akacarlyann
Copy link
Collaborator

Hi @xchen0326 sorry for the delay. Hope you found a workaround in the meantime! This bug is due to an oversight where some default values are not being set in the main.html template when legend is set to False. The easiest way around this would be to update the mapboxgl.viz.MapViz.create_html method so that all of the legend-based settings are included in the template either way. This could be as simple as changing lines 303-322
https://github.com/mapbox/mapboxgl-jupyter/blob/master/mapboxgl/viz.py#L303-L322 to the following:

        if self.legend:

            if all([self.legend, self.legend_gradient, self.legend_function == 'radius']):
                raise LegendError(' '.join(['Gradient legend format not compatible with a variable radius legend.',
                                            'Please either change `legend_gradient` to False or `legend_function` to "color".']))

        options.update(
            showLegend=self.legend,
            legendLayout=self.legend_layout,
            legendFunction=self.legend_function,
            legendStyle=self.legend_style, # reserve for custom CSS
            legendGradient=json.dumps(self.legend_gradient),
            legendFill=self.legend_fill,
            legendHeaderFill=self.legend_header_fill,
            legendTextColor=self.legend_text_color,
            legendNumericPrecision=json.dumps(self.legend_text_numeric_precision),
            legendTitleHaloColor=self.legend_title_halo_color,
            legendKeyShape=self.legend_key_shape,
            legendKeyBordersOn=json.dumps(self.legend_key_borders_on)
        )

(basically move the options.update({...}) outside of the if self.legend if block. Does that make sense? I think the CSS needs an overhaul so I'll think if there's a good way to address this there.

@akacarlyann akacarlyann added the bug label Dec 6, 2020
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

2 participants