@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,47 @@
|
|
|
1
|
+
package com.github.wuxudong.rncharts.utils;
|
|
2
|
+
|
|
3
|
+
import android.graphics.Typeface;
|
|
4
|
+
|
|
5
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
6
|
+
import com.facebook.react.bridge.ReadableType;
|
|
7
|
+
import com.facebook.react.views.text.ReactFontManager;
|
|
8
|
+
import com.github.mikephil.charting.charts.Chart;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Created by wuxudong on 2018/7/25.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
public class TypefaceUtils {
|
|
15
|
+
public static Typeface getTypeface(Chart chart, ReadableMap propMap) {
|
|
16
|
+
String fontFamily = propMap.getString("fontFamily");
|
|
17
|
+
boolean italic = false;
|
|
18
|
+
boolean bold = false;
|
|
19
|
+
int style = Typeface.NORMAL;
|
|
20
|
+
if (BridgeUtils.validate(propMap, ReadableType.String, "fontStyle")) {
|
|
21
|
+
italic = "italic".equals(propMap.getString("fontStyle"));
|
|
22
|
+
}
|
|
23
|
+
if (BridgeUtils.validate(propMap, ReadableType.String, "fontWeight")) {
|
|
24
|
+
bold = "bold".equals(propMap.getString("fontWeight"));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (italic && bold) {
|
|
28
|
+
style = Typeface.BOLD_ITALIC;
|
|
29
|
+
} else if (italic) {
|
|
30
|
+
style = Typeface.ITALIC;
|
|
31
|
+
} else if (bold) {
|
|
32
|
+
style = Typeface.BOLD;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return getTypeface(chart, fontFamily, style);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public static Typeface getTypeface(Chart chart, String fontFamily) {
|
|
39
|
+
return getTypeface(chart, fontFamily, Typeface.NORMAL);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
private static Typeface getTypeface(Chart chart, String fontFamily, int style) {
|
|
43
|
+
return ReactFontManager.getInstance().getTypeface(fontFamily,
|
|
44
|
+
style,
|
|
45
|
+
chart.getContext().getAssets());
|
|
46
|
+
}
|
|
47
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<LinearLayout
|
|
3
|
+
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
4
|
+
android:orientation="vertical"
|
|
5
|
+
android:layout_width="wrap_content"
|
|
6
|
+
android:layout_height="wrap_content">
|
|
7
|
+
|
|
8
|
+
<ImageView
|
|
9
|
+
android:background="@drawable/circle_marker"
|
|
10
|
+
android:layout_width="15dp"
|
|
11
|
+
android:layout_height="15dp" />
|
|
12
|
+
|
|
13
|
+
</LinearLayout>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
3
|
+
android:id="@+id/oval_markerContent"
|
|
4
|
+
android:layout_width="wrap_content"
|
|
5
|
+
android:layout_height="40dp"
|
|
6
|
+
android:background="@drawable/oval_marker" >
|
|
7
|
+
|
|
8
|
+
<TextView
|
|
9
|
+
android:id="@+id/oval_tvContent"
|
|
10
|
+
android:layout_width="wrap_content"
|
|
11
|
+
android:layout_height="wrap_content"
|
|
12
|
+
android:layout_centerHorizontal="true"
|
|
13
|
+
android:layout_marginTop="8dp"
|
|
14
|
+
android:layout_marginLeft="5dp"
|
|
15
|
+
android:layout_marginRight="5dp"
|
|
16
|
+
android:text=""
|
|
17
|
+
android:textSize="12sp"
|
|
18
|
+
android:textColor="@android:color/white"
|
|
19
|
+
android:ellipsize="end"
|
|
20
|
+
android:maxLines="1"
|
|
21
|
+
android:textAppearance="?android:attr/textAppearanceSmall"
|
|
22
|
+
/>
|
|
23
|
+
|
|
24
|
+
</RelativeLayout>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
3
|
+
android:id="@+id/rectangle_markerContent"
|
|
4
|
+
android:layout_width="wrap_content"
|
|
5
|
+
android:layout_height="wrap_content"
|
|
6
|
+
>
|
|
7
|
+
|
|
8
|
+
<TextView
|
|
9
|
+
android:id="@+id/rectangle_tvContent"
|
|
10
|
+
android:layout_width="wrap_content"
|
|
11
|
+
android:layout_height="wrap_content"
|
|
12
|
+
android:background="@drawable/rectangle_marker"
|
|
13
|
+
android:layout_centerHorizontal="true"
|
|
14
|
+
android:text=""
|
|
15
|
+
android:gravity="center"
|
|
16
|
+
android:textSize="12sp"
|
|
17
|
+
android:textColor="@android:color/white"
|
|
18
|
+
android:textAppearance="?android:attr/textAppearanceSmall"
|
|
19
|
+
/>
|
|
20
|
+
|
|
21
|
+
</RelativeLayout>
|
package/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import BarChart from './lib/BarChart';
|
|
2
|
+
import HorizontalBarChart from './lib/HorizontalBarChart';
|
|
3
|
+
import BubbleChart from './lib/BubbleChart';
|
|
4
|
+
import CandleStickChart from './lib/CandleStickChart';
|
|
5
|
+
import LineChart from './lib/LineChart';
|
|
6
|
+
import PieChart from './lib/PieChart';
|
|
7
|
+
import RadarChart from './lib/RadarChart';
|
|
8
|
+
import ScatterChart from './lib/ScatterChart';
|
|
9
|
+
import CombinedChart from './lib/CombinedChart';
|
|
10
|
+
|
|
11
|
+
module.exports = {
|
|
12
|
+
BarChart,
|
|
13
|
+
HorizontalBarChart,
|
|
14
|
+
BubbleChart,
|
|
15
|
+
CandleStickChart,
|
|
16
|
+
LineChart,
|
|
17
|
+
PieChart,
|
|
18
|
+
RadarChart,
|
|
19
|
+
ScatterChart,
|
|
20
|
+
CombinedChart
|
|
21
|
+
};
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
//
|
|
2
|
+
// BalloonMarker.swift
|
|
3
|
+
// ChartsDemo
|
|
4
|
+
//
|
|
5
|
+
// Created by Daniel Cohen Gindi on 19/3/15.
|
|
6
|
+
//
|
|
7
|
+
// Copyright 2015 Daniel Cohen Gindi & Philipp Jahoda
|
|
8
|
+
// A port of MPAndroidChart for iOS
|
|
9
|
+
// Licensed under Apache License 2.0
|
|
10
|
+
//
|
|
11
|
+
// https://github.com/danielgindi/ios-charts
|
|
12
|
+
// https://github.com/danielgindi/Charts/blob/1788e53f22eb3de79eb4f08574d8ea4b54b5e417/ChartsDemo/Classes/Components/BalloonMarker.swift
|
|
13
|
+
// Edit: Added textColor
|
|
14
|
+
|
|
15
|
+
import Foundation;
|
|
16
|
+
|
|
17
|
+
import DGCharts;
|
|
18
|
+
|
|
19
|
+
import SwiftyJSON;
|
|
20
|
+
|
|
21
|
+
open class BalloonMarker: MarkerView {
|
|
22
|
+
open var color: UIColor?
|
|
23
|
+
open var arrowSize = CGSize(width: 15, height: 11)
|
|
24
|
+
open var font: UIFont?
|
|
25
|
+
open var textColor: UIColor?
|
|
26
|
+
open var minimumSize = CGSize()
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
fileprivate var insets = UIEdgeInsets(top: 8.0,left: 8.0,bottom: 20.0,right: 8.0)
|
|
30
|
+
fileprivate var topInsets = UIEdgeInsets(top: 20.0,left: 8.0,bottom: 8.0,right: 8.0)
|
|
31
|
+
|
|
32
|
+
fileprivate var labelns: NSString?
|
|
33
|
+
fileprivate var _labelSize: CGSize = CGSize()
|
|
34
|
+
fileprivate var _size: CGSize = CGSize()
|
|
35
|
+
fileprivate var _paragraphStyle: NSMutableParagraphStyle?
|
|
36
|
+
fileprivate var _drawAttributes = [NSAttributedString.Key: Any]()
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
public init(color: UIColor, font: UIFont, textColor: UIColor, textAlign: NSTextAlignment) {
|
|
40
|
+
super.init(frame: CGRect.zero);
|
|
41
|
+
self.color = color
|
|
42
|
+
self.font = font
|
|
43
|
+
self.textColor = textColor
|
|
44
|
+
|
|
45
|
+
_paragraphStyle = NSParagraphStyle.default.mutableCopy() as? NSMutableParagraphStyle
|
|
46
|
+
_paragraphStyle?.alignment = textAlign
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public required init?(coder aDecoder: NSCoder) {
|
|
50
|
+
fatalError("init(coder:) has not been implemented");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
func drawRect(context: CGContext, point: CGPoint) -> CGRect{
|
|
55
|
+
|
|
56
|
+
let chart = super.chartView
|
|
57
|
+
|
|
58
|
+
let width = _size.width
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
var rect = CGRect(origin: point, size: _size)
|
|
62
|
+
|
|
63
|
+
if point.y - _size.height < 0 {
|
|
64
|
+
|
|
65
|
+
if point.x - _size.width / 2.0 < 0 {
|
|
66
|
+
drawTopLeftRect(context: context, rect: rect)
|
|
67
|
+
} else if (chart != nil && point.x + width - _size.width / 2.0 > (chart?.bounds.width)!) {
|
|
68
|
+
rect.origin.x -= _size.width
|
|
69
|
+
drawTopRightRect(context: context, rect: rect)
|
|
70
|
+
} else {
|
|
71
|
+
rect.origin.x -= _size.width / 2.0
|
|
72
|
+
drawTopCenterRect(context: context, rect: rect)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
rect.origin.y += self.topInsets.top
|
|
76
|
+
rect.size.height -= self.topInsets.top + self.topInsets.bottom
|
|
77
|
+
|
|
78
|
+
} else {
|
|
79
|
+
|
|
80
|
+
rect.origin.y -= _size.height
|
|
81
|
+
|
|
82
|
+
if point.x - _size.width / 2.0 < 0 {
|
|
83
|
+
drawLeftRect(context: context, rect: rect)
|
|
84
|
+
} else if (chart != nil && point.x + width - _size.width / 2.0 > (chart?.bounds.width)!) {
|
|
85
|
+
rect.origin.x -= _size.width
|
|
86
|
+
drawRightRect(context: context, rect: rect)
|
|
87
|
+
} else {
|
|
88
|
+
rect.origin.x -= _size.width / 2.0
|
|
89
|
+
drawCenterRect(context: context, rect: rect)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
rect.origin.y += self.insets.top
|
|
93
|
+
rect.size.height -= self.insets.top + self.insets.bottom
|
|
94
|
+
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return rect
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
func drawCenterRect(context: CGContext, rect: CGRect) {
|
|
101
|
+
|
|
102
|
+
context.setFillColor((color?.cgColor)!)
|
|
103
|
+
context.beginPath()
|
|
104
|
+
context.move(to: CGPoint(x: rect.origin.x, y: rect.origin.y))
|
|
105
|
+
context.addLine(to: CGPoint(x: rect.origin.x + rect.size.width, y: rect.origin.y))
|
|
106
|
+
context.addLine(to: CGPoint(x: rect.origin.x + rect.size.width, y: rect.origin.y + rect.size.height - arrowSize.height))
|
|
107
|
+
context.addLine(to: CGPoint(x: rect.origin.x + (rect.size.width + arrowSize.width) / 2.0, y: rect.origin.y + rect.size.height - arrowSize.height))
|
|
108
|
+
context.addLine(to: CGPoint(x: rect.origin.x + rect.size.width / 2.0, y: rect.origin.y + rect.size.height))
|
|
109
|
+
context.addLine(to: CGPoint(x: rect.origin.x + (rect.size.width - arrowSize.width) / 2.0, y: rect.origin.y + rect.size.height - arrowSize.height))
|
|
110
|
+
context.addLine(to: CGPoint(x: rect.origin.x, y: rect.origin.y + rect.size.height - arrowSize.height))
|
|
111
|
+
context.addLine(to: CGPoint(x: rect.origin.x, y: rect.origin.y))
|
|
112
|
+
context.fillPath()
|
|
113
|
+
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
func drawLeftRect(context: CGContext, rect: CGRect) {
|
|
117
|
+
context.setFillColor((color?.cgColor)!)
|
|
118
|
+
context.beginPath()
|
|
119
|
+
context.move(to: CGPoint(x: rect.origin.x, y: rect.origin.y))
|
|
120
|
+
context.addLine(to: CGPoint(x: rect.origin.x + rect.size.width, y: rect.origin.y))
|
|
121
|
+
context.addLine(to: CGPoint(x: rect.origin.x + rect.size.width, y: rect.origin.y + rect.size.height - arrowSize.height))
|
|
122
|
+
context.addLine(to: CGPoint(x: rect.origin.x + arrowSize.width / 2.0, y: rect.origin.y + rect.size.height - arrowSize.height))
|
|
123
|
+
context.addLine(to: CGPoint(x: rect.origin.x, y: rect.origin.y + rect.size.height))
|
|
124
|
+
context.addLine(to: CGPoint(x: rect.origin.x, y: rect.origin.y))
|
|
125
|
+
context.fillPath()
|
|
126
|
+
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
func drawRightRect(context: CGContext, rect: CGRect) {
|
|
130
|
+
context.setFillColor((color?.cgColor)!)
|
|
131
|
+
context.beginPath()
|
|
132
|
+
context.move(to: CGPoint(x: rect.origin.x, y: rect.origin.y))
|
|
133
|
+
context.addLine(to: CGPoint(x: rect.origin.x + rect.size.width, y: rect.origin.y))
|
|
134
|
+
context.addLine(to: CGPoint(x: rect.origin.x + rect.size.width, y: rect.origin.y + rect.size.height))
|
|
135
|
+
context.addLine(to: CGPoint(x: rect.origin.x + rect.size.width - arrowSize.width / 2.0, y: rect.origin.y + rect.size.height - arrowSize.height))
|
|
136
|
+
context.addLine(to: CGPoint(x: rect.origin.x, y: rect.origin.y + rect.size.height - arrowSize.height))
|
|
137
|
+
context.addLine(to: CGPoint(x: rect.origin.x, y: rect.origin.y))
|
|
138
|
+
context.fillPath()
|
|
139
|
+
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
func drawTopCenterRect(context: CGContext, rect: CGRect) {
|
|
143
|
+
|
|
144
|
+
context.setFillColor((color?.cgColor)!)
|
|
145
|
+
context.beginPath()
|
|
146
|
+
context.move(to: CGPoint(x: rect.origin.x + rect.size.width / 2.0, y: rect.origin.y))
|
|
147
|
+
context.addLine(to: CGPoint(x: rect.origin.x + (rect.size.width + arrowSize.width) / 2.0, y: rect.origin.y + arrowSize.height))
|
|
148
|
+
context.addLine(to: CGPoint(x: rect.origin.x + rect.size.width, y: rect.origin.y + arrowSize.height))
|
|
149
|
+
context.addLine(to: CGPoint(x: rect.origin.x + rect.size.width, y: rect.origin.y + rect.size.height))
|
|
150
|
+
context.addLine(to: CGPoint(x: rect.origin.x, y: rect.origin.y + rect.size.height))
|
|
151
|
+
context.addLine(to: CGPoint(x: rect.origin.x, y: rect.origin.y + arrowSize.height))
|
|
152
|
+
context.addLine(to: CGPoint(x: rect.origin.x + (rect.size.width - arrowSize.width) / 2.0, y: rect.origin.y + arrowSize.height))
|
|
153
|
+
context.addLine(to: CGPoint(x: rect.origin.x + rect.size.width / 2.0, y: rect.origin.y))
|
|
154
|
+
context.fillPath()
|
|
155
|
+
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
func drawTopLeftRect(context: CGContext, rect: CGRect) {
|
|
159
|
+
context.setFillColor((color?.cgColor)!)
|
|
160
|
+
context.beginPath()
|
|
161
|
+
context.move(to: CGPoint(x: rect.origin.x, y: rect.origin.y))
|
|
162
|
+
context.addLine(to: CGPoint(x: rect.origin.x + arrowSize.width / 2.0, y: rect.origin.y + arrowSize.height))
|
|
163
|
+
context.addLine(to: CGPoint(x: rect.origin.x + rect.size.width, y: rect.origin.y + arrowSize.height))
|
|
164
|
+
context.addLine(to: CGPoint(x: rect.origin.x + rect.size.width, y: rect.origin.y + rect.size.height))
|
|
165
|
+
context.addLine(to: CGPoint(x: rect.origin.x, y: rect.origin.y + rect.size.height))
|
|
166
|
+
context.addLine(to: CGPoint(x: rect.origin.x, y: rect.origin.y))
|
|
167
|
+
context.fillPath()
|
|
168
|
+
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
func drawTopRightRect(context: CGContext, rect: CGRect) {
|
|
172
|
+
context.setFillColor((color?.cgColor)!)
|
|
173
|
+
context.beginPath()
|
|
174
|
+
context.move(to: CGPoint(x: rect.origin.x + rect.size.width, y: rect.origin.y))
|
|
175
|
+
context.addLine(to: CGPoint(x: rect.origin.x + rect.size.width, y: rect.origin.y + rect.size.height))
|
|
176
|
+
context.addLine(to: CGPoint(x: rect.origin.x, y: rect.origin.y + rect.size.height))
|
|
177
|
+
context.addLine(to: CGPoint(x: rect.origin.x, y: rect.origin.y + arrowSize.height))
|
|
178
|
+
context.addLine(to: CGPoint(x: rect.origin.x + rect.size.width - arrowSize.height / 2.0, y: rect.origin.y + arrowSize.height))
|
|
179
|
+
context.addLine(to: CGPoint(x: rect.origin.x + rect.size.width, y: rect.origin.y))
|
|
180
|
+
context.fillPath()
|
|
181
|
+
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
open override func draw(context: CGContext, point: CGPoint) {
|
|
187
|
+
if (labelns == nil || labelns?.length == 0) {
|
|
188
|
+
return
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
context.saveGState()
|
|
192
|
+
|
|
193
|
+
let rect = drawRect(context: context, point: point)
|
|
194
|
+
|
|
195
|
+
UIGraphicsPushContext(context)
|
|
196
|
+
|
|
197
|
+
labelns?.draw(in: rect, withAttributes: _drawAttributes)
|
|
198
|
+
|
|
199
|
+
UIGraphicsPopContext()
|
|
200
|
+
|
|
201
|
+
context.restoreGState()
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
open override func refreshContent(entry: ChartDataEntry, highlight: Highlight) {
|
|
205
|
+
|
|
206
|
+
var label : String;
|
|
207
|
+
|
|
208
|
+
if let candleEntry = entry as? CandleChartDataEntry {
|
|
209
|
+
|
|
210
|
+
label = candleEntry.close.description
|
|
211
|
+
} else {
|
|
212
|
+
label = entry.y.description
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if let object = entry.data as? JSON {
|
|
216
|
+
if object["marker"].exists() {
|
|
217
|
+
label = object["marker"].stringValue;
|
|
218
|
+
|
|
219
|
+
if highlight.stackIndex != -1 && object["marker"].array != nil {
|
|
220
|
+
label = object["marker"].arrayValue[highlight.stackIndex].stringValue
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
labelns = label as NSString
|
|
226
|
+
|
|
227
|
+
_drawAttributes.removeAll()
|
|
228
|
+
_drawAttributes[NSAttributedString.Key.font] = self.font
|
|
229
|
+
_drawAttributes[NSAttributedString.Key.paragraphStyle] = _paragraphStyle
|
|
230
|
+
_drawAttributes[NSAttributedString.Key.foregroundColor] = self.textColor
|
|
231
|
+
|
|
232
|
+
_labelSize = labelns?.size(withAttributes: _drawAttributes) ?? CGSize.zero
|
|
233
|
+
_size.width = _labelSize.width + self.insets.left + self.insets.right
|
|
234
|
+
_size.height = _labelSize.height + self.insets.top + self.insets.bottom
|
|
235
|
+
_size.width = max(minimumSize.width, _size.width)
|
|
236
|
+
_size.height = max(minimumSize.height, _size.height)
|
|
237
|
+
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
//
|
|
2
|
+
// ChartGroupHolder.swift
|
|
3
|
+
// Charts
|
|
4
|
+
//
|
|
5
|
+
// Created by wuxudong on 2018/10/1.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
|
|
10
|
+
import DGCharts
|
|
11
|
+
|
|
12
|
+
class ChartHolder {
|
|
13
|
+
open weak var chart:BarLineChartViewBase?
|
|
14
|
+
open var syncX: Bool;
|
|
15
|
+
open var syncY:Bool;
|
|
16
|
+
|
|
17
|
+
init( chart: BarLineChartViewBase, syncX: Bool, syncY: Bool) {
|
|
18
|
+
self.chart = chart
|
|
19
|
+
self.syncX = syncX
|
|
20
|
+
self.syncY = syncY
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
open class ChartGroupHolder {
|
|
25
|
+
static var chartGroup: Dictionary<String, Dictionary<String, ChartHolder>> = [:]
|
|
26
|
+
|
|
27
|
+
public static func addChart(group: String, identifier: String , chart: BarLineChartViewBase, syncX: Bool, syncY: Bool) {
|
|
28
|
+
objc_sync_enter(chartGroup)
|
|
29
|
+
defer { objc_sync_exit(chartGroup) }
|
|
30
|
+
|
|
31
|
+
let keyExists = chartGroup[group] != nil
|
|
32
|
+
|
|
33
|
+
if !keyExists {
|
|
34
|
+
chartGroup[group] = [:]
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
chartGroup[group]![identifier] = ChartHolder(chart: chart, syncX: syncX, syncY: syncY)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
// sync gesture to other chart in the same group
|
|
42
|
+
public static func sync( group: String, identifier: String, scaleX: CGFloat, scaleY:CGFloat, centerX: CGFloat, centerY:CGFloat, performImmediately: Bool) {
|
|
43
|
+
|
|
44
|
+
objc_sync_enter(chartGroup)
|
|
45
|
+
defer { objc_sync_exit(chartGroup) }
|
|
46
|
+
|
|
47
|
+
if let identifierMap = chartGroup[group] {
|
|
48
|
+
for (identifierKey, chartHolder) in identifierMap {
|
|
49
|
+
if identifierKey != identifier {
|
|
50
|
+
if let chart = chartHolder.chart {
|
|
51
|
+
|
|
52
|
+
let axis = chart.getAxis(YAxis.AxisDependency.left).enabled ? YAxis.AxisDependency.left : YAxis.AxisDependency.right
|
|
53
|
+
|
|
54
|
+
let contentRect = chart.contentRect
|
|
55
|
+
|
|
56
|
+
let originalCenterValue = chart.valueForTouchPoint(point: CGPoint(x: contentRect.midX, y: contentRect.midY), axis: axis)
|
|
57
|
+
|
|
58
|
+
let finalScaleX = chartHolder.syncX ? scaleX : chart.scaleX
|
|
59
|
+
let finalScaleY = chartHolder.syncY ? scaleY : chart.scaleY
|
|
60
|
+
|
|
61
|
+
let finalCenterX = chartHolder.syncX ? centerX : originalCenterValue.x;
|
|
62
|
+
let finalCenterY = chartHolder.syncY ? centerY : originalCenterValue.y;
|
|
63
|
+
|
|
64
|
+
chart.zoom(scaleX: finalScaleX, scaleY: finalScaleY, xValue: Double(finalCenterX), yValue: Double(finalCenterY), axis: axis);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import DGCharts
|
|
3
|
+
|
|
4
|
+
open class CircleMarker: MarkerImage
|
|
5
|
+
{
|
|
6
|
+
open var color: UIColor
|
|
7
|
+
open var strokeColor: UIColor
|
|
8
|
+
open var strokeSize: Int
|
|
9
|
+
|
|
10
|
+
public init(
|
|
11
|
+
color: UIColor,
|
|
12
|
+
strokeColor: UIColor,
|
|
13
|
+
size: CGSize,
|
|
14
|
+
strokeSize: Int
|
|
15
|
+
)
|
|
16
|
+
{
|
|
17
|
+
self.color = color
|
|
18
|
+
self.strokeColor = strokeColor
|
|
19
|
+
self.strokeSize = strokeSize
|
|
20
|
+
|
|
21
|
+
super.init()
|
|
22
|
+
|
|
23
|
+
self.size = size
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
open override func offsetForDrawing(atPoint point: CGPoint) -> CGPoint
|
|
27
|
+
{
|
|
28
|
+
var offset = self.offset
|
|
29
|
+
var size = self.size
|
|
30
|
+
|
|
31
|
+
if size.width == 0.0 && image != nil
|
|
32
|
+
{
|
|
33
|
+
size.width = image!.size.width
|
|
34
|
+
}
|
|
35
|
+
if size.height == 0.0 && image != nil
|
|
36
|
+
{
|
|
37
|
+
size.height = image!.size.height
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
let width = size.width
|
|
41
|
+
let height = size.height
|
|
42
|
+
let padding: CGFloat = 8.0
|
|
43
|
+
|
|
44
|
+
var origin = point
|
|
45
|
+
origin.x -= width / 2
|
|
46
|
+
origin.y -= height
|
|
47
|
+
|
|
48
|
+
if origin.x + offset.x < 0.0
|
|
49
|
+
{
|
|
50
|
+
offset.x = -origin.x + padding
|
|
51
|
+
}
|
|
52
|
+
else if let chart = chartView,
|
|
53
|
+
origin.x + width + offset.x > chart.bounds.size.width
|
|
54
|
+
{
|
|
55
|
+
offset.x = chart.bounds.size.width - origin.x - width - padding
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if origin.y + offset.y < 0
|
|
59
|
+
{
|
|
60
|
+
offset.y = height + padding;
|
|
61
|
+
}
|
|
62
|
+
else if let chart = chartView,
|
|
63
|
+
origin.y + height + offset.y > chart.bounds.size.height
|
|
64
|
+
{
|
|
65
|
+
offset.y = chart.bounds.size.height - origin.y - height - padding
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return offset
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
open override func draw(context: CGContext, point: CGPoint)
|
|
72
|
+
{
|
|
73
|
+
let offset = self.offsetForDrawing(atPoint: point)
|
|
74
|
+
let color = self.color;
|
|
75
|
+
let size = self.size
|
|
76
|
+
let strokeSize = self.strokeSize
|
|
77
|
+
let strokeColor = self.strokeColor;
|
|
78
|
+
|
|
79
|
+
var rect = CGRect(
|
|
80
|
+
origin: CGPoint(
|
|
81
|
+
x: point.x + offset.x,
|
|
82
|
+
y: point.y + offset.y
|
|
83
|
+
),
|
|
84
|
+
size: size
|
|
85
|
+
)
|
|
86
|
+
rect.origin.x -= size.width / 2.0
|
|
87
|
+
rect.origin.y -= size.height / 2.0
|
|
88
|
+
|
|
89
|
+
context.saveGState()
|
|
90
|
+
|
|
91
|
+
context.setFillColor(color.cgColor)
|
|
92
|
+
context.setLineWidth(CGFloat(strokeSize))
|
|
93
|
+
context.setStrokeColor(strokeColor.cgColor)
|
|
94
|
+
|
|
95
|
+
context.addEllipse(in: rect)
|
|
96
|
+
context.drawPath(using: .fillStroke)
|
|
97
|
+
|
|
98
|
+
UIGraphicsPushContext(context)
|
|
99
|
+
|
|
100
|
+
UIGraphicsPopContext()
|
|
101
|
+
|
|
102
|
+
context.restoreGState()
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
open override func refreshContent(entry: ChartDataEntry, highlight: Highlight)
|
|
106
|
+
{
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import DGCharts
|
|
3
|
+
|
|
4
|
+
open class ConfigurableMinimumLinePositionFillFormatter: NSObject, FillFormatter {
|
|
5
|
+
|
|
6
|
+
open var min = CGFloat(0)
|
|
7
|
+
|
|
8
|
+
public override init() {
|
|
9
|
+
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
public init(_ min: CGFloat) {
|
|
13
|
+
self.min = min;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
open func getFillLinePosition(dataSet: LineChartDataSetProtocol, dataProvider: LineChartDataProvider) -> CGFloat {
|
|
17
|
+
return min
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
//
|
|
2
|
+
// CustomChartDateFormatter.swift
|
|
3
|
+
// Charts
|
|
4
|
+
//
|
|
5
|
+
// Created by wuxudong on 2018/10/6.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import DGCharts
|
|
10
|
+
|
|
11
|
+
open class CustomChartDateFormatter: NSObject, ValueFormatter, AxisValueFormatter {
|
|
12
|
+
|
|
13
|
+
open var dateFormatter = DateFormatter();
|
|
14
|
+
|
|
15
|
+
open var since = 0.0
|
|
16
|
+
|
|
17
|
+
open var timeUnit : String?
|
|
18
|
+
|
|
19
|
+
public override init() {
|
|
20
|
+
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public init(pattern: String?, since: Double, timeUnit: String?, locale: String?) {
|
|
24
|
+
self.dateFormatter.locale = Locale(identifier: locale ?? Locale.current.languageCode ?? "en_US");
|
|
25
|
+
self.dateFormatter.dateFormat = pattern;
|
|
26
|
+
self.since = since
|
|
27
|
+
self.timeUnit = timeUnit
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
open func stringForValue(_ value: Double, axis: AxisBase?) -> String {
|
|
31
|
+
return format(value)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
open func stringForValue(_ value: Double, entry: ChartDataEntry, dataSetIndex: Int, viewPortHandler: ViewPortHandler?) -> String {
|
|
35
|
+
return format(value)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
fileprivate func format(_ value: Double) -> String
|
|
39
|
+
{
|
|
40
|
+
var span = 0.0
|
|
41
|
+
|
|
42
|
+
// TODO: any better enum other than String equals to java.util.TimeUnit
|
|
43
|
+
switch timeUnit {
|
|
44
|
+
case "MILLISECONDS":
|
|
45
|
+
span = value / 1000.0
|
|
46
|
+
case "SECONDS":
|
|
47
|
+
span = value
|
|
48
|
+
case "MINUTES":
|
|
49
|
+
span = value * 60
|
|
50
|
+
case "HOURS":
|
|
51
|
+
span = value * 60 * 60
|
|
52
|
+
case "DAYS":
|
|
53
|
+
span = value * 60 * 60 * 24
|
|
54
|
+
default:
|
|
55
|
+
span = value / 1000.0
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
let timeIntervalSince1970 = self.since / 1000.0 + span
|
|
59
|
+
|
|
60
|
+
let date = Date(timeIntervalSince1970: timeIntervalSince1970);
|
|
61
|
+
return self.dateFormatter.string(from: date);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
}
|