omf_web 1.2.6 → 1.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. data/.travis.yml +13 -0
  2. data/README.md +6 -0
  3. data/example/bridge/README.md +1 -1
  4. data/example/bridge/bridge.yaml +10 -0
  5. data/example/bridge/bridge_viz_server +41 -0
  6. data/example/bridge/data_sources/sensor-sqlite.rb +3 -2
  7. data/example/bridge/htdocs/graph/js/event_table.js +2 -7
  8. data/example/bridge/tabs/overview.yaml +82 -0
  9. data/example/openflow-gec15/dashboard_tab.yaml +1 -0
  10. data/example/simple/simple.yaml +1 -1
  11. data/example/simple/simple_dynamic.yaml +5 -3
  12. data/example/topo_discovery/data_sources/links.csv +3 -0
  13. data/example/topo_discovery/data_sources/links2.csv +21 -0
  14. data/example/topo_discovery/data_sources/node_info.csv +10 -0
  15. data/example/topo_discovery/data_sources/nodes.csv +4 -0
  16. data/example/topo_discovery/data_sources/nodes2.csv +11 -0
  17. data/example/topo_discovery/introduction.md +17 -0
  18. data/example/topo_discovery/topo_discovery_simple.yaml +35 -0
  19. data/example/topo_discovery/topo_discovery_simple2.yaml +32 -0
  20. data/example/topo_discovery/widgets/network.yaml +52 -0
  21. data/example/topo_discovery/widgets/node_info.yaml +23 -0
  22. data/lib/omf-web/content/file_repository.rb +5 -1
  23. data/lib/omf-web/content/git_repository.rb +11 -0
  24. data/lib/omf-web/content/repository.rb +13 -2
  25. data/lib/omf-web/data_source_proxy.rb +22 -10
  26. data/lib/omf-web/theme.rb +11 -4
  27. data/lib/omf-web/theme/abstract_page.rb +5 -0
  28. data/lib/omf-web/thin/server.rb +62 -16
  29. data/lib/omf-web/version.rb +1 -1
  30. data/lib/omf-web/widget/code_widget.rb +24 -23
  31. data/lib/omf-web/widget/data_widget.rb +14 -5
  32. data/lib/omf-web/widget/text/maruku.rb +16 -1
  33. data/lib/omf-web/widget/text/text_widget.rb +1 -1
  34. data/share/htdocs/graph/js/abstract_chart.js +7 -1
  35. data/share/htdocs/graph/js/abstract_multiple_datasource_chart.js +21 -3
  36. data/share/htdocs/graph/js/abstract_nv_chart.js +17 -11
  37. data/share/htdocs/graph/js/abstract_widget.js +44 -14
  38. data/share/htdocs/graph/js/line_chart3.js +5 -9
  39. data/share/htdocs/graph/js/map2.js +122 -79
  40. data/share/htdocs/graph/js/network2.js +205 -36
  41. data/share/htdocs/graph/js/table2.js +7 -11
  42. data/share/htdocs/js/data_source3.js +24 -4
  43. data/share/htdocs/vendor/VERSION_MAP.yaml +1 -1
  44. data/share/htdocs/vendor/{font-awesome-4.0.3 → font-awesome-4.1.0}/css/font-awesome.css +251 -23
  45. data/share/htdocs/vendor/font-awesome-4.1.0/css/font-awesome.min.css +4 -0
  46. data/share/htdocs/vendor/font-awesome-4.1.0/fonts/FontAwesome.otf +0 -0
  47. data/share/htdocs/vendor/font-awesome-4.1.0/fonts/fontawesome-webfont.eot +0 -0
  48. data/share/htdocs/vendor/font-awesome-4.1.0/fonts/fontawesome-webfont.svg +504 -0
  49. data/share/htdocs/vendor/font-awesome-4.1.0/fonts/fontawesome-webfont.ttf +0 -0
  50. data/share/htdocs/vendor/font-awesome-4.1.0/fonts/fontawesome-webfont.woff +0 -0
  51. data/share/htdocs/vendor/{font-awesome-4.0.3 → font-awesome-4.1.0}/less/bordered-pulled.less +0 -0
  52. data/share/htdocs/vendor/{font-awesome-4.0.3 → font-awesome-4.1.0}/less/core.less +0 -0
  53. data/share/htdocs/vendor/{font-awesome-4.0.3 → font-awesome-4.1.0}/less/fixed-width.less +0 -0
  54. data/share/htdocs/vendor/font-awesome-4.1.0/less/font-awesome.less +17 -0
  55. data/share/htdocs/vendor/{font-awesome-4.0.3 → font-awesome-4.1.0}/less/icons.less +97 -3
  56. data/share/htdocs/vendor/{font-awesome-4.0.3 → font-awesome-4.1.0}/less/larger.less +0 -0
  57. data/share/htdocs/vendor/{font-awesome-4.0.3 → font-awesome-4.1.0}/less/list.less +0 -0
  58. data/share/htdocs/vendor/{font-awesome-4.0.3 → font-awesome-4.1.0}/less/mixins.less +0 -0
  59. data/share/htdocs/vendor/font-awesome-4.1.0/less/path.less +14 -0
  60. data/share/htdocs/vendor/{font-awesome-4.0.3 → font-awesome-4.1.0}/less/rotated-flipped.less +0 -0
  61. data/share/htdocs/vendor/{font-awesome-4.0.3 → font-awesome-4.1.0}/less/spinning.less +8 -6
  62. data/share/htdocs/vendor/{font-awesome-4.0.3 → font-awesome-4.1.0}/less/stacked.less +0 -0
  63. data/share/htdocs/vendor/{font-awesome-4.0.3 → font-awesome-4.1.0}/less/variables.less +463 -329
  64. data/share/htdocs/vendor/{font-awesome-4.0.3 → font-awesome-4.1.0}/scss/_bordered-pulled.scss +0 -0
  65. data/share/htdocs/vendor/{font-awesome-4.0.3 → font-awesome-4.1.0}/scss/_core.scss +0 -0
  66. data/share/htdocs/vendor/{font-awesome-4.0.3 → font-awesome-4.1.0}/scss/_fixed-width.scss +0 -0
  67. data/share/htdocs/vendor/{font-awesome-4.0.3 → font-awesome-4.1.0}/scss/_icons.scss +97 -3
  68. data/share/htdocs/vendor/{font-awesome-4.0.3 → font-awesome-4.1.0}/scss/_larger.scss +0 -0
  69. data/share/htdocs/vendor/{font-awesome-4.0.3 → font-awesome-4.1.0}/scss/_list.scss +0 -0
  70. data/share/htdocs/vendor/{font-awesome-4.0.3 → font-awesome-4.1.0}/scss/_mixins.scss +2 -2
  71. data/share/htdocs/vendor/{font-awesome-4.0.3 → font-awesome-4.1.0}/scss/_path.scss +0 -0
  72. data/share/htdocs/vendor/{font-awesome-4.0.3 → font-awesome-4.1.0}/scss/_rotated-flipped.scss +0 -0
  73. data/share/htdocs/vendor/{font-awesome-4.0.3 → font-awesome-4.1.0}/scss/_spinning.scss +8 -6
  74. data/share/htdocs/vendor/{font-awesome-4.0.3 → font-awesome-4.1.0}/scss/_stacked.scss +0 -0
  75. data/share/htdocs/vendor/{font-awesome-4.0.3 → font-awesome-4.1.0}/scss/_variables.scss +464 -330
  76. data/share/htdocs/vendor/{font-awesome-4.0.3 → font-awesome-4.1.0}/scss/font-awesome.scss +1 -1
  77. data/share/htdocs/vendor/jquery-ui-1.8.23/js/jquery-ui.js +125 -0
  78. data/share/htdocs/vendor/spin/jquery.spin.js +46 -24
  79. data/share/htdocs/vendor/spin/spin.js +20 -17
  80. metadata +277 -237
  81. data/example/bridge/data_sources/test2.oml +0 -1808
  82. data/example/bridge/data_sources/test2.sq3 +0 -0
  83. data/example/bridge/data_sources/test31.sq3 +0 -0
  84. data/example/bridge/viz_server.rb +0 -59
  85. data/share/htdocs/vendor/font-awesome-4.0.3/css/font-awesome.min.css +0 -4
  86. data/share/htdocs/vendor/font-awesome-4.0.3/fonts/FontAwesome.otf +0 -0
  87. data/share/htdocs/vendor/font-awesome-4.0.3/fonts/fontawesome-webfont.eot +0 -0
  88. data/share/htdocs/vendor/font-awesome-4.0.3/fonts/fontawesome-webfont.svg +0 -414
  89. data/share/htdocs/vendor/font-awesome-4.0.3/fonts/fontawesome-webfont.ttf +0 -0
  90. data/share/htdocs/vendor/font-awesome-4.0.3/fonts/fontawesome-webfont.woff +0 -0
  91. data/share/htdocs/vendor/font-awesome-4.0.3/less/font-awesome.less +0 -17
  92. data/share/htdocs/vendor/font-awesome-4.0.3/less/path.less +0 -14
  93. data/share/htdocs/vendor/spin/spin.min.js +0 -1
@@ -34,19 +34,28 @@ module OMF::Web::Widget
34
34
 
35
35
  if (ds = opts.delete(:data_source))
36
36
  # single source
37
- data_sources = {:default => ds}
37
+ #data_sources = {:default => ds}
38
+ data_sources = [ds]
38
39
  end
39
40
  unless data_sources ||= opts.delete(:data_sources)
40
41
  raise "Missing option ':data_sources' for widget '#{name}'"
41
42
  end
42
- unless data_sources.kind_of? Hash
43
- data_sources = {:default => data_sources}
43
+ if data_sources.kind_of? Hash
44
+ # turn into array an set stream
45
+ data_sources = data_sources.map do |sname, ds_descr|
46
+ ds_descr[:stream] ||= sname
47
+ end
48
+ end
49
+ unless data_sources.kind_of? Array
50
+ #data_sources = {:default => data_sources}
51
+ raise "Unexpected ':data_sources' for widget '#{name}' - #{data_sources}"
44
52
  end
45
- opts[:data_sources] = data_sources.collect do |name, ds_descr|
53
+ i = 0
54
+ opts[:data_sources] = data_sources.map do |ds_descr|
46
55
  unless ds_descr.is_a? Hash
47
56
  ds_descr = {:name => ds_descr}
48
57
  end
49
- ds_descr[:alias] = "#{name}_#{self.object_id}"
58
+ ds_descr[:alias] = "#{name}_#{self.object_id}_#{i += 1}"
50
59
  #{:stream => ds_descr, :name => name}
51
60
  unless OMF::Web::DataSourceProxy.validate_ds_description(ds_descr)
52
61
  raise "Unknown data source requested for data widget - #{ds_descr}"
@@ -43,6 +43,16 @@ module OMF::Web::Widget::Text
43
43
  ::Maruku.new(content)
44
44
  end
45
45
 
46
+ # The markdown document may have some meta instructions at the
47
+ # beginning of the document which are formatted like an HTTP header
48
+ def self.count_header_lines(content)
49
+ count = 0
50
+ match = (content =~ /\A((\w[\w\s\_\-]+: .*\n)+)\s*\n/)
51
+ return 0 if match != 0
52
+
53
+ headers = $1
54
+ headers.split("\n").length + 1
55
+ end
46
56
 
47
57
  class WidgetElement < OMF::Base::LObject
48
58
 
@@ -138,7 +148,8 @@ if __FILE__ == $0
138
148
  if fname = ARGV[0]
139
149
  content = File.open(fname).read
140
150
  else
141
- content = %{
151
+ content = %{title: Lorem2
152
+
142
153
  # Lorem ipsum dolor sit
143
154
 
144
155
  Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin
@@ -152,6 +163,10 @@ lorem, gravida scelerisque velit est vitae eros. Suspendisse eu
152
163
  lacinia elit.
153
164
  }
154
165
  end
166
+
167
+
155
168
  x = OMF::Web::Widget::Text::Maruku.format_content(content)
169
+ puts "HEADER LENGTH: #{OMF::Web::Widget::Text::Maruku.count_header_lines(content)}"
170
+
156
171
  puts x.to_html(suppress_section: false)
157
172
  end
@@ -53,7 +53,7 @@ module OMF::Web::Widget
53
53
  end
54
54
 
55
55
  def content_id
56
- @content_proxy.content_id
56
+ @content_proxy.content_url
57
57
  end
58
58
 
59
59
  def mime_type
@@ -61,7 +61,7 @@ define(["graph/abstract_widget"], function (abstract_widget) {
61
61
 
62
62
 
63
63
  var vis = this.init_svg(this.w, this.h);
64
- this.configure_base_layer(vis);
64
+ if (vis) this.configure_base_layer(vis);
65
65
 
66
66
  var self = this;
67
67
  OHUB.bind("graph.highlighted", function(evt) {
@@ -74,6 +74,7 @@ define(["graph/abstract_widget"], function (abstract_widget) {
74
74
  });
75
75
 
76
76
  //this.update(null);
77
+ this.init_chart();
77
78
  this.update();
78
79
  },
79
80
 
@@ -84,6 +85,11 @@ define(["graph/abstract_widget"], function (abstract_widget) {
84
85
  }
85
86
  },
86
87
 
88
+ // This is called once and just before update()
89
+ init_chart: function() {
90
+ // Do nothing, but allow override
91
+ },
92
+
87
93
  _resize_base_el: function(w, h) {
88
94
  // Do not add margins to the base_el, but to the inside of the SVG panes
89
95
  this.w = w;
@@ -38,17 +38,34 @@ define(["graph/abstract_chart"], function(abstract_chart) {
38
38
  process_schema: function() {
39
39
  var self = this;
40
40
  var ds_names = self.data_source_names;
41
+ var outstanding_schemas = ds_names.slice(0); // real copy
41
42
 
42
- var schemas = self.schema = {};
43
- _.each(ds_names, function(ds_name) {
44
- schemas[ds_name] = self.process_single_schema(self.data_source[ds_name]);
43
+ // CHeck for all the schemas first and when we have them, really
44
+ // process the schemas
45
+ _.each(ds_names, function(name) {
46
+ self.data_source[name].on_schema(function() {
47
+ outstanding_schemas = _.without(outstanding_schemas, name);
48
+ if (_.isEmpty(outstanding_schemas.length)) {
49
+ self._process_schema();
50
+ }
51
+ });
45
52
  });
53
+ },
46
54
 
55
+ _process_schema: function() {
56
+ var self = this;
57
+ var ds_names = self.data_source_names;
47
58
  var om = self.opts.mapping;
48
59
  if (om == undefined) {
49
60
  throw "Missing mapping instructions in 'options'.";
50
61
  }
51
62
  self.mapping = {};
63
+ var schemas = self.schema = {};
64
+
65
+ _.each(ds_names, function(ds_name) {
66
+ schemas[ds_name] = self.process_single_schema(self.data_source[ds_name]);
67
+ });
68
+
52
69
  _.each(ds_names, function(ds_name) {
53
70
  var mapping = om[ds_name];
54
71
  if (mapping == undefined) {
@@ -56,6 +73,7 @@ define(["graph/abstract_chart"], function(abstract_chart) {
56
73
  }
57
74
  self.mapping[ds_name] = self.process_single_mapping(ds_name, mapping, self.decl_properties[ds_name]);
58
75
  });
76
+ self.init_mapping();
59
77
  },
60
78
 
61
79
  /*
@@ -1,9 +1,5 @@
1
1
 
2
- require.config({
3
- shim: {
4
- "vendor/nv_d3/js/nv.d3": ["vendor/d3/d3", "css!vendor/nv_d3/css/nv.d3"]
5
- }
6
- });
2
+ OML.require_dependency("vendor/nv_d3/js/nv.d3", ["vendor/d3/d3", "css!vendor/nv_d3/css/nv.d3"]);
7
3
 
8
4
  define(["graph/abstract_chart", 'vendor/nv_d3/js/nv.d3'], function (abstract_chart) {
9
5
 
@@ -37,9 +33,18 @@ define(["graph/abstract_chart", 'vendor/nv_d3/js/nv.d3'], function (abstract_cha
37
33
 
38
34
  configure_base_layer: function(vis) {
39
35
  this.base_layer = vis;
40
- var chart = this.chart = this._create_model(); //nv.models.lineWithFocusChart();
41
- this._configure_mapping(this.mapping, chart);
42
- this._configure_options(this.opts, chart);
36
+ this._configure_options(this.opts, this.get_chart());
37
+ },
38
+
39
+ get_chart: function() {
40
+ if (! this.chart) {
41
+ this.chart = this._create_model(); //nv.models.lineWithFocusChart();
42
+ }
43
+ return this.chart;
44
+ },
45
+
46
+ init_mapping: function() {
47
+ this._configure_mapping(this.mapping, this.get_chart());
43
48
  },
44
49
 
45
50
  _configure_mapping: function(m, chart) {
@@ -116,9 +121,10 @@ define(["graph/abstract_chart", 'vendor/nv_d3/js/nv.d3'], function (abstract_cha
116
121
  var self = this;
117
122
  abstract_nv_chart.__super__.resize.call(this);
118
123
  if (this.chart) {
119
- this.chart.width(self.width);
120
- this.chart.height(self.height);
121
- //this.chart.update();
124
+ // this.chart.width(self.width);
125
+ // this.chart.height(self.height);
126
+ this.chart.width(self.w);
127
+ this.chart.height(self.h);
122
128
  }
123
129
  },
124
130
 
@@ -142,12 +142,17 @@ define(['omf/data_source_repo', 'vendor/d3/d3'], function(ds_repo) {
142
142
  return ds;
143
143
  },
144
144
 
145
+ init_mapping: function() {},
145
146
 
146
147
  process_schema: function() {
147
- this.schema = this.process_single_schema(this.data_source);
148
- if (typeof(this.decl_properties) != "undefined") {
149
- this.mapping = this.process_single_mapping(null, this.opts.mapping, this.decl_properties);
150
- }
148
+ var self = this;
149
+ this.data_source.on_schema(function() {
150
+ self.schema = self.process_single_schema(self.data_source);
151
+ if (typeof(self.decl_properties) != "undefined") {
152
+ self.mapping = self.process_single_mapping(null, self.opts.mapping, self.decl_properties);
153
+ }
154
+ self.init_mapping();
155
+ });
151
156
  },
152
157
 
153
158
  process_single_schema: function(data_source) {
@@ -155,8 +160,12 @@ define(['omf/data_source_repo', 'vendor/d3/d3'], function(ds_repo) {
155
160
  var o = this.opts;
156
161
  var schema = {};
157
162
  _.map(data_source.schema, function(s, i) {
158
- s['index'] = i;
159
- schema[s.name] = s;
163
+ // TODO: Remove, this is quick hack to addres a bug in Job Service
164
+ if (_.isArray(s)) { s = {name: s[0], type: s[1]}; }
165
+ // End of hack
166
+
167
+ s['index'] = i;
168
+ schema[s.name] = s;
160
169
  });
161
170
  return schema;
162
171
  },
@@ -295,19 +304,40 @@ define(['omf/data_source_repo', 'vendor/d3/d3'], function(ds_repo) {
295
304
  return v;
296
305
  };
297
306
  case 'color':
298
- var color_fname = descr.color;
299
- if (color_fname == undefined) {
300
- throw "Missing color function for '" + mname + "'.";
307
+ var color_fdecl = descr.color;
308
+ if (color_fdecl == undefined) {
309
+ throw "Missing color mapping declaration for '" + mname + "'.";
301
310
  }
302
- var color_fp = self.decl_color_func[color_fname];
303
- if (color_fp == undefined) {
304
- throw "Unknown color function '" + color_fname + "'.";
311
+ var color_f = null;
312
+ if (typeof color_fdecl == 'string') {
313
+ var color_fp = self.decl_color_func[color_fdecl];
314
+ if (color_fp == undefined) {
315
+ throw "Unknown color function '" + color_fname + "'.";
316
+ }
317
+ color_f = color_fp();
318
+ } else if (color_fdecl instanceof Object) {
319
+ if (color_fdecl instanceof Array) {
320
+ var l = color_fdecl.length;
321
+ color_f = function(v) {
322
+ if (v < 0) v = 0;
323
+ if (v >= l) v = l - 1;
324
+ return color_fdecl[v];
325
+ };
326
+ } else {
327
+ // hash table, mapping some name to color
328
+ return function(d) {
329
+ var key = d[index];
330
+ var c = color_fdecl[key] || 'black';
331
+ return c;
332
+ };
333
+ }
334
+ } else {
335
+ throw "Unknown color function type '" + color_fdecl + "'.";
305
336
  }
306
- var color_f = color_fp();
307
337
  var scale = descr.scale;
308
338
  var min_value = descr.min;
309
339
  return function(d) {
310
- var v = d[index];
340
+ var v = parseInt(d[index]);
311
341
  if (scale != undefined) v = v * scale;
312
342
  if (min_value != undefined && v < min_value) v = min_value;
313
343
  var color = color_f(v);
@@ -1,11 +1,7 @@
1
1
 
2
- require.config({
3
- shim: {
4
- "vendor/nv_d3/js/nv.d3": ["vendor/d3/d3", "css!vendor/nv_d3/css/nv.d3"],
5
- "vendor/nv_d3/js/models/line": ["vendor/nv_d3/js/nv.d3"],
6
- "vendor/nv_d3/js/models/lineChart": ["vendor/nv_d3/js/models/line"],
7
- }
8
- });
2
+ OML.require_dependency("vendor/nv_d3/js/nv.d3", ["vendor/d3/d3", "css!vendor/nv_d3/css/nv.d3"]);
3
+ OML.require_dependency("vendor/nv_d3/js/models/line", ["vendor/nv_d3/js/nv.d3"]);
4
+ OML.require_dependency("vendor/nv_d3/js/models/lineChart", ["vendor/nv_d3/js/models/line"]);
9
5
 
10
6
  define(["graph/abstract_nv_chart",
11
7
  "graph/abstract_chart", "graph/axis",
@@ -52,7 +48,7 @@ define(["graph/abstract_nv_chart",
52
48
  // ;
53
49
 
54
50
  this.opts.transition_duration = 0; // force no smooth transition
55
- this._configure_xy_axis(opts, chart)
51
+ this._configure_xy_axis(opts, chart);
56
52
  },
57
53
 
58
54
  _datum: function(data, chart) {
@@ -67,7 +63,7 @@ define(["graph/abstract_nv_chart",
67
63
  } else {
68
64
  data = [data];
69
65
  };
70
- chart.showLegend(data.length > 1);
66
+ chart.showLegend(group_by != null);
71
67
 
72
68
  return data.map(function(rows, i) {
73
69
  var name = m.group_by != null ? m.group_by(rows[0]) : 'unknown';
@@ -1,26 +1,28 @@
1
1
 
2
2
 
3
3
  //L.provide('OML.map', ["d3", "http://maps.googleapis.com/maps/api/js?sensor=true"], function () {
4
- L.provide('OML.googleLoader', ["http://www.google.com/jsapi"], function () {
5
- google.load("maps", "3", {"callback" : onMapLoaded, "other_params":"sensor=true"});
6
- });
7
-
8
- function onMapLoaded() {
9
-
10
- L.provide('OML.map2', ["graph/js/abstract_chart", "#OML.abstract_chart"], function () {
11
-
12
- OML.map2 = OML.abstract_chart.extend({
4
+ // define(["http://www.google.com/jsapi"], function () {
5
+ // google.load("maps", "3", {"callback" : onMapLoaded, "other_params":"sensor=true"});
6
+ // });
7
+
8
+
9
+ define(["graph/abstract_chart", "http://www.google.com/jsapi"], function (abstract_chart) {
10
+
11
+ //L.provide('OML.map2', ["graph/js/abstract_chart", "#OML.abstract_chart"], function () {
12
+
13
+ var map2 = abstract_chart.extend({
13
14
  //this.opts = opts;
14
-
15
+
15
16
  decl_properties: [
16
- ['lat', 'float', {}],
17
- ['lng', 'float', {}],
18
- ['radius', 'int', 10],
19
- ['fill_color', 'color', 'blue'],
20
- ['stroke_width', 'int', 1],
21
- ['stroke_color', 'color', 'black'],
17
+ ['latitude', 'key', {property: 'latitude'}],
18
+ ['longitude', 'key', {property: 'longitude'}],
19
+ //['radius', 'key', {property: 'radius', type: 'int', default: 10}],
20
+ ['radius', 'int', 10],
21
+ ['fill_color', 'color', 'blue'],
22
+ ['stroke_width', 'int', 1],
23
+ ['stroke_color', 'color', 'black'],
22
24
  ],
23
-
25
+
24
26
  defaults: function() {
25
27
  return this.deep_defaults({
26
28
  margin: {
@@ -29,10 +31,13 @@ function onMapLoaded() {
29
31
  right: 20,
30
32
  bottom: 0
31
33
  },
32
- }, OML.map2.__super__.defaults.call(this));
33
- },
34
-
35
-
34
+ events: {
35
+ // click: event_name
36
+ }
37
+ }, map2.__super__.defaults.call(this));
38
+ },
39
+
40
+
36
41
  init_svg: function(w, h) {
37
42
  //this.init = function(opts) {
38
43
  var self = this;
@@ -40,9 +45,9 @@ function onMapLoaded() {
40
45
  var base_el = opts.base_el || '#map';
41
46
  d3.select(base_el)
42
47
  .style('position', 'relative')
43
- .style("height", "100%")
48
+ .style("height", "100%")
44
49
  .style("width", "100%")
45
- .style("height", h)
50
+ .style("height", h)
46
51
  .style("width", w)
47
52
  ;
48
53
 
@@ -54,74 +59,90 @@ function onMapLoaded() {
54
59
  var center = opts.map.center || [151.197189, -33.895508];
55
60
  var zoom = opts.map.zoom;
56
61
  if (zoom == undefined) zoom = 17;
57
- var map = this.map = new google.maps.Map(node, {
58
- zoom: zoom,
59
- center: new google.maps.LatLng(center[1], center[0]),
60
- mapTypeId: google.maps.MapTypeId.ROADMAP
61
- });
62
62
  // force width and height AFTER creating the map, otherwise height is zero.
63
63
  var ca = this.widget_area;
64
64
  d3.select('#' + map_el)
65
- .style("height", ca.h + "px")
65
+ .style("height", ca.h + "px")
66
66
  .style("width", ca.w + "px")
67
67
  .style("position", "relative")
68
68
  // .style("position", "absolute")
69
- .style("top", ca.ty + "px")
69
+ .style("top", ca.ty + "px")
70
70
  .style("left", ca.x + "px")
71
- //.style('z-index', '10')
71
+ //.style('z-index', '10')
72
72
  ;
73
73
 
74
74
  this.offset = {left: 0, top: 0};
75
-
76
- google.maps.event.addListener(map, 'bounds_changed', function() {
77
- self._resize();
78
- self.redraw();
79
- });
80
- google.maps.event.addListener(map, 'zoom_changed', function() {
81
- // some things aren't set yet when 'bounds_changed' is called after a zoom'
82
- setTimeout(function() {
83
- self._resize();
75
+
76
+ var map = null;
77
+ google.load("maps", "3", {
78
+ "other_params":"sensor=true",
79
+ "callback" : function() {
80
+ map = self.map = new google.maps.Map(node, {
81
+ zoom: zoom,
82
+ center: new google.maps.LatLng(center[1], center[0]),
83
+ mapTypeId: google.maps.MapTypeId.ROADMAP
84
+ });
85
+
86
+ google.maps.event.addListener(map, 'bounds_changed', function() {
87
+ self._resize();
88
+ self.redraw();
89
+ });
90
+ google.maps.event.addListener(map, 'zoom_changed', function() {
91
+ // some things aren't set yet when 'bounds_changed' is called after a zoom'
92
+ setTimeout(function() {
93
+ self._resize();
94
+ self.redraw();
95
+ }, 100);
96
+ });
97
+
98
+ self._configure_base_layer();
84
99
  self.redraw();
85
- }, 100);
86
- });
100
+ }
101
+ });
102
+ return null;
87
103
  },
88
-
104
+
105
+ // _google_init: function() {
106
+ //
107
+ // },
108
+
89
109
  _resize: function() {
90
110
  var self = this;
91
-
111
+
92
112
  if (self.svg_layer) {
93
113
  var map_el = self.map_el;
94
114
  var map = $('#' + map_el);
95
- var div = $('#' + map_el + '_div');
115
+ var div = $('#' + map_el + '_div');
96
116
  var svg = $('#' + map_el + '_svg');
97
117
  var map_offset = map.offset();
98
118
  var div_offset = div.offset();
99
-
119
+
100
120
  svg.width($('#' + map_el).width());
101
- svg.height($('#' + map_el).height());
121
+ svg.height($('#' + map_el).height());
102
122
 
103
123
  //console.log(map_offset.left - div_offset.left);
104
124
  // Reposition the SVG layer to cover the entire map area - requires readjustment later (this.offset)
105
125
  self.svg_layer
106
- .style("top", (self.offset.top = map_offset.top - div_offset.top) + "px")
126
+ .style("top", (self.offset.top = map_offset.top - div_offset.top) + "px")
107
127
  .style("left", (self.offset.left = map_offset.left - div_offset.left) + "px")
108
- ;
109
- }
128
+ ;
129
+ }
110
130
  },
111
-
131
+
112
132
  redraw: function() {
113
133
  //console.log("redraw");
114
134
  if (this.draw_layer) this._draw(null);
115
135
  //this.overlay.map_changed();
116
136
  },
117
-
137
+
118
138
  _draw: function(overlay) {
119
- var projection = this.overlay.getProjection();
139
+ var self = this;
140
+ var projection = this.overlay.getProjection();
120
141
  var m = this.mapping;
121
142
  var offset = this.offset;
122
143
  var x_f = function(d) {
123
- var lat = m.lat(d.value);
124
- var lng = m.lng(d.value);
144
+ var lat = m.latitude(d.value);
145
+ var lng = m.longitude(d.value);
125
146
  var point = new google.maps.LatLng(lat, lng);
126
147
  var xy = d.xy = projection.fromLatLngToDivPixel(point);
127
148
  return xy.x - offset.left;
@@ -131,60 +152,82 @@ function onMapLoaded() {
131
152
  };
132
153
  var m_f = function(d, m) {
133
154
  return (typeof m === "function") ? m(d.value) : m;
134
- }
135
-
155
+ };
156
+
136
157
  var data = d3.entries(this.data_source.rows());
137
158
  this.draw_layer.selectAll('.marker')
138
159
  .data(data)
139
- .attr("cx", x_f)
160
+ .attr("cx", x_f)
140
161
  .attr("cy", y_f)
141
- .attr("r", function(d) {return m_f(d, m.radius)})
142
- .style("fill", function(d) {return m_f(d, m.fill_color)})
143
- .style("stroke", function(d) {return m_f(d, m.stroke_color)})
144
- .style("stroke-width", function(d) {return m_f(d, m.stroke_width)})
162
+ .attr("r", function(d) {return m_f(d, m.radius);})
163
+ .style("fill", function(d) {return m_f(d, m.fill_color);})
164
+ .style("stroke", function(d) {return m_f(d, m.stroke_color);})
165
+ .style("stroke-width", function(d) {return m_f(d, m.stroke_width);})
145
166
  .enter().append('svg:circle')
146
167
  .attr("class", "marker")
147
- .attr("cx", x_f)
168
+ .attr("cx", x_f)
148
169
  .attr("cy", y_f)
149
- .attr("r", function(d) {return m_f(d, m.radius)})
150
- .style("fill", function(d) {return m_f(d, m.fill_color)})
151
- .style("stroke", function(d) {return m_f(d, m.stroke_color)})
152
- .style("stroke-width", function(d) {return m_f(d, m.stroke_width)})
170
+ .attr("r", function(d) {return m_f(d, m.radius);})
171
+ .style("fill", function(d) {return m_f(d, m.fill_color);})
172
+ .style("stroke", function(d) {return m_f(d, m.stroke_color);})
173
+ .style("stroke-width", function(d) {return m_f(d, m.stroke_width);})
174
+ .call(self._configure_events, self.opts.events, self)
175
+ .style("cursor", 'pointer')
176
+ // .on('click', function(d) {
177
+ // var x = self;
178
+ // var i = 0;
179
+ // })
180
+ // .on('mouseover', function(d) {
181
+ // var x = self;
182
+ // var i = 0;
183
+ // })
153
184
  ;
154
185
  },
155
186
 
156
- configure_base_layer: function(vis) {
187
+ _configure_events: function(el, events, self) {
188
+ _.each(events, function(v, event) {
189
+ el.on(event, function(d) {
190
+ var ev_name = v;
191
+ OHUB.trigger(ev_name, {el: self, datum: d.value, schema: self.schema});
192
+ });
193
+ });
194
+ },
195
+
196
+ // Should only call this after Google map is initialised
197
+ _configure_base_layer: function(vis) {
157
198
  var overlay = this.overlay = new google.maps.OverlayView();
158
199
  var self = this;
159
-
200
+
160
201
  // Add the container when the overlay is added to the map.
161
202
  overlay.onAdd = function() {
162
- var overlay_layer = this.getPanes().overlayLayer;
203
+ var overlay_layer = this.getPanes().overlayMouseTarget;
163
204
  d3.select(overlay_layer).attr('id', 'fooooo');
164
205
  self.div_layer = d3.select(overlay_layer).append("div")
165
206
  .attr('id', self.map_el + '_div')
166
207
  //.attr('class', this.base_css_class);
167
- ;
208
+ ;
168
209
  self.svg_layer = self.div_layer.append("svg:svg")
169
210
  .attr('id', self.map_el + '_svg')
170
211
  .style("position", "absolute")
171
- .style('z-index', '10')
212
+ .style('z-index', '10')
172
213
  ;
173
214
  self.draw_layer = self.svg_layer.append("svg:g")
174
215
  ;
175
216
  self._resize();
176
-
217
+
177
218
  overlay.draw = function() {
178
- //console.log("overlay draw");
179
- self._draw(this)
219
+ //console.log("overlay draw");
220
+ self._draw(this);
180
221
  };
181
- };
222
+ };
182
223
  overlay.setMap(this.map);
183
224
  }
184
- })
225
+
226
+ });
227
+
228
+ return map2;
185
229
  });
186
230
 
187
- }
188
231
 
189
232
  /*
190
233
  Local Variables:
@@ -192,4 +235,4 @@ function onMapLoaded() {
192
235
  tab-width: 2
193
236
  indent-tabs-mode: nil
194
237
  End:
195
- */
238
+ */