Comparing version 3.0.3 to 3.0.4-beta.1
{ | ||
"name": "@antv/g2", | ||
"version": "3.0.3", | ||
"version": "3.0.4-beta.1", | ||
"description": "the Grammar of Graphics in Javascript", | ||
@@ -5,0 +5,0 @@ "main": "build/g2.js", |
@@ -279,15 +279,12 @@ /** | ||
const field = scale.field; | ||
const isShowTitle = !!(Global.axis[position] && Global.axis[position].title); // 用户全局禁用 title | ||
let titleCfg; | ||
// bugfix: title was set by chart.axis('field', { title: {} }) | ||
if (isShowTitle || (options[field] && options[field].title)) { | ||
titleCfg = { | ||
cfg = Util.deepMix({}, Global.axis[position], cfg, options[field]); | ||
if (cfg.title) { | ||
Util.deepMix(cfg, { | ||
title: { | ||
text: scale.alias || field | ||
} | ||
}; | ||
}); | ||
} | ||
cfg = Util.deepMix({}, Global.axis[position], cfg, options[field]); | ||
Util.deepMix(cfg, titleCfg); | ||
cfg.ticks = scale.getTicks(); | ||
@@ -294,0 +291,0 @@ |
@@ -383,10 +383,13 @@ const Util = require('../../util'); | ||
const legendCfg = Util.deepMix({ | ||
title: { | ||
text: scale.alias || scale.field | ||
} | ||
}, Global.legend[position], legendOptions[field] || legendOptions, { | ||
const legendCfg = Util.deepMix({}, Global.legend[position], legendOptions[field] || legendOptions, { | ||
maxLength, | ||
items | ||
}); | ||
if (legendCfg.title) { | ||
Util.deepMix(legendCfg, { | ||
title: { | ||
text: scale.alias || scale.field | ||
} | ||
}); | ||
} | ||
@@ -451,10 +454,13 @@ const legend = container.addGroup(Legend.Category, legendCfg); | ||
const legendCfg = Util.deepMix({ | ||
title: { | ||
text: scale.alias || scale.field | ||
} | ||
}, defaultCfg, options[field] || options, { | ||
const legendCfg = Util.deepMix({}, defaultCfg, options[field] || options, { | ||
items, | ||
attr | ||
}); | ||
if (legendCfg.title) { | ||
Util.deepMix(legendCfg, { | ||
title: { | ||
text: scale.alias || scale.field | ||
} | ||
}); | ||
} | ||
@@ -461,0 +467,0 @@ if (attr.type === 'color') { |
@@ -146,3 +146,3 @@ /** | ||
return Util.mix(defaultCfg, crosshairsCfg, { | ||
isTransposed: geoms[0].get('coord').isTransposed | ||
isTransposed: geoms.length && geoms[0].get('coord') ? geoms[0].get('coord').isTransposed : false | ||
}); | ||
@@ -149,0 +149,0 @@ } |
@@ -100,3 +100,3 @@ /** | ||
let titleOffset = title.offset; | ||
if (!titleOffset) { // 没有指定 offset 则自动计算 | ||
if (Util.isNil(titleOffset)) { // 没有指定 offset 则自动计算 | ||
titleOffset = 20; | ||
@@ -115,4 +115,3 @@ const labelsGroup = self.get('labelsGroup'); | ||
const vector = self.getAxisVector(); // 坐标轴方向的向量 | ||
if (title.autoRotate && !textStyle.rotate) { // 自动旋转并且用户没有指定标题的旋转角度 | ||
if (title.autoRotate && Util.isNil(textStyle.rotate)) { // 自动旋转并且用户没有指定标题的旋转角度 | ||
let angle = 0; | ||
@@ -126,3 +125,3 @@ if (!Util.snapEqual(vector[1], 0)) { // 所有水平坐标轴,文本不转置 | ||
cfg.rotate = angle * (180 / Math.PI); | ||
} else if (textStyle.rotate) { // 用户设置了旋转角度就以用户设置的为准 | ||
} else if (!Util.isNil(textStyle.rotate)) { // 用户设置了旋转角度就以用户设置的为准 | ||
cfg.rotate = (textStyle.rotate / 180) * Math.PI; // 将角度转换为弧度 | ||
@@ -129,0 +128,0 @@ } |
@@ -118,6 +118,6 @@ /** | ||
cfg = Util.mix({}, cfg, textStyle); | ||
if (textCfg.autoRotate && !textStyle.rotate) { | ||
if (textCfg.autoRotate && Util.isNil(textStyle.rotate)) { // 自动旋转且用户没有设置旋转角度 | ||
const angle = vec2.angleTo([ end.x - start.x, end.y - start.y ], [ 1, 0 ], 1); | ||
cfg.rotate = angle; | ||
} else if (textStyle.rotate) { | ||
} else if (!Util.isNil(textStyle.rotate)) { // 用户设置了旋转角度 | ||
cfg.rotate = (textStyle.rotate * Math.PI) / 180; | ||
@@ -124,0 +124,0 @@ } |
@@ -8,2 +8,3 @@ /** | ||
const MAX_COUNT = 8; | ||
const SUB_COUNT = 4; // 控制个数不能过小 | ||
@@ -21,28 +22,46 @@ function getSimpleArray(data) { | ||
} | ||
function getGreatestFactor(count, number) { | ||
let i; | ||
for (i = number; i > 0; i--) { | ||
if (count % i === 0) { break; } | ||
} | ||
// 如果是素数,没有可以整除的数字 | ||
if (i === 1) { | ||
for (i = number; i > 0; i--) { | ||
if ((count - 1) % i === 0) { break; } | ||
} | ||
} | ||
return i; | ||
} | ||
module.exports = function(info) { | ||
const rst = {}; | ||
let ticks = []; | ||
const tickCount = info.maxCount || MAX_COUNT; | ||
const ticks = []; | ||
const maxCount = info.maxCount || MAX_COUNT; | ||
const categories = getSimpleArray(info.data); | ||
if (categories.length <= tickCount + tickCount / 2) { | ||
ticks = [].concat(categories); | ||
} else { | ||
const length = categories.length; | ||
const step = parseInt(length / (tickCount - 1), 10); | ||
const length = categories.length; | ||
let tickCount = getGreatestFactor(length - 1, maxCount - 1) + 1; | ||
const groups = categories.map(function(e, i) { | ||
return i % step === 0 ? categories.slice(i, i + step) : null; | ||
}).filter(function(e) { | ||
return e; | ||
}); | ||
// 如果计算出来只有两个坐标点,则直接使用传入的 maxCount | ||
if (tickCount === 2) { | ||
tickCount = maxCount; | ||
} else if (tickCount < maxCount - SUB_COUNT) { | ||
tickCount = maxCount - SUB_COUNT; | ||
} | ||
const step = parseInt(length / (tickCount - 1), 10); | ||
ticks.push(categories[0]); | ||
for (let i = 1; (i < groups.length) && (i < tickCount - 1); i++) { | ||
ticks.push(groups[i][0]); | ||
} | ||
const groups = categories.map(function(e, i) { | ||
return i % step === 0 ? categories.slice(i, i + step) : null; | ||
}).filter(function(e) { | ||
return e; | ||
}); | ||
ticks.push(categories[length - 1]); | ||
ticks.push(categories[0]); | ||
for (let i = 1; (i < groups.length) && (i * step < length - step); i++) { | ||
ticks.push(groups[i][0]); | ||
} | ||
const last = categories[length - 1]; | ||
if (ticks.indexOf(last) === -1) { | ||
ticks.push(last); | ||
} | ||
@@ -49,0 +68,0 @@ rst.categories = categories; |
@@ -38,3 +38,3 @@ /** | ||
*/ | ||
tickCount: 5 | ||
tickCount: 7 | ||
}); | ||
@@ -67,8 +67,13 @@ } | ||
const count = self.tickCount; | ||
const temp = catAuto({ | ||
maxCount: count, | ||
data: self.values | ||
}); | ||
let ticks; | ||
if (count) { | ||
const temp = catAuto({ | ||
maxCount: count, | ||
data: self.values | ||
}); | ||
ticks = temp.ticks; | ||
} else { | ||
ticks = self.values; | ||
} | ||
const ticks = temp.ticks; | ||
if (formated) { | ||
@@ -75,0 +80,0 @@ Util.each(ticks, function(value, index) { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4346157
63388
1