@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,605 @@
|
|
|
1
|
+
package com.github.wuxudong.rncharts.charts;
|
|
2
|
+
|
|
3
|
+
import android.content.res.ColorStateList;
|
|
4
|
+
import android.os.Build;
|
|
5
|
+
import android.view.MotionEvent;
|
|
6
|
+
import android.view.View;
|
|
7
|
+
|
|
8
|
+
import com.facebook.react.bridge.ReadableArray;
|
|
9
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
10
|
+
import com.facebook.react.bridge.ReadableType;
|
|
11
|
+
import com.facebook.react.uimanager.SimpleViewManager;
|
|
12
|
+
import com.facebook.react.uimanager.annotations.ReactProp;
|
|
13
|
+
import com.github.mikephil.charting.animation.Easing;
|
|
14
|
+
import com.github.mikephil.charting.charts.Chart;
|
|
15
|
+
import com.github.mikephil.charting.components.AxisBase;
|
|
16
|
+
import com.github.mikephil.charting.components.Description;
|
|
17
|
+
import com.github.mikephil.charting.components.Legend;
|
|
18
|
+
import com.github.mikephil.charting.components.Legend.LegendForm;
|
|
19
|
+
import com.github.mikephil.charting.components.LegendEntry;
|
|
20
|
+
import com.github.mikephil.charting.components.LimitLine;
|
|
21
|
+
import com.github.mikephil.charting.components.MarkerView;
|
|
22
|
+
import com.github.mikephil.charting.components.XAxis;
|
|
23
|
+
import com.github.mikephil.charting.components.XAxis.XAxisPosition;
|
|
24
|
+
import com.github.mikephil.charting.data.Entry;
|
|
25
|
+
import com.github.mikephil.charting.formatter.IndexAxisValueFormatter;
|
|
26
|
+
import com.github.mikephil.charting.formatter.LargeValueFormatter;
|
|
27
|
+
import com.github.mikephil.charting.formatter.PercentFormatter;
|
|
28
|
+
import com.github.mikephil.charting.highlight.Highlight;
|
|
29
|
+
import com.github.wuxudong.rncharts.data.DataExtract;
|
|
30
|
+
import com.github.wuxudong.rncharts.markers.RNRectangleMarkerView;
|
|
31
|
+
import com.github.wuxudong.rncharts.markers.RNCircleMarkerView;
|
|
32
|
+
import com.github.wuxudong.rncharts.utils.BridgeUtils;
|
|
33
|
+
import com.github.wuxudong.rncharts.utils.EasingFunctionHelper;
|
|
34
|
+
import com.github.wuxudong.rncharts.utils.TypefaceUtils;
|
|
35
|
+
|
|
36
|
+
import java.util.ArrayList;
|
|
37
|
+
import java.util.List;
|
|
38
|
+
import java.util.Locale;
|
|
39
|
+
import java.util.concurrent.TimeUnit;
|
|
40
|
+
|
|
41
|
+
public abstract class ChartBaseManager<T extends Chart, U extends Entry> extends SimpleViewManager<T> {
|
|
42
|
+
|
|
43
|
+
protected static final int MOVE_VIEW_TO = 1;
|
|
44
|
+
protected static final int MOVE_VIEW_TO_X = 2;
|
|
45
|
+
protected static final int MOVE_VIEW_TO_ANIMATED = 3;
|
|
46
|
+
protected static final int CENTER_VIEW_TO = 4;
|
|
47
|
+
protected static final int CENTER_VIEW_TO_ANIMATED = 6;
|
|
48
|
+
protected static final int FIT_SCREEN = 7;
|
|
49
|
+
protected static final int HIGHLIGHTS = 8;
|
|
50
|
+
|
|
51
|
+
protected static final int SET_DATA_AND_LOCK_INDEX = 9;
|
|
52
|
+
|
|
53
|
+
abstract DataExtract getDataExtract();
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* More details about legend customization: https://github.com/PhilJay/MPAndroidChart/wiki/Legend
|
|
57
|
+
*/
|
|
58
|
+
@ReactProp(name = "legend")
|
|
59
|
+
public void setLegend(T chart, ReadableMap propMap) {
|
|
60
|
+
Legend legend = chart.getLegend();
|
|
61
|
+
|
|
62
|
+
if (BridgeUtils.validate(propMap, ReadableType.Boolean, "enabled")) {
|
|
63
|
+
legend.setEnabled(propMap.getBoolean("enabled"));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Styling
|
|
67
|
+
if (BridgeUtils.validate(propMap, ReadableType.Number, "textColor")) {
|
|
68
|
+
legend.setTextColor(propMap.getInt("textColor"));
|
|
69
|
+
}
|
|
70
|
+
if (BridgeUtils.validate(propMap, ReadableType.Number, "textSize")) {
|
|
71
|
+
legend.setTextSize((float) propMap.getDouble("textSize"));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Wrapping / clipping avoidance
|
|
75
|
+
if (BridgeUtils.validate(propMap, ReadableType.Boolean, "wordWrapEnabled")) {
|
|
76
|
+
legend.setWordWrapEnabled(propMap.getBoolean("wordWrapEnabled"));
|
|
77
|
+
}
|
|
78
|
+
if (BridgeUtils.validate(propMap, ReadableType.Number, "maxSizePercent")) {
|
|
79
|
+
legend.setMaxSizePercent((float) propMap.getDouble("maxSizePercent"));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Customizing
|
|
83
|
+
if (BridgeUtils.validate(propMap, ReadableType.String, "horizontalAlignment")) {
|
|
84
|
+
legend.setHorizontalAlignment(Legend.LegendHorizontalAlignment.valueOf(propMap.getString("horizontalAlignment").toUpperCase(Locale.ENGLISH)));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (BridgeUtils.validate(propMap, ReadableType.String, "verticalAlignment")) {
|
|
88
|
+
legend.setVerticalAlignment(Legend.LegendVerticalAlignment.valueOf(propMap.getString("verticalAlignment").toUpperCase(Locale.ENGLISH)));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (BridgeUtils.validate(propMap, ReadableType.String, "orientation")) {
|
|
92
|
+
legend.setOrientation(Legend.LegendOrientation.valueOf(propMap.getString("orientation").toUpperCase(Locale.ENGLISH)));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (BridgeUtils.validate(propMap, ReadableType.Boolean, "drawInside")) {
|
|
96
|
+
legend.setDrawInside(propMap.getBoolean("drawInside"));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (BridgeUtils.validate(propMap, ReadableType.String, "direction")) {
|
|
100
|
+
legend.setDirection(Legend.LegendDirection.valueOf(propMap.getString("direction").toUpperCase(Locale.ENGLISH)));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (BridgeUtils.validate(propMap, ReadableType.String, "fontFamily")) {
|
|
104
|
+
legend.setTypeface(TypefaceUtils.getTypeface(chart, propMap));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (BridgeUtils.validate(propMap, ReadableType.String, "form")) {
|
|
108
|
+
legend.setForm(LegendForm.valueOf(propMap.getString("form").toUpperCase(Locale.ENGLISH)));
|
|
109
|
+
}
|
|
110
|
+
if (BridgeUtils.validate(propMap, ReadableType.Number, "formSize")) {
|
|
111
|
+
legend.setFormSize((float) propMap.getDouble("formSize"));
|
|
112
|
+
}
|
|
113
|
+
if (BridgeUtils.validate(propMap, ReadableType.Number, "xEntrySpace")) {
|
|
114
|
+
legend.setXEntrySpace((float) propMap.getDouble("xEntrySpace"));
|
|
115
|
+
}
|
|
116
|
+
if (BridgeUtils.validate(propMap, ReadableType.Number, "yEntrySpace")) {
|
|
117
|
+
legend.setYEntrySpace((float) propMap.getDouble("yEntrySpace"));
|
|
118
|
+
}
|
|
119
|
+
if (BridgeUtils.validate(propMap, ReadableType.Number, "formToTextSpace")) {
|
|
120
|
+
legend.setFormToTextSpace((float) propMap.getDouble("formToTextSpace"));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Custom labels & colors
|
|
124
|
+
if (BridgeUtils.validate(propMap, ReadableType.Map, "custom")) {
|
|
125
|
+
ReadableMap customMap = propMap.getMap("custom");
|
|
126
|
+
if (BridgeUtils.validate(customMap, ReadableType.Array, "colors") &&
|
|
127
|
+
BridgeUtils.validate(customMap, ReadableType.Array, "labels")) {
|
|
128
|
+
|
|
129
|
+
ReadableArray colorsArray = customMap.getArray("colors");
|
|
130
|
+
ReadableArray labelsArray = customMap.getArray("labels");
|
|
131
|
+
|
|
132
|
+
if (colorsArray.size() == labelsArray.size()) {
|
|
133
|
+
// TODO null label should start a group
|
|
134
|
+
// TODO -2 color should avoid drawing a form
|
|
135
|
+
String[] labels = BridgeUtils.convertToStringArray(labelsArray);
|
|
136
|
+
int[] colorsParsed = BridgeUtils.convertToIntArray(colorsArray);
|
|
137
|
+
|
|
138
|
+
LegendEntry[] legendEntries = new LegendEntry[labels.length];
|
|
139
|
+
for (int i = 0; i < legendEntries.length; i++) {
|
|
140
|
+
legendEntries[i] = new LegendEntry();
|
|
141
|
+
legendEntries[i].formColor = colorsParsed[i];
|
|
142
|
+
legendEntries[i].label = labels[i];
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
legend.setCustom(legendEntries);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// TODO resetCustom function
|
|
151
|
+
// TODO extra
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
@ReactProp(name = "logEnabled")
|
|
155
|
+
public void setLogEnabled(Chart chart, boolean enabled) {
|
|
156
|
+
chart.setLogEnabled(enabled);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
@ReactProp(name = "chartBackgroundColor")
|
|
160
|
+
public void setChartBackgroundColor(Chart chart, Integer color) {
|
|
161
|
+
chart.setBackgroundColor(color);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
@ReactProp(name = "highlightPerTapEnabled")
|
|
165
|
+
public void setHighlightPerTapEnabled(Chart chart, boolean enabled) {
|
|
166
|
+
chart.setHighlightPerTapEnabled(enabled);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
@ReactProp(name = "chartDescription")
|
|
170
|
+
public void setChartDescription(Chart chart, ReadableMap propMap) {
|
|
171
|
+
|
|
172
|
+
Description description = new Description();
|
|
173
|
+
|
|
174
|
+
if (BridgeUtils.validate(propMap, ReadableType.String, "text")) {
|
|
175
|
+
description.setText(propMap.getString("text"));
|
|
176
|
+
}
|
|
177
|
+
if (BridgeUtils.validate(propMap, ReadableType.Number, "textColor")) {
|
|
178
|
+
description.setTextColor(propMap.getInt("textColor"));
|
|
179
|
+
}
|
|
180
|
+
if (BridgeUtils.validate(propMap, ReadableType.Number, "textSize")) {
|
|
181
|
+
description.setTextSize((float) propMap.getDouble("textSize"));
|
|
182
|
+
}
|
|
183
|
+
if (BridgeUtils.validate(propMap, ReadableType.Number, "positionX") &&
|
|
184
|
+
BridgeUtils.validate(propMap, ReadableType.Number, "positionY")) {
|
|
185
|
+
description.setPosition((float) propMap.getDouble("positionX"), (float) propMap.getDouble("positionY"));
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
chart.setDescription(description);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
@ReactProp(name = "noDataText")
|
|
192
|
+
public void setNoDataText(Chart chart, String noDataText) {
|
|
193
|
+
chart.setNoDataText(noDataText);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
@ReactProp(name = "noDataTextColor")
|
|
197
|
+
public void setNoDataTextColor(Chart chart, Integer color) {
|
|
198
|
+
chart.setNoDataTextColor(color);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
@ReactProp(name = "touchEnabled")
|
|
202
|
+
public void setTouchEnabled(Chart chart, boolean enabled) {
|
|
203
|
+
chart.setTouchEnabled(enabled);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
@ReactProp(name = "dragDecelerationEnabled")
|
|
207
|
+
public void setDragDecelerationEnabled(Chart chart, boolean enabled) {
|
|
208
|
+
chart.setDragDecelerationEnabled(enabled);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
@ReactProp(name = "dragDecelerationFrictionCoef")
|
|
212
|
+
public void setDragDecelerationFrictionCoef(Chart chart, float coef) {
|
|
213
|
+
chart.setDragDecelerationFrictionCoef(coef);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Animations docs: https://github.com/PhilJay/MPAndroidChart/wiki/Animations
|
|
218
|
+
*/
|
|
219
|
+
@ReactProp(name = "animation")
|
|
220
|
+
public void setAnimation(Chart chart, ReadableMap propMap) {
|
|
221
|
+
Integer durationX = null;
|
|
222
|
+
Integer durationY = null;
|
|
223
|
+
Easing.EasingFunction easingX = Easing.Linear;
|
|
224
|
+
Easing.EasingFunction easingY = Easing.Linear;
|
|
225
|
+
|
|
226
|
+
if (BridgeUtils.validate(propMap, ReadableType.Number, "durationX")) {
|
|
227
|
+
durationX = propMap.getInt("durationX");
|
|
228
|
+
}
|
|
229
|
+
if (BridgeUtils.validate(propMap, ReadableType.Number, "durationY")) {
|
|
230
|
+
durationY = propMap.getInt("durationY");
|
|
231
|
+
}
|
|
232
|
+
if (BridgeUtils.validate(propMap, ReadableType.String, "easingX")) {
|
|
233
|
+
easingX = EasingFunctionHelper.getEasingFunction(propMap.getString("easingX"));
|
|
234
|
+
}
|
|
235
|
+
if (BridgeUtils.validate(propMap, ReadableType.String, "easingY")) {
|
|
236
|
+
easingY = EasingFunctionHelper.getEasingFunction(propMap.getString("easingY"));
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
if (durationX != null && durationY != null) {
|
|
240
|
+
chart.animateXY(durationX, durationY, easingX, easingY);
|
|
241
|
+
} else if (durationX != null) {
|
|
242
|
+
chart.animateX(durationX, easingX);
|
|
243
|
+
} else if (durationY != null) {
|
|
244
|
+
chart.animateY(durationY, easingY);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* xAxis config details: https://github.com/PhilJay/MPAndroidChart/wiki/XAxis
|
|
250
|
+
*/
|
|
251
|
+
@ReactProp(name = "xAxis")
|
|
252
|
+
public void setXAxis(Chart chart, ReadableMap propMap) {
|
|
253
|
+
XAxis axis = chart.getXAxis();
|
|
254
|
+
|
|
255
|
+
setCommonAxisConfig(chart, axis, propMap);
|
|
256
|
+
|
|
257
|
+
if (BridgeUtils.validate(propMap, ReadableType.Number, "labelRotationAngle")) {
|
|
258
|
+
axis.setLabelRotationAngle((float) propMap.getDouble("labelRotationAngle"));
|
|
259
|
+
}
|
|
260
|
+
if (BridgeUtils.validate(propMap, ReadableType.Boolean, "avoidFirstLastClipping")) {
|
|
261
|
+
axis.setAvoidFirstLastClipping(propMap.getBoolean("avoidFirstLastClipping"));
|
|
262
|
+
}
|
|
263
|
+
if (BridgeUtils.validate(propMap, ReadableType.String, "position")) {
|
|
264
|
+
axis.setPosition(XAxisPosition.valueOf(propMap.getString("position")));
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
@ReactProp(name = "marker")
|
|
270
|
+
public void setMarker(Chart chart, ReadableMap propMap) {
|
|
271
|
+
if (!BridgeUtils.validate(propMap, ReadableType.Boolean, "enabled") || !propMap.getBoolean("enabled")) {
|
|
272
|
+
chart.setMarker(null);
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
String markerType = propMap.hasKey("markerType") ? propMap.getString("markerType") : "";
|
|
277
|
+
|
|
278
|
+
MarkerView markerView = null;
|
|
279
|
+
switch(markerType) {
|
|
280
|
+
case "circle":
|
|
281
|
+
markerView = circleMarker(chart);
|
|
282
|
+
|
|
283
|
+
break;
|
|
284
|
+
default:
|
|
285
|
+
markerView = rectangleMarker(chart, propMap);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
markerView.setChartView(chart);
|
|
289
|
+
chart.setMarker(markerView);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
private RNRectangleMarkerView rectangleMarker(Chart chart, ReadableMap propMap) {
|
|
293
|
+
RNRectangleMarkerView marker = new RNRectangleMarkerView(chart.getContext());
|
|
294
|
+
setMarkerParams(marker, propMap);
|
|
295
|
+
return marker;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
private RNCircleMarkerView circleMarker(Chart chart) {
|
|
299
|
+
return new RNCircleMarkerView(chart.getContext());
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
private void setMarkerParams(RNRectangleMarkerView marker, ReadableMap propMap) {
|
|
303
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP &&
|
|
304
|
+
BridgeUtils.validate(propMap, ReadableType.Number, "markerColor")) {
|
|
305
|
+
marker.getTvContent()
|
|
306
|
+
.setBackgroundTintList(
|
|
307
|
+
ColorStateList.valueOf(propMap.getInt("markerColor"))
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
if (BridgeUtils.validate(propMap, ReadableType.Number, "digits")) {
|
|
312
|
+
marker.setDigits(propMap.getInt("digits"));
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
if (BridgeUtils.validate(propMap, ReadableType.Number, "textColor")) {
|
|
316
|
+
marker.getTvContent().setTextColor(propMap.getInt("textColor"));
|
|
317
|
+
}
|
|
318
|
+
if (BridgeUtils.validate(propMap, ReadableType.Number, "textSize")) {
|
|
319
|
+
marker.getTvContent().setTextSize(propMap.getInt("textSize"));
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
if (BridgeUtils.validate(propMap, ReadableType.String, "textAlign")) {
|
|
323
|
+
|
|
324
|
+
int alignment = View.TEXT_ALIGNMENT_CENTER;
|
|
325
|
+
switch (propMap.getString("textAlign")) {
|
|
326
|
+
case "left":
|
|
327
|
+
alignment = View.TEXT_ALIGNMENT_TEXT_START;
|
|
328
|
+
break;
|
|
329
|
+
case "center":
|
|
330
|
+
alignment = View.TEXT_ALIGNMENT_CENTER;
|
|
331
|
+
break;
|
|
332
|
+
case "right":
|
|
333
|
+
alignment = View.TEXT_ALIGNMENT_TEXT_END;
|
|
334
|
+
break;
|
|
335
|
+
}
|
|
336
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
|
337
|
+
marker.getTvContent().setTextAlignment(alignment);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* General axis config details: https://github.com/PhilJay/MPAndroidChart/wiki/The-Axis
|
|
344
|
+
*/
|
|
345
|
+
protected void setCommonAxisConfig(Chart chart, AxisBase axis, ReadableMap propMap) {
|
|
346
|
+
// what is drawn
|
|
347
|
+
if (BridgeUtils.validate(propMap, ReadableType.Boolean, "enabled")) {
|
|
348
|
+
axis.setEnabled(propMap.getBoolean("enabled"));
|
|
349
|
+
}
|
|
350
|
+
if (BridgeUtils.validate(propMap, ReadableType.Boolean, "drawLabels")) {
|
|
351
|
+
axis.setDrawLabels(propMap.getBoolean("drawLabels"));
|
|
352
|
+
}
|
|
353
|
+
if (BridgeUtils.validate(propMap, ReadableType.Boolean, "drawAxisLine")) {
|
|
354
|
+
axis.setDrawAxisLine(propMap.getBoolean("drawAxisLine"));
|
|
355
|
+
}
|
|
356
|
+
if (BridgeUtils.validate(propMap, ReadableType.Boolean, "drawGridLines")) {
|
|
357
|
+
axis.setDrawGridLines(propMap.getBoolean("drawGridLines"));
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// style
|
|
361
|
+
if (BridgeUtils.validate(propMap, ReadableType.Number, "textColor")) {
|
|
362
|
+
axis.setTextColor(propMap.getInt("textColor"));
|
|
363
|
+
}
|
|
364
|
+
if (BridgeUtils.validate(propMap, ReadableType.Number, "textSize")) {
|
|
365
|
+
axis.setTextSize((float) propMap.getDouble("textSize"));
|
|
366
|
+
}
|
|
367
|
+
if (BridgeUtils.validate(propMap, ReadableType.String, "fontFamily")) {
|
|
368
|
+
axis.setTypeface(TypefaceUtils.getTypeface(chart, propMap));
|
|
369
|
+
}
|
|
370
|
+
if (BridgeUtils.validate(propMap, ReadableType.Number, "yOffset")) {
|
|
371
|
+
axis.setYOffset((float)(propMap.getDouble("yOffset")));
|
|
372
|
+
}
|
|
373
|
+
if (BridgeUtils.validate(propMap, ReadableType.Number, "gridColor")) {
|
|
374
|
+
axis.setGridColor(propMap.getInt("gridColor"));
|
|
375
|
+
}
|
|
376
|
+
if (BridgeUtils.validate(propMap, ReadableType.Number, "gridLineWidth")) {
|
|
377
|
+
axis.setGridLineWidth((float) propMap.getDouble("gridLineWidth"));
|
|
378
|
+
}
|
|
379
|
+
if (BridgeUtils.validate(propMap, ReadableType.Number, "axisLineColor")) {
|
|
380
|
+
axis.setAxisLineColor(propMap.getInt("axisLineColor"));
|
|
381
|
+
}
|
|
382
|
+
if (BridgeUtils.validate(propMap, ReadableType.Number, "axisLineWidth")) {
|
|
383
|
+
axis.setAxisLineWidth((float) propMap.getDouble("axisLineWidth"));
|
|
384
|
+
}
|
|
385
|
+
if (BridgeUtils.validate(propMap, ReadableType.Map, "gridDashedLine")) {
|
|
386
|
+
ReadableMap gridDashedLine = propMap.getMap("gridDashedLine");
|
|
387
|
+
float lineLength = 0;
|
|
388
|
+
float spaceLength = 0;
|
|
389
|
+
float phase = 0;
|
|
390
|
+
|
|
391
|
+
if (BridgeUtils.validate(gridDashedLine, ReadableType.Number, "lineLength")) {
|
|
392
|
+
lineLength = (float) gridDashedLine.getDouble("lineLength");
|
|
393
|
+
}
|
|
394
|
+
if (BridgeUtils.validate(gridDashedLine, ReadableType.Number, "spaceLength")) {
|
|
395
|
+
spaceLength = (float) gridDashedLine.getDouble("spaceLength");
|
|
396
|
+
}
|
|
397
|
+
if (BridgeUtils.validate(gridDashedLine, ReadableType.Number, "phase")) {
|
|
398
|
+
phase = (float) gridDashedLine.getDouble("phase");
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
axis.enableGridDashedLine(lineLength, spaceLength, phase);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
// limit lines
|
|
405
|
+
if (BridgeUtils.validate(propMap, ReadableType.Array, "limitLines")) {
|
|
406
|
+
ReadableArray limitLines = propMap.getArray("limitLines");
|
|
407
|
+
|
|
408
|
+
axis.removeAllLimitLines();
|
|
409
|
+
for (int i = 0; i < limitLines.size(); i++) {
|
|
410
|
+
if (!ReadableType.Map.equals(limitLines.getType(i))) {
|
|
411
|
+
continue;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
ReadableMap limitLineMap = limitLines.getMap(i);
|
|
415
|
+
if (BridgeUtils.validate(limitLineMap, ReadableType.Number, "limit")) {
|
|
416
|
+
LimitLine limitLine = new LimitLine((float) limitLineMap.getDouble("limit"));
|
|
417
|
+
|
|
418
|
+
if (BridgeUtils.validate(limitLineMap, ReadableType.String, "label")) {
|
|
419
|
+
limitLine.setLabel(limitLineMap.getString("label"));
|
|
420
|
+
}
|
|
421
|
+
if (BridgeUtils.validate(limitLineMap, ReadableType.Number, "lineColor")) {
|
|
422
|
+
limitLine.setLineColor(limitLineMap.getInt("lineColor"));
|
|
423
|
+
}
|
|
424
|
+
if (BridgeUtils.validate(limitLineMap, ReadableType.Number, "lineWidth")) {
|
|
425
|
+
limitLine.setLineWidth((float) limitLineMap.getDouble("lineWidth"));
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
if (BridgeUtils.validate(limitLineMap, ReadableType.Number, "valueTextColor")) {
|
|
429
|
+
limitLine.setTextColor(limitLineMap.getInt("valueTextColor"));
|
|
430
|
+
}
|
|
431
|
+
if (BridgeUtils.validate(limitLineMap, ReadableType.Number, "valueFont")) {
|
|
432
|
+
limitLine.setTextSize(limitLineMap.getInt("valueFont"));
|
|
433
|
+
}
|
|
434
|
+
if (BridgeUtils.validate(limitLineMap, ReadableType.String, "fontFamily")) {
|
|
435
|
+
limitLine.setTypeface(TypefaceUtils.getTypeface(chart, limitLineMap));
|
|
436
|
+
}
|
|
437
|
+
if (BridgeUtils.validate(limitLineMap, ReadableType.String, "labelPosition")) {
|
|
438
|
+
limitLine.setLabelPosition(LimitLine.LimitLabelPosition.valueOf(limitLineMap.getString("labelPosition")));
|
|
439
|
+
}
|
|
440
|
+
if (BridgeUtils.validate(limitLineMap, ReadableType.Number, "lineDashPhase")
|
|
441
|
+
&& BridgeUtils.validate(limitLineMap, ReadableType.Array, "lineDashLengths")) {
|
|
442
|
+
if (limitLineMap.getArray("lineDashLengths").size() > 1) {
|
|
443
|
+
float lineDashPhase = (float) limitLineMap.getDouble("lineDashPhase");
|
|
444
|
+
float lineLength = limitLineMap.getArray("lineDashLengths").getInt(0);
|
|
445
|
+
float spaceLength = limitLineMap.getArray("lineDashLengths").getInt(1);
|
|
446
|
+
limitLine.enableDashedLine(lineLength, spaceLength, lineDashPhase);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
axis.addLimitLine(limitLine);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
if (BridgeUtils.validate(propMap, ReadableType.Boolean, "drawLimitLinesBehindData")) {
|
|
456
|
+
axis.setDrawLimitLinesBehindData(propMap.getBoolean("drawLimitLinesBehindData"));
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
if (BridgeUtils.validate(propMap, ReadableType.Number, "axisMaximum")) {
|
|
460
|
+
axis.setAxisMaximum((float) propMap.getDouble("axisMaximum"));
|
|
461
|
+
}
|
|
462
|
+
if (BridgeUtils.validate(propMap, ReadableType.Number, "axisMinimum")) {
|
|
463
|
+
axis.setAxisMinimum((float) propMap.getDouble("axisMinimum"));
|
|
464
|
+
}
|
|
465
|
+
if (BridgeUtils.validate(propMap, ReadableType.Number, "granularity")) {
|
|
466
|
+
axis.setGranularity((float) propMap.getDouble("granularity"));
|
|
467
|
+
}
|
|
468
|
+
if (BridgeUtils.validate(propMap, ReadableType.Boolean, "granularityEnabled")) {
|
|
469
|
+
axis.setGranularityEnabled(propMap.getBoolean("granularityEnabled"));
|
|
470
|
+
}
|
|
471
|
+
if (BridgeUtils.validate(propMap, ReadableType.Number, "labelCount")) {
|
|
472
|
+
boolean labelCountForce = false;
|
|
473
|
+
if (BridgeUtils.validate(propMap, ReadableType.Boolean, "labelCountForce")) {
|
|
474
|
+
labelCountForce = propMap.getBoolean("labelCountForce");
|
|
475
|
+
}
|
|
476
|
+
axis.setLabelCount(propMap.getInt("labelCount"), labelCountForce);
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
// formatting
|
|
480
|
+
if (BridgeUtils.validate(propMap, ReadableType.String, "valueFormatter")) {
|
|
481
|
+
String valueFormatter = propMap.getString("valueFormatter");
|
|
482
|
+
|
|
483
|
+
if ("largeValue".equals(valueFormatter)) {
|
|
484
|
+
axis.setValueFormatter(new LargeValueFormatter());
|
|
485
|
+
} else if ("percent".equals(valueFormatter)) {
|
|
486
|
+
axis.setValueFormatter(new PercentFormatter());
|
|
487
|
+
} else if ("date".equals(valueFormatter)) {
|
|
488
|
+
String valueFormatterPattern = propMap.getString("valueFormatterPattern");
|
|
489
|
+
|
|
490
|
+
long since = 0;
|
|
491
|
+
if (BridgeUtils.validate(propMap, ReadableType.Number, "since")) {
|
|
492
|
+
since = (long) propMap.getDouble("since");
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
TimeUnit timeUnit = TimeUnit.MILLISECONDS;
|
|
496
|
+
|
|
497
|
+
if (BridgeUtils.validate(propMap, ReadableType.String, "timeUnit")) {
|
|
498
|
+
timeUnit = TimeUnit.valueOf(propMap.getString("timeUnit").toUpperCase());
|
|
499
|
+
}
|
|
500
|
+
Locale locale = Locale.getDefault();
|
|
501
|
+
|
|
502
|
+
if (BridgeUtils.validate(propMap, ReadableType.String, "locale")) {
|
|
503
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
504
|
+
locale = Locale.forLanguageTag(propMap.getString("locale"));
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
axis.setValueFormatter(new DateFormatter(valueFormatterPattern, since, timeUnit, locale));
|
|
509
|
+
} else {
|
|
510
|
+
axis.setValueFormatter(new CustomFormatter(valueFormatter));
|
|
511
|
+
}
|
|
512
|
+
} else if (BridgeUtils.validate(propMap, ReadableType.Array, "valueFormatter")) {
|
|
513
|
+
axis.setValueFormatter(new IndexAxisValueFormatter(BridgeUtils.convertToStringArray(propMap.getArray("valueFormatter"))));
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
if (BridgeUtils.validate(propMap, ReadableType.Boolean, "centerAxisLabels")) {
|
|
517
|
+
axis.setCenterAxisLabels(propMap.getBoolean("centerAxisLabels"));
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* Dataset config details: https://github.com/PhilJay/MPAndroidChart/wiki/DataSet-classes-in-detail
|
|
525
|
+
*/
|
|
526
|
+
@ReactProp(name = "data")
|
|
527
|
+
public void setData(T chart, ReadableMap propMap) {
|
|
528
|
+
chart.setData(getDataExtract().extract(chart, propMap));
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
@ReactProp(name = "highlights")
|
|
532
|
+
public void setHighlights(T chart, ReadableArray array) {
|
|
533
|
+
List<Highlight> highlights = new ArrayList<>();
|
|
534
|
+
|
|
535
|
+
for (int i = 0; i < array.size(); i++) {
|
|
536
|
+
if (!ReadableType.Map.equals(array.getType(i))) {
|
|
537
|
+
continue;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
ReadableMap highlightMap = array.getMap(i);
|
|
541
|
+
|
|
542
|
+
if (BridgeUtils.validate(highlightMap, ReadableType.Number, "x")) {
|
|
543
|
+
|
|
544
|
+
int dataSetIndex = BridgeUtils.validate(highlightMap, ReadableType.Number, "dataSetIndex") ? highlightMap.getInt("dataSetIndex") : 0;
|
|
545
|
+
|
|
546
|
+
float y = BridgeUtils.validate(highlightMap, ReadableType.Number, "y") ? (float) highlightMap.getDouble("y") : 0;
|
|
547
|
+
|
|
548
|
+
Highlight e = null;
|
|
549
|
+
if (BridgeUtils.validate(highlightMap, ReadableType.Number, "stackIndex")) {
|
|
550
|
+
e = new Highlight((float) highlightMap.getDouble("x"), dataSetIndex, highlightMap.getInt("stackIndex"));
|
|
551
|
+
} else {
|
|
552
|
+
e = new Highlight((float) highlightMap.getDouble("x"), y, dataSetIndex);
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
if (BridgeUtils.validate(highlightMap, ReadableType.Number, "dataIndex")) {
|
|
556
|
+
e.setDataIndex(highlightMap.getInt("dataIndex"));
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
highlights.add(e);
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
chart.highlightValues(highlights.toArray(new Highlight[highlights.size()]));
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
@ReactProp(name = "disallowInterceptTouch")
|
|
567
|
+
public void setDisallowInterceptTouch(Chart chart, boolean enabled) {
|
|
568
|
+
if (enabled) {
|
|
569
|
+
chart.setOnTouchListener(new View.OnTouchListener() {
|
|
570
|
+
@Override
|
|
571
|
+
public boolean onTouch(View v, MotionEvent event) {
|
|
572
|
+
switch (event.getAction()) {
|
|
573
|
+
case MotionEvent.ACTION_CANCEL:
|
|
574
|
+
case MotionEvent.ACTION_UP: {
|
|
575
|
+
v.getParent().requestDisallowInterceptTouchEvent(false);
|
|
576
|
+
break;
|
|
577
|
+
}
|
|
578
|
+
case MotionEvent.ACTION_DOWN: {
|
|
579
|
+
v.getParent().requestDisallowInterceptTouchEvent(true);
|
|
580
|
+
break;
|
|
581
|
+
}
|
|
582
|
+
case MotionEvent.ACTION_MOVE: {
|
|
583
|
+
v.getParent().requestDisallowInterceptTouchEvent(true);
|
|
584
|
+
break;
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
return false;
|
|
588
|
+
}
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
protected void onAfterDataSetChanged(T chart) {
|
|
594
|
+
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
@Override
|
|
598
|
+
protected void onAfterUpdateTransaction(T chart) {
|
|
599
|
+
super.onAfterUpdateTransaction(chart);
|
|
600
|
+
chart.notifyDataSetChanged();
|
|
601
|
+
onAfterDataSetChanged(chart);
|
|
602
|
+
chart.postInvalidate();;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
package com.github.wuxudong.rncharts.charts;
|
|
2
|
+
|
|
3
|
+
import com.github.mikephil.charting.charts.BarLineChartBase;
|
|
4
|
+
import com.github.mikephil.charting.components.YAxis;
|
|
5
|
+
import com.github.mikephil.charting.jobs.ZoomJob;
|
|
6
|
+
import com.github.mikephil.charting.utils.MPPointD;
|
|
7
|
+
import com.github.mikephil.charting.utils.MPPointF;
|
|
8
|
+
import com.github.mikephil.charting.utils.Transformer;
|
|
9
|
+
|
|
10
|
+
import java.lang.ref.WeakReference;
|
|
11
|
+
import java.util.HashMap;
|
|
12
|
+
import java.util.Map;
|
|
13
|
+
|
|
14
|
+
class ChartHolder {
|
|
15
|
+
public WeakReference<BarLineChartBase> chart;
|
|
16
|
+
public boolean syncX;
|
|
17
|
+
public boolean syncY;
|
|
18
|
+
|
|
19
|
+
public ChartHolder(WeakReference<BarLineChartBase> chart, boolean syncX, boolean syncY) {
|
|
20
|
+
this.chart = chart;
|
|
21
|
+
this.syncX = syncX;
|
|
22
|
+
this.syncY = syncY;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public class ChartGroupHolder {
|
|
27
|
+
|
|
28
|
+
private static Map<String, Map<String, ChartHolder>> chartGroups = new HashMap<>();
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
public static synchronized void addChart(String group, String identifier, BarLineChartBase chart, boolean syncX, boolean syncY) {
|
|
33
|
+
if (!chartGroups.containsKey(group)) {
|
|
34
|
+
chartGroups.put(group, new HashMap<String, ChartHolder>());
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
chartGroups.get(group).put(identifier, new ChartHolder(new WeakReference<>(chart), syncX, syncY));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public static synchronized void removeChart(String group, String identifier) {
|
|
41
|
+
if (chartGroups.containsKey(group)) {
|
|
42
|
+
chartGroups.get(group).remove(identifier);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// sync gesture to other chart in the same group
|
|
47
|
+
public static synchronized void sync(String group, String identifier, float scaleX, float scaleY, float centerX, float centerY) {
|
|
48
|
+
|
|
49
|
+
Map<String, ChartHolder> identifierMap = chartGroups.get(group);
|
|
50
|
+
if (identifierMap != null) {
|
|
51
|
+
for (Map.Entry<String, ChartHolder> entry : identifierMap.entrySet()) {
|
|
52
|
+
if (!entry.getKey().equals(identifier)) {
|
|
53
|
+
ChartHolder chartHolder = entry.getValue();
|
|
54
|
+
WeakReference<BarLineChartBase> reference = chartHolder.chart;
|
|
55
|
+
BarLineChartBase chart = reference.get();
|
|
56
|
+
if (chart != null) {
|
|
57
|
+
|
|
58
|
+
YAxis.AxisDependency axis = chart.getAxisLeft().isEnabled() ? YAxis.AxisDependency.LEFT : YAxis.AxisDependency.RIGHT;
|
|
59
|
+
Transformer transformer = chart.getTransformer(axis);
|
|
60
|
+
|
|
61
|
+
float zoomScaleX = scaleX / chart.getScaleX();
|
|
62
|
+
float zoomScaleY = scaleY / chart.getScaleY();
|
|
63
|
+
|
|
64
|
+
MPPointF originalCenter = chart.getCenter();
|
|
65
|
+
MPPointD originalCenterValue = chart.getValuesByTouchPoint(originalCenter.x, originalCenter.y, axis);
|
|
66
|
+
|
|
67
|
+
float finalScaleX = chartHolder.syncX ? zoomScaleX : 1;
|
|
68
|
+
float finalScaleY = chartHolder.syncY ? zoomScaleY : 1;
|
|
69
|
+
|
|
70
|
+
float finalCenterX = chartHolder.syncX ? centerX : (float) originalCenterValue.x;
|
|
71
|
+
float finalCenterY = chartHolder.syncY ? centerY : (float) originalCenterValue.y;
|
|
72
|
+
|
|
73
|
+
ZoomJob.getInstance(chart.getViewPortHandler(), finalScaleX, finalScaleY, finalCenterX, finalCenterY, transformer, axis, chart).run();
|
|
74
|
+
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|