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

Geo name map, Grid layout enhancement, other tweaks

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