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

Polymer 2 support #19

Closed
nicolasr75 opened this issue May 19, 2017 · 9 comments · Fixed by #24
Closed

Polymer 2 support #19

nicolasr75 opened this issue May 19, 2017 · 9 comments · Fixed by #24

Comments

@nicolasr75
Copy link

This is really great work!
I am very interested in testing your components. Unfortunately my project uses Polymer 2. Do you know whether the components work in Polymer 2 in hybrid mode?

@saeidzebardast
Copy link
Owner

Unfortunately, I didn't test nvd3-elements in Polymer v2.

@nicolasr75
Copy link
Author

Ok, I'm going to try it myself and report back.

@saeidzebardast
Copy link
Owner

saeidzebardast commented May 21, 2017 via email

@nicolasr75
Copy link
Author

nicolasr75 commented May 22, 2017

I tested line, pie and discrete-bar in Polymer v2 and so far it works as expected! bower adds a 'resolution' section to map the old polymer version demanded by nvd3-elements to 2.0.0.

The only thing I have not yet been able to get working is make the charts fill 100% of the container. I set the flex-size and auto-resize attributes and omitted explicit height and width attributes. Both line and discrete-bar charts get rendered too big in y-direction.

Assume I have an (empty) container div that fills 100% of the browser window which I simply checked by setting its background-color. As soon as I place a chart with flexSize in it, a y-scrollbar appears because the chart is too big.

Do you have any advice on that? How to correctly use flexSize and viewBoxHeight/Width?

@saeidzebardast
Copy link
Owner

saeidzebardast commented May 24, 2017

Thanks for testing it with Polymer 2.0. I'll check and upgrade Polymer on Bower soon.
Please create a demo (https://plnkr.co/) for the problem.

@nicolasr75
Copy link
Author

I tried to create a demo but got stuck when trying to create a chart. The Polymer stuff works but I don't know how to correctly import nvd3-elements. Do you know what is missing? Here is the plunker.

Apart from that I noticed that I didn't correctly understand the viewport thing. I found a lot of stackoverflows now about responsive d3 charts but I do not yet understand how to make an nvd3-element chart fill the container. Without specifying height/width/viewPortHeight/viewPortWidth/flexSize the chart is stretched to the full width of the container which is half the way. I guess in the end I will have to set the height in code :-(

Sorry for bothering you with this but I thought in the age of responsiveness it would be a great feature to easily have the chart fill the container. Any more ideas?

@saeidzebardast
Copy link
Owner

You need to set the height for NVD3 Charts. If you check samples on nvd3.org, you will see the height settings. I'll try to make charts more responsive while switching to Polymer 2.0.

@nicolasr75
Copy link
Author

Ok, I tried it and was suprised how much time it took until I got it all sorted out :-( In case anyone else has this problem I shortly sketch my solution:
the chart is supposed to always fill the containing element, initially and after window resizing. The containing element is itself either set to height: 100% or part of a flexbox. Initializing must be deferred until the clientHeight property of the element is available! For auto-resizing the window.onresize event can be used but of course should be debounced. As of now there seems to be almost no information and examples about the new Polymer 2.0 debouncing APIs, except this great SO post.

In the attachedCallback I have this for the initialization:

setTimeout(function() {
	this.$.barChart.height = this.clientHeight;
	this.$.barChart.refresh();			
}.bind(this), 0);

In the ready callback I have this for auto-resizing:

window.addEventListener('resize', function() {
	this._debouncer = Polymer.Debouncer.debounce(
		this._debouncer,
		Polymer.Async.timeOut.after(200),
		function() {
			this.$.barChart.height = this.clientHeight;
			this.$.barChart.refresh();
		}.bind(this));
	
}.bind(this));

@hegsie
Copy link

hegsie commented Jul 19, 2017

Hey Guys,
Is there any news on when this will be available?

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

Successfully merging a pull request may close this issue.

3 participants