diff --git a/android/src/main/java/cn/mandata/react_native_mpchart/MPBarChartManager.java b/android/src/main/java/cn/mandata/react_native_mpchart/MPBarChartManager.java index 6882b02..bf43d64 100644 --- a/android/src/main/java/cn/mandata/react_native_mpchart/MPBarChartManager.java +++ b/android/src/main/java/cn/mandata/react_native_mpchart/MPBarChartManager.java @@ -84,6 +84,26 @@ public void setData(BarChart chart,ReadableMap rm){ } chart.setData(barData); - chart.invalidate(); + + /** + * Graph animation configurations + * If no animation config provided, call chart.invalidate() + * animation configs are maps with the following keys + * - duration or durationX/durationY in case of animateXY + * - support for easeFunction yet to be given + */ + if (rm.hasKey("animateX")) { + chart.animateX(rm.getMap("animateX").getInt("duration")); + } else if (rm.hasKey("animateY")) { + chart.animateY(rm.getMap("animateY").getInt("duration")); + } else if (rm.hasKey("animateXY")) { + ReadableMap animationConfig = rm.getMap("animateXY"); + chart.animateXY( + animationConfig.getInt("durationX"), + animationConfig.getInt("durationY") + ); + } else { + chart.invalidate(); + } } } diff --git a/android/src/main/java/cn/mandata/react_native_mpchart/MPLineChartManager.java b/android/src/main/java/cn/mandata/react_native_mpchart/MPLineChartManager.java index ee5ac24..5625e2d 100644 --- a/android/src/main/java/cn/mandata/react_native_mpchart/MPLineChartManager.java +++ b/android/src/main/java/cn/mandata/react_native_mpchart/MPLineChartManager.java @@ -119,6 +119,26 @@ public void setData(LineChart chart,ReadableMap rm){ chartData.addDataSet(dataSet); } chart.setData(chartData); - chart.invalidate(); + + /** + * Graph animation configurations + * If no animation config provided, call chart.invalidate() + * animation configs are maps with the following keys + * - duration or durationX/durationY in case of animateXY + * - support for easeFunction yet to be given + */ + if (rm.hasKey("animateX")) { + chart.animateX(rm.getMap("animateX").getInt("duration")); + } else if (rm.hasKey("animateY")) { + chart.animateY(rm.getMap("animateY").getInt("duration")); + } else if (rm.hasKey("animateXY")) { + ReadableMap animationConfig = rm.getMap("animateXY"); + chart.animateXY( + animationConfig.getInt("durationX"), + animationConfig.getInt("durationY") + ); + } else { + chart.invalidate(); + } } }