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

<linechart> in custom elements results in Error: Invalid negative value for <rect> attribute height=x #440

Open
marcj opened this issue Feb 25, 2016 · 8 comments

Comments

@marcj
Copy link
Contributor

marcj commented Feb 25, 2016

If I use following html snipped in my application at a very high DOM level (near to body)

<linechart style="height: 150px;" data="app.getCurrentJobStats().loss" options="app.chartOptions"></linechart>

then everything works just fine. If I wrap that snipped above with Bootstrap's tab-system (where ng-if's and custom elements are involved) I'm getting following error:

Error: Invalid negative value for <rect> attribute width="-80"
Error: Invalid negative value for <rect> attribute height="-40"
Error: Invalid negative value for <rect> attribute width="-80"
Error: Invalid negative value for <rect> attribute height="-40"

I guess it has something todo with the Bootstrap code, because in my regular ng-if layouting stuff this doesn't happen (meaning that if my app starts without initially displaying the linechart because another div is currently in the DOM this effect doesn't happen). I tried a bit around with it and and figured out it has something todo with custom elements.

If I do this:

    <dummy-element style="height: 150px;">
        <linechart style="height: 150px;" data="app.getCurrentJobStats().loss" options="app.chartOptions"></linechart>
    </dummy-element>

then this will trigger the same errors as above. I haven't yet figured out a way to workaround this. Tried with registering dummy-element using document.registerElement but that didn't help.

@marcj
Copy link
Contributor Author

marcj commented Feb 25, 2016

Ok, the one with dummy-element is fixed if I place a display: block to its style. Issue remains with the Bootstrap tab-set:

<uib-tabset>
    <uib-tab heading="STATS">
        <div style="height: 150px;">
            <linechart style="height: 150px;" data="app.getCurrentJobStats().loss" options="app.chartOptions"></linechart>
        </div>
    </uib-tab>
</uib-tabset>

Anyone an idea?

@marcj
Copy link
Contributor Author

marcj commented Feb 25, 2016

I got it a bit more working in the form that it is displaying at least the line-chart even though the error still is shown in the console.

To get it displayed I put a little directive inside my app which hooks into 'uib-tab' and triggers windows.resize event when the tab gets visible:

    .directive('uibTab', () => {
        return {
            link: function(scope, element, attributes) {
                scope.$watch(() => {
                    return !!element[0].offsetParent;
                }, () => {
                    angular.element(window).triggerHandler('resize'); //redraw line-chart
                });
            }
        }
    })

But still, there are nasty error in the console :)

@marcj
Copy link
Contributor Author

marcj commented Feb 25, 2016

Since Angular-Bootstrap's tab-system is using transclude (https://github.com/angular-ui/bootstrap/blob/master/src/tabs/tabs.js#L118) I really believe the error comes from rendering n3-charts during a time where it isn't attached to the DOM and thus has no dimensions it can read (results in 0px/0px), where d3 is then trying to fit a graph in a 0 size space which isn't possible. Maybe we could make n3-charts pause rendering when it isn't attached to the DOM (offsetParent is not set) and only start rendering when its injected into the DOM again.

@marcj
Copy link
Contributor Author

marcj commented Feb 25, 2016

I worked around with this issue by using a own tab system which uses z-index: -1 to hide tabs instead of using transclude and DOM magic to do it. I let it open because I still think it would be useful to get at least the errors go away by only rendering the chart if its injected into the DOM.

@chaosmail
Copy link
Contributor

Hi @marcj
is everything working for you? there are some issues with inferring the dimensions from the parent element when the element is not visible initially. You can see 2 workarounds in #465
Best,
Christoph

@marcj
Copy link
Contributor Author

marcj commented Apr 22, 2016

hey @chaosmail,

unfortunately not. I had to switch back to tab system that uses ng-if, which again produces hundreds of nasty errors in the console.

d3.min.js:1 Error: <path> attribute d: Expected number, "MNaN,29.681999999…".a @ d3.min.js:1(anonymous function) @ d3.min.js:3Y @ d3.min.js:1Aa.each @ d3.min.js:3Aa.attr @ d3.min.js:3Area.updateData @ LineChart.js:2761(anonymous function) @ LineChart.js:2527(anonymous function) @ d3.min.js:3Y @ d3.min.js:1Aa.each @ d3.min.js:3SeriesFactory.updateSeries @ LineChart.js:2524SeriesFactory.updateSeriesContainer @ LineChart.js:2515SeriesFactory.softUpdate @ LineChart.js:2489SeriesFactory.update @ LineChart.js:2479t @ d3.min.js:1EventManager.trigger @ LineChart.js:718updateData @ LineChart.js:3149Scope.$digest @ angular.js:16869Scope.$apply @ angular.js:17133done @ angular.js:11454completeRequest @ angular.js:11652requestLoaded @ angular.js:11593
d3.min.js:1 Error: <path> attribute d: Expected number, "MNaN,61.2714LNaN,…".a @ d3.min.js:1(anonymous function) @ d3.min.js:3Y @ d3.min.js:1Aa.each @ d3.min.js:3Aa.attr @ d3.min.js:3Area.updateData @ LineChart.js:2761(anonymous function) @ LineChart.js:2527(anonymous function) @ d3.min.js:3Y @ d3.min.js:1Aa.each @ d3.min.js:3SeriesFactory.updateSeries @ LineChart.js:2524SeriesFactory.updateSeriesContainer @ LineChart.js:2515SeriesFactory.softUpdate @ LineChart.js:2489SeriesFactory.update @ LineChart.js:2479t @ d3.min.js:1EventManager.trigger @ LineChart.js:718updateData @ LineChart.js:3149Scope.$digest @ angular.js:16869Scope.$apply @ angular.js:17133done @ angular.js:11454completeRequest @ angular.js:11652requestLoaded @ angular.js:11593
d3.min.js:1 Error: <path> attribute d: Expected number, "MNaN,29.681999999…".a @ d3.min.js:1(anonymous function) @ d3.min.js:3Y @ d3.min.js:1Aa.each @ d3.min.js:3Aa.attr @ d3.min.js:3Line.updateData @ LineChart.js:2685(anonymous function) @ LineChart.js:2527(anonymous function) @ d3.min.js:3Y @ d3.min.js:1Aa.each @ d3.min.js:3SeriesFactory.updateSeries @ LineChart.js:2524SeriesFactory.updateSeriesContainer @ LineChart.js:2515SeriesFactory.softUpdate @ LineChart.js:2489SeriesFactory.update @ LineChart.js:2479t @ d3.min.js:1EventManager.trigger @ LineChart.js:718updateData @ LineChart.js:3149Scope.$digest @ angular.js:16869Scope.$apply @ angular.js:17133done @ angular.js:11454completeRequest @ angular.js:11652requestLoaded @ angular.js:11593
d3.min.js:1 Error: <path> attribute d: Expected number, "MNaN,61.2714LNaN,…".a @ d3.min.js:1(anonymous function) @ d3.min.js:3Y @ d3.min.js:1Aa.each @ d3.min.js:3Aa.attr @ d3.min.js:3Line.updateData @ LineChart.js:2685(anonymous function) @ LineChart.js:2527(anonymous function) @ d3.min.js:3Y @ d3.min.js:1Aa.each @ d3.min.js:3SeriesFactory.updateSeries @ LineChart.js:2524SeriesFactory.updateSeriesContainer @ LineChart.js:2515SeriesFactory.softUpdate @ LineChart.js:2489SeriesFactory.update @ LineChart.js:2479t @ d3.min.js:1EventManager.trigger @ LineChart.js:718updateData @ LineChart.js:3149Scope.$digest @ angular.js:16869Scope.$apply @ angular.js:17133done @ angular.js:11454completeRequest @ angular.js:11652requestLoaded @ angular.js:11593
2d3.min.js:1 Error: <path> attribute d: Expected number, "MNaN,NaNLNaN,NaNL…".a @ d3.min.js:1(anonymous function) @ d3.min.js:3Y @ d3.min.js:1Aa.each @ d3.min.js:3Aa.attr @ d3.min.js:3Area.updateData @ LineChart.js:2761(anonymous function) @ LineChart.js:2527(anonymous function) @ d3.min.js:3Y @ d3.min.js:1Aa.each @ d3.min.js:3SeriesFactory.updateSeries @ LineChart.js:2524SeriesFactory.updateSeriesContainer @ LineChart.js:2515SeriesFactory.softUpdate @ LineChart.js:2489SeriesFactory.update @ LineChart.js:2479t @ d3.min.js:1EventManager.trigger @ LineChart.js:718updateData @ LineChart.js:3149Scope.$digest @ angular.js:16869Scope.$apply @ angular.js:17133done @ angular.js:11454completeRequest @ angular.js:11652requestLoaded @ angular.js:11593
2d3.min.js:1 Error: <path> attribute d: Expected number, "MNaN,NaNLNaN,NaNL…".a @ d3.min.js:1(anonymous function) @ d3.min.js:3Y @ d3.min.js:1Aa.each @ d3.min.js:3Aa.attr @ d3.min.js:3Line.updateData @ LineChart.js:2685(anonymous function) @ LineChart.js:2527(anonymous function) @ d3.min.js:3Y @ d3.min.js:1Aa.each @ d3.min.js:3SeriesFactory.updateSeries @ LineChart.js:2524SeriesFactory.updateSeriesContainer @ LineChart.js:2515SeriesFactory.softUpdate @ LineChart.js:2489SeriesFactory.update @ LineChart.js:2479t @ d3.min.js:1EventManager.trigger @ LineChart.js:718updateData @ LineChart.js:3149Scope.$digest @ angular.js:16869Scope.$apply @ angular.js:17133done @ angular.js:11454completeRequest @ angular.js:11652requestLoaded @ angular.js:11593
30d3.min.js:1 Error: <circle> attribute cx: Expected length, "NaN".a @ d3.min.js:1(anonymous function) @ d3.min.js:3Y @ d3.min.js:1Aa.each @ d3.min.js:3Aa.attr @ d3.min.js:3updatePoint @ LineChart.js:2571Aa.call @ d3.min.js:3Dot.updateData @ LineChart.js:2609(anonymous function) @ LineChart.js:2527(anonymous function) @ d3.min.js:3Y @ d3.min.js:1Aa.each @ d3.min.js:3SeriesFactory.updateSeries @ LineChart.js:2524SeriesFactory.updateSeriesContainer @ LineChart.js:2515SeriesFactory.softUpdate @ LineChart.js:2489SeriesFactory.update @ LineChart.js:2479t @ d3.min.js:1EventManager.trigger @ LineChart.js:718updateData @ LineChart.js:3149Scope.$digest @ angular.js:16869Scope.$apply @ angular.js:17133done @ angular.js:11454completeRequest @ angular.js:11652requestLoaded @ angular.js:11593
30d3.min.js:1 Error: <circle> attribute cy: Expected length, "NaN".a @ d3.min.js:1(anonymous function) @ d3.min.js:3Y @ d3.min.js:1Aa.each @ d3.min.js:3Aa.attr @ d3.min.js:3updatePoint @ LineChart.js:2571Aa.call @ d3.min.js:3Dot.updateData @ LineChart.js:2609(anonymous function) @ LineChart.js:2527(anonymous function) @ d3.min.js:3Y @ d3.min.js:1Aa.each @ d3.min.js:3SeriesFactory.updateSeries @ LineChart.js:2524SeriesFactory.updateSeriesContainer @ LineChart.js:2515SeriesFactory.softUpdate @ LineChart.js:2489SeriesFactory.update @ LineChart.js:2479t @ d3.min.js:1EventManager.trigger @ LineChart.js:718updateData @ LineChart.js:3149Scope.$digest @ angular.js:16869Scope.$apply @ angular.js:17133done @ angular.js:11454completeRequest @ angular.js:11652requestLoaded @ angular.js:11593
30d3.min.js:1 Error: <circle> attribute cx: Expected length, "NaN".a @ d3.min.js:1(anonymous function) @ d3.min.js:3Y @ d3.min.js:1Aa.each @ d3.min.js:3Aa.attr @ d3.min.js:3updatePoint @ LineChart.js:2571Aa.call @ d3.min.js:3Dot.updateData @ LineChart.js:2611(anonymous function) @ LineChart.js:2527(anonymous function) @ d3.min.js:3Y @ d3.min.js:1Aa.each @ d3.min.js:3SeriesFactory.updateSeries @ LineChart.js:2524SeriesFactory.updateSeriesContainer @ LineChart.js:2515SeriesFactory.softUpdate @ LineChart.js:2489SeriesFactory.update @ LineChart.js:2479t @ d3.min.js:1EventManager.trigger @ LineChart.js:718updateData @ LineChart.js:3149Scope.$digest @ angular.js:16869Scope.$apply @ angular.js:17133done @ angular.js:11454completeRequest @ angular.js:11652requestLoaded @ angular.js:11593
30d3.min.js:1 Error: <circle> attribute cy: Expected length, "NaN".a @ d3.min.js:1(anonymous function) @ d3.min.js:3Y @ d3.min.js:1Aa.each @ d3.min.js:3Aa.attr @ d3.min.js:3updatePoint @ LineChart.js:2571Aa.call @ d3.min.js:3Dot.updateData @ LineChart.js:2611(anonymous function) @ LineChart.js:2527(anonymous function) @ d3.min.js:3Y @ d3.min.js:1Aa.each @ d3.min.js:3SeriesFactory.updateSeries @ LineChart.js:2524SeriesFactory.updateSeriesContainer @ LineChart.js:2515SeriesFactory.softUpdate @ LineChart.js:2489SeriesFactory.update @ LineChart.js:2479t @ d3.min.js:1EventManager.trigger @ LineChart.js:718updateData @ LineChart.js:3149Scope.$digest @ angular.js:16869Scope.$apply @ angular.js:17133done @ angular.js:11454completeRequest @ angular.js:11652requestLoaded @ angular.js:11593
30d3.min.js:1 Error: <circle> attribute cx: Expected length, "NaN".a @ d3.min.js:1(anonymous function) @ d3.min.js:3Y @ d3.min.js:1Aa.each @ d3.min.js:3Aa.attr @ d3.min.js:3updatePoint @ LineChart.js:2571Aa.call @ d3.min.js:3Dot.updateData @ LineChart.js:2609(anonymous function) @ LineChart.js:2527(anonymous function) @ d3.min.js:3Y @ d3.min.js:1Aa.each @ d3.min.js:3SeriesFactory.updateSeries @ LineChart.js:2524SeriesFactory.updateSeriesContainer @ LineChart.js:2515SeriesFactory.softUpdate @ LineChart.js:2489SeriesFactory.update @ LineChart.js:2479t @ d3.min.js:1EventManager.trigger @ LineChart.js:718updateData @ LineChart.js:3149Scope.$digest @ angular.js:16869Scope.$apply @ angular.js:17133done @ angular.js:11454completeRequest @ angular.js:11652requestLoaded @ angular.js:11593
30d3.min.js:1 Error: <circle> attribute cy: Expected length, "NaN".a @ d3.min.js:1(anonymous function) @ d3.min.js:3Y @ d3.min.js:1Aa.each @ d3.min.js:3Aa.attr @ d3.min.js:3updatePoint @ LineChart.js:2571Aa.call @ d3.min.js:3Dot.updateData @ LineChart.js:2609(anonymous function) @ LineChart.js:2527(anonymous function) @ d3.min.js:3Y @ d3.min.js:1Aa.each @ d3.min.js:3SeriesFactory.updateSeries @ LineChart.js:2524SeriesFactory.updateSeriesContainer @ LineChart.js:2515SeriesFactory.softUpdate @ LineChart.js:2489SeriesFactory.update @ LineChart.js:2479t @ d3.min.js:1EventManager.trigger @ LineChart.js:718updateData @ LineChart.js:3149Scope.$digest @ angular.js:16869Scope.$apply @ angular.js:17133done @ angular.js:11454completeRequest @ angular.js:11652requestLoaded @ angular.js:11593
30d3.min.js:1 Error: <circle> attribute cx: Expected length, "NaN".a @ d3.min.js:1(anonymous function) @ d3.min.js:3Y @ d3.min.js:1Aa.each @ d3.min.js:3Aa.attr @ d3.min.js:3updatePoint @ LineChart.js:2571Aa.call @ d3.min.js:3Dot.updateData @ LineChart.js:2611(anonymous function) @ LineChart.js:2527(anonymous function) @ d3.min.js:3Y @ d3.min.js:1Aa.each @ d3.min.js:3SeriesFactory.updateSeries @ LineChart.js:2524SeriesFactory.updateSeriesContainer @ LineChart.js:2515SeriesFactory.softUpdate @ LineChart.js:2489SeriesFactory.update @ LineChart.js:2479t @ d3.min.js:1EventManager.trigger @ LineChart.js:718updateData @ LineChart.js:3149Scope.$digest @ angular.js:16869Scope.$apply @ angular.js:17133done @ angular.js:11454completeRequest @ angular.js:11652requestLoaded @ angular.js:11593
30d3.min.js:1 Error: <circle> attribute cy: Expected length, "NaN".

I still believe that it's a good idea to stop rendering when there's no parentElement detected or the size is 0px/0px, so this errors won't appear.

@marcj
Copy link
Contributor Author

marcj commented Jun 21, 2016

@chaosmail can you give me a hint where I can start fixing this? I'd like to contribute it.

@chaosmail
Copy link
Contributor

Hi @marcj
maybe you could give a look into the line https://github.com/n3-charts/line-chart/blob/master/src/angularjs/LineChart.ts#L128
I guess we could make an option to disable parentElement dimensions
Does this help you?
Best,
Christoph

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

2 participants