Skip to content

Commit b2c37bd

Browse files
committed
Sync with AAInfographics for AAChartView+API.swift
1 parent deaa45e commit b2c37bd

File tree

2 files changed

+12
-41
lines changed

2 files changed

+12
-41
lines changed

AAInfographics-Pro/AAChartCreator/AAChartView+API.swift

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
*/
3232

33-
import UIKit
33+
import Foundation
3434

3535
// MARK: - Configure Chart View Content With AAChartModel
3636
@available(iOS 10.0, macCatalyst 13.1, macOS 10.13, *)
@@ -71,12 +71,16 @@ extension AAChartView {
7171
public func aa_drawChartWithChartOptions(_ aaOptions: AAOptions) {
7272
if optionsJson == nil {
7373
configureOptionsJsonStringWithAAOptions(aaOptions)
74-
let path = BundlePathLoader()
74+
guard let path = BundlePathLoader()
7575
.path(forResource: "AAChartView",
7676
ofType: "html",
77-
inDirectory: "AAJSFiles.bundle")
78-
let urlStr = NSURL.fileURL(withPath: path!)
79-
let urlRequest = NSURLRequest(url: urlStr) as URLRequest
77+
inDirectory: "AAJSFiles.bundle") else {
78+
// Consider more robust error handling or logging framework for production code
79+
print("Error: AAChartView.html not found in AAJSFiles.bundle. Chart cannot be loaded.")
80+
return
81+
}
82+
let fileURL = URL(fileURLWithPath: path) // 'path' is a non-optional String here
83+
let urlRequest = URLRequest(url: fileURL)
8084
load(urlRequest)
8185
} else {
8286
aa_refreshChartWholeContentWithChartOptions(aaOptions)
@@ -260,15 +264,15 @@ extension AAChartView {
260264
/// Show the series element content with index
261265
///
262266
/// - Parameter elementIndex: elementIndex element index
263-
public func aa_showTheSeriesElementContentWithSeriesElementIndex(_ elementIndex: NSInteger) {
267+
public func aa_showTheSeriesElementContentWithSeriesElementIndex(_ elementIndex: Int) {
264268
let jsStr = "showTheSeriesElementContentWithIndex('\(elementIndex)');"
265269
safeEvaluateJavaScriptString(jsStr)
266270
}
267271

268272
/// Hide the series element content with index
269273
///
270274
/// - Parameter elementIndex: element index
271-
public func aa_hideTheSeriesElementContentWithSeriesElementIndex(_ elementIndex: NSInteger) {
275+
public func aa_hideTheSeriesElementContentWithSeriesElementIndex(_ elementIndex: Int) {
272276
let jsStr = "hideTheSeriesElementContentWithIndex('\(elementIndex)');"
273277
safeEvaluateJavaScriptString(jsStr as String)
274278
}
@@ -313,39 +317,6 @@ extension AAChartView {
313317
let jsStr = "redrawWithAnimation('\(animation)')"
314318
safeEvaluateJavaScriptString(jsStr)
315319
}
316-
317-
#if os(iOS)
318-
/// Set the chart view content be adaptive to screen rotation with default animation effect
319-
public func aa_adaptiveScreenRotation() {
320-
let aaAnimation = AAAnimation()
321-
.duration(800)
322-
.easing(.easeOutQuart)
323-
aa_adaptiveScreenRotationWithAnimation(aaAnimation)
324-
}
325-
326-
/// Set the chart view content be adaptive to screen rotation with custom animation effect
327-
/// Refer to https://api.highcharts.com/highcharts#Chart.setSize
328-
///
329-
/// - Parameter animation: The instance object of AAAnimation
330-
public func aa_adaptiveScreenRotationWithAnimation(_ animation: AAAnimation) {
331-
NotificationCenter.default.addObserver(
332-
forName: UIDevice.orientationDidChangeNotification,
333-
object: nil,
334-
queue: nil) { [weak self] _ in
335-
//Delay execution by 0.01 seconds to prevent incorrect screen width and height obtained when the screen is rotated
336-
DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
337-
self?.aa_resizeChart(animation: animation)
338-
}
339-
}
340-
}
341-
342-
public func aa_resizeChart(animation: AAAnimation) {
343-
let animationJsonStr = animation.toJSON()
344-
let jsFuncStr = "changeChartSize('\(frame.size.width)','\(frame.size.height)','\(animationJsonStr)')"
345-
safeEvaluateJavaScriptString(jsFuncStr)
346-
}
347-
#endif
348-
349320
}
350321

351322

AAInfographics-ProDemo/Demo/ViewController/AABaseChartVC.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class AABaseChartVC: UIViewController {
8484
aaChartView = AAChartView()
8585
aaChartView!.isScrollEnabled = false
8686
aaChartView!.delegate = self as AAChartViewDelegate
87-
aaChartView!.aa_adaptiveScreenRotation()
87+
// aaChartView!.aa_adaptiveScreenRotation()
8888
view.addSubview(aaChartView!)
8989

9090
aaChartView?.translatesAutoresizingMaskIntoConstraints = false

0 commit comments

Comments
 (0)