annotate exif-graphr.js @ 1:a11817a35877

Update to D3js v4.9.1 and newer D3-tooltip
author IBBoard <dev@ibboard.co.uk>
date Mon, 29 May 2017 14:06:47 +0100
parents 42c058ce5b7c
children b83d9186c2af
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 var debug = false;
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 var photo_data = {};
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
3
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4 /* Helper functions */
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 function byID(d) { return d.id; }
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 function byValue(d) { return d; }
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 function makeUrl(method, vals) {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 vals = vals || {};
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 var parts = [];
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 if (debug) {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 for (var key in vals) {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 parts.push(encodeURIComponent(key) + '-' + encodeURIComponent(vals[key]));
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 }
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 var extra = parts.join('-');
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 if (extra != '') {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 extra = '-' + extra;
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 }
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 var url = "./data-" + method + extra + ".json";
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 } else {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 for (var key in vals) {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 parts.push(encodeURIComponent(key) + '=' + encodeURIComponent(vals[key]));
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 }
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24 var extra = parts.join('&');
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 if (extra != '') {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 extra = '&' + extra;
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 }
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 var url = "https://ibboard.co.uk/exif-graphr/api.php?method=" + method + extra;
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 }
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 return url;
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32 }
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
34 /* The real code */
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
35 function visualise() {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
36 photo_data = {};
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
37 var userFoundFunc = function(error,data) {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
38 if (error) {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
39 alert(error.responseText ? error.responseText : error.statusText);
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
40 return;
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
41 }
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
42 if (data.stat != 'ok') {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
43 if (data.message) {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
44 alert(data.message);
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
45 } else {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
46 alert("Unknown error");
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
47 }
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
48 return;
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
49 }
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
50 var nsid = getNSID(data);
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
51 getPhotos(nsid);
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
52 }
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
53
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
54 var username = document.getElementById('username').value;
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
55
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
56 if (/[0-9]+@N[0-9]+/.test(username)) {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
57 getPhotos(username);
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
58 } else if (/https?:\/\/www\.flickr\.com\/photos\/[0-9a-z]+(\/.*)+/.test(username)) {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
59 getNSID = function(data) {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
60 return data.user.id;
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
61 };
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
62 d3.json(makeUrl('flickr.urls.lookupUser', { 'url': username }), userFoundFunc);
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
63 } else {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
64 getNSID = function(data) {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
65 return data.user.nsid;
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
66 };
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
67 d3.json(makeUrl('flickr.people.findByUsername', { 'username': username }), userFoundFunc);
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
68 }
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
69 }
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
70
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
71 function getPhotos(nsid) {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
72 d3.json(makeUrl('flickr.people.getPublicPhotos', { 'user_id': nsid, 'per_page' : 100, 'extras': 'url_t' }), function(error, data) {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
73 data.photos.photo.forEach(getExif);
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
74 });
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
75 }
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
76
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
77 function getExif(photo) {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
78 var photo_id = photo.id;
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
79 var thumb_url = photo.url_t;
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
80 var url = "https://flickr.com/photos/" + photo.owner + "/" + photo_id;
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
81 d3.json(makeUrl('flickr.photos.getExif', { 'photo_id' : photo_id }), function(error, data) {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
82 if (error || data.code) {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
83 console.log("Error fetching details for " + photo_id + ": " + data.message);
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
84 return;
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
85 }
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
86 var exifs = data.photo.exif;
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
87 var len = exifs.length;
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
88 var exposure = '';
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
89 var f_number = '';
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
90 var iso = '';
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
91 var focal_length = '';
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
92 var timestamp = '';
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
93 var make = '';
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
94 var model = '';
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
95
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
96 for (var i = 0; i < len; i++) {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
97 var exif = exifs[i];
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
98 if (exif.tagspace == 'ExifIFD') {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
99 if (exif.tag == 'ExposureTime') {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
100 if (exif.clean) {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
101 exposure = exif.clean._content;
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
102 } else if (/^[0-9]+(\.[0-9]+)?$/.test(exif.raw._content)) {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
103 exposure = exif.raw._content + " sec (" + exif.raw._content + ")";
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
104 } else {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
105 console.log("No clean exposure time for "+photo.id+". Raw was "+exif.raw._content); continue;
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
106 }
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
107 } else if (exif.tag == 'FNumber') {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
108 f_number = exif.raw._content;
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
109 } else if (exif.tag == 'ISO') {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
110 iso = exif.raw._content;
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
111 } else if (exif.tag == 'FocalLength') {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
112 if (/^[0-9\.]+ mm/.test(exif.raw._content)) {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
113 focal_length = parseInt(exif.raw._content);
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
114 }
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
115 } else if (exif.tag == 'DateTimeOriginal') {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
116 timestamp = Date.parse(exif.raw._content.replace(/^([0-9][0-9][0-9][0-9]):([0-9][0-9]):([0-9][0-9]) /, '$1/$2/$3 '));
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
117 }
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
118 } else if (exif.tagspace == 'IFD0') {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
119 if (exif.tag == 'Make') {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
120 make = exif.raw._content;
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
121 } else if (exif.tag == 'Model') {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
122 model = exif.raw._content;
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
123 } else if (exif.tag == 'FocalLength') {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
124 if (!focal_length) { focal_length = exif.raw._content.replace(/^([0-9]+(\.[0-9]+)?).*$/, '$1'); }
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
125 } else if (exif.tag == 'ExposureTime') {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
126 if (!exposure) { exposure = exif.raw._content + " sec (" + exif.raw._content + ")"; }
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
127 } else if (exif.tag == 'FNumber') {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
128 if (!f_number) { f_number = Math.round(exif.raw._content / 100); /* Trial and error guess - it is a rational number */ }
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
129 }
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
130
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
131 }
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
132 }
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
133
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
134 var exp_matches = exposure.match(/^(1\/)?([0-9\.]+) sec( \(([^\)]+)\))?/);
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
135 var exp_parts = [ '', '' ];
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
136 if (exp_matches) {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
137 if (exp_matches[1]) {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
138 // We got a non-decimal numeric version
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
139 exp_parts[0] = 1 / exp_matches[2];
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
140 } else {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
141 exp_parts[0] = exp_matches[2];
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
142 }
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
143
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
144 if (exp_matches[4]) {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
145 exp_parts[1] = exp_matches[4];
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
146 var exp_fraction = exp_parts[1].match(/^1\/([0-9]+)$/);
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
147 if (exp_fraction) {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
148 //Override for accuracy - the "clean" version rounds too much - 1/909 through 1/2000 ⇒ 0.001
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
149 exp_parts[0] = 1 / exp_fraction[1];
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
150 }
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
151 } else {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
152 exp_parts[1] = exp_parts[0] >= 1 ? exp_parts[0] : "1/"+(1/exp_parts[0]);
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
153 }
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
154 }
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
155 var exp_sec = exp_parts[0];
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
156 var exp_str = exp_parts[1];
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
157
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
158 var camera = '';
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
159 make = make.replace(/ CORPORATION$/, '');
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
160 if (make && model && !(model.indexOf(make) === 0)) {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
161 camera = make + " " + model;
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
162 } else {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
163 camera = model;
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
164 }
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
165
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
166 photo_data[photo.id] = { 'id': photo.id, 'exposure': +exp_sec, 'exposure_string': exp_str, 'f_number': f_number, 'iso': +iso, 'focal_length': +focal_length, 'camera': camera, 'make': make, 'model' : model, 'timestamp': timestamp, 'thumb': thumb_url, 'url': url };
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
167 update();
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
168 });
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
169 }
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
170
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
171 function clone(obj) {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
172 if (null == obj || "object" != typeof obj) return obj;
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
173 var copy = obj.constructor();
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
174 for (var attr in obj) {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
175 if (obj.hasOwnProperty(attr)) copy[attr] = clone(obj[attr]);
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
176 }
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
177 return copy;
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
178 }
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
179
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
180 function hashcode(s){
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
181 return s.split("").reduce(function(a,b){a=((a<<5)-a)+b.charCodeAt(0);return a&a},0);
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
182 }
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
183
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
184 var margin = {top: 40, right: 20, bottom: 50, left: 55},
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
185 width = 960 - margin.left - margin.right,
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
186 height = 600 - margin.top - margin.bottom,
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
187 axisHeight = height - margin.bottom;
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
188 var svg = d3.select("#graph").append("svg")
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
189 .attr("width", width + margin.left + margin.right)
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
190 .attr("height", height + margin.top + margin.bottom)
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
191 .append("g")
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
192 .attr("transform", "translate(" + margin.left + "," + margin.top + ")");
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
193 var photoTable = d3.select("#photoTable");
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
194 var legend = d3.select("#legend").append("svg");
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
195 var legendGradients = legend.append("defs");
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
196 var legends = legend.append("g");
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
197
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
198 var tip = d3.tip()
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
199 .attr('class', 'd3-tip')
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
200 .offset([-10, 0])
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
201 .html(function(d) {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
202 return "Photo " + d.id + '<br /><img src="' + d.thumb + '" alt="Photo ' + d.id + '" />' + "<br />Aperture: f/" + d.f_number + "<br />Focal Length: " + d.focal_length + "<br />Exposure: " + d.exposure_string + "<br />ISO: " + d.iso + "<br />Camera: " + d.camera;
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
203 });
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
204 svg.call(tip);
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
205
1
a11817a35877 Update to D3js v4.9.1 and newer D3-tooltip
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
206 var flAxisScale = d3.scaleLinear()
0
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
207 .rangeRound([axisHeight, 0]);
1
a11817a35877 Update to D3js v4.9.1 and newer D3-tooltip
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
208 var flAxis = d3.axisLeft(flAxisScale);
a11817a35877 Update to D3js v4.9.1 and newer D3-tooltip
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
209 var expAxisScale = d3.scaleLog()
0
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
210 .rangeRound([0, width]);
1
a11817a35877 Update to D3js v4.9.1 and newer D3-tooltip
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
211 var expAxis = d3.axisTop(expAxisScale)
0
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
212 .tickFormat(function(d) { if (d < 1) { return "1∕" + (1 / d).toFixed(2).replace(/\.?0+$/, ''); } else { return d; } });
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
213 var circlesG = svg.append("svg:g");
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
214 var axises = svg.append("svg:g");
1
a11817a35877 Update to D3js v4.9.1 and newer D3-tooltip
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
215 var saturationScale = d3.scaleLog().range([30,90]);
0
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
216 axises.append("g")
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
217 .attr("class", "y axis")
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
218 .call(flAxis);
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
219 axises.append("g")
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
220 .attr("class", "x axis")
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
221 .attr("transform", "translate(0," + (axisHeight) + ")")
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
222 .call(expAxis)
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
223 .selectAll("text")
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
224 .style("text-anchor", "start")
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
225 .attr("y", 0)
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
226 .attr("x", 9)
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
227 .attr("dy", ".35em")
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
228 .attr("transform", function(d) {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
229 return "rotate(90)"
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
230 });
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
231 axises.append("text")
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
232 .attr("transform", "translate(" + (width / 2) + " ," + (height + (margin.bottom/2)) + ")")
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
233 .style("text-anchor", "middle")
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
234 .text("Shutter Speed (Exposure) in Seconds");
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
235 svg.append("text")
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
236 .attr("transform", "rotate(-90)")
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
237 .attr("y", 0 - margin.left)
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
238 .attr("x",0 - (height / 2))
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
239 .attr("dy", "1em")
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
240 .style("text-anchor", "middle")
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
241 .text("Focal Length in mm");
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
242
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
243 function update() {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
244 var photos = [];
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
245 for (var key in photo_data) {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
246 if (photo_data.hasOwnProperty(key)) {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
247 photos.push(photo_data[key]);
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
248 }
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
249 }
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
250
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
251 var photosWithExif = photos.filter(function(d) { return d.focal_length != '' && d.exposure != '' && d.f_number != '' && d.iso != '';});
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
252 saturationScale.domain([d3.min(photosWithExif, function(val) { return val.iso; }), d3.max(photosWithExif, function(val) { return val.iso; })]);
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
253
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
254 update_graph(photosWithExif);
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
255 update_table(photos);
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
256 update_legend(photosWithExif);
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
257 }
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
258
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
259 function update_graph(filteredPhotos) {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
260 flAxisScale.domain([d3.min(filteredPhotos, function(val) { return val.focal_length; }) * 0.9, d3.max(filteredPhotos, function(val) { return val.focal_length; }) * 1.1]);
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
261 flAxis.scale(flAxisScale);
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
262 axises.selectAll(".y.axis").call(flAxis);
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
263 expAxisScale.domain([d3.min(filteredPhotos, function(val) { return val.exposure; }) * 0.9, d3.max(filteredPhotos, function(val) { return val.exposure; }) * 1.1]);
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
264 expAxis.scale(expAxisScale);
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
265 axises.selectAll(".x.axis").call(expAxis)
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
266 .selectAll("text")
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
267 .style("text-anchor", "start")
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
268 .attr("y", 0)
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
269 .attr("x", 9)
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
270 .attr("dy", ".35em")
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
271 .attr("transform", function(d) {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
272 return "rotate(90)"
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
273 });
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
274 var circles = circlesG.selectAll("circle")
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
275 .data(filteredPhotos, byID);
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
276 circles.exit().remove();
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
277 circles.enter()
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
278 .append("circle")
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
279 .on('mouseover', tip.show)
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
280 .on('mouseout', tip.hide)
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
281 // .transition()
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
282 // .duration(750);
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
283
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
284 circles/*.transition().duration(250)*/
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
285 .attr("cx", function (d) { return expAxisScale(d.exposure); })
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
286 .attr("cy", function (d) { return flAxisScale(d.focal_length); })
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
287 .attr("r", function (d) { return 50 / d.f_number; })
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
288 .attr("fill", function (d) { var h = make_camera_hue(d.camera); var s = saturationScale(d.iso); return "hsl("+h+","+s+"%,50%)";})
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
289 .attr("stroke", "#000")
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
290 .attr("stroke-width", 1);
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
291 circles.sort(function(a, b) { var f_sort = a.f_number - b.f_number; if (f_sort != 0) { return f_sort; } else { return a.exposure - b.exposure; } });
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
292 }
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
293
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
294 function make_camera_hue(camera) {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
295 return (hashcode(camera) % 90) * 4;
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
296 }
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
297
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
298 function update_table(photos) {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
299 var photoRows = photoTable.selectAll("tr").data(photos, byID);
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
300 photoRows.exit().remove();
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
301 photoRows.enter()
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
302 .append("tr");
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
303 photoRows.sort(function(a,b){ return b.timestamp - a.timestamp;});
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
304 photoCells = photoRows.selectAll("td")
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
305 .data(function(photo) {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
306 var thumb = '<a href="' + photo.url + '"><img src="' + photo.thumb + '" alt="Photo ' + photo.id + '" /></a>';
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
307 return [ thumb, photo.camera, photo.exposure_string != '' ? photo.exposure_string + "s" : '', photo.focal_length != '' ? photo.focal_length + "mm" : '', photo.f_number != '' ? "f/" + photo.f_number : '', photo.iso ]; })
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
308 .enter()
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
309 .append("td")
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
310 .html(function(d) { return d; });
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
311 }
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
312
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
313 function update_legend(photos) {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
314 var legendBlockWidth = 200;
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
315 var legendBlockHeight = 20;
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
316 var cameras = d3.set(photos.map(function(d){ return d.camera ? d.camera : "Unknown"; })).values();
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
317 legend.attr("width", 400)
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
318 .attr("height", cameras.length * legendBlockHeight + legendBlockHeight);
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
319 var gradients = legendGradients.selectAll("linearGradient").data(cameras, byValue);
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
320 gradients.exit().remove();
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
321 var newGradients = gradients.enter().append("linearGradient")
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
322 .attr("id", function(d,i) { return "Gradient" + i; });
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
323 newGradients.append("stop")
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
324 .attr("offset", "0%")
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
325 .attr("stop-color", function(camera){var h = make_camera_hue(camera); return "hsl("+h+","+saturationScale.range()[0]+"%,50%)";});
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
326 newGradients.append("stop")
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
327 .attr("offset", "100%")
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
328 .attr("stop-color", function(camera){var h = make_camera_hue(camera); return "hsl("+h+","+saturationScale.range()[1]+"%,50%)";});
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
329 var cameraLegends = legends.selectAll("g").data(cameras, byValue);
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
330 cameraLegends.exit().remove();
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
331 var newCameraLegends = cameraLegends.enter().append("g")
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
332 newCameraLegends.append("title").text(function(d){return d;});
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
333 newCameraLegends.append("rect")
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
334 .attr("x", 0)
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
335 .attr("y", function(d,i){ return i * legendBlockHeight; })
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
336 .attr("width", legendBlockWidth)
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
337 .attr("height", legendBlockHeight)
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
338 .attr("fill", function(d,i) { return "url(#Gradient" + i + ")"; })
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
339 .on('mouseover', function(d) { setCircleOpacity(d, 0.1); })
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
340 .on('mouseout', function(d) { setCircleOpacity(d, 1); });
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
341 newCameraLegends.append("text")
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
342 .text(function(d){ return d; })
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
343 .attr("x", legendBlockWidth + 5)
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
344 .attr("y", function(d,i) { return i * legendBlockHeight + (legendBlockHeight / 4) * 3; });
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
345 }
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
346
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
347 function setCircleOpacity(camera, opacity) {
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
348 // Set opacity of all circles that AREN'T photos from this camera to highlight the ones that are
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
349 circlesG.selectAll("circle")
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
350 .attr('opacity', function (d) { return (d.camera != camera) ? opacity : 1; });
42c058ce5b7c Initial public commit of Exif-Graphr
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
351 }