Permalink
Browse files

feat: the drawing order of geoms can be decided by scale values.

  • Loading branch information...
simaQ committed May 24, 2018
1 parent 4059801 commit 1f2993e6ba818d795108522b56f9d5949a8b7d2c
Showing with 29 additions and 3 deletions.
  1. +2 −0 src/chart/chart.js
  2. +2 −3 src/geom/base.js
  3. +25 −0 test/unit/geom/geom-spec.js
@@ -265,10 +265,12 @@ class Chart extends Base {
_initGeoms(geoms) {
const coord = this.get('coord');
const data = this.get('filteredData');
const colDefs = this.get('colDefs');
for (let i = 0, length = geoms.length; i < length; i++) {
const geom = geoms[i];
geom.set('data', data);
geom.set('coord', coord);
geom.set('colDefs', colDefs);
geom.init();
}
}
@@ -109,8 +109,7 @@ class Geom extends Base {
// 分组数据
_groupData(data) {
const self = this;
const chart = self.get('chart');
const colDefs = chart.get('colDefs');
const colDefs = self.get('colDefs');
const groupScales = self._getGroupScales();
if (groupScales.length) {
const appendConditions = {};
@@ -119,7 +118,7 @@ class Geom extends Base {
const field = scale.field;
names.push(field);
if (colDefs && colDefs[field] && colDefs[field].values) { // 用户指定了顺序
appendConditions[scale.field] = scale.values;
appendConditions[scale.field] = colDefs[field].values;
}
});
return Util.Array.group(data, names, appendConditions);
@@ -173,6 +173,7 @@ describe('test geoms', function() {
expect(geom.get('attrs')).eqls({});
// expect(geom.get('adjusts')).eqls(null);
});
it('test total init', function() {
geom.position('a*b').color('c');
geom.init();
@@ -181,6 +182,30 @@ describe('test geoms', function() {
expect(dataArray[1][0].b).eqls(3);
});
it('test group data with values setting in colDefs', function() {
geom.reset();
geom.set('colDefs', {
c: {
values: [ '2', '1' ]
}
});
geom.position('a*b').color('c');
geom._initAttrs();
const geomData = [
{ a: 1, b: 2, c: '1' },
{ a: 1, b: 3, c: '2' },
{ a: 2, b: 1, c: '1' },
{ a: 2, b: 4, c: '2' },
{ a: 3, b: 5, c: '1' },
{ a: 3, b: 1, c: '2' }
];
const arr = geom._groupData(geomData);
expect(arr.length).equal(2);
expect(arr[0][0].c).equal('2');
expect(arr[1][0].c).equal('1');
});
it('destroy', function() {
geom.destroy();
expect(geom.destroyed).equal(true);

0 comments on commit 1f2993e

Please sign in to comment.