Skip to content

Commit ee8a837

Browse files
committed
Optimize more details
1 parent 5fefbc5 commit ee8a837

File tree

7 files changed

+59
-57
lines changed

7 files changed

+59
-57
lines changed

AAInfographics/AAChartCreator/AAChartModel.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -484,11 +484,11 @@ public class AAChartModel: AAObject {
484484

485485
public override init() {
486486
backgroundColor = AAColor.white
487-
animationType = AAChartAnimationType.easeInQuad
487+
animationType = .easeInQuad
488488
animationDuration = 800 //以毫秒为单位
489-
chartType = AAChartType.line
490-
stacking = AAChartStackingType.none
491-
zoomType = AAChartZoomType.none //默认禁用手势缩放
489+
chartType = .line
490+
stacking = Optional.none
491+
zoomType = Optional.none //默认禁用手势缩放
492492
colorsTheme = ["#1e90ff","#ef476f","#ffd066","#04d69f","#25547c",]
493493
dataLabelsEnabled = true
494494
tooltipEnabled = true
@@ -503,13 +503,13 @@ public class AAChartModel: AAObject {
503503
borderRadius = 0 //柱状图长条图头部圆角半径(可用于设置头部的形状,仅对条形图,柱状图有效,设置为1000时,柱形图或者条形图头部为楔形)
504504
markerRadius = 5 //折线连接点的半径长度,如果设置默认值为0,那么这样就相当于不显示了
505505
titleFontColor = AAColor.black //标题字体颜色为黑色
506-
titleFontWeight = AAChartFontWeightType.regular //常规字体
506+
titleFontWeight = .regular //常规字体
507507
titleFontSize = 11
508508
subtitleFontColor = AAColor.black //副标题字体颜色为黑色
509-
subtitleFontWeight = AAChartFontWeightType.regular //常规字体
509+
subtitleFontWeight = .regular //常规字体
510510
subtitleFontSize = 9
511511
dataLabelsFontColor = AAColor.black //数据标签默认颜色为黑色
512-
dataLabelsFontWeight = AAChartFontWeightType.bold //图表的数据字体为粗体
512+
dataLabelsFontWeight = .bold //图表的数据字体为粗体
513513
dataLabelsFontSize = 10
514514
yAxisTitle = ""
515515

AAInfographics/AAChartCreator/AAChartView.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ public class AAChartView: WKWebView {
156156
})
157157
}
158158

159-
private func configureTheJavaScriptStringWithOptions(_ chartOptions: AAOptions) {
160-
var modelJsonStr = chartOptions.toJSON()!
159+
private func configureTheJavaScriptStringWithOptions(_ aaOptions: AAOptions) {
160+
var modelJsonStr = aaOptions.toJSON()!
161161
modelJsonStr = modelJsonStr.replacingOccurrences(of: "\n", with: "") as String
162162

163163
let jsString = NSString.localizedStringWithFormat("loadTheHighChartView('%@','%f','%f');",
@@ -171,9 +171,9 @@ public class AAChartView: WKWebView {
171171
extension AAChartView {
172172
/// Function of drawing chart view
173173
///
174-
/// - Parameter chartModel: The instance object of chart model
175-
public func aa_drawChartWithChartModel(_ chartModel: AAChartModel) {
176-
let options = AAOptionsConstructor.configureAAOptions(aaChartModel: chartModel)
174+
/// - Parameter aaChartModel: The instance object of chart model
175+
public func aa_drawChartWithChartModel(_ aaChartModel: AAChartModel) {
176+
let options = AAOptionsConstructor.configureChartOptions(aaChartModel)
177177
aa_drawChartWithChartOptions(options)
178178
}
179179

@@ -186,15 +186,15 @@ extension AAChartView {
186186

187187
/// Function of refreshing whole chart view content
188188
///
189-
/// - Parameter chartModel: The instance object of chart model
190-
public func aa_refreshChartWholeContentWithChartModel(_ chartModel: AAChartModel) {
191-
let options = AAOptionsConstructor.configureAAOptions(aaChartModel: chartModel)
192-
aa_refreshChartWholeContentWithChartOptions(options)
189+
/// - Parameter aaChartModel: The instance object of chart model
190+
public func aa_refreshChartWholeContentWithChartModel(_ aaChartModel: AAChartModel) {
191+
let aaOptions = AAOptionsConstructor.configureChartOptions(aaChartModel)
192+
aa_refreshChartWholeContentWithChartOptions(aaOptions)
193193
}
194194

195-
public func aa_drawChartWithChartOptions(_ options: AAOptions) {
195+
public func aa_drawChartWithChartOptions(_ aaOoptions: AAOptions) {
196196
if optionsJson == nil {
197-
configureTheJavaScriptStringWithOptions(options)
197+
configureTheJavaScriptStringWithOptions(aaOoptions)
198198
let path = Bundle(for: self.classForCoder)
199199
.path(forResource: "AAChartView",
200200
ofType: "html",
@@ -203,7 +203,7 @@ extension AAChartView {
203203
let urlRequest = NSURLRequest(url: urlStr) as URLRequest
204204
self.load(urlRequest)
205205
} else {
206-
configureTheJavaScriptStringWithOptions(options)
206+
configureTheJavaScriptStringWithOptions(aaOoptions)
207207
drawChart()
208208
}
209209
}
@@ -215,8 +215,8 @@ extension AAChartView {
215215
evaluateJavaScriptWithFunctionNameString(jsStr)
216216
}
217217

218-
public func aa_refreshChartWholeContentWithChartOptions(_ options: AAOptions) {
219-
configureTheJavaScriptStringWithOptions(options)
218+
public func aa_refreshChartWholeContentWithChartOptions(_ aaOptions: AAOptions) {
219+
configureTheJavaScriptStringWithOptions(aaOptions)
220220
drawChart()
221221
}
222222

AAInfographics/AAChartCreator/AAOptionsConstructor.swift

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ import UIKit
3434

3535
public class AAOptionsConstructor {
3636

37-
public static func configureAAOptions(
38-
aaChartModel: AAChartModel
37+
public static func configureChartOptions(
38+
_ aaChartModel: AAChartModel
3939
) -> AAOptions {
4040
let aaChart = AAChart()
4141
.type(aaChartModel.chartType!) //绘图类型
@@ -83,8 +83,8 @@ public class AAOptionsConstructor {
8383
)
8484
}
8585

86-
configureAAPlotOptionsMarkerStyle(aaChartModel, aaPlotOptions)
87-
configureAAPlotOptionsDataLabels(aaPlotOptions, aaChartModel)
86+
configurePlotOptionsMarkerStyle(aaChartModel, aaPlotOptions)
87+
configurePlotOptionsDataLabels(aaPlotOptions, aaChartModel)
8888

8989
let aaLegend = AALegend()
9090
.enabled(aaChartModel.legendEnabled) //是否显示 legend
@@ -108,13 +108,13 @@ public class AAOptionsConstructor {
108108
return aaOptions
109109
}
110110

111-
private static func configureAAPlotOptionsMarkerStyle(
111+
private static func configurePlotOptionsMarkerStyle(
112112
_ aaChartModel: AAChartModel,
113113
_ aaPlotOptions: AAPlotOptions
114114
) {
115115
let chartType = aaChartModel.chartType!
116116

117-
//数据点标记相关配置,只有线性图(折线图、曲线图、折线区域填充图、曲线区域填充图)才有数据点标记
117+
//数据点标记相关配置,只有线性图(折线图、曲线图、折线区域填充图、曲线区域填充图、散点图、折线范围填充图、曲线范围填充图、多边形图)才有数据点标记
118118
if chartType == .area
119119
|| chartType == .areaspline
120120
|| chartType == .line
@@ -127,11 +127,13 @@ public class AAOptionsConstructor {
127127
.radius(aaChartModel.markerRadius) //曲线连接点半径,默认是4
128128
.symbol(aaChartModel.symbol?.rawValue) //曲线点类型:"circle", "square", "diamond", "triangle","triangle-down",默认是"circle"
129129
if (aaChartModel.symbolStyle == .innerBlank) {
130-
aaMarker.fillColor("#ffffff") //点的填充色(用来设置折线连接点的填充色)
130+
aaMarker
131+
.fillColor("#ffffff") //点的填充色(用来设置折线连接点的填充色)
131132
.lineWidth(2.0) //外沿线的宽度(用来设置折线连接点的轮廓描边的宽度)
132133
.lineColor("") //外沿线的颜色(用来设置折线连接点的轮廓描边颜色,当值为空字符串时,默认取数据点或数据列的颜色)
133134
} else if (aaChartModel.symbolStyle == .borderBlank) {
134-
aaMarker.lineWidth(2.0)
135+
aaMarker
136+
.lineWidth(2.0)
135137
.lineColor(aaChartModel.backgroundColor)
136138
}
137139
let aaSeries = aaPlotOptions.series
@@ -140,7 +142,7 @@ public class AAOptionsConstructor {
140142
}
141143

142144

143-
private static func configureAAPlotOptionsDataLabels(
145+
private static func configurePlotOptionsDataLabels(
144146
_ aaPlotOptions: AAPlotOptions,
145147
_ aaChartModel: AAChartModel
146148
) {

AAInfographicsDemo/Demo/AdditionalContent/CustomTooltipWithJSFunctionVC.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class CustomTooltipWithJSFunctionVC: UIViewController {
109109
,
110110
])
111111

112-
let aaOptions = AAOptionsConstructor.configureAAOptions(aaChartModel: aaChartModel)
112+
let aaOptions = AAOptionsConstructor.configureChartOptions(aaChartModel)
113113
aaOptions.tooltip?
114114
.useHTML(true)
115115
.formatter("""
@@ -158,7 +158,7 @@ function () {
158158
,
159159
])
160160

161-
let aaOptions = AAOptionsConstructor.configureAAOptions(aaChartModel: aaChartModel)
161+
let aaOptions = AAOptionsConstructor.configureChartOptions(aaChartModel)
162162
aaOptions.tooltip?
163163
.useHTML(true)
164164
.enabled(true)
@@ -204,7 +204,7 @@ function () {
204204
,
205205
])
206206

207-
let aaOptions = AAOptionsConstructor.configureAAOptions(aaChartModel: aaChartModel)
207+
let aaOptions = AAOptionsConstructor.configureChartOptions(aaChartModel)
208208
aaOptions.tooltip?
209209
.useHTML(true)
210210
.formatter(#"""
@@ -266,7 +266,7 @@ function () {
266266
,
267267
])
268268

269-
let aaOptions = AAOptionsConstructor.configureAAOptions(aaChartModel: aaChartModel)
269+
let aaOptions = AAOptionsConstructor.configureChartOptions(aaChartModel)
270270
aaOptions.tooltip?
271271
.useHTML(true)
272272
.formatter(#"""
@@ -321,7 +321,7 @@ function () {
321321
+ "最小值: {point.low}<br/>"
322322
)
323323

324-
let aaOptions = AAOptionsConstructor.configureAAOptions(aaChartModel: aaChartModel)
324+
let aaOptions = AAOptionsConstructor.configureChartOptions(aaChartModel)
325325
aaOptions.tooltip?
326326
.useHTML(true)
327327
.headerFormat("<em>实验号码: {point.key}</em><br/>")
@@ -374,7 +374,7 @@ function () {
374374
}
375375
"""#)
376376

377-
let aaOptions = AAOptionsConstructor.configureAAOptions(aaChartModel: aaChartModel)
377+
let aaOptions = AAOptionsConstructor.configureChartOptions(aaChartModel)
378378
aaOptions.yAxis?.labels(aaYAxisLabels)
379379

380380
return aaOptions
@@ -395,7 +395,7 @@ function () {
395395
.name("Tokyo Hot")
396396
.lineWidth(5.0)
397397
.fillOpacity(0.4)
398-
.data([229.9, 771.5, 1106.4, 1129.2, 6644.0, 1176.0, 8835.6, 148.5, 8816.4, 6694.1, 7795.6, 9954.4])
398+
.data([1])
399399
,
400400
])
401401

@@ -422,7 +422,7 @@ function () {
422422
}
423423
"""#)
424424

425-
let aaOptions = AAOptionsConstructor.configureAAOptions(aaChartModel: aaChartModel)
425+
let aaOptions = AAOptionsConstructor.configureChartOptions(aaChartModel)
426426
aaOptions.yAxis?
427427
.opposite(true)
428428
.tickWidth(2)
@@ -470,7 +470,7 @@ function () {
470470
)
471471

472472
/*Custom Tooltip Style --- 自定义图表浮动提示框样式及内容*/
473-
let aaOptions = AAOptionsConstructor.configureAAOptions(aaChartModel: aaChartModel)
473+
let aaOptions = AAOptionsConstructor.configureChartOptions(aaChartModel)
474474
aaOptions.tooltip?
475475
.shared(false)
476476
.formatter(#"""

AAInfographicsDemo/Demo/AdditionalContent/DoubleChartsLinkedWorkVC.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class DoubleChartsLinkedWorkVC: UIViewController, AAChartViewDelegate {
8181
,
8282
])
8383

84-
let aaOptions = AAOptionsConstructor.configureAAOptions(aaChartModel: aaChartModel1)
84+
let aaOptions = AAOptionsConstructor.configureChartOptions(aaChartModel1)
8585
aaOptions.xAxis?
8686
.crosshair(AACrosshair()
8787
.dashStyle(AALineDashStyleType.longDashDot)

AAInfographicsDemo/Demo/AdditionalContent/DrawChartWithAAOptionsVC.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class DrawChartWithAAOptionsVC: UIViewController {
116116
.data([0.60, 0.51, 0.52, 0.53, 0.64, 0.84, 0.65, 0.68, 0.63, 0.47, 0.72, 0.60, 0.65, 0.74, 0.66, 0.65, 0.71, 0.59, 0.65, 0.77, 0.52, 0.53, 0.58, 0.53])
117117
,
118118
])
119-
let aaOptions = AAOptionsConstructor.configureAAOptions(aaChartModel: aaChartModel)
119+
let aaOptions = AAOptionsConstructor.configureChartOptions(aaChartModel)
120120
aaOptions.legend!
121121
.itemMarginTop(20)
122122
.symbolRadius(10)//图标圆角
@@ -159,7 +159,7 @@ class DrawChartWithAAOptionsVC: UIViewController {
159159
]
160160
)
161161

162-
let aaOptions = AAOptionsConstructor.configureAAOptions(aaChartModel: aaChartModel)
162+
let aaOptions = AAOptionsConstructor.configureChartOptions(aaChartModel)
163163
aaOptions.chart?.plotBackgroundImage("https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=2859216016,2109779587&fm=27&gp=0.jpg")
164164

165165
return aaOptions
@@ -183,7 +183,7 @@ class DrawChartWithAAOptionsVC: UIViewController {
183183
]
184184
)
185185

186-
let aaOptions = AAOptionsConstructor.configureAAOptions(aaChartModel: aaChartModel)
186+
let aaOptions = AAOptionsConstructor.configureChartOptions(aaChartModel)
187187
//是否将坐标轴显示在对立面,默认情况下 x 轴是在图表的下方显示,y 轴是在左方,
188188
//坐标轴显示在对立面后,x 轴是在上方显示,y 轴是在右方显示(即坐标轴会显示在对立面)。
189189
//该配置一般是用于多坐标轴区分展示,另外在 Highstock 中,y 轴默认是在对立面显示的。
@@ -207,7 +207,7 @@ class DrawChartWithAAOptionsVC: UIViewController {
207207
]
208208
)
209209

210-
let aaOptions = AAOptionsConstructor.configureAAOptions(aaChartModel: aaChartModel)
210+
let aaOptions = AAOptionsConstructor.configureChartOptions(aaChartModel)
211211
aaOptions.yAxis?.min(1000)
212212
return aaOptions
213213
}
@@ -316,7 +316,7 @@ class DrawChartWithAAOptionsVC: UIViewController {
316316
]
317317
)
318318

319-
let aaOptions = AAOptionsConstructor.configureAAOptions(aaChartModel: aaChartModel)
319+
let aaOptions = AAOptionsConstructor.configureChartOptions(aaChartModel)
320320

321321
aaOptions.xAxis?
322322
.tickInterval(3)
@@ -344,7 +344,7 @@ class DrawChartWithAAOptionsVC: UIViewController {
344344
]
345345
)
346346

347-
let aaOptions = AAOptionsConstructor.configureAAOptions(aaChartModel: aaChartModel)
347+
let aaOptions = AAOptionsConstructor.configureChartOptions(aaChartModel)
348348
// * 关于 `pointPadding`
349349
//https://api.highcharts.com.cn/highcharts#plotOptions.column.groupPadding
350350
//
@@ -368,7 +368,7 @@ class DrawChartWithAAOptionsVC: UIViewController {
368368
.data([80]
369369
)])
370370

371-
let aaOptions = AAOptionsConstructor.configureAAOptions(aaChartModel: aaChartModel)
371+
let aaOptions = AAOptionsConstructor.configureChartOptions(aaChartModel)
372372

373373
aaOptions.pane(
374374
AAPane()
@@ -404,7 +404,7 @@ class DrawChartWithAAOptionsVC: UIViewController {
404404
.data([80]
405405
)])
406406

407-
let aaOptions = AAOptionsConstructor.configureAAOptions(aaChartModel: aaChartModel)
407+
let aaOptions = AAOptionsConstructor.configureChartOptions(aaChartModel)
408408

409409
aaOptions.pane(
410410
AAPane()
@@ -449,7 +449,7 @@ class DrawChartWithAAOptionsVC: UIViewController {
449449
.lineWidth(10)
450450
,
451451
])
452-
let aaOptions = AAOptionsConstructor.configureAAOptions(aaChartModel: aaChartModel)
452+
let aaOptions = AAOptionsConstructor.configureChartOptions(aaChartModel)
453453
let aaPlotBandsArr = [
454454
AAPlotBandsElement()
455455
.from(0)
@@ -502,7 +502,7 @@ class DrawChartWithAAOptionsVC: UIViewController {
502502
])
503503
,
504504
])
505-
let aaOptions = AAOptionsConstructor.configureAAOptions(aaChartModel: aaChartModel)
505+
let aaOptions = AAOptionsConstructor.configureChartOptions(aaChartModel)
506506

507507

508508
let aaPlotLinesArr = [
@@ -609,7 +609,7 @@ function () {
609609
)
610610

611611

612-
let aaOptions = AAOptionsConstructor.configureAAOptions(aaChartModel: aaChartModel)
612+
let aaOptions = AAOptionsConstructor.configureChartOptions(aaChartModel)
613613
aaOptions.tooltip(aaTooltip)
614614

615615
return aaOptions
@@ -659,7 +659,7 @@ function () {
659659
]
660660
)
661661

662-
let aaOptions = AAOptionsConstructor.configureAAOptions(aaChartModel: aaChartModel)
662+
let aaOptions = AAOptionsConstructor.configureChartOptions(aaChartModel)
663663
let aaCrosshair = AACrosshair()
664664
.dashStyle(.longDashDot)
665665
.color(AAColor.red)
@@ -703,7 +703,7 @@ function () {
703703
]
704704
);
705705

706-
let aaOptions = AAOptionsConstructor.configureAAOptions(aaChartModel: aaChartModel)
706+
let aaOptions = AAOptionsConstructor.configureChartOptions(aaChartModel)
707707
aaOptions.xAxis?.labels?.useHTML(true)
708708
return aaOptions
709709
}
@@ -742,7 +742,7 @@ function () {
742742
]
743743
)
744744

745-
let aaOptions = AAOptionsConstructor.configureAAOptions(aaChartModel: aaChartModel)
745+
let aaOptions = AAOptionsConstructor.configureChartOptions(aaChartModel)
746746
aaOptions.xAxis?.labels?.useHTML(true)
747747

748748
return aaOptions
@@ -780,7 +780,7 @@ function () {
780780
.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]),
781781
])
782782

783-
let aaOptions = AAOptionsConstructor.configureAAOptions(aaChartModel: aaChartModel)
783+
let aaOptions = AAOptionsConstructor.configureChartOptions(aaChartModel)
784784
aaOptions.plotOptions?.areaspline?.dataLabels?
785785
.enabled(true)
786786
.style(AAStyle()
@@ -848,7 +848,7 @@ function () {
848848
.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]),
849849
])
850850

851-
let aaOptions = AAOptionsConstructor.configureAAOptions(aaChartModel: aaChartModel)
851+
let aaOptions = AAOptionsConstructor.configureChartOptions(aaChartModel)
852852
let aaPlotBandsArr = [
853853
AAPlotBandsElement()
854854
.from(-0.25)//值域颜色带X轴起始值

0 commit comments

Comments
 (0)