~smagoun/whoopsie/whoopsie-lp1017637

« back to all changes in this revision

Viewing changes to backend/stats/static/js/d3/src/geo/bounds.js

  • Committer: Evan Dandrea
  • Date: 2012-05-09 05:53:45 UTC
  • Revision ID: evan.dandrea@canonical.com-20120509055345-z2j41tmcbf4as5uf
The backend now lives in lp:daisy and the website (errors.ubuntu.com) now lives in lp:errors.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 * Given a GeoJSON object, returns the corresponding bounding box. The bounding
3
 
 * box is represented by a two-dimensional array: [[left, bottom], [right,
4
 
 * top]], where left is the minimum longitude, bottom is the minimum latitude,
5
 
 * right is maximum longitude, and top is the maximum latitude.
6
 
 */
7
 
d3.geo.bounds = function(feature) {
8
 
  var left = Infinity,
9
 
      bottom = Infinity,
10
 
      right = -Infinity,
11
 
      top = -Infinity;
12
 
  d3_geo_bounds(feature, function(x, y) {
13
 
    if (x < left) left = x;
14
 
    if (x > right) right = x;
15
 
    if (y < bottom) bottom = y;
16
 
    if (y > top) top = y;
17
 
  });
18
 
  return [[left, bottom], [right, top]];
19
 
};
20
 
 
21
 
function d3_geo_bounds(o, f) {
22
 
  if (d3_geo_boundsTypes.hasOwnProperty(o.type)) d3_geo_boundsTypes[o.type](o, f);
23
 
}
24
 
 
25
 
var d3_geo_boundsTypes = {
26
 
  Feature: d3_geo_boundsFeature,
27
 
  FeatureCollection: d3_geo_boundsFeatureCollection,
28
 
  GeometryCollection: d3_geo_boundsGeometryCollection,
29
 
  LineString: d3_geo_boundsLineString,
30
 
  MultiLineString: d3_geo_boundsMultiLineString,
31
 
  MultiPoint: d3_geo_boundsLineString,
32
 
  MultiPolygon: d3_geo_boundsMultiPolygon,
33
 
  Point: d3_geo_boundsPoint,
34
 
  Polygon: d3_geo_boundsPolygon
35
 
};
36
 
 
37
 
function d3_geo_boundsFeature(o, f) {
38
 
  d3_geo_bounds(o.geometry, f);
39
 
}
40
 
 
41
 
function d3_geo_boundsFeatureCollection(o, f) {
42
 
  for (var a = o.features, i = 0, n = a.length; i < n; i++) {
43
 
    d3_geo_bounds(a[i].geometry, f);
44
 
  }
45
 
}
46
 
 
47
 
function d3_geo_boundsGeometryCollection(o, f) {
48
 
  for (var a = o.geometries, i = 0, n = a.length; i < n; i++) {
49
 
    d3_geo_bounds(a[i], f);
50
 
  }
51
 
}
52
 
 
53
 
function d3_geo_boundsLineString(o, f) {
54
 
  for (var a = o.coordinates, i = 0, n = a.length; i < n; i++) {
55
 
    f.apply(null, a[i]);
56
 
  }
57
 
}
58
 
 
59
 
function d3_geo_boundsMultiLineString(o, f) {
60
 
  for (var a = o.coordinates, i = 0, n = a.length; i < n; i++) {
61
 
    for (var b = a[i], j = 0, m = b.length; j < m; j++) {
62
 
      f.apply(null, b[j]);
63
 
    }
64
 
  }
65
 
}
66
 
 
67
 
function d3_geo_boundsMultiPolygon(o, f) {
68
 
  for (var a = o.coordinates, i = 0, n = a.length; i < n; i++) {
69
 
    for (var b = a[i][0], j = 0, m = b.length; j < m; j++) {
70
 
      f.apply(null, b[j]);
71
 
    }
72
 
  }
73
 
}
74
 
 
75
 
function d3_geo_boundsPoint(o, f) {
76
 
  f.apply(null, o.coordinates);
77
 
}
78
 
 
79
 
function d3_geo_boundsPolygon(o, f) {
80
 
  for (var a = o.coordinates[0], i = 0, n = a.length; i < n; i++) {
81
 
    f.apply(null, a[i]);
82
 
  }
83
 
}