Rectangle 27 5

One element of the solution is no doubt the rescale = FALSE parameter to igraph::plot() as I suggested in comment. OP asked why ey gets an empty plot with this? It's because the plotting area is still limited to the [-1; 1] interval along both x and y axes. This is default of igraph::plot(). So we need to give xlim = c(-180, 180) and ylim = c(-90, 90) parameters. This already gives a correct positioning. However, if our aim is to produce a figure with the map of the world, maybe it is the best to write the igraph plot onto a cairo SVG device. Then we will be able to place the map behind the graph in any SVG editor (e.g. Inkscape is a great solution), and we are still free to scale and edit the graph and the labels. For doing this, some other igraph.plotting parameters necessary to be set, but this is already about proportions and aesthetics. Here is the code I used to produce the SVG output:

#!/usr/bin/Rscript

require(igraph)
require(Cairo)

df <- data.frame("from" = c("Bob", "Klaus", "Edith", "Liu"), 
    "to" = c("Edith", "Edith", "Bob", "Klaus"))

meta <- data.frame("name" = c("Bob", "Klaus", "Edith", "Liu"), 
    "lon" = c(-74.00714, 13.37699, 2.34120, 116.40708), 
    "lat" = c(40.71455, 52.51607, 48.85693, 39.90469))

g <- graph.data.frame(df, directed = TRUE, vertices = meta)

lo <- layout.norm(as.matrix(meta[,2:3]))

dpi = 1.0
Cairo(file = 'map-graph.svg', type = "svg", 
    units = "in", 
    width = 4 / dpi, 
    height = 2 / dpi, 
    dpi = dpi)

plot.igraph(g, 
    layout = lo, 
    xlim = c(-180, 180), 
    ylim = c(-90, 90), 
    rescale = FALSE, 
    edge.curved = TRUE, 
    edge.arrow.size = 10 / dpi, 
    edge.arrow.width = 0.5 / dpi, 
    vertex.label.dist = 50 / dpi, 
    vertex.label.degree = 90 / dpi, 
    vertex.size = 200 / dpi, 
    vertex.label.cex = 21 / dpi,
    vertex.frame.color = NA, 
    vertex.label.color = '#FFFF00', 
    edge.color = '#FFFFFF',
    vertex.label.family = 'sans-serif',
    edge.width = 16 / dpi)

dev.off()

When the SVG produced by igraph looks fine, we can open it in Inkscape. Then import (Ctrl+i) the map in case it is pixmap; or open if it is vector graphics (e.g. PDF, SVG). Manually scale and position the map to set the same scale as the graph in the SVG (i.e. until the points get to their right place) for proportional scaling, hold the Ctrl in Inkscape. Here is the result of this method:

I think igraph is capable to produce figures like this, but this is not the primary aim of this software, so it has its limitations. At some point you might consider to use some Geographic Information System (GIS) software which is designed exactly to do things like this. I have no experience with those, but qgis probably worths to take a look at.

This is perfect. Great solution. The great circles suggestion was really useful as well (flowingdata.com/2011/05/11/) to visually do what I needed.

geolocation - Using geo-coordinates as vertex coordinates in the igrap...

r geolocation igraph network-analysis
Rectangle 27 29

This is in case someone is having the same problem on Ubuntu 14.04, as I did using Python 3.4.3. By using bits and hints from JDong's answer, I've solved the problem as follows. (Basically change the MatPlotLib backend to qt5agg.)

The above steps have solved it for me on Ubuntu 14.04. I hope that helps.

Confirmed to work in Ubuntu 14.04 with Python 3.4 - FWIW the file appear to be installed in /usr/local/lib/python3.4/dist-packages/matplotlib/mpl-data/matplotlibrc and that should be the same for everyone (although the method suggested by @Ray works just fine).

Python matplotlib Cairo error - Stack Overflow

python matplotlib plot python-3.4
Rectangle 27 6

This does seem to be a real issue; upon further playing I found an error message:

/usr/lib/python3.4/site-packages/matplotlib/backends/backend_gtk3agg.py:18:
UserWarning: The Gtk3Agg backend is known to not work on Python 3.x with pycairo.
Try installing cairocffi.
"The Gtk3Agg backend is known to not work on Python 3.x with pycairo."

Oddly however, I did install cairocffi. The best solution I found is to use a different backend, as tcaswell suggested in the comments. I found export to pdf very agreeable with just the line: plt.savefig("Graph.pdf").

skytux mentions that changing the backend to Tk works. https://stackoverflow.com/a/21791045/2534876 shows how to do this.

Mar 2016 update: plotly is a great alternative to matplotlib that I use now. It works with the browser to generate documents and I haven't had platform issues.

Python matplotlib Cairo error - Stack Overflow

python matplotlib plot python-3.4
Rectangle 27 3

Upon installation Matplotlib warned me to install cairocffi, because of incompatibilities in my system. After experiencing the NotImplementedError (plots not being drawn), installing Debian's python3-cairocffi package solved the problem.

This should be voted up. Much better solution than changing the backend to Qt.

Python matplotlib Cairo error - Stack Overflow

python matplotlib plot python-3.4
Rectangle 27 2

In the case of Python 2.7 it can be solved by installing the package python-pyqt5 and using pyplot like this:

import matplotlib
matplotlib.use('Qt5Agg')
import matplotlib.pyplot as plt

If you have sudo acces you can also set Qt5Agg as your default backend, see Matplotlib Backend for other ways to set your backend.

Python matplotlib Cairo error - Stack Overflow

python matplotlib plot python-3.4
Rectangle 27 50

Scaling by a fixed value isn't a good idea... as I'm sure anyone who used the accepted answer here probably found out when the iPhone 5 came out.

Here's a code snippet to scale dynamically based on the screen resolution to eliminate the letter boxing.

// Device's screen size (ignoring rotation intentionally):
CGSize screenSize = [[UIScreen mainScreen] bounds].size;

// iOS is going to calculate a size which constrains the 4:3 aspect ratio
// to the screen size. We're basically mimicking that here to determine
// what size the system will likely display the image at on screen.
// NOTE: screenSize.width may seem odd in this calculation - but, remember,
// the devices only take 4:3 images when they are oriented *sideways*.
float cameraAspectRatio = 4.0 / 3.0;
float imageWidth = floorf(screenSize.width * cameraAspectRatio);
float scale = ceilf((screenSize.height / imageWidth) * 10.0) / 10.0;

self.ipc.cameraViewTransform = CGAffineTransformMakeScale(scale, scale);

I'm still getting a black line at the bottom when using iPhone 5..

@Danpe were you able to find a solution for iPhone 5? I am having the same issue - thanks!

@steve, could you take a look at this for iPhone 6/iPhone 6Plus please, this doesn't quite fill up the screen yet. A simple project with the imagepicker loading in the parent view controller as a test with this code copied and pasted will yield the same results as mine. Please do get back to us, cheers.

iphone - UIImagePickerController doesn't fill screen - Stack Overflow

iphone uiimagepickercontroller
Rectangle 27 453

You use an addtional attribute; fill-opacity: This attribute takes a decimal number between 0.0 and 1.0, inclusive; where 0.0 is completely transparent.

<rect ... fill="#044B94" fill-opacity="0.4"/>

Additionally you have the following:

stroke-opacity
opacity

MDN provides a good overview of the this and other related attributes in their SVG Tutorial, developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/

you can also put these in the style attribute: <rect style="fill:#044B94;fill-opacity: 0.4;" />

SVG fill color transparency / alpha? - Stack Overflow

colors svg transparency alpha fill
Rectangle 27 66

I needed something similar and wanted to stick with CSS. Here are LESS and SCSS mixins as well as plain CSS that can help you with this. Unfortunately, it's browser support is a bit lax. See below for details on browser support.

.element-color(@color) {
  background-image: url('data:image/svg+xml;utf8,<svg ...><g stroke="@{color}" ... /></g></svg>');
}
.element-color(#fff);
@mixin element-color($color) {
  background-image: url('data:image/svg+xml;utf8,<svg ...><g stroke="#{$color}" ... /></g></svg>');
}
@include element-color(#fff);
// color: red
background-image: url('data:image/svg+xml;utf8,<svg ...><g stroke="red" ... /></g></svg>');

Here is more info on embedding the full SVG code into your CSS file. It also mentioned browser compatibility which is a bit too small for this to be a viable option.

Although there is a little overhead, because I have to hardcoded all svg items, I think this is the best solution for a while. Thanks

You should mention whether this mixin thing is actually a CSS feature or not.

Is it valid CSS? (I mean the mixin, not the data URI or the SVG.)

Note that you must urlencode the # character for your hex colors to make this work in Firefox. So something like <svg fill="#ffffff" ...></svg> becomes <svg fill="%23ffffff" ...></svg>.

html - Modify SVG fill color when being served as Background-Image - S...

html css html5 css3 svg
Rectangle 27 31

Yet another approach is to use mask. You then change the background color of the masked element. This has the same effect as changing the fill attribute of the svg.

<glyph class="star"/>
<glyph class="heart" />
<glyph class="heart" style="background-color: green"/>
<glyph class="heart" style="background-color: blue"/>
glyph {
    display: inline-block;
    width:  24px;
    height: 24px;
}

glyph.star {
  -webkit-mask: url(star.svg) no-repeat 100% 100%;
  mask: url(star.svg) no-repeat 100% 100%;
  -webkit-mask-size: cover;
  mask-size: cover;
  background-color: yellow;
}

glyph.heart {
  -webkit-mask: url(heart.svg) no-repeat 100% 100%;
  mask: url(heart.svg) no-repeat 100% 100%;
  -webkit-mask-size: cover;
  mask-size: cover;
  background-color: red;
}

One thing to note on this is browser support. I believe IE (as usual) is way behind on this.

Unfortunately mask is neither supported by IE nor Edge: caniuse.com/#search=mask

Does not work on IE 11 (11.608.15063.0)

html - Modify SVG fill color when being served as Background-Image - S...

html css html5 css3 svg
Rectangle 27 42

I think the only way for you to do this is to serve your svg from some server side mechanism. Simply create a resource server side that outputs your svg according to GET parameters, and you serve it on a certain url.

Then you just use that url in your css.

Because as a background img, it isn't part of the DOM and you can't manipulate it. Another possibility would be to use it regularly, embed it in a page in a normal way, but position it absolutely, make it full width & height of a page and then use z-index css property to put it behind all the other DOM elements on a page.

Don't forget if you're serving the SVG from a server-side script, to make sure you also send the correct MIME header. In PHP this would be: <?php header('Content-type: image/svg+xml'); ?>

You can use the svg image as mask and manipulate the background-color of the element. This will have the same effect as changing the fill. (detailed answer provided)

This answer was great as of 2012, but now CSS masks and/or filters have been supported in all browsers for some time. I recommend that anyone reading this now check out the links in widged's answer below or just skip to CSS Masks here, which is a really easy solution -- note it still requires 2 version of the rule, one with -webkit- prefix at the present time. For Microsoft Edge, currently CSS filters are supported but not yet masks.

html - Modify SVG fill color when being served as Background-Image - S...

html css html5 css3 svg
Rectangle 27 37

The camera's aspect ratio is 4:3 and the screen's aspect ratio is 3:2. So there is simply no way for the camera picture to fill the screen unless you're willing to crop is to 3:2. To do that, apply an appropriate scale transform.

This was exactly it. Thanks! I'm going to update my question with the code that got everything working.

Does anyone have an answer to this that will work on all devices? Scaling with the factors above will distort the picture and scaling with ANY hard-coded number will only work on a device with the same form factor and coordinate system. Is there a way to find the camera view frame and bounds and adjust to the window's bounds?

iphone - UIImagePickerController doesn't fill screen - Stack Overflow

iphone uiimagepickercontroller
Rectangle 27 1102

They're the same thing (in API Level 8+). Use match_parent.

FILL_PARENT (renamed MATCH_PARENT in API Level 8 and higher), which means that the view wants to be as big as its parent (minus padding)

fill_parent: The view should be as big as its parent (minus padding). This constant is deprecated starting from API Level 8 and is replaced by match_parent.

There must be some differences right? Otherwise why Google deprecated it and renamed the new one?

@Halim No, there is no differece: Both are defined as constant -1. I you feel better about it, I don't get the impovement in that either... :-)

@jlovison No, there are no differences. Both are -1. You get the error because the older platform does not know about the new name of the very same constant.

It is so weird that Android Studio still puts "fill_parent" in all default template created layouts! I know they are the same, but I keep coming back to this SO question every year to make sure no one has discovered that there really is a difference. Can the Google/Android-team please change the default value from "fill_parent" to "match_parent"? Thanks in advance! :)

android - What is the difference between match_parent and fill_parent?...

android android-layout
Rectangle 27 1

python-gi-cairo
sudo apt-get install python-gi-cairo

Python matplotlib Cairo error - Stack Overflow

python matplotlib plot python-3.4
Rectangle 27 542

Update: There are reports this no longer works in Chrome.

$(".date-pick").datepicker('setDate', new Date());

This is a MUCH nicer solution than the accepted solution!

This will not work, first you should call $(".date-pick").datepicker(); and then $(".date-pick").datepicker('setDate', new Date());

javascript - How do I pre-populate a jQuery Datepicker textbox with to...

javascript jquery jquery-ui date jquery-ui-datepicker
Rectangle 27 507

2015 update: the flexbox approach

There are two other answers briefly mentioning flexbox; however, that was more than two years ago, and they don't provide any examples. The specification for flexbox has definitely settled now.

Note: Though CSS Flexible Boxes Layout specification is at the Candidate Recommendation stage, not all browsers have implemented it. WebKit implementation must be prefixed with -webkit-; Internet Explorer implements an old version of the spec, prefixed with -ms-; Opera 12.10 implements the latest version of the spec, unprefixed. See the compatibility table on each property for an up-to-date compatibility status.

All major browsers and IE11+ support Flexbox. For IE 10 or older, you can use the FlexieJS shim.

With flexbox you can easily switch between any of your rows or columns either having fixed dimensions, content-sized dimensions or remaining-space dimensions. In my example I have set the header to snap to its content (as per the OPs question), I've added a footer to show how to add a fixed-height region and then set the content area to fill up the remaining space.

html,
body {
  height: 100%;
  margin: 0
}

.box {
  display: flex;
  flex-flow: column;
  height: 100%;
}

.box .row {
  border: 1px dotted grey;
}

.box .row.header {
  flex: 0 1 auto;
  /* The above is shorthand for:
  flex-grow: 0,
  flex-shrink: 1,
  flex-basis: auto
  */
}

.box .row.content {
  flex: 1 1 auto;
}

.box .row.footer {
  flex: 0 1 40px;
}
<!-- Obviously, you could use HTML5 tags like `header`, `footer` and `section` -->

<div class="box">
  <div class="row header">
    <p><b>header</b>
      <br />
      <br />(sized to content)</p>
  </div>
  <div class="row content">
    <p>
      <b>content</b>
      (fills remaining space)
    </p>
  </div>
  <div class="row footer">
    <p><b>footer</b> (fixed height)</p>
  </div>
</div>

In the CSS above, the flex property shorthands the flex-grow, flex-shrink, and flex-basis properties to establish the flexibility of the flex items. Mozilla has a good introduction to the flexible boxes model.

Why the flex: 0 1 30px; attribute in box .row as it's override in every div?

Here's the browser support for flexbox - nice to see all that green - caniuse.com/#feat=flexbox

Link to Flexie.js is dead. Here the github project github.com/doctyper/flexie

Definitely it is a very good approach and it almost work ;) There is a small problem when a content of div.content exceeds an original flex-ed height. In current implementation the "footer" will be push lower and this is not what the developers expects ;) So I made an very easy fix. jsfiddle.net/przemcio/xLhLuzf9/3 I added additioal flex on container and overflow scroll.

@przemcio nice point, but I don't think having scrollable content is what every developer expects ;) you should only need to add overflow-y: auto to .row.content to achieve what you need however.

css - Make a div fill the height of the remaining screen space - Stack...

css html html-table
Rectangle 27 46

byte, int are primitive, collection works on object. you need something like this

public static Map<Byte, Integer> sizeNeeded = new HashMap<Byte, Integer>() {

        {
            put(new Byte("1"), 1);
            put(new Byte("2"), 2);
        }

        ;
    };

Not me, but probably because of new Byte((byte) 1).. and maybe not relying on autoboxing.. And the not used ; at the end of the init clause.. just looks ugly!

-1 from be because I think this is a horrible abuse, and you're not even explaining what it is.

java - Fill hash map during creation - Stack Overflow

java collections initialization
Rectangle 27 307

According to Android platform developer Dianne Hackborn in this discussion group post, Dialogs set their Window's top level layout width and height to WRAP_CONTENT. To make the Dialog bigger, you can set those parameters to MATCH_PARENT.

AlertDialog.Builder adb = new AlertDialog.Builder(this);
    Dialog d = adb.setView(new View(this)).create();
    // (That new View is just there to have something inside the dialog that can grow big enough to cover the whole screen.)

    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    lp.copyFrom(d.getWindow().getAttributes());
    lp.width = WindowManager.LayoutParams.MATCH_PARENT;
    lp.height = WindowManager.LayoutParams.MATCH_PARENT;
    d.show();
    d.getWindow().setAttributes(lp);

Note that the attributes are set after the Dialog is shown. The system is finicky about when they are set. (I guess that the layout engine must set them the first time the dialog is shown, or something.)

It would be better to do this by extending Theme.Dialog, then you wouldn't have to play a guessing game about when to call setAttributes. (Although it's a bit more work to have the dialog automatically adopt an appropriate light or dark theme, or the Honeycomb Holo theme. That can be done according to http://developer.android.com/guide/topics/ui/themes.html#SelectATheme )

Whether I don't understand the answer, or it doesn't work for me.

I dont get how this answers the question? Does the code suggested by @nmr make the Dialog to be 90% of the screen? Cause I dont see it. The dialog is just set to fill_width, so thats 100%, not 90%, right?

@Ted, the theme used by AlertDialog has a margin. So the result does not reach to the edge of the screen, it fills about 90% of it. (It's definitely not exactly 90%, just an aesthetic approximation of 90%)

Just calling d.getWindow().getAttributes().width = WindowManager.LayoutParams.FILL_PARENT; before calling show() will do the trick. Also, I've had some issues with the given method as background of the dialog was becoming non-transparent. As soon as removed copyFrom(() the problem fixed itself.

android - How to make an alert dialog fill 90% of screen size? - Stack...

android dialog
Rectangle 27 38

Auto-sizing Images to Fit a Div - Making the CSS Work

Here is one way of doing it, start with the following HTML:

<div class="container portrait">
    <h4>Portrait Style</h4>
    <img src="http://placekitten.com/150/300">
</div>

and the CSS:

.container {
    height: 300px;
    width: 240px;
    background-color: red;
    float: left;
    overflow: hidden;
    margin: 20px;
}
.container img {
    display: block;
}

.portrait img {
    width: 100%;
}
.landscape img {
    height: 100%;
}

When you have an image oriented as a portrait, you need to scale the width to 100%. Conversely, when the image is landscape oriented, you need to scale the height.

Unfortunately, there is no combination of selectors in CSS that targets the aspect ratio of the image, so you can't use CSS to pick out the correct scaling.

In addition, you have no easy way of centering the image since the top left corner of the image is pinned to the top left corner of the containing block.

You can use the following jQuery action to determine which class to set based on the aspect ratio of the image.

$(".container").each(function(){
    // Uncomment the following if you need to make this dynamic
    //var refH = $(this).height();
    //var refW = $(this).width();
    //var refRatio = refW/refH;

    // Hard coded value...
    var refRatio = 240/300;

    var imgH = $(this).children("img").height();
    var imgW = $(this).children("img").width();

    if ( (imgW/imgH) < refRatio ) { 
        $(this).addClass("portrait");
    } else {
        $(this).addClass("landscape");
    }
})

For each image in .container, get the height and width, test if width<height and then set the appropriate class.

Also, I added a check to take into account the aspect ratio of the containing block. Before, I had implicitly assumed a square view panel.

Hi. Thanks, this is working very well - great explanation, too!

Glad to help! You can embellish the jQuery to center the image if you need to.

However, the dimensions of the div are 240x300, so the simple imgW < imgH doesn't work if an image is e.g. 250x300. It should be landscape in this case, but is already handled as a portrait image. Any way to include the 4:5 ratio in that JS?

I extended the jQuery code to account for the aspect ratio of the view panel.

javascript - Make image fill div completely without stretching - Stack...

javascript html css image
Rectangle 27 17

Hey I saw some people were still getting the black bar at the bottom after calculating the scale for the iPhone 5. I had this problem for a while but then I figured out you have to translate the view so it is in the middle of the screen and then apply the scale. Here is my code for doing those two things and it works for me!

CGSize screenBounds = [UIScreen mainScreen].bounds.size;

    CGFloat cameraAspectRatio = 4.0f/3.0f;

    CGFloat camViewHeight = screenBounds.width * cameraAspectRatio;
    CGFloat scale = screenBounds.height / camViewHeight;

    m_imagePickerController.cameraViewTransform = CGAffineTransformMakeTranslation(0, (screenBounds.height - camViewHeight) / 2.0);
    m_imagePickerController.cameraViewTransform = CGAffineTransformScale(m_imagePickerController.cameraViewTransform, scale, scale);

This solution works great on the iPhone 5. However, as reported in this question, CGAffineTransformTranslate doesn't work in UIImagePickerController with older iOS (not sure when they fixed it). In addition, it seems that you need to do the ceilf rounding trick in Steve's answer in order for the CGAffineTransformScale to work in older iOS.

You are right, I should have added "iPhone 5 running iOS 7". I was pulling my hair out for a while with the CGAffineTransformScale not working in older iOSs.

Working great. Saved a lot of time.

@strikerdude10 Thanks a lot buddy !

iphone - UIImagePickerController doesn't fill screen - Stack Overflow

iphone uiimagepickercontroller
Rectangle 27 266

It sounds like you want a StackPanel where the final element uses up all the remaining space. But why not use a DockPanel? Decorate the other elements in the DockPanel with DockPanel.Dock="Top", and then your help control can fill the remaining space.

<DockPanel Width="200" Height="200" Background="PowderBlue">
    <TextBlock DockPanel.Dock="Top">Something</TextBlock>
    <TextBlock DockPanel.Dock="Top">Something else</TextBlock>
    <DockPanel
        HorizontalAlignment="Stretch" 
        VerticalAlignment="Stretch" 
        Height="Auto" 
        Margin="10">

      <GroupBox 
        DockPanel.Dock="Right" 
        Header="Help" 
        Width="100" 
        Background="Beige" 
        VerticalAlignment="Stretch" 
        VerticalContentAlignment="Stretch" 
        Height="Auto">
        <TextBlock Text="This is the help that is available on the news screen." 
                   TextWrapping="Wrap" />
     </GroupBox>

      <StackPanel DockPanel.Dock="Left" Margin="10" 
           Width="Auto" HorizontalAlignment="Stretch">
          <TextBlock Text="Here is the news that should wrap around." 
                     TextWrapping="Wrap"/>
      </StackPanel>
    </DockPanel>
</DockPanel>

If you are on a platform without DockPanel available (e.g. WindowsStore), you can create the same effect with a grid. Here's the above example accomplished using grids instead:

<Grid Width="200" Height="200" Background="PowderBlue">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <StackPanel Grid.Row="0">
        <TextBlock>Something</TextBlock>
        <TextBlock>Something else</TextBlock>
    </StackPanel>
    <Grid Height="Auto" Grid.Row="1" Margin="10">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="100"/>
        </Grid.ColumnDefinitions>
        <GroupBox
            Width="100"
            Height="Auto"
            Grid.Column="1"
            Background="Beige"
            Header="Help">
            <TextBlock Text="This is the help that is available on the news screen." 
              TextWrapping="Wrap"/>
        </GroupBox>
        <StackPanel Width="Auto" Margin="10" DockPanel.Dock="Left">
            <TextBlock Text="Here is the news that should wrap around." 
              TextWrapping="Wrap"/>
        </StackPanel>
    </Grid>
</Grid>

Brilliant! I've spent the last hour trying to figure out how to get StackPanel to do this. From now on, I'll look here first for my WPF (and other) info.

I can't believe how much time I've spent trying to get StackPanels to do what I wanted. Thanks for sharing! DockPanels are what I wanted all along.

@Teomanshipahi have updated with an alternative using Grid

wpf - How to get StackPanel's children to fill maximum space downward?...

wpf xaml autolayout autoresize dockpanel