How can I make the size of stacked-area-chart in nvd3-angularjs-directives adjustable depending on the size of the div? - width

I have a chart created using nvd3-angularjs-directives. I want the size of this graph adjust depending on the size of its div. My problem initially is that the value of y reach this value 2000000000 and the label is cut off somewhere in between. I want the graph to be able to adjust so that the whole graph even the label will be displayed correctly.
Here's the chart
<div ng-controller="GraphController">
<nvd3-stacked-area-chart
data="GraphData"
id="Graphs"
showXAxis="true"
showYAxis="true"
showLegend="true"
interactive="true"
tooltips="true"
objectEquality="true"
width="auto"
xAxisTickFormat="xAxisTickFormatFunction()"
yAxisTickFormat="yAxisTickFormatFunction()"
>
<svg></svg>
</nvd3-stacked-area-chart>
</div>
1) I changed the value of width equal to auto. But it didn't work.
2) I added this in the div style="color:blue;width:auto;". It didnt work as well

I believe in you have to give it an absolute size. What I did to work around this was to define the size inline:
<nvd3-stacked-area-chart
style="width:{{chartSettings.width}}px; height:{{chartSettings.height}}px;"
...
</nvd3-stacked-area-chart>
and then determine the size dynamically in the controller:
$scope.chartSettings= {
width: $window.innerWidth*0.8,
height: $window.innerHeight*0.8
}

Related

Tabulator layout:"fitColumns" causes vibrating DIV

I have a tabulator 4.9 contained within one element of a flexbox. The flexbox element has flex-grow>0.
Some of my columns are hidden during the initial draw. The select element above the table hides columns and shows the selected column, and redraws the table.
When using layout:"fitColumns", the table has two issues when first rendered-
The table is wider than it's container, by roughly the width of the scrollbar. Changing the selectbox above the table causes the table to redraw and fixes this issue.
The table vibrates erratically. Both the container DIV and the table are shifting back and forth by 1 or 2 pixels. They appear to be stuck in a feedback loop.
I am using Chrome 87.0.4280.141 (Official Build) (64-bit)
Example here:
https://beta.tspcenter.com/tabulator.php
Tabulator code:
table = new Tabulator("#leaderboardTablesContainer", {
height: "311px",
layout:"fitColumns",
index:"Username",
data: results,
columns:headers,
initialSort:[{column:firstVisibleColumn, dir:"desc"}]
});
Select element code:
select.addEventListener('change',function(e) {
table.clearFilter();
table.hideColumn(table.currentColumnVisible);
table.showColumn(e.target.value);
table.setSort(e.target.value,"desc");
table.currentColumnVisible = e.target.value;
table.setFilter(e.target.value, "!=", "");
table.redraw();
});
I'm not sure why this works. But specifying a width on the flex-element fixed the problem.
flex: 2000 1 450px; width: 5px;
It seems to go against my understanding of flexbox. And indeed, the flexbox grows well past the 5px anyway. It seems kind of hacky but it stops the feedback loop problem and the table displays correctly.

React Virtualized - Render Table with full height to show all rows

According to the react-virtualized docs, "The AutoSizer component decorates a React element and automatically manages width and height properties so that decorated element fills the available space".
The suggestion is usually to add height: 100%; or flex: 1; to all parent elements in the DOM to render the table's full height.
What if one of those elements, e.g. an absolutely positioned full page overlay container, has height: 100vh; overflow: scroll; ?
In this case, the Table's parent height is 100vh, but allows overflow if the children have height greater than 100vh.
Say our table has many rows of varying height and exceeds 100vh when rendered. Autosizer will return a height in pixels that equals 100vh, as a maximum, meaning the last rows in our table will be cutoff as AutoSizer will not stretch its parents height to render all rows.
My current workaround is to use <CellMeasurer /> and CellMeasurerCache() to manually determine table height from this.cache; // (component instance of CellMeasurerCache) using private properties, for example in my table component:
componentDidUpdate = () => {
const { tableHeight } = this.state;
const tableRowHeights = Object.values(this.cache._rowHeightCache);
const newRowsHeight = tableRowHeights.reduce(
(height, nextRowHeight) => height + nextRowHeight,
0
);
if (tableHeight !== newRowsHeight) {
this.setState({ tableHeight: newRowsHeight });
}
}
Is there no way to accomplish this with react-virtualized components and APIs,without accessing private properties from the CellMeasurerCache() instance?
What if one of those elements, e.g. an absolutely positioned full page overlay container, has height: 100vh; overflow: scroll; ?
In this case, the Table's parent height is 100vh, but allows overflow if the children have height greater than 100vh.
I don't think this (overflow behavior) make sense in the case of react-virtualized. In most cases- unless you're using WindowScroller for a Facebook/Twitter like layout- react-virtualized components should manage their own scrolling.
So in that case, if 100vh height is available, you would want RV to fill exactly that amount and- if there's more content than will fit into that area- (which is likely, if you're using RV in the first place)- it will setup the scrolling styles within itself.
On the other hand, if you tell a react-virtualized component that its height is numRows * rowHeight then it's going to render everything, and completely defeat the purpose of windowing. :)

How to control line height between non block level elements with different font sizes?

I have a layout where I need to control the line height between wrapped non block level elements:
<p class="payments"><small class="light">You Pay</small><abbr title="GBP">£</abbr>121.50<br><small>per month</small></p>
What I want to achieve is something like:
I don't want to rely on absolute positioning as there will be elements beneath which need to clear this and simply setting a low line-height on he paragraph results in an object which breaks out of its box, see the Fiddle below:
http://jsfiddle.net/mdHKy/2/
Any ideas?
You can first give the p a height then set its line-height to half that amount (being 2 lines).
p.payments {
line-height: 1em;
height:2em;
}
Then set the line-height of small to 1em and give that a vertical-align:
p.payments small {
line-height:1em;
vertical-align:top;
}
Then set the vertical-align of your .light:
p.payments small.light {
vertical-align:baseline;
}
JSFiddle example.

Dojo and heights of widgets

I am trying to figure out how "heights" are worked out when instancing a widget.
I am not going very far...
At the moment, I have a simple HTML page that goes like this:
</head>
<body class="claro"><div id="appContainer"></div></body>
</html>
The CSS is like this:
html, body {
height: 100%;
margin: 0;
padding: 0;
overflow: hidden;
}
#appContainer {
height: 100%;
}
When my app starts, this happens (this is a simplification):
// Create the "application" object, and places them in the right spot.
appContainer = new BorderContainer( {} , 'appContainer');
Left as it is, the app has the right size and everything.
** Q1: why do I need to specify the height for html, body and #appContainer?
Then, I have:
// Create the new BookingDojo application
bookingDojo = new BookingDojo( { id: 'bookingDojo', region: 'center' } );
appContainer.addChild( bookingDojo );
and finally:
appContainer.startup();
BookingDojo has this CSS:
#bookingDojo {
height: 100%;
}
.bookingDojo {
height: 100%;
}
And uses this template:
templateString: '' +
'<div>' +
' <div class="bookingDojo" data-dojo-type="dijit.layout.BorderContainer" data-dojo-props="design: \'headline\'">' +
' <div data-dojo-type="dijit.layout.TabContainer" data-dojo-props="region: \'center\', tabPosition: \'left-h\'">' +
' <div data-dojo-type="hotplate.bd.Settings" data-dojo-props="title: \'Settings\'">Settings</div>' +
' <div data-dojo-type="dijit.layout.TabContainer" data-dojo-props="title: \'attempt\', tabPosition: \'top\'" data-dojo-attach-point="settingsTab">' +
' <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="title:\'One\'">ONE</div>' +
' <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="title:\'Two\'">TWO</div>' +
' </div>' +
' <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="title: \'Two\'">Section Two</div>' +
' <div data-dojo-type="hotplate.bd.Dashboard" data-dojo-props="title: \'Dashboard\'">Section One</div>' +
' </div>'+
' </div>' +
'</div>',
Note that
class="bookingDojo"
within the widget:
** Q2: If I take out wither #bookingDojo or .bookingDojo from the CSS, the app isn't rendered properly.
I mean, I also have a problem where I cannot get the Dashboard to render properly, because it comes out with height 0, but that's a different (probably related) story for which I have added a different post.
** Q3: Can somebody please explain to me the whole "heights of widgets" issue? I am aware that widgets need startup(), and I am aware that if you create an inner-widget and it's invisible, it will need a resize(). But that's obviously not all I need to know, since I find myself struggling over and over to get a widget to appear (and I go trying CSS, doLayout, resize, etc.) so... well, I must be missing something!
Thanks a million,
Merc.
For Q1, the documentation says :
The outer size must be specified on the BorderContainer node. Width must be specified for the sides and height for the top and bottom, respectively. No dimensions should be specified on the center; it will fill the remaining space.
In your CSS, you are setting the appContainer to take the full screen, because a height of 100% means 100% of the parent element... and your structure is
<html><body><div id="appContainer">...etc
Therefore, you have to set both body and html to 100% if you want your appContainer to take 100% of the screen height...
By default, block elements are already 100% wide, so no need to set the width there...
For Q2, I suggest you have a look at your html in firebug. You will notice a div with id="bookingDojo", which will be the outmost div of your template. The first inner div has a class="bookingDojo". Again, these 2 divs are nested, and for that reason, they both need to be set to a height of 100% if you want them to fill-in the full height of their parent container div (which is your BorderContainer, which you already set to be 100% high). I made a little example here http://jsfiddle.net/psoares/7JQWC/
You will see something like your bookingDojo where I set #bookingDojo to 100% height, but didn't specify a height for the .bookingDojo class. Try to set it and you will see the red border expand...
For Q3, well, I think the whole issue here is understanding how nested boxes get their sizes, so for that you can refer to Q1 and Q2...
I hope this helps...

DOJO ContentPane inner DIV height changing on ContentPane resize

I'm using DOJO's ContentPane module. I have a div element in one of the panes and I need to give it a certain height - 100 pixels less than the height of the ContentPane so that the div changes its height dynamically when you change the ContentPane size by dragging the splitters. I'm new to Dojo and would be happy if somebody could help me with this.
Thanks.
I think the best solution is via nested BorderContainers with properly set splitters, because that way dijit/layout will take care of resizing and you won't need to write any JavaScript code and your layout will be based solely on CSS.
It's kinda cumbersome to explain, so I created a working example for you at jsFiddle: http://jsfiddle.net/phusick/Ayg8F/ + a diagram:
NB: Do not forget to set height: 100% for html, body and the top BorderContainer.
The drawback of this solution is you will have to replace plain divs with ContentPanes. If you do not want to or can't you can use dojo/aspect and connect to BorderContainer or ContentPane resize method and resize your divs manually whenever the size changes:
require([
"dojo/ready",
"dojo/aspect",
"dijit/registry",
"dijit/layout/ContentPane",
"dijit/layout/BorderContainer"
], function(
ready,
aspect,
registry
) {
ready(function() {
var bc = registry.byId("borderContainer1");
aspect.after(bc, "resize", function() {
// calculate and set <div> size here
console.log("resize divs");
});
});
});​

Resources