champagne anarchist | armchair activist

Strava wants my commute data

Dutch tv recently aired a fascinating documentary on the «smart city» phenomenon. Companies like Google are teaming up with local governments to further expand their already huge datasets on human behaviour, raising the spectre of total control and absence of privacy (someone used the word panoptical).

Proponents claim the smart city will make cities more efficient and perhaps even sustainable. But judging by the examples given by Amsterdam’s smart city czar (he was quoted in the same documentary), the main beneficients may well be motorists. Big data is used to help them navigate their car through the city and find a place to park it. In fact, only one out of Amsterdam’s ~100 smart city projects even mentions the word fiets (bicycle).

And now Strava wants my commute data. They’ve proclaimed tomorrow, the 10th of May, Bike to Work Day. If you’ll upload your ride to work, they promise to make your commutes count:

With data like this, cities can better understand how people choose to interact with the network of roads, bike paths and intersections. The result is improved decision-making, smarter planning, safer streets and more people biking, running and walking. Better data is a catalyst for change.

Bringing a bit more balance to the smart city phenomenon by adding lots of cycling data sounds like a good idea. But will it work? When a very similar initiative was run by Dutch cyclists’ organisation Fietsersbond, Bicycle Count Week, a critic argued that some of the worst bicycle infrastructure in Amsterdam can easily be identified without recording any rides. These problems remain unsolved not for lack of data, but for lack of political will.

Personally, I’d argue that data can be useful, if used critically. But I’m not sure the interpretation of data should be left to the smart city alliance of local governments and corporations.

So will I upload my ride to work tomorrow? To be honest, I’ll probably forget to record it in the first place.

The smart city documentary, part of VPRO’s Tegenlicht series, can be seen in Dutch here. The VPRO has translated some of its Tegenlicht (Backlight) documentaries, but I don’t think this one is available in English yet.

Tags: 

Embedding D3.js charts in a responsive website

For a number of reasons, I like to use D3.js for my charts. However, I’ve been struggling for a while to get them to behave properly on my blog which has a responsive theme. I’ve tried quite a few solutions from Stack Overflow and elsewhere but none seemed to work.

I want to embed the chart using an iframe. The width of the iframe should adapt to the column width and the height to the width of the iframe, maintaining the aspect ratio of the chart. The chart itself should fill up the iframe. Preferably, when people rotate their phone, the size of the iframe and its contents should update without the need to reload the entire page.

Styling the iframe

Smashing Magazine has described a solution for embedding videos. You enclose the iframe in a div and use css to add a padding of, say, 40% to that div (the percentage depending on the aspect ratio you want). You can then set both width and height of the iframe itself to 100%. Here’s an adapted version of the code:

<style>
.container_chart_1 {
    position: relative;
    padding-bottom: 40%;
    height: 0;
    overflow: hidden;
}

.container_chart_1 iframe {
    position: absolute;
    top:0;
    left: 0;
    width: 100%;
    height: 100%;
}
</style>

<div class ='container_chart_1'>
<iframe src='http://dirkmjk.nl/2016/embed_d3/chart_1.html' frameborder='0' scrolling = 'no' id = 'iframe_chart_1'>
</iframe>
</div>

Making the chart adapt to the iframe size

The next question is how to make the D3 chart adapt to the dimensions of the iframe. Here’s what I thought might work but didn’t: in the chart, obtain the dimensions of the iframe using window.innerWidth and window.innerHeight (minus 16px - something to do with scrollbars apparently?) and use those to define the size of your chart.

Using innerWidth and innerHeight seemed to work - until I tested it on my iPhone. Upon loading a page it starts out OK, but then the update function increases the size of the chart until only a small detail is visible in the iframe (rotate your phone to replicate this). Apparently, iOS returns not the dimensions of the iframe but something else when innerWidth and innerHeight are used. I didn’t have that problem when I tested on an Android phone.

Adapt to the iframe size: Alternative solution

Here’s an alternative approach for making the D3 chart adapt to the dimensions of the iframe. Set width to the width of the div that the chart is appended to (or to the width of the body) and set height to width * aspect ratio. Here’s the relevant code:

aspect_ratio = 0.4;
var frame_width = $('#chart_2').width();
var frame_height = aspect_ratio * frame_width;

The disadvantage of this approach is that you’ll have to set the aspect ratio in two places: both in the css for the div containing the iframe and in the html-page that is loaded in the iframe. So if you decide to change the aspect ratio, you’ll have to change it in both places. Other than that, it appears to work.

Reloading the chart upon window resize

Then write a function that reloads the iframe content upon window resize, so as to adapt the size of the chart when people rotate their phone. Note that on mobile devices, scrolling may trigger the window resize. You don’t want to reload the contents of the iframe each time someone scrolls the page. To prevent this, you may add a check whether the window width has changed (a trick I picked up here). Also note that with Drupal, you need to use jQuery instead of $.

width = jQuery(window).width;
jQuery(window).resize(function(){
    if(jQuery(window).width() != width){
        document.getElementById('iframe_chart_1').src = document.getElementById('iframe_chart_1').src;
        width = jQuery(window).width;
    }
});

In case you know a better way - do let me know!

FYI, here’s the chart used as illustration in its original context.

Tags: 

‘Open company data played role in downfall of Spanish minister’

How transparent are countries when it regards company data? Score of the Netherlands on Open Corporates’ Open Company Data Index, compared to other EU countries. Ordered by score and alphabetically on English name. Source Open Corporates, chart dirkmjk.nl.

«There is a delicious irony in Soria being brought down in part by open data», Open Corporates wrote on their blog a week ago. By Soria they refer to former minister José Manuel Soria of the right-wing Partido Popular, who had just stepped down. The story, as summarised by Open Corporates:

Soria was discovered in the Panama Papers, but denied any connection to the Bahamas company referenced in them. It turns out that a company of the same name, UK Lines Limited, had been incorporated in the UK, with officerships linked to him and his family. Further investigation into this company and another UK one, Oceanic Lines Limited, used company filings and shareholder documents to show that these were indeed connected with Soria and his family. Yesterday, newspaper El Mundo nailed the case showing Soria was also director of a Jersey company when he was already a politician.

Information about the UK connection was obtained from Open Corporates. Journalists in other countries - from Nigeria to Argentina - have similarly used data from Open Corporates to make sense of the Panama Papers.

The information they used may well have been available from official databases as well. However, the fact that countries like the UK have opened up company data, and that Open Corporates serves as a portal to such information, makes it much easier to investigate abuses compared to a situation in which you have to buy each document you want to take a look at.

So what about the ‘delicious irony’ mentioned at the beginning of this article? Spain happens to be one of the most secretive countries in the world when it comes to company data, according Open Corporates:

you can’t even search to see if a company exists without giving your credit card, and they have been adamant that they will not open up the register, still less make it available as open data.

This earns Spain a score of 0/100 on the Open Company Data Index, which is even worse than the embarrassingly low score of 20/100 for the Netherlands. The good news here is that the Dutch Lower House has passed a motion asking the government to see whether it can open up the company register (KvK) as open data, and to report to Parliament this spring.

Tags: 

My entry for the Best Worst Viz competition

Number of tweets with hashtag #BestWorstViz, per date of the month April 2016 and time of the day. Times are UTC, 18 April is the deadline. Data updates every hour; clear browser history to refresh. Entry for Best Worst Viz competition, created by dirkmjk.

I love to hate bad graphs (who doesn’t), and I think Andy Kirk’s idea to organise a Best Worst Viz competition is quite brilliant. As he explains, there’s something fair about creating your own bad graph rather than criticising somebody else’s:

[..] picking on bad visualisation involves work by other people who we might never meet or have a chance to learn about what the true circumstances and intent of a project were. The essence of this challenge is based on your best worst visualisation - the best worst visualisation you can possibly make.

I had to give it a try. But how? An exploding 3D pie chart, truncated y-axis, out-of-control spaghetti chart - it all seemed a bit too obvious. I aimed for something different, drawing inspiration from the blink element of the early days of web design. The shifting colours of the stacked bar chart pointlessly illustrate the direction of time - or whatever. I think it’s pretty bad.

Standalone version of graph here.

Links between businesses and politics II: revolving door and access to ministers

Eline Huisman and Ariejan Korteweg of the Volkskrant have done some good investigative journalism by finding out how often companies, organisations and inviduals have visited the current ministers (this data wasn’t publicly available in the Netherlands). It’s interesting to compare the top–10 of companies with access to ministers to the top–10 of revolving door companies (companies where national politicians have or have had a position).

Position of companies on the access to ministers ranking and the revolving door ranking

Access Revolving door
Air France-KLM 1 6
Rabobank 2 1
Shell 3 2
ING Bank 4 5
ABN AMRO 5 3
Schiphol 6 -
Aegon 7 8
KPN 8 -
SNS Reaal 9 -
KPMG 10 4
NS 7
Delta Lloyd - 9
PGGM 10

I’m sure more can be said about this, but the comparison shows there’s conciderable overlap between the two lists (for the geeks among you: the Jaccard index is 0.54). The following companies score high on both measures of political ties: Air France-KLM, Rabobank, Shell, ING Bank, ABN Amro, Aegon and KPMG. Dutch Railways (NS) and PGGM don’t feature in the Volkskrant business ranking because they classify them as semipublic.

Of course, these lists provide no basis for firm conclusions about cause and effect. However, one can imagine that companies that participate actively in the revolving door could have easier access to ministers.

The details of the Volkskrant investigation can be found in this visualisation, which unfortunately isn’t easily searcheable. The underlying data are available here as csv. If you’d classify NS and PGGM as companies in the Volkskrant list, the overlap wouldn’t change because other companies would drop out of the top–10. Further, for comparability I’ve removed industry and lobby organisations such as employers’ organisation VNO-NCW from the access to ministers ranking. Alphabetical order was used where two companies have the same score.

Tags: 

Pages