From 1f580606d4ea07cdbd0e5c871923b436cd5541db Mon Sep 17 00:00:00 2001 From: An An <2236368544@qq.com> Date: Tue, 15 Oct 2024 11:46:13 +0800 Subject: [PATCH] Fix #496 --- AAInfographicsDemo.xcodeproj/project.pbxproj | 10 +- .../AdvancedFeaturesListVC.swift | 13 +- .../CustomTooltipEventCallbackVC.swift | 111 ++++++++++++++++++ 3 files changed, 131 insertions(+), 3 deletions(-) create mode 100644 AAInfographicsDemo/Demo/AdditionalContent1/CustomTooltipEventCallbackVC.swift diff --git a/AAInfographicsDemo.xcodeproj/project.pbxproj b/AAInfographicsDemo.xcodeproj/project.pbxproj index 65da583..f1edf7e 100644 --- a/AAInfographicsDemo.xcodeproj/project.pbxproj +++ b/AAInfographicsDemo.xcodeproj/project.pbxproj @@ -56,6 +56,7 @@ 84086B2128E6F499006BD30D /* JSFunctionForAAOptionsVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84086B2028E6F499006BD30D /* JSFunctionForAAOptionsVC.swift */; }; 840AC39A280CFFA200B10289 /* AAAxis.swift in Sources */ = {isa = PBXBuildFile; fileRef = 840AC396280CFFA200B10289 /* AAAxis.swift */; }; 8418479928B8755900094106 /* JSFunctionForAAChartEventsVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8418479828B8755900094106 /* JSFunctionForAAChartEventsVC.swift */; }; + 842FC3EE2CBE119500FBAD3A /* CustomTooltipEventCallbackVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 842FC3ED2CBE119500FBAD3A /* CustomTooltipEventCallbackVC.swift */; }; 844007702B6F37180072FB66 /* CustomStyleForBubbleChartComposer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8440076F2B6F37180072FB66 /* CustomStyleForBubbleChartComposer.swift */; }; 844007742B6F3FA00072FB66 /* MixedChartVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 844007732B6F3FA00072FB66 /* MixedChartVC.swift */; }; 844007762B6F41A50072FB66 /* SpecialChartComposer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 844007752B6F41A50072FB66 /* SpecialChartComposer.swift */; }; @@ -262,6 +263,7 @@ 84086B2028E6F499006BD30D /* JSFunctionForAAOptionsVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSFunctionForAAOptionsVC.swift; sourceTree = ""; }; 840AC396280CFFA200B10289 /* AAAxis.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AAAxis.swift; sourceTree = ""; }; 8418479828B8755900094106 /* JSFunctionForAAChartEventsVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSFunctionForAAChartEventsVC.swift; sourceTree = ""; }; + 842FC3ED2CBE119500FBAD3A /* CustomTooltipEventCallbackVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomTooltipEventCallbackVC.swift; sourceTree = ""; }; 8440076F2B6F37180072FB66 /* CustomStyleForBubbleChartComposer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomStyleForBubbleChartComposer.swift; sourceTree = ""; }; 844007732B6F3FA00072FB66 /* MixedChartVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MixedChartVC.swift; sourceTree = ""; }; 844007752B6F41A50072FB66 /* SpecialChartComposer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpecialChartComposer.swift; sourceTree = ""; }; @@ -354,6 +356,7 @@ 448330B724E270FE00368A30 /* AdvancedUpdatingFeatureVC.swift */, 84DEA0D72846013F00D0206F /* CustomTouchEndEventCallbackVC.swift */, 844F11452B689B8600ADEB1C /* CustomXAxisLabelsClickEventCallbackVC.swift */, + 842FC3ED2CBE119500FBAD3A /* CustomTooltipEventCallbackVC.swift */, ); path = AdditionalContent1; sourceTree = ""; @@ -750,6 +753,7 @@ TargetAttributes = { 278C54AD1EE9472300770B97 = { CreatedOnToolsVersion = 8.3.2; + DevelopmentTeam = BPAYP34L8N; LastSwiftMigration = 1020; ProvisioningStyle = Automatic; }; @@ -871,6 +875,7 @@ 2770FBBF1F93673700091C75 /* OnlyRefreshChartDataVC.swift in Sources */, 84F2185A292E10DE007AA726 /* OfficialBarOrColumnChartVC.swift in Sources */, 27766455207C55BE00F0A62C /* MixedChartComposer.swift in Sources */, + 842FC3EE2CBE119500FBAD3A /* CustomTooltipEventCallbackVC.swift in Sources */, 278C55161EE948C900770B97 /* SpecialChartVC.swift in Sources */, 27FADB8620D6569000FED960 /* HideOrShowChartSeriesVC.swift in Sources */, 84AE6B1F26A58380001F0755 /* AADateUTCTool.swift in Sources */, @@ -1137,13 +1142,14 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = AAInfographicsDemo/AAInfographicsDemo.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; + "CODE_SIGN_IDENTITY[sdk=macosx*]" = "-"; CODE_SIGN_STYLE = Automatic; DERIVE_MACCATALYST_PRODUCT_BUNDLE_IDENTIFIER = YES; - DEVELOPMENT_TEAM = ""; + DEVELOPMENT_TEAM = BPAYP34L8N; INFOPLIST_FILE = AAInfographicsDemo/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = Love.AAInfographics9990; + PRODUCT_BUNDLE_IDENTIFIER = Love.AAInfographics9998; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; SUPPORTS_MACCATALYST = YES; diff --git a/AAInfographicsDemo/Demo/AAChartListVC/AdvancedFeaturesListVC.swift b/AAInfographicsDemo/Demo/AAChartListVC/AdvancedFeaturesListVC.swift index 1b7baec..c0879d3 100644 --- a/AAInfographicsDemo/Demo/AAChartListVC/AdvancedFeaturesListVC.swift +++ b/AAInfographicsDemo/Demo/AAChartListVC/AdvancedFeaturesListVC.swift @@ -31,6 +31,8 @@ class AdvancedFeaturesListVC: AABaseListVC { "XIB AAChartView | 在 XIB 中创建 AAChartView", "Custom Chart Event Callback | 自定义交互事件回调", "Custom X Axis Labels Click Event Callback | 自定义 X 轴文字点击事件回调", + "CustomTooltipEventCallbackVC | 自定义tooltip事件回调" + ] chartTypeTitleArr = [ @@ -130,7 +132,10 @@ class AdvancedFeaturesListVC: AABaseListVC { [ "自定义X轴文字点击事件回调---CustomXAxisLabelsClickEventCallbackVC" ], - + /*CustomTooltipEventCallbackVC*/ + [ + "自定义tooltip事件回调---CustomTooltipEventCallbackVC" + ], ] @@ -348,6 +353,12 @@ extension AdvancedFeaturesListVC { let vc = CustomXAxisLabelsClickEventCallbackVC() vc.hidesBottomBarWhenPushed = true navigationController?.pushViewController(vc, animated: true) + + case 12: + /*CustomTooltipEventCallbackVC*/ + let vc = CustomTooltipEventCallbackVC() + vc.hidesBottomBarWhenPushed = true + navigationController?.pushViewController(vc, animated: true) default: break diff --git a/AAInfographicsDemo/Demo/AdditionalContent1/CustomTooltipEventCallbackVC.swift b/AAInfographicsDemo/Demo/AdditionalContent1/CustomTooltipEventCallbackVC.swift new file mode 100644 index 0000000..600b159 --- /dev/null +++ b/AAInfographicsDemo/Demo/AdditionalContent1/CustomTooltipEventCallbackVC.swift @@ -0,0 +1,111 @@ +// +// CustomTooltipEventCallbackVC.swift +// AAInfographicsDemo +// +// Created by AnAn on 2024/10/15. +// Copyright © 2024 An An. All rights reserved. +// + +import AAInfographics +import WebKit + +class CustomTooltipEventCallbackVC: UIViewController { + let kUserContentMessageNameTooltipIsHidden = "tooltipIsHidden" + + private var aaChartView: AAChartView! + + override func viewDidLoad() { + super.viewDidLoad() + + view.backgroundColor = .white + + configureChartView() + configureChartViewCustomEventMessageHandler() + + let aaOptions = configureChartOptions() + aaChartView.aa_drawChartWithChartOptions(aaOptions) + } + + private func configureChartView() { + aaChartView = AAChartView() + let chartViewWidth = view.frame.size.width + let chartViewHeight = view.frame.size.height - 220 + aaChartView!.frame = CGRect(x: 0, y: 60, width: chartViewWidth, height: chartViewHeight) + aaChartView!.isScrollEnabled = false//Disable chart content scrolling + aaChartView!.isClearBackgroundColor = true + aaChartView!.delegate = self as AAChartViewDelegate + view.addSubview(aaChartView!) + } + + private func configureChartViewCustomEventMessageHandler() { + aaChartView!.configuration.userContentController.add(AALeakAvoider.init(delegate: self), name: kUserContentMessageNameTooltipIsHidden) + } + + private func configureChartOptions() -> AAOptions { + AAOptions() + .chart(AAChart() + .type(.areaspline) + .events(AAChartEvents() + .load(""" + function() { + var chart = this; + + setInterval(function() { + window.webkit.messageHandlers.\(kUserContentMessageNameTooltipIsHidden).postMessage("Tooltip is hidden: " + chart.tooltip.isHidden); + }, 1000); + } + """))) + .xAxis(AAXAxis() + .categories(["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"])) + .series([ + AASeriesElement() + .data([7.0, 6.9, 2.5, 14.5, 18.2, 21.5, 5.2, 26.5, 23.3, 45.3, 13.9, 9.6]) + .marker(AAMarker() + .lineColor(AAColor.green) + .lineWidth(3) + .radius(10)) + ]) + } +} + + +extension CustomTooltipEventCallbackVC: WKScriptMessageHandler { + func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) { + if message.name == kUserContentMessageNameTooltipIsHidden { + if let messageBody = message.body as? String { + // 处理 JavaScript 回调的信息 + print("Received message from JavaScript: \(messageBody)") + } + } + } +} + + +extension CustomTooltipEventCallbackVC: AAChartViewDelegate { + open func aaChartViewDidFinishLoad(_ aaChartView: AAChartView) { + print("🚀🚀🚀, AAChartView Did Finished Load!!!") + } + + open func aaChartView(_ aaChartView: AAChartView, clickEventMessage: AAClickEventMessageModel) { + print( + """ + + clicked point series element name: \(clickEventMessage.name ?? "") + 🖱🖱🖱WARNING!!!!!!!!!!!!!!!!!!!! Click Event Message !!!!!!!!!!!!!!!!!!!! WARNING🖱🖱🖱 + ------------------------------------------------------------------------------------------ + user finger moved over!!!,get the move over event message: { + category = \(String(describing: clickEventMessage.category)) + index = \(String(describing: clickEventMessage.index)) + name = \(String(describing: clickEventMessage.name)) + offset = \(String(describing: clickEventMessage.offset)) + x = \(String(describing: clickEventMessage.x)) + y = \(String(describing: clickEventMessage.y)) + } + ------------------------------------------------------------------------------------------ + + + """ + ) + } + +}