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

chart body's clip-path not working with Angular html5 mode #1079

Closed
yandongCoder opened this issue Jan 4, 2016 · 8 comments
Closed

chart body's clip-path not working with Angular html5 mode #1079

yandongCoder opened this issue Jan 4, 2016 · 8 comments
Labels
Milestone

Comments

@yandongCoder
Copy link

Angular SVG url problem as follow:
https://github.com/jeffbcross/angular-svg-base.

change:

.attr('clip-path', 'url(#' + getClipPathId() + ')');

to:

.attr("clip-path", "url(" + window.location.href + "#" + getClipPathId() + ")");

this could avoid failure of clip-path when use Angular html5 mode.
gx8 i2_9tv c0mb yng9fp

@gordonwoodhull
Copy link
Contributor

Hi @yandongCoder, thanks for the report.

Out of curiosity, are you using angular-dc or are you embedding dc.js in Angular another way?

This looks like a safe change but I wish I had a test case.

@gordonwoodhull gordonwoodhull added this to the v2.0 milestone Jan 4, 2016
@yandongCoder
Copy link
Author

Hi @gordonwoodhull
I'm just embedding dc.js in Angular Directive.

angular.module('admin9cApp')
  .directive('c3Chart', function ($timeout) {
    return {
      restrict: 'E',
      scope: {
          data: "="
      },
      link: function postLink(scope, element, attrs) {
        var chart = c3.generate({
            bindto: element[0],
            data: {
              json: {
                  data: scope.data
              }
.......

@gordonwoodhull
Copy link
Contributor

I don't have a codebase for testing this in Angular, but I've added the fix for 2.0 beta 28, and verified that it doesn't break other charts, and updated the tests to match.

@gordonwoodhull
Copy link
Contributor

Thanks @yandongCoder!

@mtraynham
Copy link
Contributor

mtraynham commented May 17, 2016

Just butting in, this actually breaks the clip path for me...
HTML5 mode is off by default in Angular and it will put # in the URL for routing. This is a fragment identifier, so you can route within the single page application without reloading.

In URIs for MIME text/html pages such as http://www.example.org/foo.html#bar the fragment refers to the element with id="bar".

If you have a URL like:
http://localhost:8080/#/dashboard/foo
The clip-path reference becomes:
http://localhost:8080/#/dashboard/foo#chart-a-clip
Which is an invalid selector.

We should be chopping off the existing fragment identifier if it exists.

var href = window.location.href,
    fragmentLocation = href.indexOf('#');
href = fragmentLocation > -1 ? href.substr(0, fragmentLocation) : href;
...
.attr('clip-path', 'url(' + href + '#' + getClipPathId() + ')');

Although I still fail to see why this is necessary, using '#' + getClipPathId() without the href should refer to the containing document.

@gordonwoodhull
Copy link
Contributor

gordonwoodhull commented May 18, 2016

Good catch @mtraynham, yes we absolutely must support URLs that already have fragments.

I tried a few times to understand what the Angular base tag is about (there's a link to an issue in the library linked above), but ultimately I don't really want to understand Angular (too rigid for me)... so I'll just take people's word on this as long as it doesn't break the library for anyone else.

I'll reopen this and do something like what you suggested in the next release.

@gordonwoodhull
Copy link
Contributor

gordonwoodhull commented May 23, 2016

Going with window.location.href.split('#')[0]

http://stackoverflow.com/a/5818302/676195

@mtraynham
Copy link
Contributor

Mmm nice and concise, I like it!

gordonwoodhull added a commit to dc-js/dc.graph.js that referenced this issue Oct 23, 2017
someone is breaking fragment references on angular/firefox
see dc-js/dc.js#1079 for more details
gordonwoodhull added a commit to dc-js/dc.graph.js that referenced this issue Oct 27, 2017
someone is breaking fragment references on angular/firefox
see dc-js/dc.js#1079 for more details
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

3 participants