(ecModel: GlobalModel)
| 27 | export const graphCategoryVisualStageHandler = createSimpleOverallStageHandler(SERIES_TYPE_GRAPH, categoryVisual); |
| 28 | |
| 29 | function categoryVisual(ecModel: GlobalModel) { |
| 30 | |
| 31 | const paletteScope: Dictionary<ColorString> = {}; |
| 32 | ecModel.eachSeriesByType(SERIES_TYPE_GRAPH, function (seriesModel: GraphSeriesModel) { |
| 33 | const categoriesData = seriesModel.getCategoriesData(); |
| 34 | const data = seriesModel.getData(); |
| 35 | |
| 36 | const categoryNameIdxMap: Dictionary<number> = {}; |
| 37 | |
| 38 | categoriesData.each(function (idx) { |
| 39 | const name = categoriesData.getName(idx); |
| 40 | // Add prefix to avoid conflict with Object.prototype. |
| 41 | categoryNameIdxMap['ec-' + name] = idx; |
| 42 | const itemModel = categoriesData.getItemModel<GraphNodeItemOption>(idx); |
| 43 | |
| 44 | const style = itemModel.getModel('itemStyle').getItemStyle(); |
| 45 | if (!style.fill) { |
| 46 | // Get color from palette. |
| 47 | style.fill = seriesModel.getColorFromPalette(name, paletteScope); |
| 48 | } |
| 49 | categoriesData.setItemVisual(idx, 'style', style); |
| 50 | |
| 51 | const symbolVisualList = ['symbol', 'symbolSize', 'symbolKeepAspect'] as const; |
| 52 | |
| 53 | for (let i = 0; i < symbolVisualList.length; i++) { |
| 54 | const symbolVisual = itemModel.getShallow(symbolVisualList[i], true); |
| 55 | if (symbolVisual != null) { |
| 56 | categoriesData.setItemVisual(idx, symbolVisualList[i], symbolVisual); |
| 57 | } |
| 58 | } |
| 59 | }); |
| 60 | |
| 61 | // Assign category color to visual |
| 62 | if (categoriesData.count()) { |
| 63 | data.each(function (idx) { |
| 64 | const model = data.getItemModel<GraphNodeItemOption>(idx); |
| 65 | let categoryIdx = model.getShallow('category'); |
| 66 | if (categoryIdx != null) { |
| 67 | if (isString(categoryIdx)) { |
| 68 | categoryIdx = categoryNameIdxMap['ec-' + categoryIdx]; |
| 69 | } |
| 70 | |
| 71 | const categoryStyle = categoriesData.getItemVisual(categoryIdx, 'style'); |
| 72 | const style = data.ensureUniqueItemVisual(idx, 'style'); |
| 73 | extend(style, categoryStyle); |
| 74 | |
| 75 | const visualList = ['symbol', 'symbolSize', 'symbolKeepAspect'] as const; |
| 76 | |
| 77 | for (let i = 0; i < visualList.length; i++) { |
| 78 | data.setItemVisual( |
| 79 | idx, visualList[i], |
| 80 | categoriesData.getItemVisual(categoryIdx, visualList[i]) |
| 81 | ); |
| 82 | } |
| 83 | } |
| 84 | }); |
| 85 | } |
| 86 | }); |
nothing calls this directly
no test coverage detected
searching dependent graphs…