@urvish-procare/react-native-charts-wrapper 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +258 -0
- package/android/build.gradle +43 -0
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/java/com/github/wuxudong/rncharts/MPAndroidChartPackage.java +49 -0
- package/android/src/main/java/com/github/wuxudong/rncharts/charts/BarChartManager.java +46 -0
- package/android/src/main/java/com/github/wuxudong/rncharts/charts/BarLineChartBaseManager.java +415 -0
- package/android/src/main/java/com/github/wuxudong/rncharts/charts/BubbleChartManager.java +32 -0
- package/android/src/main/java/com/github/wuxudong/rncharts/charts/CandleStickChartManager.java +31 -0
- package/android/src/main/java/com/github/wuxudong/rncharts/charts/ChartBaseManager.java +605 -0
- package/android/src/main/java/com/github/wuxudong/rncharts/charts/ChartGroupHolder.java +80 -0
- package/android/src/main/java/com/github/wuxudong/rncharts/charts/CombinedChartManager.java +62 -0
- package/android/src/main/java/com/github/wuxudong/rncharts/charts/ConfigurableMinimumLinePositionFillFormatter.java +19 -0
- package/android/src/main/java/com/github/wuxudong/rncharts/charts/CustomFormatter.java +25 -0
- package/android/src/main/java/com/github/wuxudong/rncharts/charts/DateFormatter.java +34 -0
- package/android/src/main/java/com/github/wuxudong/rncharts/charts/HorizontalBarChartManager.java +23 -0
- package/android/src/main/java/com/github/wuxudong/rncharts/charts/IndexValueFormatter.java +102 -0
- package/android/src/main/java/com/github/wuxudong/rncharts/charts/LabelByXValueFormatter.java +25 -0
- package/android/src/main/java/com/github/wuxudong/rncharts/charts/LineChartManager.java +31 -0
- package/android/src/main/java/com/github/wuxudong/rncharts/charts/PieChartManager.java +147 -0
- package/android/src/main/java/com/github/wuxudong/rncharts/charts/RadarChartManager.java +118 -0
- package/android/src/main/java/com/github/wuxudong/rncharts/charts/ScatterChartManager.java +32 -0
- package/android/src/main/java/com/github/wuxudong/rncharts/charts/YAxisChartBase.java +51 -0
- package/android/src/main/java/com/github/wuxudong/rncharts/data/BarDataExtract.java +106 -0
- package/android/src/main/java/com/github/wuxudong/rncharts/data/BubbleDataExtract.java +74 -0
- package/android/src/main/java/com/github/wuxudong/rncharts/data/CandleDataExtract.java +102 -0
- package/android/src/main/java/com/github/wuxudong/rncharts/data/CombinedDataExtract.java +70 -0
- package/android/src/main/java/com/github/wuxudong/rncharts/data/DataExtract.java +77 -0
- package/android/src/main/java/com/github/wuxudong/rncharts/data/LineDataExtract.java +130 -0
- package/android/src/main/java/com/github/wuxudong/rncharts/data/PieDataExtract.java +101 -0
- package/android/src/main/java/com/github/wuxudong/rncharts/data/RadarDataExtract.java +58 -0
- package/android/src/main/java/com/github/wuxudong/rncharts/data/ScatterDataExtract.java +75 -0
- package/android/src/main/java/com/github/wuxudong/rncharts/listener/RNOnChartGestureListener.java +129 -0
- package/android/src/main/java/com/github/wuxudong/rncharts/listener/RNOnChartValueSelectedListener.java +52 -0
- package/android/src/main/java/com/github/wuxudong/rncharts/markers/RNCircleMarkerView.java +19 -0
- package/android/src/main/java/com/github/wuxudong/rncharts/markers/RNRectangleMarkerView.java +134 -0
- package/android/src/main/java/com/github/wuxudong/rncharts/utils/BridgeUtils.java +52 -0
- package/android/src/main/java/com/github/wuxudong/rncharts/utils/ChartDataSetConfigUtils.java +197 -0
- package/android/src/main/java/com/github/wuxudong/rncharts/utils/ConversionUtil.java +144 -0
- package/android/src/main/java/com/github/wuxudong/rncharts/utils/DrawableUtils.java +51 -0
- package/android/src/main/java/com/github/wuxudong/rncharts/utils/EasingFunctionHelper.java +128 -0
- package/android/src/main/java/com/github/wuxudong/rncharts/utils/EntryToWritableMapUtils.java +147 -0
- package/android/src/main/java/com/github/wuxudong/rncharts/utils/TypefaceUtils.java +47 -0
- package/android/src/main/res/drawable-nodpi/circle_marker.xml +8 -0
- package/android/src/main/res/drawable-nodpi/oval_marker.png +0 -0
- package/android/src/main/res/drawable-nodpi/rectangle_marker.9.png +0 -0
- package/android/src/main/res/drawable-nodpi/rectangle_marker_left.9.png +0 -0
- package/android/src/main/res/drawable-nodpi/rectangle_marker_right.9.png +0 -0
- package/android/src/main/res/drawable-nodpi/rectangle_marker_top.9.png +0 -0
- package/android/src/main/res/drawable-nodpi/rectangle_marker_top_left.9.png +0 -0
- package/android/src/main/res/drawable-nodpi/rectangle_marker_top_right.9.png +0 -0
- package/android/src/main/res/layout/circle_marker.xml +13 -0
- package/android/src/main/res/layout/oval_marker.xml +24 -0
- package/android/src/main/res/layout/rectangle_marker.xml +21 -0
- package/index.js +21 -0
- package/ios/ReactNativeCharts/BalloonMarker.swift +240 -0
- package/ios/ReactNativeCharts/ChartGroupHolder.swift +70 -0
- package/ios/ReactNativeCharts/CircleMarker.swift +108 -0
- package/ios/ReactNativeCharts/ConfigurableMinimumLinePositionFillFormatter.swift +19 -0
- package/ios/ReactNativeCharts/CustomChartDateFormatter.swift +64 -0
- package/ios/ReactNativeCharts/DataExtract.swift +80 -0
- package/ios/ReactNativeCharts/IndexValueFormatter.swift +49 -0
- package/ios/ReactNativeCharts/RNBarLineChartBaseManager.swift +115 -0
- package/ios/ReactNativeCharts/RNBarLineChartManagerBridge.h +40 -0
- package/ios/ReactNativeCharts/RNBarLineChartViewBase.swift +294 -0
- package/ios/ReactNativeCharts/RNChartManagerBridge.h +36 -0
- package/ios/ReactNativeCharts/RNChartViewBase.swift +593 -0
- package/ios/ReactNativeCharts/RNCharts-Bridging-Header.h +9 -0
- package/ios/ReactNativeCharts/RNYAxisChartManagerBridge.h +17 -0
- package/ios/ReactNativeCharts/RNYAxisChartViewBase.swift +53 -0
- package/ios/ReactNativeCharts/ReactNativeCharts.xcodeproj/project.pbxproj +376 -0
- package/ios/ReactNativeCharts/bar/BarDataExtract.swift +89 -0
- package/ios/ReactNativeCharts/bar/RNBarChartManager.swift +53 -0
- package/ios/ReactNativeCharts/bar/RNBarChartManagerBridge.m +17 -0
- package/ios/ReactNativeCharts/bar/RNBarChartView.swift +41 -0
- package/ios/ReactNativeCharts/bar/RNBarChartViewBase.swift +27 -0
- package/ios/ReactNativeCharts/bar/RNHorizontalBarChartManager.swift +45 -0
- package/ios/ReactNativeCharts/bar/RNHorizontalBarChartManagerBridge.m +16 -0
- package/ios/ReactNativeCharts/bar/RNHorizontalBarChartView.swift +41 -0
- package/ios/ReactNativeCharts/bubble/BubbleDataExtract.swift +61 -0
- package/ios/ReactNativeCharts/bubble/RNBubbleChartManager.swift +53 -0
- package/ios/ReactNativeCharts/bubble/RNBubbleChartManagerBridge.m +15 -0
- package/ios/ReactNativeCharts/bubble/RNBubbleChartView.swift +39 -0
- package/ios/ReactNativeCharts/candlestick/CandleDataExtract.swift +101 -0
- package/ios/ReactNativeCharts/candlestick/RNCandleStickChartManager.swift +53 -0
- package/ios/ReactNativeCharts/candlestick/RNCandleStickChartManagerBridge.m +16 -0
- package/ios/ReactNativeCharts/candlestick/RNCandleStickChartView.swift +44 -0
- package/ios/ReactNativeCharts/combine/CombinedDataExtract.swift +81 -0
- package/ios/ReactNativeCharts/combine/RNCombinedChartManager.swift +53 -0
- package/ios/ReactNativeCharts/combine/RNCombinedChartManagerBridge.m +19 -0
- package/ios/ReactNativeCharts/combine/RNCombinedChartView.swift +61 -0
- package/ios/ReactNativeCharts/formatters/ChartDateFormatter.swift +38 -0
- package/ios/ReactNativeCharts/formatters/LabelByXValueFormatter.swift +35 -0
- package/ios/ReactNativeCharts/formatters/LargeValueFormatter.swift +72 -0
- package/ios/ReactNativeCharts/line/LineDataExtract.swift +178 -0
- package/ios/ReactNativeCharts/line/RNLineChartManager.swift +53 -0
- package/ios/ReactNativeCharts/line/RNLineChartManagerBridge.m +14 -0
- package/ios/ReactNativeCharts/line/RNLineChartView.swift +41 -0
- package/ios/ReactNativeCharts/pie/PieDataExtract.swift +97 -0
- package/ios/ReactNativeCharts/pie/RNPieChartManager.swift +19 -0
- package/ios/ReactNativeCharts/pie/RNPieChartManagerBridge.m +30 -0
- package/ios/ReactNativeCharts/pie/RNPieChartView.swift +192 -0
- package/ios/ReactNativeCharts/radar/RNRadarChartManager.swift +19 -0
- package/ios/ReactNativeCharts/radar/RNRadarChartManagerBridge.m +25 -0
- package/ios/ReactNativeCharts/radar/RNRadarChartView.swift +99 -0
- package/ios/ReactNativeCharts/radar/RadarDataExtract.swift +50 -0
- package/ios/ReactNativeCharts/scatter/RNScatterChartManager.swift +53 -0
- package/ios/ReactNativeCharts/scatter/RNScatterChartManagerBridge.m +15 -0
- package/ios/ReactNativeCharts/scatter/RNScatterChartView.swift +43 -0
- package/ios/ReactNativeCharts/scatter/ScatterDataExtract.swift +76 -0
- package/ios/ReactNativeCharts/utils/BridgeUtils.swift +333 -0
- package/ios/ReactNativeCharts/utils/ChartDataSetConfigUtils.swift +147 -0
- package/ios/ReactNativeCharts/utils/EntryToDictionaryUtils.swift +66 -0
- package/ios/ReactNativeCharts/utils/FontUtils.swift +29 -0
- package/ios/ReactNativeCharts/utils/HighlightUtils.swift +41 -0
- package/lib/AxisIface.js +102 -0
- package/lib/BarChart.js +43 -0
- package/lib/BarLineChartBase.js +86 -0
- package/lib/BubbleChart.js +40 -0
- package/lib/CandleStickChart.js +40 -0
- package/lib/ChartBase.js +131 -0
- package/lib/ChartDataConfig.js +263 -0
- package/lib/ChartDataSetConfig.js +80 -0
- package/lib/CombinedChart.js +43 -0
- package/lib/HighlightEnhancer.js +15 -0
- package/lib/HorizontalBarChart.js +43 -0
- package/lib/LineChart.js +39 -0
- package/lib/MoveEnhancer.js +49 -0
- package/lib/PieChart.js +64 -0
- package/lib/PieRadarChartBase.js +18 -0
- package/lib/RadarChart.js +52 -0
- package/lib/ScaleEnhancer.js +16 -0
- package/lib/ScatterChart.js +38 -0
- package/lib/ScrollEnhancer.js +15 -0
- package/package.json +40 -0
- package/react-native-charts-wrapper.podspec +26 -0
|
@@ -0,0 +1,593 @@
|
|
|
1
|
+
//
|
|
2
|
+
// RNChartViewBase.swift
|
|
3
|
+
// reactNativeCharts
|
|
4
|
+
//
|
|
5
|
+
// Created by xudong wu on 25/02/2017.
|
|
6
|
+
// Copyright wuxudong
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
import UIKit
|
|
10
|
+
import DGCharts
|
|
11
|
+
import SwiftyJSON
|
|
12
|
+
|
|
13
|
+
// In react native, because object-c is unaware of swift protocol extension. use baseClass as workaround
|
|
14
|
+
|
|
15
|
+
@objcMembers
|
|
16
|
+
open class RNChartViewBase: UIView, ChartViewDelegate {
|
|
17
|
+
open var onSelect:RCTBubblingEventBlock?
|
|
18
|
+
|
|
19
|
+
open var onChange:RCTBubblingEventBlock?
|
|
20
|
+
|
|
21
|
+
private var group: String?
|
|
22
|
+
|
|
23
|
+
private var identifier: String?
|
|
24
|
+
|
|
25
|
+
private var syncX = true
|
|
26
|
+
|
|
27
|
+
private var syncY = false
|
|
28
|
+
|
|
29
|
+
override open func reactSetFrame(_ frame: CGRect)
|
|
30
|
+
{
|
|
31
|
+
super.reactSetFrame(frame);
|
|
32
|
+
|
|
33
|
+
let chartFrame = CGRect(x: 0, y: 0, width: frame.width, height: frame.height)
|
|
34
|
+
chart.reactSetFrame(chartFrame)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
var chart: ChartViewBase {
|
|
38
|
+
fatalError("subclass should override this function.")
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
var dataExtract : DataExtract {
|
|
42
|
+
fatalError("subclass should override this function.")
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
func setData(_ data: NSDictionary) {
|
|
46
|
+
let json = BridgeUtils.toJson(data)
|
|
47
|
+
|
|
48
|
+
let extractedChartData: ChartData? = dataExtract.extract(json)
|
|
49
|
+
|
|
50
|
+
guard let chartData = extractedChartData else { return }
|
|
51
|
+
|
|
52
|
+
// https://github.com/danielgindi/Charts/issues/4690
|
|
53
|
+
let originValueFormatters = chartData.map {$0.valueFormatter}
|
|
54
|
+
|
|
55
|
+
chart.data = chartData
|
|
56
|
+
|
|
57
|
+
for (set, valueFormatter) in zip(chartData, originValueFormatters) {
|
|
58
|
+
set.valueFormatter = valueFormatter
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
func setLegend(_ config: NSDictionary) {
|
|
63
|
+
let json = BridgeUtils.toJson(config)
|
|
64
|
+
|
|
65
|
+
let legend = chart.legend;
|
|
66
|
+
|
|
67
|
+
if json["enabled"].bool != nil {
|
|
68
|
+
legend.enabled = json["enabled"].boolValue;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if json["textColor"].int != nil {
|
|
72
|
+
legend.textColor = RCTConvert.uiColor(json["textColor"].intValue);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if json["textSize"].number != nil {
|
|
76
|
+
legend.font = legend.font.withSize(CGFloat(truncating: json["textSize"].numberValue))
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Wrapping / clipping avoidance
|
|
80
|
+
if json["wordWrapEnabled"].bool != nil {
|
|
81
|
+
legend.wordWrapEnabled = json["wordWrapEnabled"].boolValue
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if json["maxSizePercent"].number != nil {
|
|
85
|
+
legend.maxSizePercent = CGFloat(truncating: json["maxSizePercent"].numberValue)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if json["horizontalAlignment"].string != nil {
|
|
89
|
+
legend.horizontalAlignment = BridgeUtils.parseLegendHorizontalAlignment(json["horizontalAlignment"].stringValue)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if json["verticalAlignment"].string != nil {
|
|
93
|
+
legend.verticalAlignment = BridgeUtils.parseLegendVerticalAlignment(json["verticalAlignment"].stringValue)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if json["orientation"].string != nil {
|
|
97
|
+
legend.orientation = BridgeUtils.parseLegendOrientation(json["orientation"].stringValue)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if json["drawInside"].bool != nil {
|
|
101
|
+
legend.drawInside = json["drawInside"].boolValue
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if json["direction"].string != nil {
|
|
105
|
+
legend.direction = BridgeUtils.parseLegendDirection(json["direction"].stringValue)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if let font = FontUtils.getFont(json) {
|
|
109
|
+
legend.font = font
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if json["form"].string != nil {
|
|
113
|
+
legend.form = BridgeUtils.parseLegendForm(json["form"].stringValue)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if json["formSize"].number != nil {
|
|
117
|
+
legend.formSize = CGFloat(truncating: json["formSize"].numberValue)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if json["xEntrySpace"].number != nil {
|
|
121
|
+
legend.xEntrySpace = CGFloat(truncating: json["xEntrySpace"].numberValue)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if json["yEntrySpace"].number != nil {
|
|
125
|
+
legend.yEntrySpace = CGFloat(truncating: json["yEntrySpace"].numberValue)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if json["formToTextSpace"].number != nil {
|
|
129
|
+
legend.formToTextSpace = CGFloat(truncating: json["formToTextSpace"].numberValue)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
// Custom labels & colors
|
|
134
|
+
if json["custom"].exists() {
|
|
135
|
+
let customMap = json["custom"]
|
|
136
|
+
if customMap["colors"].exists() && customMap["labels"].exists() {
|
|
137
|
+
|
|
138
|
+
let colorsArray = customMap["colors"].arrayValue
|
|
139
|
+
let labelsArray = customMap["labels"].arrayValue
|
|
140
|
+
|
|
141
|
+
if colorsArray.count == labelsArray.count {
|
|
142
|
+
// TODO null label should start a group
|
|
143
|
+
// TODO -2 color should avoid drawing a form
|
|
144
|
+
|
|
145
|
+
var legendEntries = [LegendEntry]();
|
|
146
|
+
|
|
147
|
+
for i in 0..<labelsArray.count {
|
|
148
|
+
let legendEntry = LegendEntry()
|
|
149
|
+
legendEntry.formColor = RCTConvert.uiColor(colorsArray[i].intValue);
|
|
150
|
+
legendEntry.label = labelsArray[i].stringValue;
|
|
151
|
+
|
|
152
|
+
legendEntries.append(legendEntry)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
legend.setCustom(entries: legendEntries)
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// TODO extra
|
|
161
|
+
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
func setChartBackgroundColor(_ backgroundColor: Int) {
|
|
165
|
+
chart.backgroundColor = RCTConvert.uiColor(backgroundColor)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
func setChartDescription(_ config: NSDictionary) {
|
|
169
|
+
let json = BridgeUtils.toJson(config)
|
|
170
|
+
|
|
171
|
+
let chartDescription = Description()
|
|
172
|
+
|
|
173
|
+
if json["text"].string != nil {
|
|
174
|
+
chartDescription.text = json["text"].stringValue
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if json["textColor"].int != nil {
|
|
178
|
+
chartDescription.textColor = RCTConvert.uiColor(json["textColor"].intValue)
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if json["textSize"].float != nil {
|
|
182
|
+
chartDescription.font = chartDescription.font.withSize(CGFloat(json["textSize"].floatValue))
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
if json["positionX"].number != nil && json["positionY"].number != nil {
|
|
187
|
+
chartDescription.position = CGPoint(x: CGFloat(truncating: json["positionX"].numberValue), y: CGFloat(truncating: json["positionY"].numberValue))
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
chart.chartDescription = chartDescription
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
func setNoDataText(_ noDataText: String) {
|
|
194
|
+
chart.noDataText = noDataText
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
func setNoDataTextColor(_ color: Int) {
|
|
198
|
+
chart.noDataTextColor = RCTConvert.uiColor(color)
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
func setTouchEnabled(_ touchEnabled: Bool) {
|
|
202
|
+
chart.isUserInteractionEnabled = touchEnabled
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
func setHighlightPerTapEnabled(_ enabled: Bool) {
|
|
206
|
+
chart.highlightPerTapEnabled = enabled
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
func setDragDecelerationEnabled(_ dragDecelerationEnabled: Bool) {
|
|
210
|
+
chart.dragDecelerationEnabled = dragDecelerationEnabled
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
func setDragDecelerationFrictionCoef(_ dragDecelerationFrictionCoef: NSNumber) {
|
|
214
|
+
chart.dragDecelerationFrictionCoef = CGFloat(truncating: dragDecelerationFrictionCoef)
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
func setAnimation(_ config: NSDictionary) {
|
|
218
|
+
let json = BridgeUtils.toJson(config)
|
|
219
|
+
|
|
220
|
+
let durationX = json["durationX"].double != nil ?
|
|
221
|
+
json["durationX"].doubleValue / 1000.0 : 0
|
|
222
|
+
let durationY = json["durationY"].double != nil ?
|
|
223
|
+
json["durationY"].doubleValue / 1000.0 : 0
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
var easingX: ChartEasingOption = .linear
|
|
227
|
+
var easingY: ChartEasingOption = .linear
|
|
228
|
+
|
|
229
|
+
if json["easingX"].string != nil {
|
|
230
|
+
easingX = BridgeUtils.parseEasingOption(json["easingX"].stringValue)
|
|
231
|
+
}
|
|
232
|
+
if json["easingY"].string != nil {
|
|
233
|
+
easingY = BridgeUtils.parseEasingOption(json["easingY"].stringValue)
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if durationX != 0 && durationY != 0 {
|
|
237
|
+
chart.animate(xAxisDuration: durationX, yAxisDuration: durationY, easingOptionX: easingX, easingOptionY: easingY)
|
|
238
|
+
} else if (durationX != 0) {
|
|
239
|
+
chart.animate(xAxisDuration: durationX, easingOption: easingX)
|
|
240
|
+
} else if (durationY != 0) {
|
|
241
|
+
chart.animate(yAxisDuration: durationY, easingOption: easingY)
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
func setXAxis(_ config: NSDictionary) {
|
|
246
|
+
let json = BridgeUtils.toJson(config)
|
|
247
|
+
|
|
248
|
+
let xAxis = chart.xAxis;
|
|
249
|
+
|
|
250
|
+
setCommonAxisConfig(xAxis, config: json)
|
|
251
|
+
|
|
252
|
+
if json["labelRotationAngle"].number != nil {
|
|
253
|
+
xAxis.labelRotationAngle = CGFloat(truncating: json["labelRotationAngle"].numberValue)
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if json["avoidFirstLastClipping"].bool != nil {
|
|
257
|
+
xAxis.avoidFirstLastClippingEnabled = json["avoidFirstLastClipping"].boolValue
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if json["position"].string != nil {
|
|
261
|
+
xAxis.labelPosition = BridgeUtils.parseXAxisLabelPosition(json["position"].stringValue)
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
func setCommonAxisConfig(_ axis: AxisBase, config: JSON) {
|
|
266
|
+
|
|
267
|
+
// what is drawn
|
|
268
|
+
if config["enabled"].bool != nil {
|
|
269
|
+
axis.enabled = config["enabled"].boolValue
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
if config["drawLabels"].bool != nil {
|
|
273
|
+
axis.drawLabelsEnabled = config["drawLabels"].boolValue
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
if config["drawAxisLine"].bool != nil {
|
|
277
|
+
axis.drawAxisLineEnabled = config["drawAxisLine"].boolValue
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
if config["drawGridLines"].bool != nil {
|
|
281
|
+
axis.drawGridLinesEnabled = config["drawGridLines"].boolValue
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// style
|
|
285
|
+
if let font = FontUtils.getFont(config) {
|
|
286
|
+
axis.labelFont = font
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
if config["textColor"].int != nil {
|
|
290
|
+
axis.labelTextColor = RCTConvert.uiColor(config["textColor"].intValue)
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
if config["textSize"].float != nil {
|
|
294
|
+
axis.labelFont = axis.labelFont.withSize(CGFloat(config["textSize"].floatValue))
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
if config["yOffset"].number != nil {
|
|
298
|
+
axis.yOffset = CGFloat(truncating: config["yOffset"].numberValue)
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
if config["gridColor"].int != nil {
|
|
302
|
+
axis.gridColor = RCTConvert.uiColor(config["gridColor"].intValue)
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
if config["gridLineWidth"].number != nil {
|
|
306
|
+
axis.gridLineWidth = CGFloat(truncating: config["gridLineWidth"].numberValue)
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
if config["axisLineColor"].int != nil {
|
|
310
|
+
axis.axisLineColor = RCTConvert.uiColor(config["axisLineColor"].intValue)
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
if config["axisLineWidth"].number != nil {
|
|
314
|
+
axis.axisLineWidth = CGFloat(truncating: config["axisLineWidth"].numberValue)
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
if config["gridDashedLine"].exists() {
|
|
318
|
+
let gridDashedLine = config["gridDashedLine"]
|
|
319
|
+
|
|
320
|
+
var lineLength = CGFloat(0)
|
|
321
|
+
var spaceLength = CGFloat(0)
|
|
322
|
+
|
|
323
|
+
if gridDashedLine["lineLength"].number != nil {
|
|
324
|
+
lineLength = CGFloat(truncating: gridDashedLine["lineLength"].numberValue)
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
if gridDashedLine["spaceLength"].number != nil {
|
|
328
|
+
spaceLength = CGFloat(truncating: gridDashedLine["spaceLength"].numberValue)
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
if gridDashedLine["phase"].number != nil {
|
|
332
|
+
axis.gridLineDashPhase = CGFloat(truncating: gridDashedLine["phase"].numberValue)
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
axis.gridLineDashLengths = [lineLength, spaceLength]
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// limit lines
|
|
339
|
+
if config["limitLines"].array != nil {
|
|
340
|
+
let limitLinesConfig = config["limitLines"].arrayValue
|
|
341
|
+
|
|
342
|
+
axis.removeAllLimitLines()
|
|
343
|
+
for limitLineConfig in limitLinesConfig {
|
|
344
|
+
|
|
345
|
+
if limitLineConfig["limit"].double != nil {
|
|
346
|
+
|
|
347
|
+
let limitLine = ChartLimitLine(limit: limitLineConfig["limit"].doubleValue)
|
|
348
|
+
|
|
349
|
+
if limitLineConfig["label"].string != nil {
|
|
350
|
+
limitLine.label = limitLineConfig["label"].stringValue
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
if (limitLineConfig["lineColor"].int != nil) {
|
|
354
|
+
limitLine.lineColor = RCTConvert.uiColor(limitLineConfig["lineColor"].intValue)
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
if (limitLineConfig["valueTextColor"].int != nil) {
|
|
358
|
+
limitLine.valueTextColor = RCTConvert.uiColor(limitLineConfig["valueTextColor"].intValue)
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
let fontSize = limitLineConfig["valueFont"].int != nil ? CGFloat(limitLineConfig["valueFont"].intValue) : CGFloat(13)
|
|
362
|
+
|
|
363
|
+
if let parsedFont = FontUtils.getFont(limitLineConfig) {
|
|
364
|
+
limitLine.valueFont = RCTFont.update(parsedFont, withSize: NSNumber(value: Float(fontSize)))
|
|
365
|
+
} else {
|
|
366
|
+
limitLine.valueFont = NSUIFont.systemFont(ofSize: fontSize)
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
if limitLineConfig["lineWidth"].number != nil {
|
|
370
|
+
limitLine.lineWidth = CGFloat(truncating: limitLineConfig["lineWidth"].numberValue)
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
if limitLineConfig["labelPosition"].string != nil {
|
|
374
|
+
limitLine.labelPosition = BridgeUtils.parseLimitlineLabelPosition(limitLineConfig["labelPosition"].stringValue);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
if limitLineConfig["lineDashPhase"].float != nil {
|
|
378
|
+
limitLine.lineDashPhase = CGFloat(limitLineConfig["lineDashPhase"].floatValue);
|
|
379
|
+
}
|
|
380
|
+
if limitLineConfig["lineDashLengths"].arrayObject != nil {
|
|
381
|
+
limitLine.lineDashLengths = limitLineConfig["lineDashLengths"].arrayObject as? [CGFloat];
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
axis.addLimitLine(limitLine)
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
if config["drawLimitLinesBehindData"].bool != nil {
|
|
390
|
+
axis.drawLimitLinesBehindDataEnabled = config["drawLimitLinesBehindData"].boolValue
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
if config["axisMaximum"].double != nil {
|
|
394
|
+
axis.axisMaximum = config["axisMaximum"].doubleValue
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
if config["axisMinimum"].double != nil {
|
|
398
|
+
axis.axisMinimum = config["axisMinimum"].doubleValue
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
if config["granularity"].double != nil {
|
|
402
|
+
axis.granularity = config["granularity"].doubleValue
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
if config["granularityEnabled"].bool != nil {
|
|
406
|
+
axis.granularityEnabled = config["granularityEnabled"].boolValue
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
if config["labelCount"].int != nil {
|
|
410
|
+
var labelCountForce = false
|
|
411
|
+
if config["labelCountForce"].bool != nil {
|
|
412
|
+
labelCountForce = config["labelCountForce"].boolValue
|
|
413
|
+
}
|
|
414
|
+
axis.setLabelCount(config["labelCount"].intValue, force: labelCountForce)
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
// formatting
|
|
418
|
+
// TODO: other formatting options
|
|
419
|
+
let valueFormatter = config["valueFormatter"];
|
|
420
|
+
if valueFormatter.array != nil {
|
|
421
|
+
axis.valueFormatter = IndexAxisValueFormatter(values: valueFormatter.arrayValue.map({ $0.stringValue }))
|
|
422
|
+
} else if valueFormatter.string != nil {
|
|
423
|
+
if "largeValue" == valueFormatter.stringValue {
|
|
424
|
+
axis.valueFormatter = LargeValueFormatter();
|
|
425
|
+
} else if "percent" == valueFormatter.stringValue {
|
|
426
|
+
let percentFormatter = NumberFormatter()
|
|
427
|
+
percentFormatter.numberStyle = .percent
|
|
428
|
+
|
|
429
|
+
axis.valueFormatter = DefaultAxisValueFormatter(formatter: percentFormatter);
|
|
430
|
+
} else if "date" == valueFormatter.stringValue {
|
|
431
|
+
let valueFormatterPattern = config["valueFormatterPattern"].stringValue;
|
|
432
|
+
let since = config["since"].double != nil ? config["since"].doubleValue : 0
|
|
433
|
+
let timeUnit = config["timeUnit"].string != nil ? config["timeUnit"].stringValue : "MILLISECONDS"
|
|
434
|
+
let locale = config["locale"].string;
|
|
435
|
+
axis.valueFormatter = CustomChartDateFormatter(pattern: valueFormatterPattern, since: since, timeUnit: timeUnit, locale: locale);
|
|
436
|
+
} else {
|
|
437
|
+
let customFormatter = NumberFormatter()
|
|
438
|
+
customFormatter.positiveFormat = valueFormatter.stringValue
|
|
439
|
+
customFormatter.negativeFormat = valueFormatter.stringValue
|
|
440
|
+
|
|
441
|
+
axis.valueFormatter = DefaultAxisValueFormatter(formatter: customFormatter);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
if config["centerAxisLabels"].bool != nil {
|
|
446
|
+
axis.centerAxisLabelsEnabled = config["centerAxisLabels"].boolValue
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
func setMarker(_ config: NSDictionary) {
|
|
451
|
+
let json = BridgeUtils.toJson(config)
|
|
452
|
+
|
|
453
|
+
if json["enabled"].exists() && !json["enabled"].boolValue {
|
|
454
|
+
chart.marker = nil
|
|
455
|
+
return
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
var markerFont = UIFont.systemFont(ofSize: 12.0)
|
|
459
|
+
|
|
460
|
+
if json["textSize"].float != nil {
|
|
461
|
+
markerFont = markerFont.withSize(CGFloat(json["textSize"].floatValue))
|
|
462
|
+
}
|
|
463
|
+
switch (json["markerType"].string) {
|
|
464
|
+
case "circle":
|
|
465
|
+
let marker = CircleMarker(
|
|
466
|
+
color: RCTConvert.uiColor(json["markerColor"].intValue),
|
|
467
|
+
strokeColor: RCTConvert.uiColor(json["markerStrokeColor"].intValue),
|
|
468
|
+
size: CGSize(
|
|
469
|
+
width: json["markerSize"].intValue,
|
|
470
|
+
height: json["markerSize"].intValue
|
|
471
|
+
),
|
|
472
|
+
strokeSize: json["markerStrokeSize"].intValue
|
|
473
|
+
)
|
|
474
|
+
chart.marker = marker
|
|
475
|
+
marker.chartView = chart
|
|
476
|
+
|
|
477
|
+
default:
|
|
478
|
+
let marker = BalloonMarker(
|
|
479
|
+
color: RCTConvert.uiColor(json["markerColor"].intValue),
|
|
480
|
+
font: markerFont,
|
|
481
|
+
textColor: RCTConvert.uiColor(json["textColor"].intValue),
|
|
482
|
+
textAlign: RCTConvert.nsTextAlignment(json["textAlign"].stringValue)
|
|
483
|
+
)
|
|
484
|
+
chart.marker = marker
|
|
485
|
+
marker.chartView = chart
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
func setHighlights(_ config: NSArray) {
|
|
490
|
+
chart.highlightValues(HighlightUtils.getHighlights(config))
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
@objc public func chartValueSelected(_ chartView: ChartViewBase, entry: ChartDataEntry, highlight: Highlight) {
|
|
494
|
+
|
|
495
|
+
if self.onSelect == nil {
|
|
496
|
+
return
|
|
497
|
+
} else {
|
|
498
|
+
self.onSelect!(EntryToDictionaryUtils.entryToDictionary(entry))
|
|
499
|
+
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
@objc public func chartValueNothingSelected(_ chartView: ChartViewBase) {
|
|
504
|
+
if self.onSelect == nil {
|
|
505
|
+
return
|
|
506
|
+
} else {
|
|
507
|
+
self.onSelect!(nil)
|
|
508
|
+
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
@objc public func chartScaled(_ chartView: ChartViewBase, scaleX: CoreGraphics.CGFloat, scaleY: CoreGraphics.CGFloat) {
|
|
513
|
+
sendEvent("chartScaled")
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
@objc public func chartTranslated(_ chartView: ChartViewBase, dX: CoreGraphics.CGFloat, dY: CoreGraphics.CGFloat) {
|
|
517
|
+
sendEvent("chartTranslated")
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
@objc public func chartViewDidEndPanning(_ chartView: ChartViewBase) {
|
|
521
|
+
sendEvent("chartPanEnd")
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
func sendEvent(_ action:String) {
|
|
525
|
+
var dict = [AnyHashable: Any]()
|
|
526
|
+
|
|
527
|
+
dict["action"] = action
|
|
528
|
+
if chart is BarLineChartViewBase {
|
|
529
|
+
let viewPortHandler = chart.viewPortHandler
|
|
530
|
+
let barLineChart = chart as! BarLineChartViewBase
|
|
531
|
+
|
|
532
|
+
dict["scaleX"] = barLineChart.scaleX
|
|
533
|
+
dict["scaleY"] = barLineChart.scaleY
|
|
534
|
+
|
|
535
|
+
if viewPortHandler != nil {
|
|
536
|
+
let handler = viewPortHandler
|
|
537
|
+
let center = barLineChart.valueForTouchPoint(point: handler.contentCenter, axis: YAxis.AxisDependency.left)
|
|
538
|
+
dict["centerX"] = center.x
|
|
539
|
+
dict["centerY"] = center.y
|
|
540
|
+
|
|
541
|
+
let leftBottom = barLineChart.valueForTouchPoint(point: CGPoint(x: handler.contentLeft, y: handler.contentBottom), axis: YAxis.AxisDependency.left)
|
|
542
|
+
|
|
543
|
+
let rightTop = barLineChart.valueForTouchPoint(point: CGPoint(x: handler.contentRight, y: handler.contentTop), axis: YAxis.AxisDependency.left)
|
|
544
|
+
|
|
545
|
+
dict["left"] = leftBottom.x
|
|
546
|
+
dict["bottom"] = leftBottom.y
|
|
547
|
+
dict["right"] = rightTop.x
|
|
548
|
+
dict["top"] = rightTop.y
|
|
549
|
+
|
|
550
|
+
if self.group != nil && self.identifier != nil {
|
|
551
|
+
ChartGroupHolder.sync(group: self.group!, identifier: self.identifier!, scaleX: barLineChart.scaleX, scaleY: barLineChart.scaleY, centerX: center.x, centerY: center.y, performImmediately: true)
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
if self.onChange == nil {
|
|
557
|
+
return
|
|
558
|
+
} else {
|
|
559
|
+
self.onChange!(dict)
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
func setGroup(_ group: String) {
|
|
564
|
+
self.group = group
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
func setIdentifier(_ identifier: String) {
|
|
568
|
+
self.identifier = identifier
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
func setSyncX(_ syncX: Bool) {
|
|
572
|
+
self.syncX = syncX
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
func setSyncY(_ syncY: Bool) {
|
|
576
|
+
self.syncY = syncY
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
func onAfterDataSetChanged() {
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
override open func didSetProps(_ changedProps: [String]!) {
|
|
583
|
+
super.didSetProps(changedProps)
|
|
584
|
+
chart.notifyDataSetChanged()
|
|
585
|
+
onAfterDataSetChanged()
|
|
586
|
+
|
|
587
|
+
if self.group != nil && self.identifier != nil && chart is BarLineChartViewBase {
|
|
588
|
+
ChartGroupHolder.addChart(group: self.group!, identifier: self.identifier!, chart: chart as! BarLineChartViewBase, syncX: syncX, syncY: syncY);
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#import "React/RCTBridge.h"
|
|
2
|
+
#import "React/RCTViewManager.h"
|
|
3
|
+
#import "React/RCTUIManager.h"
|
|
4
|
+
#import "React/UIView+React.h"
|
|
5
|
+
#import "React/RCTBridgeModule.h"
|
|
6
|
+
#import "React/RCTEventDispatcher.h"
|
|
7
|
+
#import "React/RCTEventEmitter.h"
|
|
8
|
+
#import "React/RCTFont.h"
|
|
9
|
+
#import "React/RCTConvert.h"
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//
|
|
2
|
+
// RNYAxisChartManagerBridge.h
|
|
3
|
+
// reactNativeCharts
|
|
4
|
+
//
|
|
5
|
+
// Created by xudong wu on 26/02/2017.
|
|
6
|
+
// Copyright wuxudong
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#ifndef RNYAxisChartManagerBridge_h
|
|
10
|
+
#define RNYAxisChartManagerBridge_h
|
|
11
|
+
|
|
12
|
+
#define EXPORT_Y_AXIS_CHART_BASE_PROPERTIES \
|
|
13
|
+
EXPORT_CHART_BASE_PROPERTIES \
|
|
14
|
+
RCT_EXPORT_VIEW_PROPERTY(yAxis, NSDictionary)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
#endif /* RNYAxisChartManagerBridge_h */
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Created by xudong wu on 26/02/2017.
|
|
3
|
+
// Copyright (c) wuxudong. All rights reserved.
|
|
4
|
+
//
|
|
5
|
+
|
|
6
|
+
import Foundation
|
|
7
|
+
import DGCharts
|
|
8
|
+
import SwiftyJSON
|
|
9
|
+
|
|
10
|
+
class RNYAxisChartViewBase: RNChartViewBase {
|
|
11
|
+
func setYAxis(_ config: NSDictionary) {
|
|
12
|
+
fatalError("subclass should override this function.")
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
func setYAxisConfig(_ axis: YAxis, config: JSON) {
|
|
16
|
+
if config["inverted"].bool != nil {
|
|
17
|
+
axis.inverted = config["inverted"].boolValue
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if config["spaceTop"].float != nil {
|
|
21
|
+
axis.spaceTop = CGFloat(config["spaceTop"].floatValue)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if config["spaceBottom"].float != nil {
|
|
25
|
+
axis.spaceBottom = CGFloat(config["spaceBottom"].floatValue)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
if config["position"].string != nil {
|
|
30
|
+
axis.labelPosition = BridgeUtils.parseYAxisLabelPosition(config["position"].stringValue)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// TODO docs says the remaining config needs to be applied before setting data. Test it
|
|
34
|
+
// zero line
|
|
35
|
+
if config["zeroLine"].exists() {
|
|
36
|
+
let zeroLineConfig = config["zeroLine"]
|
|
37
|
+
|
|
38
|
+
if zeroLineConfig["enabled"].bool != nil {
|
|
39
|
+
axis.drawZeroLineEnabled = zeroLineConfig["enabled"].boolValue
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
if zeroLineConfig["lineWidth"].float != nil {
|
|
44
|
+
axis.zeroLineWidth = CGFloat(zeroLineConfig["lineWidth"].floatValue);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if zeroLineConfig["lineColor"].int != nil {
|
|
48
|
+
axis.zeroLineColor = RCTConvert.uiColor(zeroLineConfig["lineColor"].intValue);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
}
|
|
53
|
+
}
|