Daniel@0
|
1 "use strict";
|
Daniel@0
|
2
|
Daniel@0
|
3 App.module("RepresentationModule", function(RepresentationModule, App, Backbone, Marionette, $, _, Logger) {
|
Daniel@0
|
4
|
Daniel@0
|
5 RepresentationModule.addInitializer(function(options){
|
Daniel@0
|
6
|
Daniel@0
|
7 RepresentationModule.registerMaster({
|
Daniel@0
|
8 id: "view.collection.geography",
|
Daniel@0
|
9 inherit: "view._default",
|
Daniel@0
|
10
|
Daniel@0
|
11 options: {
|
Daniel@0
|
12 canHaveBase: true,
|
Daniel@0
|
13 headerSuffixesForRegionValues: {
|
Daniel@0
|
14 "planet": "whole planet",
|
Daniel@0
|
15 "africa": "Africa",
|
Daniel@0
|
16 "europe": "Europe",
|
Daniel@0
|
17 "_unknown": "unknown region"
|
Daniel@0
|
18 },
|
Daniel@0
|
19 widthToHeightRatioByRegion: {
|
Daniel@0
|
20 "planet": 0.5,
|
Daniel@0
|
21 "africa": 1.1,
|
Daniel@0
|
22 "europe": 0.8
|
Daniel@0
|
23 },
|
Daniel@0
|
24 widthToHeightRatio: 2,
|
Daniel@0
|
25 visInstanceContentHeightMin: 40,
|
Daniel@0
|
26 //visInstanceSupportedComparisonModes: ["superposition", "direct"],
|
Daniel@0
|
27 auxiliaryData: {
|
Daniel@0
|
28 //"countries": "views/geography/countries.min.geojson"
|
Daniel@0
|
29 "countryOutlines": "views/geography/world-110m.json",
|
Daniel@0
|
30 "countries": "views/geography/countries.json",
|
Daniel@0
|
31 "placeCountryNumericCodes": "views/geography/placeCountryNumericCodes.json" // run "app/console dml:views:geography:parse-places" and then "app/console dml:views:geography:extract-country-codes" to generate this file
|
Daniel@0
|
32 },
|
Daniel@0
|
33 auxiliaryAssets: [
|
Daniel@0
|
34 //"views/geography/d3.geo.projection.min.js"
|
Daniel@0
|
35 ]
|
Daniel@0
|
36 },
|
Daniel@0
|
37
|
Daniel@0
|
38 defaultConfigParameterValues: {
|
Daniel@0
|
39 displayRegion: "planet",
|
Daniel@0
|
40 showCountriesAsCircles: ""
|
Daniel@0
|
41 },
|
Daniel@0
|
42
|
Daniel@0
|
43 checkIfAuxiliaryAssetsAreReady: function() {
|
Daniel@0
|
44 return !!(d3 && d3.geo && _.isFunction(d3.geo.projection));
|
Daniel@0
|
45 },
|
Daniel@0
|
46
|
Daniel@0
|
47 // =================================================================
|
Daniel@0
|
48 // config grid header
|
Daniel@0
|
49
|
Daniel@0
|
50 _generateHeaderLabelSuffix: function(headerView) {
|
Daniel@0
|
51 var result = [];
|
Daniel@0
|
52 var region = this.getConfigParameterValueOrDefaultValue(headerView.options.config, "displayRegion", true);
|
Daniel@0
|
53 if (region != "planet") {
|
Daniel@0
|
54 var regionLabel = this.options.headerSuffixesForRegionValues[region];
|
Daniel@0
|
55 if (!regionLabel) {
|
Daniel@0
|
56 regionLabel = this.options.headerSuffixesForRegionValues["_unknown"];
|
Daniel@0
|
57 }
|
Daniel@0
|
58 result.push(_.str.sprintf(" (%s)", regionLabel));
|
Daniel@0
|
59 }
|
Daniel@0
|
60
|
Daniel@0
|
61
|
Daniel@0
|
62 var showCountriesAsCircles = this.getConfigParameterValueOrDefaultValue(headerView.options.config, "showCountriesAsCircles", true);
|
Daniel@0
|
63 if (showCountriesAsCircles) {
|
Daniel@0
|
64 result.push(", countries are shown as circles");
|
Daniel@0
|
65 }
|
Daniel@0
|
66
|
Daniel@0
|
67 return result.join('');
|
Daniel@0
|
68 },
|
Daniel@0
|
69
|
Daniel@0
|
70
|
Daniel@0
|
71 // =================================================================
|
Daniel@0
|
72 // vis instance rendering
|
Daniel@0
|
73
|
Daniel@0
|
74 calculateVisInstanceContentHeight: function(viewConfig, entityWidth) {
|
Daniel@0
|
75 var displayRegion = this.getConfigParameterValueOrDefaultValue(viewConfig, "displayRegion", true);
|
Daniel@0
|
76 var height = this.options.widthToHeightRatioByRegion[displayRegion] * entityWidth;
|
Daniel@0
|
77 if (!height) {
|
Daniel@0
|
78 height = this.options.widthToHeightRatio;
|
Daniel@0
|
79 }
|
Daniel@0
|
80 if (height < this.options.visInstanceContentHeightMin) {
|
Daniel@0
|
81 height = this.options.visInstanceContentHeightMin;
|
Daniel@0
|
82 }
|
Daniel@0
|
83 return height;
|
Daniel@0
|
84 },
|
Daniel@0
|
85
|
Daniel@0
|
86
|
Daniel@0
|
87 // -----------------------------------------------------------------
|
Daniel@0
|
88 // vis instance rendering - base
|
Daniel@0
|
89
|
Daniel@0
|
90 _generateCustomParamsForBasePerspectiveRequestParams: function(viewConfig) {
|
Daniel@0
|
91 var result = {
|
Daniel@0
|
92 "pid": "places_hist"
|
Daniel@0
|
93 };
|
Daniel@0
|
94 return result;
|
Daniel@0
|
95 },
|
Daniel@0
|
96
|
Daniel@0
|
97 _doRenderVisInstanceViewBaseWithKnownComparisonMode: function(visInstanceView, comparisonMode) {
|
Daniel@0
|
98 var viewConfig = visInstanceView.options.viewConfig;
|
Daniel@0
|
99
|
Daniel@0
|
100 // fixme precompute this somewhere else
|
Daniel@0
|
101 if (!visInstanceView._cachedViewMaster.auxiliaryData.countriesByCountryNumericCode) {
|
Daniel@0
|
102 visInstanceView._cachedViewMaster.auxiliaryData.countriesByCountryNumericCode = {};
|
Daniel@0
|
103 _.each(visInstanceView._cachedViewMaster.auxiliaryData.countries, function(country) {
|
Daniel@0
|
104 visInstanceView._cachedViewMaster.auxiliaryData.countriesByCountryNumericCode[country[1]] = country;
|
Daniel@0
|
105 });
|
Daniel@0
|
106 }
|
Daniel@0
|
107
|
Daniel@0
|
108 var options = {};
|
Daniel@0
|
109 options.comparisonMode = comparisonMode;
|
Daniel@0
|
110
|
Daniel@0
|
111 options.countryOutlines = visInstanceView._cachedViewMaster.auxiliaryData.countryOutlines;
|
Daniel@0
|
112 options.countries = visInstanceView._cachedViewMaster.auxiliaryData.countries;
|
Daniel@0
|
113 options.countriesByCountryNumericCode = visInstanceView._cachedViewMaster.auxiliaryData.countriesByCountryNumericCode;
|
Daniel@0
|
114 options.placeCountryNumericCodes = visInstanceView._cachedViewMaster.auxiliaryData.placeCountryNumericCodes;
|
Daniel@0
|
115 options.region = this.getConfigParameterValueOrDefaultValue(viewConfig, "displayRegion", true);
|
Daniel@0
|
116 options.showCountriesAsCircles = !!this.getConfigParameterValueOrDefaultValue(viewConfig, "showCountriesAsCircles", true);
|
Daniel@0
|
117
|
Daniel@0
|
118 App.GraphicsRenderingModule.render("geography", visInstanceView.$content, this._groupDataForGraphicsRendering(visInstanceView, "base"), options);
|
Daniel@0
|
119 },
|
Daniel@0
|
120
|
Daniel@0
|
121 });
|
Daniel@0
|
122 });
|
Daniel@0
|
123 }, Logger);
|