MCPcopy
hub / github.com/apache/echarts / categoryVisual

Function categoryVisual

src/chart/graph/categoryVisual.ts:29–87  ·  view source on GitHub ↗
(ecModel: GlobalModel)

Source from the content-addressed store, hash-verified

27export const graphCategoryVisualStageHandler = createSimpleOverallStageHandler(SERIES_TYPE_GRAPH, categoryVisual);
28
29function 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 });

Callers

nothing calls this directly

Calls 15

extendFunction · 0.85
eachSeriesByTypeMethod · 0.80
getCategoriesDataMethod · 0.80
getNameMethod · 0.80
getItemModelMethod · 0.80
getItemStyleMethod · 0.80
setItemVisualMethod · 0.80
getShallowMethod · 0.80
getDataMethod · 0.65
countMethod · 0.65
eachMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…