From 6a86ea9e6a74240ab975581016b8ccc335cd7a6f Mon Sep 17 00:00:00 2001 From: Prithvi Sharma Date: Sat, 25 Jun 2016 20:39:59 +0530 Subject: [PATCH 1/3] Add support for animations in line charts --- .../MPLineChartManager.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) 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 7e1d3ac..66b05d2 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 @@ -106,6 +106,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 (config.hasKey("animateX")) { + chart.animateX(config.getMap(animateX).getInt(duration)); + } else if (config.hasKey("animateY")) { + chart.animateY(config.getMap(animateY).getInt(duration)); + } else if (config.hasKey("animateXY")) { + ReadableMap animationConfig = config.getMap(animateXY); + chart.animateXY( + animationConfig.getInt(durationX), + animationConfig.getInt(durationY) + ); + } else { + chart.invalidate(); + } } } From d03122d1c6d733c0cc0d9082a58f2df3d15d2cc8 Mon Sep 17 00:00:00 2001 From: Prithvi Sharma Date: Sat, 25 Jun 2016 20:42:02 +0530 Subject: [PATCH 2/3] Add support for animations in bar charts too --- .../MPBarChartManager.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) 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 63d6174..feee099 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 @@ -80,6 +80,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 (config.hasKey("animateX")) { + chart.animateX(config.getMap(animateX).getInt(duration)); + } else if (config.hasKey("animateY")) { + chart.animateY(config.getMap(animateY).getInt(duration)); + } else if (config.hasKey("animateXY")) { + ReadableMap animationConfig = config.getMap(animateXY); + chart.animateXY( + animationConfig.getInt(durationX), + animationConfig.getInt(durationY) + ); + } else { + chart.invalidate(); + } } } From f71d38fe73025c71cb6878d71f56ba440005c5fa Mon Sep 17 00:00:00 2001 From: Prithvi Sharma Date: Sat, 25 Jun 2016 21:13:01 +0530 Subject: [PATCH 3/3] Minor bugfixes --- .../react_native_mpchart/MPBarChartManager.java | 16 ++++++++-------- .../react_native_mpchart/MPLineChartManager.java | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) 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 feee099..21c7a6d 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 @@ -88,15 +88,15 @@ public void setData(BarChart chart,ReadableMap rm){ * - duration or durationX/durationY in case of animateXY * - support for easeFunction yet to be given */ - if (config.hasKey("animateX")) { - chart.animateX(config.getMap(animateX).getInt(duration)); - } else if (config.hasKey("animateY")) { - chart.animateY(config.getMap(animateY).getInt(duration)); - } else if (config.hasKey("animateXY")) { - ReadableMap animationConfig = config.getMap(animateXY); + 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) + 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 66b05d2..bfb78ff 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 @@ -114,15 +114,15 @@ public void setData(LineChart chart,ReadableMap rm){ * - duration or durationX/durationY in case of animateXY * - support for easeFunction yet to be given */ - if (config.hasKey("animateX")) { - chart.animateX(config.getMap(animateX).getInt(duration)); - } else if (config.hasKey("animateY")) { - chart.animateY(config.getMap(animateY).getInt(duration)); - } else if (config.hasKey("animateXY")) { - ReadableMap animationConfig = config.getMap(animateXY); + 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) + animationConfig.getInt("durationX"), + animationConfig.getInt("durationY") ); } else { chart.invalidate();