susielu / d3-legend

A reusable d3 legend component.
http://d3-legend.susielu.com/
Apache License 2.0
727 stars 104 forks source link

Namespacing CSS #13

Closed ramnathv closed 9 years ago

ramnathv commented 9 years ago

First off, awesome work with this library. It really makes legends super easy!

One issue I ran into while using d3-legend was namespace clashes. For example, the labels in d3-legend have the class label, and if you use it with bootstrap, they look really weird as the fonts are displayed at 75% of their size.

One way to solve this issue would be to allow uses to specify a prefix for all classes introduced by d3-legend. It could default to "" to maintain backward compatibility. This way, one could specify a prefix d3-legend- and style appropriately, without having to worry about namespace clashes.

I would be happy to contribute a PR if you think this is something you would like to incorporate.

susielu commented 9 years ago

Got it, that's a good idea. It would be lovely if you could make a PR. Thanks for the feedback!

susielu commented 9 years ago

This has been added to all of the legend types. There is a new property called classPrefix it appends the prefix to all of the classes used in d3.legend: .cell, .label, .swatch, .legendCells, .legendTitle so as an example if you sent it a prefix of "blue" they would all become .bluecell, .bluelabel, .blueswatch, .bluelegendCells, .bluelegendTitle