Skip to content

Commit

Permalink
【重要】图表类型自注册,按需加载
Browse files Browse the repository at this point in the history
  • Loading branch information
kener committed Jun 19, 2013
1 parent 3fd4398 commit 25ae552
Show file tree
Hide file tree
Showing 24 changed files with 85 additions and 60 deletions.
11 changes: 10 additions & 1 deletion doc/asset/js/echartsExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,23 @@ require.config({
{
name: 'zrender',
location: 'http://ecomfe.github.io/zrender/src',
//location: '../../../zrender/src',
main: 'zrender'
}
]
});

var echarts;
require(
['echarts/echarts'],
[
'echarts/echarts',
'echarts/chart/line',
'echarts/chart/bar',
'echarts/chart/scatter',
'echarts/chart/k',
'echarts/chart/pie',
'echarts/chart/map'
],
function(ec) {
echarts = ec;
if (myChart && myChart.dispose) {
Expand Down
15 changes: 0 additions & 15 deletions src/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,5 @@ define(function(require) { //chart
return _chartLibrary[name];
};

// 内置图表注册
self.define('island', require('./chart/island'));

self.define('pie', require('./chart/pie'));

self.define('bar', require('./chart/bar'));

self.define('line', require('./chart/line'));

self.define('map', require('./chart/map'));

self.define('k', require('./chart/k'));

self.define('scatter', require('./chart/scatter'));

return self;
});
3 changes: 3 additions & 0 deletions src/chart/bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -760,5 +760,8 @@ define(function(require) {
init(option, component);
}

// 图表注册
require('../chart').define('bar', Bar);

return Bar;
});
3 changes: 3 additions & 0 deletions src/chart/island.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,5 +233,8 @@ define(function (require) {
self.ondragend = ondragend;
}

// 图表注册
require('../chart').define('island', Island);

return Island;
});
8 changes: 5 additions & 3 deletions src/chart/k.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,9 +433,11 @@ define(function(require) {
init(option, component);
}

var shape = require('zrender/shape');
var Candle = require('../util/shape/candle');
shape.define('candle', new Candle());
// 动态扩展zrender shape:candle
require('../util/shape/candle');

// 图表注册
require('../chart').define('k', K);

return K;
});
3 changes: 3 additions & 0 deletions src/chart/line.js
Original file line number Diff line number Diff line change
Expand Up @@ -797,5 +797,8 @@ define(function(require) {
init(option, component);
}

// 图表注册
require('../chart').define('line', Line);

return Line;
});
3 changes: 3 additions & 0 deletions src/chart/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -515,5 +515,8 @@ define(function(require) {
init(option, component);
}

// 图表注册
require('../chart').define('map', Map);

return Map;
});
3 changes: 3 additions & 0 deletions src/chart/pie.js
Original file line number Diff line number Diff line change
Expand Up @@ -876,5 +876,8 @@ define(function(require) {
init(option, component);
}

// 图表注册
require('../chart').define('pie', Pie);

return Pie;
});
10 changes: 6 additions & 4 deletions src/chart/scatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,9 +420,11 @@ define(function(require) {
init(option, component);
}

var shape = require('zrender/shape');
var Symbol = require('../util/shape/symbol');
shape.define('symbol', new Symbol());

// 动态扩展zrender shape:symbol
require('../util/shape/symbol');

// 自注册
require('../chart').define('scatter', Scatter);

return Scatter;
});
21 changes: 0 additions & 21 deletions src/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,5 @@ define(function(require) { //component
return _componentLibrary[name];
};

// 内置组件注册
self.define('axis', require('./component/axis'));

self.define('categoryAxis', require('./component/categoryAxis'));

self.define('valueAxis', require('./component/valueAxis'));

self.define('grid', require('./component/grid'));

self.define('dataZoom', require('./component/dataZoom'));

self.define('legend', require('./component/legend'));

self.define('dataRange', require('./component/dataRange'));

self.define('tooltip', require('./component/tooltip'));

self.define('toolbox', require('./component/toolbox'));

self.define('dataView', require('./component/dataView'));

return self;
});
2 changes: 2 additions & 0 deletions src/component/axis.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,5 +184,7 @@ define(function (require) {
init(option, component, axisType);
}

require('../component').define('axis', Axis);

return Axis;
});
2 changes: 2 additions & 0 deletions src/component/categoryAxis.js
Original file line number Diff line number Diff line change
Expand Up @@ -639,5 +639,7 @@ define(function (require) {
init(option, grid);
}

require('../component').define('categoryAxis', CategoryAxis);

return CategoryAxis;
});
2 changes: 2 additions & 0 deletions src/component/dataRange.js
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,8 @@ define(function (require) {
init(option);
}

require('../component').define('dataRange', DataRange);

return DataRange;
});

Expand Down
2 changes: 2 additions & 0 deletions src/component/dataView.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,5 +433,7 @@ define(function (require) {
_init();
}

require('../component').define('dataView', DataView);

return DataView;
});
2 changes: 2 additions & 0 deletions src/component/dataZoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -679,5 +679,7 @@ define(function (require) {
init(option);
}

require('../component').define('dataZoom', DataZoom);

return DataZoom;
});
2 changes: 2 additions & 0 deletions src/component/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,7 @@ define(function (require) {
init(option);
}

require('../component').define('grid', Grid);

return Grid;
});
2 changes: 2 additions & 0 deletions src/component/legend.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,8 @@ define(function (require) {
init(option);
}

require('../component').define('legend', Legend);

return Legend;
});

Expand Down
5 changes: 5 additions & 0 deletions src/component/toolbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -633,5 +633,10 @@ define(function (require) {
self.resetMagicType = resetMagicType;
}

// 动态扩展zrender shape:icon
require('../util/shape/icon');

require('../component').define('toolbox', Toolbox);

return Toolbox;
});
2 changes: 2 additions & 0 deletions src/component/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -778,5 +778,7 @@ define(function (require) {
init(option, dom);
}

require('../component').define('tooltip', Tooltip);

return Tooltip;
});
2 changes: 2 additions & 0 deletions src/component/valueAxis.js
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,8 @@ define(function (require) {
init(option, grid, series);
}

require('../component').define('valueAxis', ValueAxis);

return ValueAxis;
});

24 changes: 17 additions & 7 deletions src/echarts.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,27 @@ define(function(require) {
_zr.on(zrConfig.EVENT.DROP, _ondrop);


var shape = require('zrender/shape');
var Icon = require('./util/shape/icon');
shape.define('icon', new Icon());

// 孤岛
// 内置图表注册
var chartLibrary = require('./chart');
require('./chart/island');
// 孤岛
var Island = chartLibrary.get('island');
_island = new Island(_messageCenter, _zr);

// 工具箱


// 内置组件注册
var componentLibrary = require('./component');
require('./component/axis');
require('./component/categoryAxis');
require('./component/valueAxis');
require('./component/grid');
require('./component/dataZoom');
require('./component/legend');
require('./component/dataRange');
require('./component/tooltip');
require('./component/toolbox');
require('./component/dataView');
// 工具箱
var Toolbox = componentLibrary.get('toolbox');
_toolbox = new Toolbox(_messageCenter, _zr, dom);
}
Expand Down
6 changes: 3 additions & 3 deletions src/util/shape/candle.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ define(
}
};

var base = require('zrender/shape/base');
base.derive(Candle);

require('zrender/shape/base').derive(Candle);
require('zrender/shape').define('candle', new Candle());
return Candle;
}
);
6 changes: 3 additions & 3 deletions src/util/shape/icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,9 @@ define(
}
};

var base = require('zrender/shape/base');
base.derive(Icon);

require('zrender/shape/base').derive(Icon);
require('zrender/shape').define('icon', new Icon());
return Icon;
}
);
6 changes: 3 additions & 3 deletions src/util/shape/symbol.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ define(
}
};

var base = require('zrender/shape/base');
base.derive(Symbol);

require('zrender/shape/base').derive(Symbol);
require('zrender/shape').define('symbol', new Symbol());
return Symbol;
}
);

0 comments on commit 25ae552

Please sign in to comment.