categoryVisual.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. function _default(ecModel) {
  2. var paletteScope = {};
  3. ecModel.eachSeriesByType('graph', function (seriesModel) {
  4. var categoriesData = seriesModel.getCategoriesData();
  5. var data = seriesModel.getData();
  6. var categoryNameIdxMap = {};
  7. categoriesData.each(function (idx) {
  8. var name = categoriesData.getName(idx); // Add prefix to avoid conflict with Object.prototype.
  9. categoryNameIdxMap['ec-' + name] = idx;
  10. var itemModel = categoriesData.getItemModel(idx);
  11. var color = itemModel.get('itemStyle.normal.color') || seriesModel.getColorFromPalette(name, paletteScope);
  12. categoriesData.setItemVisual(idx, 'color', color);
  13. }); // Assign category color to visual
  14. if (categoriesData.count()) {
  15. data.each(function (idx) {
  16. var model = data.getItemModel(idx);
  17. var category = model.getShallow('category');
  18. if (category != null) {
  19. if (typeof category === 'string') {
  20. category = categoryNameIdxMap['ec-' + category];
  21. }
  22. if (!data.getItemVisual(idx, 'color', true)) {
  23. data.setItemVisual(idx, 'color', categoriesData.getItemVisual(category, 'color'));
  24. }
  25. }
  26. });
  27. }
  28. });
  29. }
  30. module.exports = _default;