-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathd3_projection.module
60 lines (54 loc) · 1.69 KB
/
d3_projection.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/*function d3_projection_views_plugins_alter(&$plugins) {
dsm($plugins);
}*/
function d3_projection_views_api() {
return array(
'api' => 3,
'path' => drupal_get_path('module', 'd3_projection') . '/views',
);
}
function template_preprocess_d3_projection_map(&$vars) {
$path = drupal_get_path('module', 'd3_projection');
// d3 libs
drupal_add_js("http://d3js.org/d3.v3.min.js");
drupal_add_js("http://d3js.org/topojson.v1.min.js");
// Send our data object to javascript
drupal_add_js(array('d3Projection' => _d3_projection_build_data_array($vars)), 'setting');
// The D3 projection script.
drupal_add_js($path . '/js/projection.js');
// Styles for the map
drupal_add_css($path . '/d3_projection.css');
}
function _d3_projection_build_data_array($vars) {
$module_path = drupal_get_path('module', 'd3_projection');
return array(
'pathToPin' => $module_path . '/pin.png',
'pathToTopo' => $module_path . '/us.json',
'options' => $vars['options'],
'mapData' => _d3_projection_parse_rows($vars['rows']),
);
}
function _d3_projection_parse_rows($rows) {
$map_data = array();
foreach($rows as $row) {
$map_data[] = array(
'node_title' => '<h2>' . $row->node_title . '<h2>',
'toolTipImg' => render( $row->field_field_tooltip[0]['rendered'] ),
'lon' => $row->field_field_geo_coords[0]['raw']['lon'],
'lat' => $row->field_field_geo_coords[0]['raw']['lat'],
);
}
return $map_data;
}
/**
* Implements hook_theme().
*/
function d3_projection_theme($existing, $type, $theme, $path) {
return array(
'd3_projection_map' => array(
'variables' => array('args' => NULL),
'template' => 'views/d3-projection-map',
),
);
}