remove most lodash functions

This commit is contained in:
黄通 2018-10-23 16:46:45 +08:00
parent 262443268c
commit f207b05b73
20 changed files with 51 additions and 42 deletions

View File

@ -184,7 +184,7 @@ class Minimap {
}
graph = this.getGraph();
miniMapViewPortActived = true;
startMatrix = Util.cloneDeep(graph.getMatrix());
startMatrix = Util.clone(graph.getMatrix());
miniMapScale = this.miniMapMatrix[0];
graphScale = startMatrix[0];
startPoint = {
@ -202,7 +202,7 @@ class Minimap {
if (miniMapViewPortActived && graph) {
const dx = startPoint.clientX - ev.clientX;
const dy = startPoint.clientY - ev.clientY;
const matrix = Util.cloneDeep(startMatrix);
const matrix = Util.clone(startMatrix);
Util.mat3.translate(matrix, matrix, [ graphScale * dx / miniMapScale, graphScale * dy / miniMapScale ]);
graph.updateMatrix(matrix);
}

View File

@ -27,7 +27,7 @@ class Controller extends Base {
group.deepEach(element => {
const id = element.gid;
const subStash = {
matrix: Util.cloneDeep(element.getMatrix())
matrix: Util.clone(element.getMatrix())
};
if (element.isItemContainer) {
subStash.enterAnimate = item.getEnterAnimate();
@ -38,7 +38,7 @@ class Controller extends Base {
if (element.isShape) {
let attrs = element.attr();
attrs = Util.omit(attrs, [ 'matrix', 'fillStyle', 'strokeStyle', 'endArrow', 'startArrow' ]);
subStash.attrs = Util.cloneDeep(attrs);
subStash.attrs = Util.clone(attrs);
}
subStash.item = item;
subStash.element = element;

View File

@ -108,7 +108,7 @@ class Graph extends Base {
const cfg = {};
Mixins.forEach(Mixin => {
Util.mix(cfg, Util.cloneDeep(Mixin.CFG), inputCfg);
Util.mix(cfg, Util.clone(Mixin.CFG), inputCfg);
});
super(cfg);
// plugin should init before all
@ -467,7 +467,7 @@ class Graph extends Base {
const model = child.model;
if (model) {
const type = child.itemType;
const saveModel = Util.cloneDeep(model);
const saveModel = Util.clone(model);
saveModel.index = index;
rst[type + 's'].push(saveModel);
}

View File

@ -98,7 +98,7 @@ class Graph2Canvas {
afterTransform } = this.options;
const canvas = this.getCanvas();
const graphBBox = graph.getBBox();
const matrixCache = Util.cloneDeep(graph.getMatrix());
const matrixCache = Util.clone(graph.getMatrix());
const padding = graph.getFitViewPadding();
const graphCanvas = graph.getCanvas();
const matrix = Util.getAutoZoomMatrix({

View File

@ -365,7 +365,7 @@ class Tree extends Graph {
}
save() {
const rst = {
roots: Util.cloneDeep(this.getSource().roots),
roots: Util.clone(this.getSource().roots),
guides: this.getGuides().map(guide => {
return guide.getModel();
})

View File

@ -8,16 +8,25 @@ const Util = require('@antv/util/lib');
const BaseUtil = {
...Util,
omit: require('lodash/omit'),
lowerFirst: require('lodash/lowerFirst'),
isPlainObject: require('lodash/isPlainObject'),
indexOf: require('lodash/indexOf'),
cloneDeep: require('lodash/cloneDeep'),
round: require('lodash/round'),
filter: require('lodash/filter'),
throttle: require('lodash/throttle'),
debounce: require('lodash/debounce'),
uniq: require('lodash/uniq'),
/**
* The opposite of pick; this method creates an object composed of the own and inherited enumerable property paths of object that are not omitted.
* var object = { 'a': 1, 'b': '2', 'c': 3 };
* omit(object, ['a', 'c']); // => { 'b': '2' }
* @param {object} object - input object
* @param {function} array - condition array
* @return {object} result object
*/
omit(object, array) {
const rst = {};
Util.each(object, (value, key) => {
if (array.indexOf(key) === -1) {
rst[key] = value;
}
});
return rst;
},
/**
* traverse tree
* @param {object} parent parent

View File

@ -17,7 +17,7 @@ const graph = new Graph({
height
});
graph.source(Util.cloneDeep(data));
graph.source(Util.clone(data));
graph.render();
@ -31,7 +31,7 @@ describe('anchor user case test', () => {
G6.registerNode('test1', {
anchor: getDefaultAnchors
});
const tmpData = Util.cloneDeep(data);
const tmpData = Util.clone(data);
tmpData.nodes = tmpData.nodes.map(item => {
item.shape = 'test1';
return item;
@ -60,7 +60,7 @@ describe('anchor user case test', () => {
},
anchor: getDefaultAnchors()
});
const tmpData = Util.cloneDeep(data);
const tmpData = Util.clone(data);
tmpData.nodes = tmpData.nodes.map(item => {
item.shape = 'test2';
return item;
@ -105,7 +105,7 @@ describe('anchor user case test', () => {
}
});
const tmpData = Util.cloneDeep(data);
const tmpData = Util.clone(data);
tmpData.nodes = tmpData.nodes.map(item => {
item.shape = 'test3';
return item;
@ -133,7 +133,7 @@ describe('anchor user case test', () => {
}
});
const tmpData = Util.cloneDeep(data);
const tmpData = Util.clone(data);
tmpData.nodes = tmpData.nodes.map(item => {
item.shape = 'test';
return item;

View File

@ -19,7 +19,7 @@ describe('test graph aniamte', () => {
}
});
it('test read', done => {
graph.read(Util.cloneDeep(data), true);
graph.read(Util.clone(data), true);
setTimeout(() => {
done();
}, delay);

View File

@ -32,7 +32,7 @@ describe('graph behaviour-mode user cases test', () => {
edit: [ 'test-2' ]
}
});
graph.source(Util.cloneDeep(data));
graph.source(Util.clone(data));
graph.render();
const canvas = graph.getCanvas();

View File

@ -26,7 +26,7 @@ const graph = new Graph({
width: 500,
height: 500
});
graph.source(Util.cloneDeep(data));
graph.source(Util.clone(data));
graph.render();
graph.update('node3', {
shape: 'custom'

View File

@ -14,7 +14,7 @@ describe('force fit user cases test', () => {
container: div
});
const el = graph.get('_canvas').get('el');
graph.source(Util.cloneDeep(data));
graph.source(Util.clone(data));
graph.render();
expect(el.style.width).equal('200px');
expect(el.style.height).equal('200px');
@ -30,7 +30,7 @@ describe('force fit user cases test', () => {
height: 500
});
const el = graph.get('_canvas').get('el');
graph.source(Util.cloneDeep(data));
graph.source(Util.clone(data));
graph.render();
expect(el.style.width).equal('200px');
expect(el.style.height).equal('500px');
@ -42,7 +42,7 @@ describe('force fit user cases test', () => {
width: 500
});
const el = graph.get('_canvas').get('el');
graph.source(Util.cloneDeep(data));
graph.source(Util.clone(data));
graph.render();
expect(el.style.width).equal('500px');
expect(el.style.height).equal('200px');

View File

@ -19,7 +19,7 @@ const graph = new Graph({
layout: layoutObj
});
graph.node().label(333);
graph.read(Util.cloneDeep(data));
graph.read(Util.clone(data));
const nodes = graph.getNodes();
Util.each(nodes, (node, index) => {
expect(node.getModel().x).equal((index + 1) * 80);
@ -34,7 +34,7 @@ describe('layout user cases test', () => {
layout: layoutObj
});
graph.node().label(333);
graph.read(Util.cloneDeep(data));
graph.read(Util.clone(data));
const nodes = graph.getNodes();
Util.each(nodes, (node, index) => {
expect(node.getModel().x).equal((index + 1) * 80);
@ -52,7 +52,7 @@ describe('layout user cases test', () => {
});
}
});
graph.read(Util.cloneDeep(data));
graph.read(Util.clone(data));
const nodes = graph.getNodes();
Util.each(nodes, (node, index) => {
expect(node.getModel().x).equal((index + 1) * 80);
@ -83,7 +83,7 @@ describe('layout user cases test', () => {
}
}
});
graph.read(Util.cloneDeep(data));
graph.read(Util.clone(data));
const nodes = graph.getNodes();
Util.each(nodes, node => {
const model = node.getModel();
@ -105,7 +105,7 @@ describe('layout user cases test', () => {
}
});
graph.node().label(333);
graph.read(Util.cloneDeep(data));
graph.read(Util.clone(data));
graph.add('node', {
id: 'node10',
y: 30
@ -129,7 +129,7 @@ describe('layout user cases test', () => {
}
}
});
graph.source(Util.cloneDeep(data));
graph.source(Util.clone(data));
graph.render();
graph.layout();
graph.destroy();

View File

@ -22,7 +22,7 @@ describe('mapping user cases test', () => {
graph.guide().label(model => {
return model.id;
});
graph.source(Util.cloneDeep(data));
graph.source(Util.clone(data));
graph.render();
it('node mapping', () => {
const nodes = graph.getNodes();

View File

@ -21,7 +21,7 @@ const graph = new Graph({
height
});
const items = [ '', 'node', 'edge' ];
graph.source(Util.cloneDeep(data));
graph.source(Util.clone(data));
graph.render();
const nodePoint = { x: 209, y: 161 };
const emptyPoint = { x: 188, y: 86 };

View File

@ -17,7 +17,7 @@ const graph = new Graph({
}
});
graph.source(Util.cloneDeep(data));
graph.source(Util.clone(data));
graph.render();
graph.update('node3', {
x: 111

View File

@ -16,7 +16,7 @@ const graph = new Graph({
width: 500,
height: 500
});
graph.source(Util.cloneDeep(data));
graph.source(Util.clone(data));
graph.render();
describe('edge item test', () => {

View File

@ -6,7 +6,7 @@ const Util = require('../../../src/util/');
const div = document.createElement('div');
let data = require('../../fixtures/sample-graph-data.json');
chai.use(chaiAlmost());
data = Util.cloneDeep(data);
data = Util.clone(data);
div.id = 'cchart';
document.body.appendChild(div);
data.nodes.forEach(node => {

View File

@ -13,7 +13,7 @@ const graph = new Graph({
width: 500,
height: 500
});
graph.source(Util.cloneDeep(data));
graph.source(Util.clone(data));
graph.render();
describe('item test', () => {

View File

@ -6,7 +6,7 @@ const Util = require('../../../src/util/');
const div = document.createElement('div');
let data = require('../../fixtures/sample-graph-data.json');
chai.use(chaiAlmost());
data = Util.cloneDeep(data);
data = Util.clone(data);
div.id = 'cchart';
document.body.appendChild(div);
data.nodes.forEach(node => {
@ -17,7 +17,7 @@ const graph = new Graph({
width: 500,
height: 500
});
graph.source(Util.cloneDeep(data));
graph.source(Util.clone(data));
graph.render();
describe('node item test', () => {

View File

@ -11,7 +11,7 @@ const graph = new Graph({
width: 500,
height: 500
});
graph.read(Util.cloneDeep(data));
graph.read(Util.clone(data));
describe('graph util test', () => {
it('isNode', () => {
expect(Util.isNode()).not.equal(true);