-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
dynamic resizing #111
Comments
A lot of people have asked for this.. I'll stick it on my todo list. |
This would be incredible. |
I'd love to see that too. What about only redrawing the svg when the resize has ended so the cpu doesn't get taxed too much. I have done that before like this, function Resize() {
var lazyTrigger = _.debounce(_triggerLazyResize, 800);
$(window).on('resize', lazyTrigger);
_bindResizeStart();
}
var _bindResizeStart = function() {
$(window).one('resize', function() {
$(window).trigger('resize:start');
});
};
var _triggerLazyResize = function() {
$(window).trigger('resize:end');
_bindResizeStart();
}; I would then remove the svg on resize:start and redraw it on resize:end. During the resize one could show a fancy preloader. Overall I think its a pretty nice effect. However I had some problems in older browsers (if you can point me in a direction I would be very grateful). What do you think. |
SVG-only fixes are an issue because old-IE uses VML instead. This is a valuable feature though -- adding to the TODO list for v0.5. |
This would be a great addition. Especially in conjunction with Backbone + Responsive layouts. |
This would be very useful. |
This would be a great feature. |
+1 |
4 similar comments
👍 |
+1 |
+1 |
+1 |
+2 |
+1 |
2 similar comments
👍 |
+1 |
Great, i hope v0.5 comes out soon! :) |
I vote for this one too! |
I'm on board for this feature too ! |
OK, resizing is in master now. Please everyone give it a test drive with their charts and let me know how it works. To enable resizing, pass If it's all good, it'll ship with v0.5.0, which will be the next release! |
It worked flawlessly in Chrome/Safari. Thanks! |
Just as a heads up, when resizing in Firefox the timeout ends up in an infinite loop and the browser crashes / hangs |
@jeremywrowe Which version of Firefox are you testing with? can you create a jsbin that demonstrates the crash bug? The example in examples/resize.html works OK for me on Firefox 25 on OS X. |
@oesmith I am on firefox 25.0. It seems to be a byproduct of having multiple charts rendering on the same page. I have a line, stacked bar, and an area chart. I can get you a jsbin later today when I have a spare second :) |
Tested under Linux Fedora with :
(I added the resize: true) BUT, I was moving the width in javascript using padding/width of others elements. It appears that resizing is made when the browser trigger a resize event (after calling $(window).trigger('resize'), the graph was correctly updated. You should precise this in the documentation containing Note: After calling resize, everything works as expected for Firefox AND Chrome |
@oesmith I'm setting data to [] to display nothing with |
Doesn't seem to work for me. I have my charts laid out in a table with multiple columns. Here's the markup: <table class="table tableBordered" width="100%">
<tbody>
<tr>
<td width="50%">
<strong>Pledge-count for the last 30 days</strong><br>
<div id="dashboardPledgesMonthCount" style="height: 160px"></div>
</td>
<td width="50%">
<strong>Amounts pledged from day-to-day</strong><br>
<div id="dashboardPledgesMonthAmounts" style="height: 160px"></div>
</td>
</tr> And these are the callers: [...]
Morris.Bar({
barColors: ['#cdcdcd'],
data: countData,
element: 'dashboardPledgesMonthCount',
grid: false,
gridTextFamily: 'Noto Sans',
hideHover: 'auto',
labels: ['Pledges Made'],
resize: true,
xkey: 'date',
ykeys: ['Pledges Made'],
});
[...]
Morris.Line({
data: amountData,
element: 'dashboardPledgesMonthAmounts',
grid: false,
gridTextFamily: 'Noto Sans',
hideHover: 'auto',
labels: ['Amount Pledged'],
lineColors: ['#242d3c', '#cdcdcd'],
parseTime: false,
preUnits: 'R ',
resize: true,
xkey: 'date',
xLabels: 'date',
ykeys: ['Amount Pledged'],
}); Result after resizing: |
Just picked up that if it is loaded with a small width, it will resize up (grow wider), but it won't resize down (thinner). |
Are there any plans to fix the issues with the resize ability of the plugin? I've set resize: true on all my charts but it doesn't appear to be working as intended? |
I did it like this:
Also to avoid getting a too wide svg, see to it that you dont forget the CSS:
View result: |
Thanks jonathanolsen! This worked perfectly! |
Also running into this problem. Resizing on window change works perfectly fine. My issue is resizing when the charts parent container resizes. For instance, I am using BS3 and showing my charts in portlets. Say the portlet is 400px on load... now the dimensions of the portlet change to say 800px. The chart stays exactly the same as it was because the window has not resized, but instead its parent container did (the portlet). I tried a similar chart plugin, Flot, which works exactly as expected in this case. It resizes to fit the size of its container rather than on window resize... problem is I like Morris charts much more than Flot. I thought the original poster of this thread was talking about the same thing as I am, but the solution provided is only for window resize. Anyone else manage to get something like this working? |
SVG is notoriously tricky on the resizing front. I'll have a dig and see if there is a way to scale from Raphael. |
Just for your information. I stopped using the redraw thingy. Because It was making Firefox halt.. badly. :p |
To clarify, you can achieve this result by using jQuery .show() and .hide() on the graph. |
Graph re-sizes when i minimize my window but stays in minimized sized even when i maximized the window. To make it fit to window i've to reload the browser every time. Any solutions? |
Thanks @JonathanOlsen. +1 |
Thanks a lot @JonathanOlsen +1 |
TNXXXXXXXXXXXXXXXXXXXXXXXX ALOT 💃 |
I achieve dynamic resizing using JQuery div resize.
Make a variable and all Morris chart initialization you required but make sure not to include the following properties while initializing Morris chart redraw: true and resize: true
Here the jquery resize function magic
Whenever DIV resize the Morris Chart automatically fit to it's parent DIV. |
To prevent it changing the size of the parent div, set the svg size in css like so: |
Hey humans, NOT sure if this is relevant, but I'm using materialize css and I found that when the chart resizes, the svg height keeps growing :/ (could be PBKAC). However if this is an actual issue I found that the following jquery keeps the svg from growing++ $(document).ready(function() {
$("#chartID").find("svg").css("maxHeight", $("#chartID").css("height"))
}) Peace ☮️ |
Is it possible to have a chart resize dynamically with parent div? i.e. 100% height/width
The text was updated successfully, but these errors were encountered: