Skip to content

Commit

Permalink
feat: the drawing order of geoms can be decided by scale values.
Browse files Browse the repository at this point in the history
  • Loading branch information
simaQ committed Jun 11, 2018
1 parent 4059801 commit 1f2993e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/chart/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/geom/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand All @@ -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);
Expand Down
25 changes: 25 additions & 0 deletions test/unit/geom/geom-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down

0 comments on commit 1f2993e

Please sign in to comment.