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

Legend selection highlighting #600

Closed
barclayadam opened this issue May 23, 2014 · 9 comments
Closed

Legend selection highlighting #600

barclayadam opened this issue May 23, 2014 · 9 comments
Milestone

Comments

@barclayadam
Copy link

Hi,

I want the ability to highlight legend items that have an active filter. To do this the legend itself needs a class to indicate there are active filters, and then each legend item gets a class to indicate if it is active.

I modified dc.js legends with a couple of lines to support the scenarios I currently have, but I do not know if it could cover everything, or exactly the best way to integrate with current infrastructure:

The top of _legend.render method becomes:

        var legendables = _parent.legendables(),
            filters = _parent.filters();

        _parent.svg().select("g.dc-legend").remove();
        _g = _parent.svg().append("g")
            .attr("class", "dc-legend")
            // MODIFICATION: Add dc-legend-active-filters
            .classed("dc-legend-active-filters", filters.length > 0)
            .attr("transform", "translate(" + _x + "," + _y + ")");

        var itemEnter = _g.selectAll('g.dc-legend-item')
            .data(legendables)
            .enter()
            .append("g")
            // MODIFICATION: Add dc-legend-selected
            .attr("class", function (d) {
                return "dc-legend-item" + (filters.indexOf(d.name.toString()) === -1 ? "" : " dc-legend-selected");
            })

The bit I'm least sure about is adding the dc-legend-selected class, finding out whether that legend item is a currently filtered item.

For reference additional CSS I'm using is:

.dc-legend-active-filters .dc-legend-item {
    opacity: 0.8;
}

.dc-legend-active-filters .dc-legend-selected {
    opacity: 1;
}

Thanks,
Adam

@gordonwoodhull gordonwoodhull added this to the v2.1 milestone Nov 30, 2014
@gordonwoodhull
Copy link
Contributor

This sounds like useful functionality. A PR would be welcome!

@rrameshkumar76
Copy link
Contributor

@barclayadam Thanks for the above solution. This works great for me in my project for html legends.

@ialarmedalien
Copy link

Could this be implemented? I keep running into problems where I am not sure which legend items are selected and which aren't. I'd be happy to implement it for the html legend, too.

@rrameshkumar76
Copy link
Contributor

rrameshkumar76 commented Sep 15, 2018

htmlLegend has the highlightSelected implemented in it. https://github.com/dc-js/dc.js/blob/develop/src/html-legend.js#L102-L108

The example page https://dc-js.github.io/dc.js/examples/html-legend.html has this set up also.

@gordonwoodhull
Copy link
Contributor

Very cool, I hadn't noticed that. Looks like it should be easy to port to the SVG legend.

@Tahirhan
Copy link
Contributor

I checked the documentation but there is no method for highligting selected legends in SVG type. Is it implemented?

@gordonwoodhull
Copy link
Contributor

Hi @Tahirhan, clearly the functionality has not been copied over yet.

If you want to give it a shot, it’s just a matter of copying all the sections having to do with highlightSelected from one class to the other.

I can get it into the next release if you make a PR!

@Tahirhan
Copy link
Contributor

Ok, i will try :)

@gordonwoodhull
Copy link
Contributor

Thanks @Tahirhan, merged for release 3.1.9

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

No branches or pull requests

5 participants