提交 302e2d93 编写于 作者: L lang

Geo name map, Grid layout enhancement, other tweaks

上级 6b52f7e0
此差异已折叠。
此差异已折叠。
...@@ -17,7 +17,7 @@ define(function (require) { ...@@ -17,7 +17,7 @@ define(function (require) {
zrUtil.each(mapSeries.seriesGroup, function (subMapSeries) { zrUtil.each(mapSeries.seriesGroup, function (subMapSeries) {
var geo = subMapSeries.coordinateSystem; var geo = subMapSeries.coordinateSystem;
var data = subMapSeries.getData(); var data = subMapSeries.getData();
if (subMapSeries.get('showLegendSymbol')) { if (subMapSeries.get('showLegendSymbol') && ecModel.getComponent('legend')) {
data.each('value', function (value, idx) { data.each('value', function (value, idx) {
var name = data.getName(idx); var name = data.getName(idx);
var region = geo.getRegion(name); var region = geo.getRegion(name);
......
...@@ -85,7 +85,6 @@ define(function(require, factory) { ...@@ -85,7 +85,6 @@ define(function(require, factory) {
* @param {module:echarts/ExtensionAPI} api * @param {module:echarts/ExtensionAPI} api
*/ */
gridProto.resize = function (gridModel, api) { gridProto.resize = function (gridModel, api) {
var gridRect = layout.parsePositionInfo({ var gridRect = layout.parsePositionInfo({
x: gridModel.get('x'), x: gridModel.get('x'),
y: gridModel.get('y'), y: gridModel.get('y'),
......
...@@ -5,13 +5,30 @@ define(function(require) { ...@@ -5,13 +5,30 @@ define(function(require) {
'use strict'; 'use strict';
require('./AxisModel'); require('./AxisModel');
var ComponentModel = require('../../model/Component');
return require('../../echarts').extendComponentModel({ return ComponentModel.extend({
type: 'grid', type: 'grid',
dependencies: ['xAxis', 'yAxis'], dependencies: ['xAxis', 'yAxis'],
mergeDefaultAndTheme: function (option, ecModel) {
// Not specify layout with x2, width, y2, height
// FIXME 通用?
if (option.x2 == null || option.width == null || option.x != null) {
option.x = option.x || '10%';
option.x2 = option.x2 || '10%';
}
if (option.y2 == null || option.height == null || option.y != null) {
option.y = option.y || 60;
option.y2 = option.y2 || 60;
}
ComponentModel.prototype.mergeDefaultAndTheme.call(
this, option, ecModel
);
},
/** /**
* @type {module:echarts/coord/cartesian/Grid} * @type {module:echarts/coord/cartesian/Grid}
*/ */
...@@ -21,10 +38,10 @@ define(function(require) { ...@@ -21,10 +38,10 @@ define(function(require) {
show: false, show: false,
zlevel: 0, // 一级层叠 zlevel: 0, // 一级层叠
z: 0, // 二级层叠 z: 0, // 二级层叠
x: '10%', // x: '10%',
y: 60, // y: 60,
x2: '10%', // x2: '10%',
y2: 60, // y2: 60,
// If grid size contain label // If grid size contain label
containLabel: false, containLabel: false,
// width: {totalWidth} - x - x2, // width: {totalWidth} - x - x2,
......
...@@ -44,14 +44,13 @@ define(function(require) { ...@@ -44,14 +44,13 @@ define(function(require) {
// There is no space for current label; // There is no space for current label;
else if (textSpaceTakenRect.intersect(rect)) { else if (textSpaceTakenRect.intersect(rect)) {
accumulatedLabelInterval++; accumulatedLabelInterval++;
continue; autoLabelInterval = Math.max(autoLabelInterval, accumulatedLabelInterval);
} }
else { else {
textSpaceTakenRect.union(rect); textSpaceTakenRect.union(rect);
// Reset
accumulatedLabelInterval = 0;
} }
autoLabelInterval = Math.max(autoLabelInterval, accumulatedLabelInterval);
// Reset
accumulatedLabelInterval = 0;
} }
return autoLabelInterval; return autoLabelInterval;
......
...@@ -16,7 +16,17 @@ define(function (require) { ...@@ -16,7 +16,17 @@ define(function (require) {
require('./fix/geoCoord') require('./fix/geoCoord')
]; ];
function Geo(name, map, geoJson, specialAreas) { /**
* [Geo description]
* @param {string} name Geo name
* @param {string} map Map type
* @param {Object} geoJson
* @param {Object} [specialAreas]
* Specify the positioned areas by left, top, width, height
* @param {Object.<string, string>} [nameMap]
* Specify name alias
*/
function Geo(name, map, geoJson, specialAreas, nameMap) {
View.call(this, name); View.call(this, name);
...@@ -33,7 +43,7 @@ define(function (require) { ...@@ -33,7 +43,7 @@ define(function (require) {
this._nameCoordMap = {}; this._nameCoordMap = {};
this.loadGeoJson(geoJson, specialAreas); this.loadGeoJson(geoJson, specialAreas, nameMap);
} }
Geo.prototype = { Geo.prototype = {
...@@ -44,27 +54,36 @@ define(function (require) { ...@@ -44,27 +54,36 @@ define(function (require) {
/** /**
* @param {Object} geoJson * @param {Object} geoJson
* @param {Object} [specialAreas]
* Specify the positioned areas by left, top, width, height
* @param {Object.<string, string>} [nameMap]
* Specify name alias
*/ */
loadGeoJson: function (geoJson, specialAreas) { loadGeoJson: function (geoJson, specialAreas, nameMap) {
// https://jsperf.com/try-catch-performance-overhead // https://jsperf.com/try-catch-performance-overhead
try { try {
this.regions = geoJson ? parseGeoJson(geoJson) : []; this.regions = geoJson ? parseGeoJson(geoJson) : [];
specialAreas = specialAreas || {};
this._specialAreas = specialAreas;
} }
catch (e) { catch (e) {
throw 'Invalid geoJson format\n' + e; throw 'Invalid geoJson format\n' + e;
} }
specialAreas = specialAreas || {};
nameMap = nameMap || {};
var regions = this.regions; var regions = this.regions;
var regionsMap = {}; var regionsMap = {};
for (var i = 0; i < regions.length; i++) { for (var i = 0; i < regions.length; i++) {
regionsMap[regions[i].name] = regions[i]; var regionName = regions[i].name;
// Try use the alias in nameMap
regionName = nameMap[regionName] || regionName;
regions[i].name = regionName;
regionsMap[regionName] = regions[i];
// Add geoJson // Add geoJson
this.addGeoCoord(regions[i].name, regions[i].center); this.addGeoCoord(regionName, regions[i].center);
// Some area like Alaska in USA map needs to be tansformed // Some area like Alaska in USA map needs to be tansformed
// to look better // to look better
var specialArea = specialAreas[regions[i].name]; var specialArea = specialAreas[regionName];
if (specialArea) { if (specialArea) {
regions[i].transformTo( regions[i].transformTo(
specialArea.left, specialArea.top, specialArea.width, specialArea.height specialArea.left, specialArea.top, specialArea.width, specialArea.height
......
...@@ -75,7 +75,9 @@ define(function (require) { ...@@ -75,7 +75,9 @@ define(function (require) {
// Warning // Warning
// } // }
var geo = new Geo( var geo = new Geo(
name + idx, name, mapData.geoJson, mapData.specialAreas name + idx, name,
mapData.geoJson, mapData.specialAreas,
geoModel.get('nameMap')
); );
geoList.push(geo); geoList.push(geo);
...@@ -115,8 +117,13 @@ define(function (require) { ...@@ -115,8 +117,13 @@ define(function (require) {
// Warning // Warning
// } // }
var nameMapList = zrUtil.map(mapSeries, function (singleMapSeries) {
return singleMapSeries.get('nameMap');
});
var geo = new Geo( var geo = new Geo(
mapType, mapType, mapData.geoJson, mapData.specialAreas mapType, mapType,
mapData.geoJson, mapData.specialAreas,
zrUtil.mergeAll(nameMapList)
); );
geoList.push(geo); geoList.push(geo);
......
...@@ -585,7 +585,7 @@ define(function (require) { ...@@ -585,7 +585,7 @@ define(function (require) {
function normalizeDimensions(dimensions) { function normalizeDimensions(dimensions) {
if (typeof (dimensions) === 'string') { if (!zrUtil.isArray(dimensions)) {
dimensions = [dimensions]; dimensions = [dimensions];
} }
return dimensions; return dimensions;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册