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

Add HTML legend support #1325

Closed
manju-reddys opened this issue Jul 26, 2017 · 6 comments
Closed

Add HTML legend support #1325

manju-reddys opened this issue Jul 26, 2017 · 6 comments

Comments

@manju-reddys
Copy link

manju-reddys commented Jul 26, 2017

Something like PR and I have asked question but I don't think if some take a look into closed PR so opened this bug for further discussions.

I strongly feel that HTML legend make more sense and it in-fact make life much easy atleast in the following cases Issue, Issue:

Case-1: huge list of items (see image 1 in our application - summarize data of 300K records since we couldn't show the complete list we added "Others" to show there more items below )

  • Showing them as a vertical list would be impossible because the SVG size may not be enough to fit all of them within the view-able area.
  • Even if we manage to show with adjusting gaps etc... it will be nightmare for user to walk through the list to find the particular item in the list.
  • Otherwise we must provide the arrow (up/down) to indicate more items are available and this logic would be too complicate and also its too much burden to user to click through the list to find the item of interest.

Case-2: Add advance features:

  • Its not easy to implement the search or filter feature in SVG when the list is huge to find the item of interest (see google maps - search by typing address - for example how it will be helpful).
  • In many cases it will be convenient to take controls of legends items to enable/disable filter on click of item based on certain condition (ex: if user is Guest / Author) - this just an example.
  • Would allow to taking advantage of JS frameworks data binding (Angular 2) and custom template to add meaningful presentation etc...
  • Add collapse and expand the legend or add more features like drag to position on the chart.

Case-3: Customize (see the google map image)

  • Allow to skin the legend to the application theme (material design!).
  • Not everyone JS developer are styling experts, many of the JS developer use the CSS frameworks like bootstrap to develop the website/web-applications and those frameworks doesn't provide the styling feature for SVG.

legend
google-maps

@gordonwoodhull
Copy link
Contributor

gordonwoodhull commented Jul 26, 2017

Thanks for posting these arguments. They are persuasive.

I agree with all of your points except for one.

For the advanced features, I don't think it will be any easier to take control over the legend click action. You can easily change the click behavior using d3, for example see this answer about toggling composite child charts on legend click.

I also think it would be easy to add collapse/expand functionality with a similar "renderlet", and maybe you could use d3.behavior.drag for dragging too. But I agree there is a much bigger ecosystem of reusable interactive behaviors on the HTML side than the SVG side.

The quickest way to get this feature into the library is to review @davejlong's PR (or start your own dc.htmlLegend if for some reason you don't like it).

If you don't want to rebase the branch, you should be able to try it out just by copying the content of src/html-legend.js into your local copy of dc.js.

Once you've tried it out, please comment on #577 and I'll reopen it.

Please carefully review the interface of the original legend:
http://dc-js.github.io/dc.js/docs/html/dc.legend.html

I think that almost all of these are layout-related and can better be done with CSS, but legendText and maxItems should probably be added to #577 if we go with that.

Would you be willing to start a new PR and add these, along with tests?

@rrameshkumar76
Copy link
Contributor

rrameshkumar76 commented Jul 28, 2017

I did not realize that Html legend PR exists. Thanks for pointing out this PR.

I will first try this by copying the content in my project and try to use it. We do use legendText currently with dc.legend. This will be a good addition to dc library for the issue i created before of scroll bar also.

@rrameshkumar76
Copy link
Contributor

rrameshkumar76 commented Aug 5, 2017

I tried the code copying the html legend into my project with some modifications. It worked great as expected. I can make a PR from my fork. I have added legendText and maxItems and made some changes to make render method common for horizontal/vertical in that fork. Please let me know if it is fine for me to make a pull request. I have used much of the code in PR, except for changes mentioned above and specs.

@gordonwoodhull
Copy link
Contributor

I took a quick look at your fork. This is great. Thanks for updating the tests along with adding the new functions.

Please open a new PR to replace #577. I will review it more closely, and then merge it for 2.1.x.

@rrameshkumar76
Copy link
Contributor

Thanks, I have made the PR

@gordonwoodhull
Copy link
Contributor

Implemented in 3.0.0

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

No branches or pull requests

3 participants