Skip to content

Commit f82e118

Browse files
committed
Add treegraph chart support and demo
Introduced the treegraph chart type to AAChartModel and updated plugin dependencies for treegraph in AAChartViewPluginProvider. Added AATreegraphChartComposer.swift and treegraphData.json to provide demo data and chart configurations. Updated ChartSampleProvider and AAOptionsData to include treegraph chart samples and data loading. Project file updated to include new source and resource files.
1 parent 20796b5 commit f82e118

File tree

7 files changed

+324
-6
lines changed

7 files changed

+324
-6
lines changed

AAInfographics-Pro/AAChartCreator/AAChartModel.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ public enum AAChartType: String {
121121
case solidgauge
122122
case histogram
123123
case bullet
124+
case treegraph
124125
/*---------------------AAInfogrphics-Pro---------------------*/
125126
}
126127

AAInfographics-Pro/AAChartCreator/AAChartViewPluginProvider.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ public class ProPluginProvider: AAChartViewPluginProvider {
8484
"AAWindbarb"
8585
], // Meteorological
8686
AAChartType.wordcloud.rawValue : ["AAWordcloud"], // Text visualization
87+
AAChartType.treegraph.rawValue : [
88+
"AATreemap",
89+
"AATreegraph"
90+
],
8791
]
8892

8993
public func getRequiredPluginPaths(for options: AAOptions) -> Set<String> {
@@ -322,7 +326,8 @@ public class ProPluginLoader: AAChartViewPluginLoader {
322326
"AAOrganization.js": "AASankey.js",
323327
"AALollipop.js": "AADumbbell.js",
324328
"AATilemap.js": "AAHeatmap.js",
325-
"AAArc-Diagram.js": "AASankey.js"
329+
"AAArc-Diagram.js": "AASankey.js",
330+
"AATreegraph.js": "AATreemap.js"
326331
]
327332

328333
// Merge external dependencies, allowing them to override base dependencies if needed

AAInfographics-ProDemo.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
840549242E557D8B00B57B44 /* AAStageControlsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 840549232E557D8B00B57B44 /* AAStageControlsView.swift */; };
3838
8418479728B861D200094106 /* AABoxplot.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8418479628B861D200094106 /* AABoxplot.swift */; };
3939
842EB1B12DEEF57A000166C2 /* AAMixedChartComposer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 842EB1B02DEEF57A000166C2 /* AAMixedChartComposer.swift */; };
40+
843E5E0D2E7AD52D0030D36E /* AATreegraphChartComposer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 843E5E0C2E7AD52D0030D36E /* AATreegraphChartComposer.swift */; };
41+
843E5E0F2E7AD6390030D36E /* treegraphData.json in Resources */ = {isa = PBXBuildFile; fileRef = 843E5E0E2E7AD6390030D36E /* treegraphData.json */; };
4042
8441A76126C2568F007EAAA7 /* AAExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8441A75E26C2568E007EAAA7 /* AAExtension.swift */; };
4143
8441A76226C2568F007EAAA7 /* AAColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8441A75F26C2568F007EAAA7 /* AAColor.swift */; };
4244
8441A76326C2568F007EAAA7 /* AAGradientColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8441A76026C2568F007EAAA7 /* AAGradientColor.swift */; };
@@ -205,6 +207,8 @@
205207
840549232E557D8B00B57B44 /* AAStageControlsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AAStageControlsView.swift; sourceTree = "<group>"; };
206208
8418479628B861D200094106 /* AABoxplot.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AABoxplot.swift; sourceTree = "<group>"; };
207209
842EB1B02DEEF57A000166C2 /* AAMixedChartComposer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AAMixedChartComposer.swift; sourceTree = "<group>"; };
210+
843E5E0C2E7AD52D0030D36E /* AATreegraphChartComposer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AATreegraphChartComposer.swift; sourceTree = "<group>"; };
211+
843E5E0E2E7AD6390030D36E /* treegraphData.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = treegraphData.json; sourceTree = "<group>"; };
208212
8441A75E26C2568E007EAAA7 /* AAExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AAExtension.swift; sourceTree = "<group>"; };
209213
8441A75F26C2568F007EAAA7 /* AAColor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AAColor.swift; sourceTree = "<group>"; };
210214
8441A76026C2568F007EAAA7 /* AAGradientColor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AAGradientColor.swift; sourceTree = "<group>"; };
@@ -479,6 +483,7 @@
479483
44D27DB4255A6CE300D0C636 /* DataJsonFiles */ = {
480484
isa = PBXGroup;
481485
children = (
486+
843E5E0E2E7AD6390030D36E /* treegraphData.json */,
482487
84A5692927FEC89E00883553 /* arcdiagram1Data.json */,
483488
84A5692A27FEC89E00883553 /* arcdiagram2Data.json */,
484489
84A5693027FEC89F00883553 /* arcdiagram3Data.json */,
@@ -633,6 +638,7 @@
633638
84DEB8BF28FAE57B00BF9423 /* AAHeatOrTreeMapChartComposer.swift */,
634639
84DEB8C128FAE58C00BF9423 /* AABubbleChartComposer.swift */,
635640
84DEB8C328FAE59F00BF9423 /* AAColumnVariantChartComposer.swift */,
641+
843E5E0C2E7AD52D0030D36E /* AATreegraphChartComposer.swift */,
636642
);
637643
path = Composer;
638644
sourceTree = "<group>";
@@ -768,6 +774,7 @@
768774
84A5693927FEC89F00883553 /* treemapWithLevelsData.json in Resources */,
769775
84A5693A27FEC89F00883553 /* heatmapData.json in Resources */,
770776
84A5693127FEC89F00883553 /* sankeyData.json in Resources */,
777+
843E5E0F2E7AD6390030D36E /* treegraphData.json in Resources */,
771778
84526E0B2CEB401500EB2563 /* AABoost.js in Resources */,
772779
84A5694327FEC89F00883553 /* sunburst2Data.json in Resources */,
773780
84DEB8CA28FAF3C800BF9423 /* volinPlotElement2Data.json in Resources */,
@@ -858,6 +865,7 @@
858865
84B13F3D289E5FAB007356C6 /* AABulletDataElement.swift in Sources */,
859866
84DEB8BE28FAE54500BF9423 /* AARelationshipChartComposer.swift in Sources */,
860867
844615B3283F580300E26DA4 /* AAPlotOptions.swift in Sources */,
868+
843E5E0D2E7AD52D0030D36E /* AATreegraphChartComposer.swift in Sources */,
861869
844615BC283F580300E26DA4 /* AAXAxis.swift in Sources */,
862870
27F872AB25E797690068380F /* ProjectBundlePathLoader.swift in Sources */,
863871
844615A7283F580300E26DA4 /* AAChart.swift in Sources */,
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
//
2+
// AATreegraphChartComposer.swift
3+
// AAInfographics-ProDemo
4+
//
5+
// Created by AnAn on 2025/9/17.
6+
//
7+
8+
import Foundation
9+
10+
class AATreegraphChartComposer {
11+
12+
static func treegraph() -> AAOptions {
13+
var aaOptions = invertedTreegraph()
14+
aaOptions.chart?.inverted = false
15+
return aaOptions
16+
}
17+
18+
static func invertedTreegraph() -> AAOptions {
19+
return AAOptions()
20+
.chart(AAChart()
21+
.inverted(true)
22+
.marginBottom(170)
23+
)
24+
.title(AATitle()
25+
.text("Inverted treegraph")
26+
.align(.left)
27+
)
28+
.series([
29+
AASeriesElement()
30+
.type(.treegraph)
31+
.data(AAOptionsData.treegraphData)
32+
.tooltip(AATooltip()
33+
.pointFormat("{point.name}")
34+
)
35+
.dataLabels(AADataLabels()
36+
.format("{point.name}")
37+
.style(AAStyle()
38+
.whiteSpace("nowrap")
39+
.color("#000000")
40+
.textOutline("3px contrast")
41+
)
42+
.crop(false)
43+
)
44+
.marker(AAMarker()
45+
.radius(6)
46+
)
47+
.levels([
48+
AALevelsElement()
49+
.level(1)
50+
.dataLabels(AADataLabels()
51+
.align(.left)
52+
.x(20)
53+
),
54+
AALevelsElement()
55+
.level(2)
56+
.colorByPoint(true)
57+
.dataLabels(AADataLabels()
58+
.verticalAlign(.bottom)
59+
.y(-20)
60+
),
61+
AALevelsElement()
62+
.level(3)
63+
.colorVariation(AAColorVariation()
64+
.key("brightness")
65+
.to(-0.5)
66+
)
67+
.dataLabels(AADataLabels()
68+
.align(.left)
69+
.rotation(90)
70+
.y(20)
71+
)
72+
])
73+
])
74+
}
75+
76+
static func treegraphWithBoxLayout() -> AAOptions {
77+
return AAOptions()
78+
.title(AATitle()
79+
.text("Treegraph with box layout")
80+
)
81+
.series([
82+
AASeriesElement()
83+
.type(.treegraph)
84+
.data(AAOptionsData.treegraphData)
85+
.tooltip(AATooltip()
86+
.pointFormat("{point.name}")
87+
)
88+
.marker(AAMarker()
89+
.symbol("rect")
90+
// .width("25%")
91+
)
92+
.borderRadius(10)
93+
.dataLabels(AADataLabels()
94+
.format("{point.name}")
95+
.style(AAStyle()
96+
.whiteSpace("nowrap")
97+
)
98+
)
99+
.levels([
100+
AALevelsElement()
101+
.level(1)
102+
// .levelIsConstant(false)
103+
,
104+
AALevelsElement()
105+
.level(2)
106+
.colorByPoint(true),
107+
AALevelsElement()
108+
.level(3)
109+
.colorVariation(AAColorVariation()
110+
.key("brightness")
111+
.to(-0.5)
112+
),
113+
AALevelsElement()
114+
.level(4)
115+
.colorVariation(AAColorVariation()
116+
.key("brightness")
117+
.to(0.5)
118+
)
119+
])
120+
])
121+
}
122+
123+
124+
}

AAInfographics-ProDemo/Demo/DataSource/AAOptionsData.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,10 @@ class AAOptionsData {
292292
getJsonDataWithJsonFileName("tilemapForAfricaData")
293293
}
294294

295+
public class var treegraphData : [Any] {
296+
getJsonDataWithJsonFileName("treegraphData")
297+
}
298+
295299
//https://www.jianshu.com/p/a4b2bd5deca6
296300
private static func getJsonDataWithJsonFileName(_ jsonFileName: String) -> [Any] {
297301
let path = Bundle.main.path(forResource: jsonFileName, ofType: "json")
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
[
2+
{
3+
"id": "0.0",
4+
"parent": "",
5+
"name": "The World"
6+
},
7+
{
8+
"id": "1.3",
9+
"parent": "0.0",
10+
"name": "Asia"
11+
},
12+
{
13+
"id": "1.1",
14+
"parent": "0.0",
15+
"name": "Africa"
16+
},
17+
{
18+
"id": "1.2",
19+
"parent": "0.0",
20+
"name": "America"
21+
},
22+
{
23+
"id": "1.4",
24+
"parent": "0.0",
25+
"name": "Europe"
26+
},
27+
{
28+
"id": "1.5",
29+
"parent": "0.0",
30+
"name": "Oceanic"
31+
},
32+
33+
{
34+
"id": "2.1",
35+
"parent": "1.1",
36+
"name": "Eastern Africa"
37+
},
38+
39+
{
40+
"id": "2.5",
41+
"parent": "1.1",
42+
"name": "Western Africa"
43+
},
44+
45+
{
46+
"id": "2.3",
47+
"parent": "1.1",
48+
"name": "North Africa"
49+
},
50+
51+
{
52+
"id": "2.2",
53+
"parent": "1.1",
54+
"name": "Central Africa"
55+
},
56+
57+
{
58+
"id": "2.4",
59+
"parent": "1.1",
60+
"name": "South America"
61+
},
62+
63+
{
64+
"id": "2.9",
65+
"parent": "1.2",
66+
"name": "South America"
67+
},
68+
69+
{
70+
"id": "2.8",
71+
"parent": "1.2",
72+
"name": "Northern America"
73+
},
74+
75+
{
76+
"id": "2.7",
77+
"parent": "1.2",
78+
"name": "Central America"
79+
},
80+
81+
{
82+
"id": "2.6",
83+
"parent": "1.2",
84+
"name": "Caribbean"
85+
},
86+
87+
{
88+
"id": "2.13",
89+
"parent": "1.3",
90+
"name": "Southern Asia"
91+
},
92+
93+
{
94+
"id": "2.11",
95+
"parent": "1.3",
96+
"name": "Eastern Asia"
97+
},
98+
99+
{
100+
"id": "2.12",
101+
"parent": "1.3",
102+
"name": "South-Eastern Asia"
103+
},
104+
105+
{
106+
"id": "2.14",
107+
"parent": "1.3",
108+
"name": "Western Asia"
109+
},
110+
111+
{
112+
"id": "2.10",
113+
"parent": "1.3",
114+
"name": "Central Asia"
115+
},
116+
117+
{
118+
"id": "2.15",
119+
"parent": "1.4",
120+
"name": "Eastern Europe"
121+
},
122+
123+
{
124+
"id": "2.16",
125+
"parent": "1.4",
126+
"name": "Northern Europe"
127+
},
128+
129+
{
130+
"id": "2.17",
131+
"parent": "1.4",
132+
"name": "Southern Europe"
133+
},
134+
135+
{
136+
"id": "2.18",
137+
"parent": "1.4",
138+
"name": "Western Europe"
139+
},
140+
141+
{
142+
"id": "2.19",
143+
"parent": "1.5",
144+
"name": "Australia and New Zealand"
145+
},
146+
147+
{
148+
"id": "2.20",
149+
"parent": "1.5",
150+
"name": "Melanesia"
151+
},
152+
153+
{
154+
"id": "2.21",
155+
"parent": "1.5",
156+
"name": "Micronesia"
157+
},
158+
159+
{
160+
"id": "2.22",
161+
"parent": "1.5",
162+
"name": "Polynesia"
163+
}
164+
]

0 commit comments

Comments
 (0)