Forráskód Böngészése

[search] Added China to the gradient map scope

Enrico Berti 10 éve
szülő
commit
694f2cb

+ 1 - 0
apps/search/src/search/templates/search.mako

@@ -369,6 +369,7 @@ ${ dashboard.layout_skeleton() }
           <select data-bind="selectedOptions: properties.scope" class="input-small">
           <select data-bind="selectedOptions: properties.scope" class="input-small">
             <option value="world">${ _("World") }</option>
             <option value="world">${ _("World") }</option>
             <option value="usa">${ _("USA") }</option>
             <option value="usa">${ _("USA") }</option>
+            <option value="chn">${ _("China") }</option>
           </select>
           </select>
         </span>
         </span>
       </div>
       </div>

+ 4 - 0
desktop/core/src/desktop/static/desktop/js/hue.geo.js

@@ -282,6 +282,10 @@ var HueGeo = {
     }
     }
     return null;
     return null;
   },
   },
+  getISOAlpha2: function (code) {
+    var _country = HueGeo.getCountryFromCode(code);
+    return _country ? _country.alpha2 : "AQ";
+  },
   getISOAlpha3: function (code) {
   getISOAlpha3: function (code) {
     var _country = HueGeo.getCountryFromCode(code);
     var _country = HueGeo.getCountryFromCode(code);
     return _country ? _country.alpha3 : "ATA";
     return _country ? _country.alpha3 : "ATA";

+ 6 - 0
desktop/core/src/desktop/static/desktop/js/ko.charts.js

@@ -587,6 +587,9 @@ ko.bindingHandlers.mapChart = {
         addToLegend(getHighestCategoryValue(cnt, item));
         addToLegend(getHighestCategoryValue(cnt, item));
         var _place = typeof item.label == "String" ? item.label.toUpperCase() : item.label;
         var _place = typeof item.label == "String" ? item.label.toUpperCase() : item.label;
         if (_place != null) {
         if (_place != null) {
+          if (_scope != "world" && _scope != "usa" && _place.indexOf(".") == -1) {
+            _place = HueGeo.getISOAlpha2(_scope) + "." + _place;
+          }
           _mapdata[_place] = {
           _mapdata[_place] = {
             fillKey: "fill_" + (_is2d ? getHighestCategoryValue(cnt, item).idx : (Math.ceil(item.value / _chunk) - 1)),
             fillKey: "fill_" + (_is2d ? getHighestCategoryValue(cnt, item).idx : (Math.ceil(item.value / _chunk) - 1)),
             id: _place,
             id: _place,
@@ -609,6 +612,9 @@ ko.bindingHandlers.mapChart = {
       $(_data).each(function (cnt, item) {
       $(_data).each(function (cnt, item) {
         var _place = item.label.toUpperCase();
         var _place = item.label.toUpperCase();
         if (_place != null) {
         if (_place != null) {
+          if (_scope != "world" && _scope != "usa" && _place.indexOf(".") == -1) {
+            _place = HueGeo.getISOAlpha2(_scope) + "." + _place;
+          }
           _mapdata[_place] = {
           _mapdata[_place] = {
             fillKey: "selected",
             fillKey: "selected",
             id: _place,
             id: _place,

+ 7 - 0
desktop/core/src/desktop/static/desktop/js/nv.d3.datamaps.js

@@ -99,6 +99,13 @@
           .scale((element.offsetWidth + 1) / 2 / Math.PI)
           .scale((element.offsetWidth + 1) / 2 / Math.PI)
           .translate([element.offsetWidth / 2, element.offsetHeight / (options.projection === "mercator" ? 1.45 : 1.8)]);
           .translate([element.offsetWidth / 2, element.offsetHeight / (options.projection === "mercator" ? 1.45 : 1.8)]);
     }
     }
+    else if (options.scope === 'chn') {
+      projection = d3.geo[options.projection]()
+          .center([104.18741784700012,34.672410587000066])
+          .rotate([0, 0])
+          .scale(380)
+          .translate([element.offsetWidth / 2, element.offsetHeight / (options.projection === "mercator" ? 1.45 : 1.8)]);
+    }
 
 
     path = d3.geo.path()
     path = d3.geo.path()
         .projection(projection);
         .projection(projection);

+ 1 - 0
desktop/core/src/desktop/templates/common_dashboard.mako

@@ -270,6 +270,7 @@
   <script src="${ static('desktop/ext/js/topojson.v1.min.js') }" type="text/javascript" charset="utf-8"></script>
   <script src="${ static('desktop/ext/js/topojson.v1.min.js') }" type="text/javascript" charset="utf-8"></script>
   <script src="${ static('desktop/ext/js/topo/world.topo.js') }" type="text/javascript" charset="utf-8"></script>
   <script src="${ static('desktop/ext/js/topo/world.topo.js') }" type="text/javascript" charset="utf-8"></script>
   <script src="${ static('desktop/ext/js/topo/usa.topo.js') }" type="text/javascript" charset="utf-8"></script>
   <script src="${ static('desktop/ext/js/topo/usa.topo.js') }" type="text/javascript" charset="utf-8"></script>
+  <script src="${ static('desktop/ext/js/topo/chn.topo.js') }" type="text/javascript" charset="utf-8"></script>
 
 
   <script src="${ static('desktop/js/nv.d3.datamaps.js') }" type="text/javascript" charset="utf-8"></script>
   <script src="${ static('desktop/js/nv.d3.datamaps.js') }" type="text/javascript" charset="utf-8"></script>
   <script src="${ static('desktop/js/nv.d3.legend.js') }" type="text/javascript" charset="utf-8"></script>
   <script src="${ static('desktop/js/nv.d3.legend.js') }" type="text/javascript" charset="utf-8"></script>

+ 1 - 0
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -63,6 +63,7 @@ from desktop.views import _ko
 <script src="${ static('desktop/ext/js/topojson.v1.min.js') }" type="text/javascript" charset="utf-8"></script>
 <script src="${ static('desktop/ext/js/topojson.v1.min.js') }" type="text/javascript" charset="utf-8"></script>
 <script src="${ static('desktop/ext/js/topo/world.topo.js') }" type="text/javascript" charset="utf-8"></script>
 <script src="${ static('desktop/ext/js/topo/world.topo.js') }" type="text/javascript" charset="utf-8"></script>
 <script src="${ static('desktop/ext/js/topo/usa.topo.js') }" type="text/javascript" charset="utf-8"></script>
 <script src="${ static('desktop/ext/js/topo/usa.topo.js') }" type="text/javascript" charset="utf-8"></script>
+<script src="${ static('desktop/ext/js/topo/chn.topo.js') }" type="text/javascript" charset="utf-8"></script>
 
 
 <script src="${ static('desktop/js/nv.d3.datamaps.js') }" type="text/javascript" charset="utf-8"></script>
 <script src="${ static('desktop/js/nv.d3.datamaps.js') }" type="text/javascript" charset="utf-8"></script>
 <script src="${ static('desktop/js/nv.d3.legend.js') }" type="text/javascript" charset="utf-8"></script>
 <script src="${ static('desktop/js/nv.d3.legend.js') }" type="text/javascript" charset="utf-8"></script>