Daniel@0: "use strict"; Daniel@0: Daniel@0: App.module("RepresentationModule", function(RepresentationModule, App, Backbone, Marionette, $, _, Logger) { Daniel@0: Daniel@0: RepresentationModule.addInitializer(function(options){ Daniel@0: Daniel@0: RepresentationModule.registerMaster({ Daniel@0: id: "view.collection.geography", Daniel@0: inherit: "view._default", Daniel@0: Daniel@0: options: { Daniel@0: canHaveBase: true, Daniel@0: headerSuffixesForRegionValues: { Daniel@0: "planet": "whole planet", Daniel@0: "africa": "Africa", Daniel@0: "europe": "Europe", Daniel@0: "_unknown": "unknown region" Daniel@0: }, Daniel@0: widthToHeightRatioByRegion: { Daniel@0: "planet": 0.5, Daniel@0: "africa": 1.1, Daniel@0: "europe": 0.8 Daniel@0: }, Daniel@0: widthToHeightRatio: 2, Daniel@0: visInstanceContentHeightMin: 40, Daniel@0: //visInstanceSupportedComparisonModes: ["superposition", "direct"], Daniel@0: auxiliaryData: { Daniel@0: //"countries": "views/geography/countries.min.geojson" Daniel@0: "countryOutlines": "views/geography/world-110m.json", Daniel@0: "countries": "views/geography/countries.json", Daniel@0: "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: }, Daniel@0: auxiliaryAssets: [ Daniel@0: //"views/geography/d3.geo.projection.min.js" Daniel@0: ] Daniel@0: }, Daniel@0: Daniel@0: defaultConfigParameterValues: { Daniel@0: displayRegion: "planet", Daniel@0: showCountriesAsCircles: "" Daniel@0: }, Daniel@0: Daniel@0: checkIfAuxiliaryAssetsAreReady: function() { Daniel@0: return !!(d3 && d3.geo && _.isFunction(d3.geo.projection)); Daniel@0: }, Daniel@0: Daniel@0: // ================================================================= Daniel@0: // config grid header Daniel@0: Daniel@0: _generateHeaderLabelSuffix: function(headerView) { Daniel@0: var result = []; Daniel@0: var region = this.getConfigParameterValueOrDefaultValue(headerView.options.config, "displayRegion", true); Daniel@0: if (region != "planet") { Daniel@0: var regionLabel = this.options.headerSuffixesForRegionValues[region]; Daniel@0: if (!regionLabel) { Daniel@0: regionLabel = this.options.headerSuffixesForRegionValues["_unknown"]; Daniel@0: } Daniel@0: result.push(_.str.sprintf(" (%s)", regionLabel)); Daniel@0: } Daniel@0: Daniel@0: Daniel@0: var showCountriesAsCircles = this.getConfigParameterValueOrDefaultValue(headerView.options.config, "showCountriesAsCircles", true); Daniel@0: if (showCountriesAsCircles) { Daniel@0: result.push(", countries are shown as circles"); Daniel@0: } Daniel@0: Daniel@0: return result.join(''); Daniel@0: }, Daniel@0: Daniel@0: Daniel@0: // ================================================================= Daniel@0: // vis instance rendering Daniel@0: Daniel@0: calculateVisInstanceContentHeight: function(viewConfig, entityWidth) { Daniel@0: var displayRegion = this.getConfigParameterValueOrDefaultValue(viewConfig, "displayRegion", true); Daniel@0: var height = this.options.widthToHeightRatioByRegion[displayRegion] * entityWidth; Daniel@0: if (!height) { Daniel@0: height = this.options.widthToHeightRatio; Daniel@0: } Daniel@0: if (height < this.options.visInstanceContentHeightMin) { Daniel@0: height = this.options.visInstanceContentHeightMin; Daniel@0: } Daniel@0: return height; Daniel@0: }, Daniel@0: Daniel@0: Daniel@0: // ----------------------------------------------------------------- Daniel@0: // vis instance rendering - base Daniel@0: Daniel@0: _generateCustomParamsForBasePerspectiveRequestParams: function(viewConfig) { Daniel@0: var result = { Daniel@0: "pid": "places_hist" Daniel@0: }; Daniel@0: return result; Daniel@0: }, Daniel@0: Daniel@0: _doRenderVisInstanceViewBaseWithKnownComparisonMode: function(visInstanceView, comparisonMode) { Daniel@0: var viewConfig = visInstanceView.options.viewConfig; Daniel@0: Daniel@0: // fixme precompute this somewhere else Daniel@0: if (!visInstanceView._cachedViewMaster.auxiliaryData.countriesByCountryNumericCode) { Daniel@0: visInstanceView._cachedViewMaster.auxiliaryData.countriesByCountryNumericCode = {}; Daniel@0: _.each(visInstanceView._cachedViewMaster.auxiliaryData.countries, function(country) { Daniel@0: visInstanceView._cachedViewMaster.auxiliaryData.countriesByCountryNumericCode[country[1]] = country; Daniel@0: }); Daniel@0: } Daniel@0: Daniel@0: var options = {}; Daniel@0: options.comparisonMode = comparisonMode; Daniel@0: Daniel@0: options.countryOutlines = visInstanceView._cachedViewMaster.auxiliaryData.countryOutlines; Daniel@0: options.countries = visInstanceView._cachedViewMaster.auxiliaryData.countries; Daniel@0: options.countriesByCountryNumericCode = visInstanceView._cachedViewMaster.auxiliaryData.countriesByCountryNumericCode; Daniel@0: options.placeCountryNumericCodes = visInstanceView._cachedViewMaster.auxiliaryData.placeCountryNumericCodes; Daniel@0: options.region = this.getConfigParameterValueOrDefaultValue(viewConfig, "displayRegion", true); Daniel@0: options.showCountriesAsCircles = !!this.getConfigParameterValueOrDefaultValue(viewConfig, "showCountriesAsCircles", true); Daniel@0: Daniel@0: App.GraphicsRenderingModule.render("geography", visInstanceView.$content, this._groupDataForGraphicsRendering(visInstanceView, "base"), options); Daniel@0: }, Daniel@0: Daniel@0: }); Daniel@0: }); Daniel@0: }, Logger);