I have been trying to use CSS grid layout with dc-js.
The graphs are defined without specifying a height and a width, letting the grid do its theoretical job.
I end up with something like the following image, where the graph ends up occupying only a third of the lateral space I had set for it in the grid layout. The svg within each individual graph's div still has default height and width set for some reason.
Is that the expected behaviour ?
If it isn't how do I solve this issue ?
EDIT : of course it works in this jsFiddle... I'm using dc version 3.0.12 if that helps.
Resizing and setting the width and height of a chart based on its container are not completely automatic in dc.js.
As you discovered, the default width and height are 200. But you can cause the chart to calculate either one by passing a non-number such as null.
This is partly for historical reasons and partly to provide more control. dc.js didn't have these features early on, and we usually try to add features in a backward-compatible way.
If your grid changes size when the window changes size, you can add an onresize listener that causes every chart to resize the SVG to the same size as the chart div:
window.onresize = function() {
[chart1,chart2,chart3,chart4].forEach(
c => {
c.width(null).height(null).rescale();
redraw_chart_no_transitions(c);
});
};
If onresize is not to your taste, take a look at the resize observer scatter example for a more modern approach. You may need a resize observer if the grid will resize for another reason than window resize.
redraw_chart_no_transitions is a small utility function available here that temporarily sets transitionDuration to zero so that redraw does not animate. Animated transitions are not good for actions that give immediate feedback like resize, pan, and zoom.
I was able to reproduce the problem pictured in your question with your fiddle by making the window really large.
To get the grid layout to use all the space I added the following CSS (not perfect, there's some stuff I don't understand here):
html, body {
position: absolute; top: 0; left: 0; right: 0; bottom: 0;
margin: 1em;
}
#test {
position: absolute; top: 0; left: 0; right: 0; bottom: 0;
/* ... */
}
By default grid cells can get larger but not smaller. Specify min-width: 0 and min-height: 0 to allow them to get smaller:
#test div {
min-width: 0; min-height: 0;
}
Here is a fork of your fiddle with four charts that fill the window and resize when the window is resized.
Posting this answer for any lost souls finding this question.
In my specific case, my grid was on a JQuery tab which was hidden on initialization of the dc graphs.
var width = element && element.getBoundingClientRect && element.getBoundingClientRect().width; at line 24 of the base-mixin (or line 1416 of dc.js) returned 0 for all my charts.
So dc could not calculate the correct sizes and ended up using default for everything.
Once I solved that, #Gordon's answer helped me for resizing.
Related
I have a dynamically generated list of moderators on a minecraft network with a tooltip generated for each head that is generated showing their username on hover. The functionality works, the tooltip generates and has the correct username in it however, the position is wrong. It's shifted to the left and falls apart as I move down the list. Here's a gif on what's happening:
I simply do not know what to do in this situation.
Well the plugin seems to work correctly (if the names are okay), I suppose it might be a css issue. Maybe the parts of the tooltip get somehow some margin on them. try to inspect them with right click and see if they have any other style attributes than the defaults.
Anyway, if you could post some of the codes, that would be easier.
Seems like this page has changed since you asked this question, but I bet it was a CSS issue. You probably needed to center the tooltip box relative to its parent. Here's some (unvetted) code that might help. I've only included the properties that would affect the centering on the tooltip container:
.parent {
position: relative;
}
.tooltip-container {
position: absolute;
left: 50%;
width: 100px;
margin-left: -50px;
}
Notice, you have to set a width on the tooltip-container. margin-left is 1/2 the width, and negative (visualize that left: 50% will put the left edge of the container at the center of the parent, and the negative margin-left will shift the container half the width of the container).
I have an image that I am using as a loading animation that is 755px wide.
http://www.salts-studios.com/resources/working_large.gif
The things is I have a requirement in one section of an app I am developing where the image width must be fluid.
IE 8 is the main supported browser (I know, I know) so scaling the image up when required isnt an option.
I cant change the image, but I could create a new additional one so long as it looked identical in style to the original.
Can anybody recommend any technique to achieve a fully fluid width?
I've tried various sliding door techniques but they fall over as the image is animated.
Thanks in advance.
There's a rather simple solution to this. In a parent div, set it to width: 100%, and set the child image also to width: 100%. Here's an example:
.bar {
width: 100%;
}
.bar img {
width: 100%;
height: 19px;
}
And here's a JSBin that has a working example
Drag your browser window to different sizes and watch the image width resize. Let me know if this is what you were thinking should happen.
I'm quite new to web development and jQuery, so please bear with me.
I'm using Nivo Slider on a website that I'm working on. It's a responsive website, and I want the slider to be easily visible on all screen sizes. I've set a breakpoint in my CSS so that when the site gets to its smallest size (around the size of a mobile screen) the slider is set to 200% width, with the overflow hidden, so that the images are larger.
This works fine, however at this size you can only see the center of the slider, while the sides are cropped off by the edge of the screen. For most of the images I'm using this isn't a problem, however one of them is cropped very awkwardly. It's easy to reposition the whole slider, but I want to try and move this ONE image over so that it can be better seen on small screens.
The CSS I've added to the default nivo-slider.css is:
#media screen and (max-width: 31.25em) { /* 500px ÷ 16px */
.slider-wrapper{
overflow: hidden;
}
.nivoSlider {
left: -50%;
width:200%;
}
.nivo-caption {
margin-left: 25%;
width: 50%;
}
}
Thanks very much!
Just using CSS, you could add a one-off type class to that particular image, and throw that into your #media query:
.my-one-off { left:??px; margin-right:??px }
You could search for that image with jQuery as well (if I'm not mistaken, Nivo uses the jQ library).
$('img[src*="one-off.jpg"]').css('margin-left',35); // just an example
Or
$('img[src*="one-off.jpg"]').addClass('my-one-off');
I looked at nivo-slider3.1. In order to select a particular image only and move it left you could use the following in css:
img[src="YourSpecialPic.jpg"]{
left:50px !important;
}
You can also set a custom animation for one particular slide with the following img attribute within the HTML:
data-transition="slideInLeft"
You can sub any attributes to get the desired effect, but I think this will do the trick.
NOTE:
Depending on what effects you are using will determine whether or not that messes up the animation (e.g. The slicing animation becomes screwed up after performing the left move. The slideInLeft animation seems to work fine.).
I don't have a quick or easy solution for fixing all the animation effects for that one particular slide, but I'm sure a conditional statement within the javascript could achieve it (I'm just not smart enough for it).
I've stumbled upon an interesting problem while playing with my website.
So I've got a containing column with a fixed width. In this I have a number (two for now, don't know whether it'll matter) of images in one row. The images' size and aspect ratio are undetermined and not equal to each other. Now, I'm looking to resize them, so that their height is equal, and their combined width is equal to that of the parent container, while keeping their aspect ratio. And also resize the container height accordingly, for that matter.
Hope I made myself clear.
I'm sure it's possible with JavaScript or similar, but I'm mainly interested in if there's a solution using CSS.
Thanks
I think that's impossible, and even if it were possible, it would be the darkest css hack i've ever seen (besides it would imply using not-very-compatible CSS). It's way easier and recommendable doing that with Javascript. (EDIT: for a jQuery solution see this: http://jsfiddle.net/martinschaer/aJtdb/)
But, for fun I did this: http://jsfiddle.net/martinschaer/cGZrF/
It's the closest you can do with CSS3 for what you need. There's a small gap that fills empty vertical space, but all the images are resized with CSS to fit in the container.
.container{
width: 600px;
margin: 10px;
background-color: #000;
display: box;
box-orient: horizontal;
box-pack: center;
box-align: center;
}
.imgwrapper {
box-flex: 1;
}
img{
max-width: 100%;
height: auto;
display:block;
}
See the jsfiddle (http://jsfiddle.net/martinschaer/cGZrF/) for the full code compatible with mozila and webkit.
EDIT: for a jQuery solution see this: http://jsfiddle.net/martinschaer/aJtdb/
I'm not too experienced with JavaScript yet, but I have one addition to make for any late comers (like myself)…
I noticed that using the provided JSFiddle in Martin's answer on multiple rows compresses the images so I'd like to add that this:
var rows = 0; // set row count for multiple 'imageWrapper' divs
$('.imageWrapper').each(function(){
rows +=1;
});
and then use rows like this:
$('.imageWrapper img').each(function(){
this.width = $(this).data('width') * (container_width / container_width_temp) * rows - 8;
});
the - 8 is because I found that the last image in the row tends to overflow the container and get pushed into a row by itself.
I'm still looking for the perfect answer to this question myself, but this got me a little closer.
I've been using jQuery Tools' overlay for some time, but I don't know what to do when the browser window isn't large enough to accomodate the contents of the overlay.
Check out the jQuery Tools example page and see what I mean:
Click one of the images to make an overlay appear
Resize your window so that the entire overlay can't fit
This may seem like a simple problem with an easy solution (make your browser window larger), but I work on a website that caters to older people, whose monitors may be set at low resolutions.
Any idea what I can do, short of building my own javascript overlay utility?
You could specify the size of the overlay div in % so that it always fits on the screen.
overlay_div {
height: 60%;
overflow-y: auto;
}
Max height solution without scroll:
overlay_div {
max-height: 95%;
}
overlay_div img {
max-height: 95%;
}
In script:
$(document).ready(function() {
$("img[rel]").overlay({
top: 25
});
});