Skip to content

Commit

Permalink
Fix #496
Browse files Browse the repository at this point in the history
  • Loading branch information
AAChartModel committed Oct 15, 2024
1 parent cbcb2e8 commit 1f58060
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 3 deletions.
10 changes: 8 additions & 2 deletions AAInfographicsDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -262,6 +263,7 @@
84086B2028E6F499006BD30D /* JSFunctionForAAOptionsVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSFunctionForAAOptionsVC.swift; sourceTree = "<group>"; };
840AC396280CFFA200B10289 /* AAAxis.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AAAxis.swift; sourceTree = "<group>"; };
8418479828B8755900094106 /* JSFunctionForAAChartEventsVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSFunctionForAAChartEventsVC.swift; sourceTree = "<group>"; };
842FC3ED2CBE119500FBAD3A /* CustomTooltipEventCallbackVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomTooltipEventCallbackVC.swift; sourceTree = "<group>"; };
8440076F2B6F37180072FB66 /* CustomStyleForBubbleChartComposer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomStyleForBubbleChartComposer.swift; sourceTree = "<group>"; };
844007732B6F3FA00072FB66 /* MixedChartVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MixedChartVC.swift; sourceTree = "<group>"; };
844007752B6F41A50072FB66 /* SpecialChartComposer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpecialChartComposer.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -354,6 +356,7 @@
448330B724E270FE00368A30 /* AdvancedUpdatingFeatureVC.swift */,
84DEA0D72846013F00D0206F /* CustomTouchEndEventCallbackVC.swift */,
844F11452B689B8600ADEB1C /* CustomXAxisLabelsClickEventCallbackVC.swift */,
842FC3ED2CBE119500FBAD3A /* CustomTooltipEventCallbackVC.swift */,
);
path = AdditionalContent1;
sourceTree = "<group>";
Expand Down Expand Up @@ -750,6 +753,7 @@
TargetAttributes = {
278C54AD1EE9472300770B97 = {
CreatedOnToolsVersion = 8.3.2;
DevelopmentTeam = BPAYP34L8N;
LastSwiftMigration = 1020;
ProvisioningStyle = Automatic;
};
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -130,7 +132,10 @@ class AdvancedFeaturesListVC: AABaseListVC {
[
"自定义X轴文字点击事件回调---CustomXAxisLabelsClickEventCallbackVC"
],

/*CustomTooltipEventCallbackVC*/
[
"自定义tooltip事件回调---CustomTooltipEventCallbackVC"
],

]

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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))
}
------------------------------------------------------------------------------------------
"""
)
}

}

0 comments on commit 1f58060

Please sign in to comment.