@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,35 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import DGCharts
|
|
3
|
+
|
|
4
|
+
open class LabelByXValueFormatter: NSObject, ValueFormatter, AxisValueFormatter {
|
|
5
|
+
|
|
6
|
+
open var labels = [Double : String]()
|
|
7
|
+
|
|
8
|
+
public override init() {
|
|
9
|
+
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
public init(_ labels: [Double : String]) {
|
|
13
|
+
self.labels = labels;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
fileprivate func format(_ value: Double) -> String
|
|
17
|
+
{
|
|
18
|
+
return self.labels[value] ?? ""
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
open func stringForValue(
|
|
22
|
+
_ value: Double, axis: AxisBase?) -> String
|
|
23
|
+
{
|
|
24
|
+
return format(value)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
open func stringForValue(
|
|
28
|
+
_ value: Double,
|
|
29
|
+
entry: ChartDataEntry,
|
|
30
|
+
dataSetIndex: Int,
|
|
31
|
+
viewPortHandler: ViewPortHandler?) -> String
|
|
32
|
+
{
|
|
33
|
+
return format(entry.x)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
//
|
|
2
|
+
// LargeValueFormatter.swift
|
|
3
|
+
// ChartsDemo
|
|
4
|
+
// Copyright © 2016 dcg. All rights reserved.
|
|
5
|
+
//
|
|
6
|
+
import Foundation
|
|
7
|
+
import DGCharts
|
|
8
|
+
|
|
9
|
+
open class LargeValueFormatter: NSObject, ValueFormatter, AxisValueFormatter
|
|
10
|
+
{
|
|
11
|
+
fileprivate static let MAX_LENGTH = 5
|
|
12
|
+
|
|
13
|
+
/// Suffix to be appended after the values.
|
|
14
|
+
///
|
|
15
|
+
/// **default**: suffix: ["", "k", "m", "b", "t"]
|
|
16
|
+
open var suffix = ["", "k", "m", "b", "t"]
|
|
17
|
+
|
|
18
|
+
/// An appendix text to be added at the end of the formatted value.
|
|
19
|
+
open var appendix: String?
|
|
20
|
+
|
|
21
|
+
public override init()
|
|
22
|
+
{
|
|
23
|
+
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public init(appendix: String?)
|
|
27
|
+
{
|
|
28
|
+
self.appendix = appendix
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
fileprivate func format(_ value: Double) -> String
|
|
32
|
+
{
|
|
33
|
+
var sig = abs(value)
|
|
34
|
+
let sign = value < 0 ? "-" : ""
|
|
35
|
+
var length = 0
|
|
36
|
+
let maxLength = suffix.count - 1
|
|
37
|
+
|
|
38
|
+
while sig >= 1000.0 && length < maxLength
|
|
39
|
+
{
|
|
40
|
+
sig /= 1000.0
|
|
41
|
+
length += 1
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
let valueFormatter = NumberFormatter()
|
|
45
|
+
valueFormatter.maximumFractionDigits = 2
|
|
46
|
+
valueFormatter.minimumFractionDigits = 0
|
|
47
|
+
|
|
48
|
+
var r = sign + (valueFormatter.string(from: NSNumber(value: sig)) ?? "") + suffix[length]
|
|
49
|
+
|
|
50
|
+
if appendix != nil
|
|
51
|
+
{
|
|
52
|
+
r += appendix!
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return r
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
open func stringForValue(
|
|
59
|
+
_ value: Double, axis: AxisBase?) -> String
|
|
60
|
+
{
|
|
61
|
+
return format(value)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
open func stringForValue(
|
|
65
|
+
_ value: Double,
|
|
66
|
+
entry: ChartDataEntry,
|
|
67
|
+
dataSetIndex: Int,
|
|
68
|
+
viewPortHandler: ViewPortHandler?) -> String
|
|
69
|
+
{
|
|
70
|
+
return format(value)
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
// Created by xudong wu on 02/03/2017.
|
|
2
|
+
// Copyright © 2017 wuxudong. All rights reserved.
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import Foundation
|
|
6
|
+
|
|
7
|
+
import SwiftyJSON
|
|
8
|
+
import DGCharts
|
|
9
|
+
import UIKit
|
|
10
|
+
|
|
11
|
+
class LineDataExtract : DataExtract {
|
|
12
|
+
override func createData() -> ChartData {
|
|
13
|
+
return LineChartData();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
override func createDataSet(_ entries: [ChartDataEntry], label: String) -> ChartDataSetProtocol {
|
|
17
|
+
return LineChartDataSet(entries: entries, label: label)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
override func dataSetConfig(_ dataSet: ChartDataSetProtocol, config: JSON) {
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
let lineDataSet = dataSet as! LineChartDataSet;
|
|
24
|
+
|
|
25
|
+
ChartDataSetConfigUtils.commonConfig(lineDataSet, config: config);
|
|
26
|
+
ChartDataSetConfigUtils.commonBarLineScatterCandleBubbleConfig(lineDataSet, config: config);
|
|
27
|
+
ChartDataSetConfigUtils.commonLineScatterCandleRadarConfig(lineDataSet, config: config);
|
|
28
|
+
ChartDataSetConfigUtils.commonLineRadarConfig(lineDataSet, config: config);
|
|
29
|
+
|
|
30
|
+
// LineDataSet only config
|
|
31
|
+
if config["circleRadius"].number != nil {
|
|
32
|
+
lineDataSet.circleRadius = CGFloat(config["circleRadius"].numberValue)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
if config["drawCircles"].bool != nil {
|
|
37
|
+
lineDataSet.drawCirclesEnabled = config["drawCircles"].boolValue
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
if config["mode"].string != nil {
|
|
42
|
+
lineDataSet.mode = BridgeUtils.parseLineChartMode(config["mode"].stringValue)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
if config["drawCubicIntensity"].number != nil {
|
|
47
|
+
lineDataSet.cubicIntensity = CGFloat(config["drawCubicIntensity"].numberValue);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
if config["circleColor"].int != nil {
|
|
52
|
+
lineDataSet.setCircleColor(RCTConvert.uiColor(config["circleColor"].intValue))
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if config["circleColors"].array != nil {
|
|
56
|
+
lineDataSet.circleColors = BridgeUtils.parseColors(config["circleColors"].arrayValue)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if config["circleHoleColor"].int != nil {
|
|
60
|
+
lineDataSet.circleHoleColor = RCTConvert.uiColor(config["circleHoleColor"].intValue)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
if config["drawCircleHole"].bool != nil {
|
|
65
|
+
lineDataSet.drawCircleHoleEnabled = config["drawCircleHole"].boolValue
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if config["dashedLine"].exists() {
|
|
69
|
+
let dashedLine = config["dashedLine"]
|
|
70
|
+
var lineLength = CGFloat(0);
|
|
71
|
+
var spaceLength = CGFloat(0);
|
|
72
|
+
var phase = CGFloat(0);
|
|
73
|
+
|
|
74
|
+
if dashedLine["lineLength"].number != nil {
|
|
75
|
+
lineLength = CGFloat(dashedLine["lineLength"].numberValue)
|
|
76
|
+
}
|
|
77
|
+
if dashedLine["spaceLength"].number != nil {
|
|
78
|
+
spaceLength = CGFloat(dashedLine["spaceLength"].numberValue)
|
|
79
|
+
}
|
|
80
|
+
if dashedLine["phase"].number != nil {
|
|
81
|
+
phase = CGFloat(dashedLine["phase"].numberValue)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
lineDataSet.lineDashLengths = [lineLength, spaceLength]
|
|
85
|
+
lineDataSet.lineDashPhase = phase
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if config["fillFormatter"].exists() {
|
|
89
|
+
let fillFormatter = config["fillFormatter"];
|
|
90
|
+
var min = CGFloat(0);
|
|
91
|
+
|
|
92
|
+
if fillFormatter["min"].number != nil {
|
|
93
|
+
min = CGFloat(fillFormatter["min"].numberValue);
|
|
94
|
+
}
|
|
95
|
+
lineDataSet.fillFormatter = ConfigurableMinimumLinePositionFillFormatter(min);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
override func createEntry(_ values: [JSON], index: Int) -> ChartDataEntry {
|
|
100
|
+
var entry: ChartDataEntry;
|
|
101
|
+
|
|
102
|
+
var x = Double(index);
|
|
103
|
+
let value = values[index];
|
|
104
|
+
|
|
105
|
+
if value.dictionary != nil {
|
|
106
|
+
let dict = value;
|
|
107
|
+
var y = Double(index);
|
|
108
|
+
|
|
109
|
+
if dict["x"].double != nil {
|
|
110
|
+
x = Double((dict["x"].doubleValue));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if dict["y"].number != nil {
|
|
114
|
+
y = dict["y"].doubleValue;
|
|
115
|
+
} else {
|
|
116
|
+
fatalError("invalid data " + values.description);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if dict["icon"].exists() {
|
|
120
|
+
let icon = dict["icon"]
|
|
121
|
+
if icon["bundle"].dictionary != nil {
|
|
122
|
+
let bundle = icon["bundle"];
|
|
123
|
+
|
|
124
|
+
let uiImage = RCTConvert.uiImage(bundle.dictionaryObject);
|
|
125
|
+
let width = CGFloat(icon["width"].numberValue)/4;
|
|
126
|
+
let height = CGFloat(icon["height"].numberValue)/4;
|
|
127
|
+
|
|
128
|
+
if let image = uiImage {
|
|
129
|
+
let realIconImage = resizeImage(image: image, width: width, height: height);
|
|
130
|
+
entry = ChartDataEntry(x: x, y: dict["y"].doubleValue, icon: realIconImage);
|
|
131
|
+
} else {
|
|
132
|
+
entry = ChartDataEntry(x: x, y: dict["y"].doubleValue, icon: uiImage);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
} else {
|
|
137
|
+
entry = ChartDataEntry(x: x, y: dict["y"].doubleValue, data: dict as AnyObject?);
|
|
138
|
+
}
|
|
139
|
+
} else {
|
|
140
|
+
entry = ChartDataEntry(x: x, y: dict["y"].doubleValue, data: dict as AnyObject?);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
} else if value.double != nil {
|
|
144
|
+
entry = ChartDataEntry(x: x, y: value.doubleValue);
|
|
145
|
+
} else {
|
|
146
|
+
fatalError("invalid data " + values.description);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return entry;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
func resizeImage(image: UIImage, width: CGFloat, height: CGFloat) -> UIImage {
|
|
153
|
+
let targetSize = CGSize(width: width, height: height)
|
|
154
|
+
let size = image.size
|
|
155
|
+
|
|
156
|
+
let widthRatio = targetSize.width / size.width
|
|
157
|
+
let heightRatio = targetSize.height / size.height
|
|
158
|
+
|
|
159
|
+
// Figure out what our orientation is, and use that to form the rectangle
|
|
160
|
+
var newSize: CGSize
|
|
161
|
+
if(widthRatio > heightRatio) {
|
|
162
|
+
newSize = CGSize(width: size.width * heightRatio, height: size.height * heightRatio)
|
|
163
|
+
} else {
|
|
164
|
+
newSize = CGSize(width: size.width * widthRatio, height: size.height * widthRatio)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// This is the rect that we've calculated out and this is what is actually used below
|
|
168
|
+
let rect = CGRect(x: 0, y: 0, width: newSize.width, height: newSize.height)
|
|
169
|
+
|
|
170
|
+
// Actually do the resizing to the rect using the ImageContext stuff
|
|
171
|
+
UIGraphicsBeginImageContextWithOptions(newSize, false, 1.0)
|
|
172
|
+
image.draw(in: rect)
|
|
173
|
+
let newImage = UIGraphicsGetImageFromCurrentImageContext()
|
|
174
|
+
UIGraphicsEndImageContext()
|
|
175
|
+
|
|
176
|
+
return newImage!
|
|
177
|
+
}
|
|
178
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Created by xudong wu on 23/02/2017.
|
|
2
|
+
// Copyright wuxudong
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import UIKit
|
|
6
|
+
|
|
7
|
+
@objc(RNLineChartManager)
|
|
8
|
+
@objcMembers
|
|
9
|
+
open class RNLineChartManager: RCTViewManager, RNBarLineChartBaseManager {
|
|
10
|
+
var _bridge: RCTBridge? {get{return self.bridge}}
|
|
11
|
+
|
|
12
|
+
override open func view() -> UIView! {
|
|
13
|
+
let ins = RNLineChartView()
|
|
14
|
+
return ins;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
override public static func requiresMainQueueSetup() -> Bool {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
func moveViewToX(_ reactTag: NSNumber, xValue: NSNumber) {
|
|
22
|
+
(self as RNBarLineChartBaseManager)._moveViewToX(reactTag, xValue: xValue)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
func moveViewTo(_ reactTag: NSNumber, xValue: NSNumber, yValue: NSNumber, axisDependency: NSString) {
|
|
26
|
+
(self as RNBarLineChartBaseManager)._moveViewTo(reactTag, xValue: xValue, yValue: yValue, axisDependency: axisDependency)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
func moveViewToAnimated(_ reactTag: NSNumber, xValue: NSNumber, yValue: NSNumber, axisDependency: NSString, duration: NSNumber) {
|
|
30
|
+
(self as RNBarLineChartBaseManager)._moveViewToAnimated(reactTag, xValue: xValue, yValue: yValue, axisDependency: axisDependency, duration: duration)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
func centerViewTo(_ reactTag: NSNumber, xValue: NSNumber, yValue: NSNumber, axisDependency: NSString) {
|
|
34
|
+
(self as RNBarLineChartBaseManager)._centerViewTo(reactTag, xValue: xValue, yValue: yValue, axisDependency: axisDependency)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
func centerViewToAnimated(_ reactTag: NSNumber, xValue: NSNumber, yValue: NSNumber, axisDependency: NSString, duration: NSNumber) {
|
|
38
|
+
(self as RNBarLineChartBaseManager)._centerViewToAnimated(reactTag, xValue: xValue, yValue: yValue, axisDependency: axisDependency, duration: duration)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
func fitScreen(_ reactTag: NSNumber) {
|
|
42
|
+
(self as RNBarLineChartBaseManager)._fitScreen(reactTag)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
func highlights(_ reactTag: NSNumber, config: NSArray) {
|
|
46
|
+
(self as RNBarLineChartBaseManager)._highlights(reactTag, config: config)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
func setDataAndLockIndex(_ reactTag: NSNumber, data: NSDictionary) {
|
|
50
|
+
(self as RNBarLineChartBaseManager)._setDataAndLockIndex(reactTag, data: data)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Created by xudong wu on 24/02/2017.
|
|
2
|
+
// Copyright © 2017 wuxudong. All rights reserved.
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
#import "React/RCTViewManager.h"
|
|
6
|
+
#import "RNChartManagerBridge.h"
|
|
7
|
+
#import "RNYAxisChartManagerBridge.h"
|
|
8
|
+
#import "RNBarLineChartManagerBridge.h"
|
|
9
|
+
|
|
10
|
+
@interface RCT_EXTERN_MODULE(RNLineChartManager, RCTViewManager)
|
|
11
|
+
|
|
12
|
+
EXPORT_BAR_LINE_CHART_BASE_PROPERTIES
|
|
13
|
+
|
|
14
|
+
@end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Created by xudong wu on 24/02/2017.
|
|
2
|
+
// Copyright wuxudong
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import DGCharts
|
|
6
|
+
import SwiftyJSON
|
|
7
|
+
|
|
8
|
+
class RNLineChartView: RNBarLineChartViewBase {
|
|
9
|
+
let _chart: LineChartView;
|
|
10
|
+
let _dataExtract : LineDataExtract;
|
|
11
|
+
|
|
12
|
+
override var chart: LineChartView {
|
|
13
|
+
return _chart
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
override var dataExtract: DataExtract {
|
|
17
|
+
return _dataExtract
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
override init(frame: CoreGraphics.CGRect) {
|
|
21
|
+
|
|
22
|
+
self._chart = LineChartView(frame: frame)
|
|
23
|
+
self._dataExtract = LineDataExtract()
|
|
24
|
+
|
|
25
|
+
super.init(frame: frame);
|
|
26
|
+
|
|
27
|
+
self._chart.delegate = self
|
|
28
|
+
self.addSubview(_chart);
|
|
29
|
+
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
override func layoutSubviews() {
|
|
33
|
+
super.layoutSubviews()
|
|
34
|
+
_chart.frame = self.bounds // Adjust the chart's frame to fill the entire component's bounds
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
required init?(coder aDecoder: NSCoder) {
|
|
38
|
+
fatalError("init(coder:) has not been implemented")
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// Created by xudong wu on 02/03/2017.
|
|
2
|
+
// Copyright © 2017 wuxudong. All rights reserved.
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import Foundation
|
|
6
|
+
|
|
7
|
+
import SwiftyJSON
|
|
8
|
+
import DGCharts
|
|
9
|
+
|
|
10
|
+
class PieDataExtract : DataExtract {
|
|
11
|
+
override func createData() -> ChartData {
|
|
12
|
+
return PieChartData();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
override func createDataSet(_ entries: [ChartDataEntry], label: String) -> ChartDataSetProtocol {
|
|
16
|
+
return PieChartDataSet(entries: entries, label: label)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
override func dataSetConfig(_ dataSet: ChartDataSetProtocol, config: JSON) {
|
|
20
|
+
let pieDataSet = dataSet as! PieChartDataSet;
|
|
21
|
+
|
|
22
|
+
ChartDataSetConfigUtils.commonConfig(pieDataSet, config: config);
|
|
23
|
+
|
|
24
|
+
// PieDataSet only config
|
|
25
|
+
if config["sliceSpace"].float != nil {
|
|
26
|
+
pieDataSet.sliceSpace = CGFloat(config["sliceSpace"].floatValue)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if config["selectionShift"].float != nil {
|
|
30
|
+
pieDataSet.selectionShift = CGFloat(config["selectionShift"].floatValue)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if config["xValuePosition"].string != nil {
|
|
34
|
+
pieDataSet.xValuePosition = BridgeUtils.parsePieChartDataSetValuePosition(config["xValuePosition"].stringValue)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if config["yValuePosition"].string != nil {
|
|
38
|
+
pieDataSet.yValuePosition = BridgeUtils.parsePieChartDataSetValuePosition(config["yValuePosition"].stringValue)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if config["valueLinePart1Length"].float != nil {
|
|
42
|
+
pieDataSet.valueLinePart1Length = CGFloat(config["valueLinePart1Length"].floatValue)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if config["valueLinePart2Length"].float != nil {
|
|
46
|
+
pieDataSet.valueLinePart2Length = CGFloat(config["valueLinePart2Length"].floatValue)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if config["valueLineColor"].int != nil {
|
|
50
|
+
pieDataSet.valueLineColor = RCTConvert.uiColor(config["valueLineColor"].intValue);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if config["valueLineWidth"].float != nil {
|
|
54
|
+
pieDataSet.valueLineWidth = CGFloat(config["valueLineWidth"].floatValue)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if config["valueLinePart1OffsetPercentage"].float != nil {
|
|
58
|
+
pieDataSet.valueLinePart1OffsetPercentage = CGFloat(config["valueLinePart1OffsetPercentage"].floatValue)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if config["valueLineVariableLength"].bool != nil {
|
|
62
|
+
pieDataSet.valueLineVariableLength = config["valueLineVariableLength"].boolValue
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
override func createEntry(_ values: [JSON], index: Int) -> ChartDataEntry {
|
|
68
|
+
var entry: PieChartDataEntry;
|
|
69
|
+
|
|
70
|
+
let item = values[index];
|
|
71
|
+
|
|
72
|
+
if item.dictionary != nil {
|
|
73
|
+
let dict = item;
|
|
74
|
+
|
|
75
|
+
var value : Double;
|
|
76
|
+
if dict["value"].double != nil {
|
|
77
|
+
value = Double((dict["value"].doubleValue));
|
|
78
|
+
} else {
|
|
79
|
+
fatalError("invalid data " + values.description);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if dict["label"].string != nil {
|
|
83
|
+
entry = PieChartDataEntry(value: value, label: dict["label"].stringValue)
|
|
84
|
+
} else {
|
|
85
|
+
entry = PieChartDataEntry(value: value)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
entry.data = dict as AnyObject?
|
|
89
|
+
} else if item.double != nil {
|
|
90
|
+
entry = PieChartDataEntry(value : item.doubleValue);
|
|
91
|
+
} else {
|
|
92
|
+
fatalError("invalid data " + values.description);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return entry;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Created by xudong wu on 23/02/2017.
|
|
2
|
+
// Copyright wuxudong
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import UIKit
|
|
6
|
+
|
|
7
|
+
@objc(RNPieChartManager)
|
|
8
|
+
@objcMembers
|
|
9
|
+
open class RNPieChartManager: RCTViewManager {
|
|
10
|
+
override open func view() -> UIView! {
|
|
11
|
+
let ins = RNPieChartView()
|
|
12
|
+
return ins;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
override public static func requiresMainQueueSetup() -> Bool {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Created by xudong wu on 24/02/2017.
|
|
2
|
+
// Copyright © 2017 wuxudong. All rights reserved.
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
#import "React/RCTViewManager.h"
|
|
6
|
+
#import "RNChartManagerBridge.h"
|
|
7
|
+
|
|
8
|
+
@interface RCT_EXTERN_MODULE(RNPieChartManager, RCTViewManager)
|
|
9
|
+
|
|
10
|
+
EXPORT_CHART_BASE_PROPERTIES
|
|
11
|
+
RCT_EXPORT_VIEW_PROPERTY(drawEntryLabels, BOOL)
|
|
12
|
+
RCT_EXPORT_VIEW_PROPERTY(usePercentValues, BOOL)
|
|
13
|
+
RCT_EXPORT_VIEW_PROPERTY(centerText, NSString)
|
|
14
|
+
RCT_EXPORT_VIEW_PROPERTY(styledCenterText, NSDictionary)
|
|
15
|
+
RCT_EXPORT_VIEW_PROPERTY(centerTextRadiusPercent, NSNumber)
|
|
16
|
+
RCT_EXPORT_VIEW_PROPERTY(holeRadius, NSNumber)
|
|
17
|
+
RCT_EXPORT_VIEW_PROPERTY(holeColor, NSInteger)
|
|
18
|
+
RCT_EXPORT_VIEW_PROPERTY(transparentCircleRadius, NSNumber)
|
|
19
|
+
RCT_EXPORT_VIEW_PROPERTY(transparentCircleColor, NSInteger)
|
|
20
|
+
RCT_EXPORT_VIEW_PROPERTY(entryLabelColor, NSInteger)
|
|
21
|
+
RCT_EXPORT_VIEW_PROPERTY(entryLabelFontFamily, NSString)
|
|
22
|
+
RCT_EXPORT_VIEW_PROPERTY(entryLabelTextSize, NSNumber)
|
|
23
|
+
RCT_EXPORT_VIEW_PROPERTY(extraOffsets, NSDictionary)
|
|
24
|
+
|
|
25
|
+
RCT_EXPORT_VIEW_PROPERTY(maxAngle, NSNumber)
|
|
26
|
+
RCT_EXPORT_VIEW_PROPERTY(minOffset, NSNumber)
|
|
27
|
+
RCT_EXPORT_VIEW_PROPERTY(rotationEnabled, BOOL)
|
|
28
|
+
RCT_EXPORT_VIEW_PROPERTY(rotationAngle, NSNumber)
|
|
29
|
+
|
|
30
|
+
@end
|