Skip to content

Commit f6a5896

Browse files
committed
Refactor plugin dependency handling in AAChartView
Replaces the pluginDependencies dictionary with a struct-based dependencies array for improved readability and type safety. Updates AACustomStageChartVC to use the new AADependency struct for configuring plugin dependencies.
1 parent 1b56169 commit f6a5896

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

AAInfographics-Pro/AAChartCreator/AAChartView.swift

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,18 @@ public class AALeakAvoider : NSObject, WKScriptMessageHandler {
8282
}
8383

8484

85+
@available(iOS 10.0, macCatalyst 13.1, macOS 10.13, *)
86+
public struct AADependency {
87+
let dependent: String // The plugin that has a dependency
88+
let on: String // The plugin it depends on
89+
90+
public init(_ dependent: String, on dependency: String) {
91+
self.dependent = dependent
92+
self.on = dependency
93+
}
94+
}
95+
96+
8597
@available(iOS 10.0, macCatalyst 13.1, macOS 10.13, *)
8698
public class AAChartView: WKWebView {
8799
let kUserContentMessageNameClick = "click"
@@ -178,7 +190,10 @@ public class AAChartView: WKWebView {
178190
private var pluginLoader: AAChartViewPluginLoader = ProPluginLoader(provider: ProPluginProvider())
179191

180192
public var userPluginPaths: Set<String> = []
181-
public var pluginDependencies: [String: String] = [:]
193+
194+
/// Configure plugin dependencies using a more readable struct-based array.
195+
/// Example: `aaChartView.dependencies = [AADependency("pluginB.js", on: "pluginA.js")]`
196+
public var dependencies: [AADependency] = []
182197
#if DEBUG
183198
public var shouldPrintOptionsJSON: Bool = true
184199
#endif
@@ -438,10 +453,15 @@ extension AAChartView: WKUIDelegate {
438453
extension AAChartView: WKNavigationDelegate {
439454
internal func loadAllPluginsAndDrawChart() {
440455
// Load plugins via loader, then draw chart in completion
456+
// Convert the dependency array to a dictionary for the loader
457+
let dependenciesDict = dependencies.reduce(into: [String: String]()) { dict, dependency in
458+
dict[dependency.dependent] = dependency.on
459+
}
460+
441461
pluginLoader.loadPluginsIfNeeded(
442462
webView: self,
443463
userPlugins: userPluginPaths,
444-
dependencies: pluginDependencies
464+
dependencies: dependenciesDict
445465
) { [weak self] in
446466
// Ensure options are ready before drawing
447467
guard let self = self, self.optionsJson != nil else {

AAInfographics-ProDemo/Demo/AAPlugins/AAStageSeries/AACustomStageChartVC.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ class AACustomStageChartVC: UIViewController {
4545
private func setupChartView() {
4646
// 创建新的图表视图
4747
aaChartView = AAChartView()
48-
aaChartView!.isScrollEnabled = false
49-
aaChartView!.delegate = self as AAChartViewDelegate
48+
aaChartView.isScrollEnabled = false
49+
aaChartView.delegate = self as AAChartViewDelegate
5050

5151
/**
5252
NSString *jsPath = [[NSBundle mainBundle] pathForResource:@"AADrilldown" ofType:@"js"];
@@ -65,16 +65,19 @@ class AACustomStageChartVC: UIViewController {
6565
return
6666
}
6767

68-
self.aaChartView?.userPluginPaths = [
68+
aaChartView.userPluginPaths = [
6969
jsPathXrange,
7070
jsPathCustom_Stage,
7171
]
7272

7373
// 配置它们的依赖关系
74-
self.aaChartView?.pluginDependencies = [
75-
"AACustom-Stage.js": "AAXrange.js"
74+
aaChartView.dependencies = [
75+
AADependency("AACustom-Stage.js", on: "AAXrange.js"),
76+
// 如果还有其他依赖, 继续在这里添加
77+
// AADependency("pluginC.js", on: "pluginA.js")
7678
]
7779

80+
7881

7982
//输出查看 AAOption 的 computedProperties 内容
8083
// AAOptions *aaOptions = [self chartConfigurationWithSelectedIndex:self.selectedIndex];

0 commit comments

Comments
 (0)