From 042380d156b3a3ae9de15ac19954749d3db57127 Mon Sep 17 00:00:00 2001 From: Stephenie Harris Date: Mon, 10 Jun 2019 15:40:45 -0600 Subject: [PATCH 01/10] Latest Post chart: show light grey bars if there is no data. --- .../ViewRelated/Stats/Charts/Charts+Support.swift | 2 +- .../ViewRelated/Stats/Charts/PostChart.swift | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Stats/Charts/Charts+Support.swift b/WordPress/Classes/ViewRelated/Stats/Charts/Charts+Support.swift index 41afc79b6942..f9d1a76ff514 100644 --- a/WordPress/Classes/ViewRelated/Stats/Charts/Charts+Support.swift +++ b/WordPress/Classes/ViewRelated/Stats/Charts/Charts+Support.swift @@ -18,7 +18,7 @@ extension BarChartDataSet { // MARK: - Charts protocols -/// Describes the visual appearance of a BarChartView. Implementation TBD. +/// Describes the visual appearance of a BarChartView. /// protocol BarChartStyling { diff --git a/WordPress/Classes/ViewRelated/Stats/Charts/PostChart.swift b/WordPress/Classes/ViewRelated/Stats/Charts/PostChart.swift index 15cd0cebc609..a35d9a405d3c 100644 --- a/WordPress/Classes/ViewRelated/Stats/Charts/PostChart.swift +++ b/WordPress/Classes/ViewRelated/Stats/Charts/PostChart.swift @@ -101,13 +101,16 @@ private final class PostChartDataTransformer { effectiveWidth = range / effectiveBars } + let totalViews = data.compactMap({$0.viewsCount}).reduce(0, +) + var entries = [BarChartDataEntry]() for datum in data { let dateInterval = datum.postDateTimeInterval ?? 0 let offset = dateInterval - firstDateInterval let x = offset - let y = Double(datum.viewsCount) + // If the chart has no data, show "stub" bars + let y = totalViews > 0 ? Double(datum.viewsCount) : 1.0 let entry = BarChartDataEntry(x: x, y: y) entries.append(entry) @@ -116,8 +119,13 @@ private final class PostChartDataTransformer { let chartData = BarChartData(entries: entries) chartData.barWidth = effectiveWidth + let primaryBarColor = totalViews > 0 ? WPStyleGuide.wordPressBlue() : WPStyleGuide.lightGrey() let xAxisFormatter: IAxisValueFormatter = HorizontalAxisFormatter(initialDateInterval: firstDateInterval) - let styling = PostChartStyling(primaryHighlightColor: type.highlightColor, xAxisValueFormatter: xAxisFormatter) + + let styling = PostChartStyling(primaryBarColor: primaryBarColor, + primaryHighlightColor: type.highlightColor, + xAxisValueFormatter: xAxisFormatter) + return (chartData, styling) } @@ -126,7 +134,7 @@ private final class PostChartDataTransformer { // MARK: - PostChartStyling private struct PostChartStyling: BarChartStyling { - let primaryBarColor: UIColor = WPStyleGuide.wordPressBlue() + let primaryBarColor: UIColor let secondaryBarColor: UIColor? = nil let primaryHighlightColor: UIColor? let secondaryHighlightColor: UIColor? = nil From 3fd1742b44a4f6a6efb5a136a18c6ceed17e6a7b Mon Sep 17 00:00:00 2001 From: Stephenie Harris Date: Mon, 10 Jun 2019 15:41:22 -0600 Subject: [PATCH 02/10] Overview chart: show grey bars if chart has no data. --- .../Stats/Charts/PeriodChart.swift | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Stats/Charts/PeriodChart.swift b/WordPress/Classes/ViewRelated/Stats/Charts/PeriodChart.swift index d969392f2749..9b06f67ef78f 100644 --- a/WordPress/Classes/ViewRelated/Stats/Charts/PeriodChart.swift +++ b/WordPress/Classes/ViewRelated/Stats/Charts/PeriodChart.swift @@ -75,6 +75,11 @@ private final class PeriodChartDataTransformer { effectiveWidth = range / effectiveBars } + let totalViews = data.compactMap({$0.viewsCount}).reduce(0, +) + let totalVisitors = data.compactMap({$0.visitorsCount}).reduce(0, +) + let totalLikes = data.compactMap({$0.likesCount}).reduce(0, +) + let totalComments = data.compactMap({$0.commentsCount}).reduce(0, +) + var viewEntries = [BarChartDataEntry]() var visitorEntries = [BarChartDataEntry]() var likeEntries = [BarChartDataEntry]() @@ -85,10 +90,11 @@ private final class PeriodChartDataTransformer { let x = offset - let viewEntry = BarChartDataEntry(x: x, y: Double(datum.viewsCount)) - let visitorEntry = BarChartDataEntry(x: x, y: Double(datum.visitorsCount)) - let likeEntry = BarChartDataEntry(x: x, y: Double(datum.likesCount)) - let commentEntry = BarChartDataEntry(x: x, y: Double(datum.commentsCount)) + // If the chart has no data, show "stub" bars + let viewEntry = BarChartDataEntry(x: x, y: totalViews > 0 ? Double(datum.viewsCount) : 1.0) + let visitorEntry = BarChartDataEntry(x: x, y: totalVisitors > 0 ? Double(datum.visitorsCount) : 1.0) + let likeEntry = BarChartDataEntry(x: x, y: totalLikes > 0 ? Double(datum.likesCount) : 1.0) + let commentEntry = BarChartDataEntry(x: x, y: totalComments > 0 ? Double(datum.commentsCount) : 1.0) viewEntries.append(viewEntry) visitorEntries.append(visitorEntry) @@ -130,10 +136,14 @@ private final class PeriodChartDataTransformer { let horizontalAxisFormatter = HorizontalAxisFormatter(initialDateInterval: firstDateInterval) let chartStyling: [BarChartStyling] = [ - ViewsPeriodChartStyling(xAxisValueFormatter: horizontalAxisFormatter), - DefaultPeriodChartStyling(xAxisValueFormatter: horizontalAxisFormatter), - DefaultPeriodChartStyling(xAxisValueFormatter: horizontalAxisFormatter), - DefaultPeriodChartStyling(xAxisValueFormatter: horizontalAxisFormatter), + ViewsPeriodChartStyling(primaryBarColor: (totalViews > 0 ? WPStyleGuide.wordPressBlue() : WPStyleGuide.lightGrey()), + xAxisValueFormatter: horizontalAxisFormatter), + DefaultPeriodChartStyling(primaryBarColor: (totalVisitors > 0 ? WPStyleGuide.wordPressBlue() : WPStyleGuide.lightGrey()), + xAxisValueFormatter: horizontalAxisFormatter), + DefaultPeriodChartStyling(primaryBarColor: (totalLikes > 0 ? WPStyleGuide.wordPressBlue() : WPStyleGuide.lightGrey()), + xAxisValueFormatter: horizontalAxisFormatter), + DefaultPeriodChartStyling(primaryBarColor: (totalComments > 0 ? WPStyleGuide.wordPressBlue() : WPStyleGuide.lightGrey()), + xAxisValueFormatter: horizontalAxisFormatter), ] return (barChartDataConvertibles, chartStyling) @@ -143,7 +153,7 @@ private final class PeriodChartDataTransformer { // MARK: - ViewsPeriodChartStyling private struct ViewsPeriodChartStyling: BarChartStyling { - let primaryBarColor: UIColor = WPStyleGuide.wordPressBlue() + let primaryBarColor: UIColor let secondaryBarColor: UIColor? = WPStyleGuide.darkBlue() let primaryHighlightColor: UIColor? = WPStyleGuide.jazzyOrange() let secondaryHighlightColor: UIColor? = WPStyleGuide.fireOrange() @@ -157,7 +167,7 @@ private struct ViewsPeriodChartStyling: BarChartStyling { // MARK: - DefaultPeriodChartStyling private struct DefaultPeriodChartStyling: BarChartStyling { - let primaryBarColor: UIColor = WPStyleGuide.wordPressBlue() + let primaryBarColor: UIColor let secondaryBarColor: UIColor? = nil let primaryHighlightColor: UIColor? = WPStyleGuide.jazzyOrange() let secondaryHighlightColor: UIColor? = nil From 38503d28fd46714714ea3bdb4a95b4a4120991c0 Mon Sep 17 00:00:00 2001 From: Stephenie Harris Date: Mon, 10 Jun 2019 16:12:21 -0600 Subject: [PATCH 03/10] Set Overview chart colors based on counts. --- .../Stats/Charts/PeriodChart.swift | 39 +++++++++++++++---- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Stats/Charts/PeriodChart.swift b/WordPress/Classes/ViewRelated/Stats/Charts/PeriodChart.swift index 9b06f67ef78f..ef807cb38cbb 100644 --- a/WordPress/Classes/ViewRelated/Stats/Charts/PeriodChart.swift +++ b/WordPress/Classes/ViewRelated/Stats/Charts/PeriodChart.swift @@ -136,27 +136,50 @@ private final class PeriodChartDataTransformer { let horizontalAxisFormatter = HorizontalAxisFormatter(initialDateInterval: firstDateInterval) let chartStyling: [BarChartStyling] = [ - ViewsPeriodChartStyling(primaryBarColor: (totalViews > 0 ? WPStyleGuide.wordPressBlue() : WPStyleGuide.lightGrey()), + ViewsPeriodChartStyling(primaryBarColor: primaryBarColor(forCount: totalViews), + secondaryBarColor: secondaryBarColor(forCount: totalViews), + primaryHighlightColor: primaryHighlightColor(forCount: totalViews), + secondaryHighlightColor: secondaryHighlightColor(forCount: totalViews), xAxisValueFormatter: horizontalAxisFormatter), - DefaultPeriodChartStyling(primaryBarColor: (totalVisitors > 0 ? WPStyleGuide.wordPressBlue() : WPStyleGuide.lightGrey()), + DefaultPeriodChartStyling(primaryBarColor: primaryBarColor(forCount: totalVisitors), + primaryHighlightColor: primaryHighlightColor(forCount: totalVisitors), xAxisValueFormatter: horizontalAxisFormatter), - DefaultPeriodChartStyling(primaryBarColor: (totalLikes > 0 ? WPStyleGuide.wordPressBlue() : WPStyleGuide.lightGrey()), + DefaultPeriodChartStyling(primaryBarColor: primaryBarColor(forCount: totalLikes), + primaryHighlightColor: primaryHighlightColor(forCount: totalLikes), xAxisValueFormatter: horizontalAxisFormatter), - DefaultPeriodChartStyling(primaryBarColor: (totalComments > 0 ? WPStyleGuide.wordPressBlue() : WPStyleGuide.lightGrey()), + DefaultPeriodChartStyling(primaryBarColor: primaryBarColor(forCount: totalComments), + primaryHighlightColor: primaryHighlightColor(forCount: totalComments), xAxisValueFormatter: horizontalAxisFormatter), ] return (barChartDataConvertibles, chartStyling) } + + static func primaryBarColor(forCount count: Int) -> UIColor { + return count > 0 ? WPStyleGuide.wordPressBlue() : WPStyleGuide.lightGrey() + } + + static func secondaryBarColor(forCount count: Int) -> UIColor { + return count > 0 ? WPStyleGuide.darkBlue() : WPStyleGuide.lightGrey() + } + + static func primaryHighlightColor(forCount count: Int) -> UIColor? { + return count > 0 ? WPStyleGuide.jazzyOrange() : nil + } + + static func secondaryHighlightColor(forCount count: Int) -> UIColor? { + return count > 0 ? WPStyleGuide.fireOrange() : nil + } + } // MARK: - ViewsPeriodChartStyling private struct ViewsPeriodChartStyling: BarChartStyling { let primaryBarColor: UIColor - let secondaryBarColor: UIColor? = WPStyleGuide.darkBlue() - let primaryHighlightColor: UIColor? = WPStyleGuide.jazzyOrange() - let secondaryHighlightColor: UIColor? = WPStyleGuide.fireOrange() + let secondaryBarColor: UIColor? + let primaryHighlightColor: UIColor? + let secondaryHighlightColor: UIColor? let labelColor: UIColor = WPStyleGuide.grey() let legendTitle: String? = NSLocalizedString("Visitors", comment: "This appears in the legend of the period chart; Visitors are superimposed over Views in that case.") let lineColor: UIColor = WPStyleGuide.greyLighten30() @@ -169,7 +192,7 @@ private struct ViewsPeriodChartStyling: BarChartStyling { private struct DefaultPeriodChartStyling: BarChartStyling { let primaryBarColor: UIColor let secondaryBarColor: UIColor? = nil - let primaryHighlightColor: UIColor? = WPStyleGuide.jazzyOrange() + let primaryHighlightColor: UIColor? let secondaryHighlightColor: UIColor? = nil let labelColor: UIColor = WPStyleGuide.grey() let legendTitle: String? = nil From 3237bc202e389816914c0fb9deff390ea503b3d1 Mon Sep 17 00:00:00 2001 From: Stephenie Harris Date: Mon, 10 Jun 2019 16:39:36 -0600 Subject: [PATCH 04/10] Don't show highlight bar on Post Stats if chart has no data. --- .../ViewRelated/Stats/Charts/PostChart.swift | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Stats/Charts/PostChart.swift b/WordPress/Classes/ViewRelated/Stats/Charts/PostChart.swift index a35d9a405d3c..a3bd132be54e 100644 --- a/WordPress/Classes/ViewRelated/Stats/Charts/PostChart.swift +++ b/WordPress/Classes/ViewRelated/Stats/Charts/PostChart.swift @@ -119,16 +119,22 @@ private final class PostChartDataTransformer { let chartData = BarChartData(entries: entries) chartData.barWidth = effectiveWidth - let primaryBarColor = totalViews > 0 ? WPStyleGuide.wordPressBlue() : WPStyleGuide.lightGrey() let xAxisFormatter: IAxisValueFormatter = HorizontalAxisFormatter(initialDateInterval: firstDateInterval) - - let styling = PostChartStyling(primaryBarColor: primaryBarColor, - primaryHighlightColor: type.highlightColor, + let styling = PostChartStyling(primaryBarColor: primaryBarColor(forCount: totalViews), + primaryHighlightColor: primaryHighlightColor(forType: type, withCount: totalViews), xAxisValueFormatter: xAxisFormatter) - return (chartData, styling) } + + static func primaryBarColor(forCount count: Int) -> UIColor { + return count > 0 ? WPStyleGuide.wordPressBlue() : WPStyleGuide.lightGrey() + } + + static func primaryHighlightColor(forType type: PostChartType, withCount count: Int) -> UIColor? { + return count > 0 ? type.highlightColor : nil + } + } // MARK: - PostChartStyling From c28772d4e26cc742f65b53667d350e5a593236f9 Mon Sep 17 00:00:00 2001 From: Stephenie Harris Date: Mon, 10 Jun 2019 17:09:01 -0600 Subject: [PATCH 05/10] Fix variable name after release/12.6 merge. --- .../Classes/ViewRelated/Stats/Charts/PeriodChart.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Stats/Charts/PeriodChart.swift b/WordPress/Classes/ViewRelated/Stats/Charts/PeriodChart.swift index a67f2a5392be..17ac85dbb7c2 100644 --- a/WordPress/Classes/ViewRelated/Stats/Charts/PeriodChart.swift +++ b/WordPress/Classes/ViewRelated/Stats/Charts/PeriodChart.swift @@ -75,10 +75,10 @@ private final class PeriodChartDataTransformer { effectiveWidth = range / effectiveBars } - let totalViews = data.compactMap({$0.viewsCount}).reduce(0, +) - let totalVisitors = data.compactMap({$0.visitorsCount}).reduce(0, +) - let totalLikes = data.compactMap({$0.likesCount}).reduce(0, +) - let totalComments = data.compactMap({$0.commentsCount}).reduce(0, +) + let totalViews = summaryData.compactMap({$0.viewsCount}).reduce(0, +) + let totalVisitors = summaryData.compactMap({$0.visitorsCount}).reduce(0, +) + let totalLikes = summaryData.compactMap({$0.likesCount}).reduce(0, +) + let totalComments = summaryData.compactMap({$0.commentsCount}).reduce(0, +) var viewEntries = [BarChartDataEntry]() var visitorEntries = [BarChartDataEntry]() From 817887d4d4dc789ab2cacf9aa6bf701ce443f857 Mon Sep 17 00:00:00 2001 From: Stephenie Harris Date: Mon, 10 Jun 2019 17:24:51 -0600 Subject: [PATCH 06/10] Adding legend color property so the legend and bar color can be set separately. --- .../Classes/ViewRelated/Stats/Charts/Charts+Support.swift | 3 +++ WordPress/Classes/ViewRelated/Stats/Charts/PeriodChart.swift | 2 ++ WordPress/Classes/ViewRelated/Stats/Charts/PostChart.swift | 1 + .../Classes/ViewRelated/Stats/Charts/StatsBarChartView.swift | 2 +- 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/WordPress/Classes/ViewRelated/Stats/Charts/Charts+Support.swift b/WordPress/Classes/ViewRelated/Stats/Charts/Charts+Support.swift index f9d1a76ff514..d70dc6a710b3 100644 --- a/WordPress/Classes/ViewRelated/Stats/Charts/Charts+Support.swift +++ b/WordPress/Classes/ViewRelated/Stats/Charts/Charts+Support.swift @@ -37,6 +37,9 @@ protocol BarChartStyling { /// This corresponds to the color of labels on the chart var labelColor: UIColor { get } + /// This corresponds to the legend color; currently only applicable when Views/Visitors overlaid. + var legendColor: UIColor? { get } + /// If specified, a legend will be presented with this value. It maps to the secondary bar color above. var legendTitle: String? { get } diff --git a/WordPress/Classes/ViewRelated/Stats/Charts/PeriodChart.swift b/WordPress/Classes/ViewRelated/Stats/Charts/PeriodChart.swift index 17ac85dbb7c2..c0dc66519783 100644 --- a/WordPress/Classes/ViewRelated/Stats/Charts/PeriodChart.swift +++ b/WordPress/Classes/ViewRelated/Stats/Charts/PeriodChart.swift @@ -181,6 +181,7 @@ private struct ViewsPeriodChartStyling: BarChartStyling { let primaryHighlightColor: UIColor? let secondaryHighlightColor: UIColor? let labelColor: UIColor = WPStyleGuide.grey() + let legendColor: UIColor? = WPStyleGuide.wordPressBlue() let legendTitle: String? = NSLocalizedString("Visitors", comment: "This appears in the legend of the period chart; Visitors are superimposed over Views in that case.") let lineColor: UIColor = WPStyleGuide.greyLighten30() let xAxisValueFormatter: IAxisValueFormatter @@ -195,6 +196,7 @@ private struct DefaultPeriodChartStyling: BarChartStyling { let primaryHighlightColor: UIColor? let secondaryHighlightColor: UIColor? = nil let labelColor: UIColor = WPStyleGuide.grey() + let legendColor: UIColor? = nil let legendTitle: String? = nil let lineColor: UIColor = WPStyleGuide.greyLighten30() let xAxisValueFormatter: IAxisValueFormatter diff --git a/WordPress/Classes/ViewRelated/Stats/Charts/PostChart.swift b/WordPress/Classes/ViewRelated/Stats/Charts/PostChart.swift index a3bd132be54e..0aaa34a7ee1d 100644 --- a/WordPress/Classes/ViewRelated/Stats/Charts/PostChart.swift +++ b/WordPress/Classes/ViewRelated/Stats/Charts/PostChart.swift @@ -145,6 +145,7 @@ private struct PostChartStyling: BarChartStyling { let primaryHighlightColor: UIColor? let secondaryHighlightColor: UIColor? = nil let labelColor: UIColor = WPStyleGuide.grey() + let legendColor: UIColor? = nil let legendTitle: String? = nil let lineColor: UIColor = WPStyleGuide.greyLighten30() let xAxisValueFormatter: IAxisValueFormatter diff --git a/WordPress/Classes/ViewRelated/Stats/Charts/StatsBarChartView.swift b/WordPress/Classes/ViewRelated/Stats/Charts/StatsBarChartView.swift index 1c8e2eade65f..62a91fbe919d 100644 --- a/WordPress/Classes/ViewRelated/Stats/Charts/StatsBarChartView.swift +++ b/WordPress/Classes/ViewRelated/Stats/Charts/StatsBarChartView.swift @@ -263,7 +263,7 @@ private extension StatsBarChartView { func configureLegendIfNeeded() { legend.enabled = false - guard let legendColor = styling.secondaryBarColor, let legendTitle = styling.legendTitle, legendView == nil else { + guard let legendColor = styling.legendColor, let legendTitle = styling.legendTitle, legendView == nil else { return } From d6fec1ba0c71f782e86848383b6d1401c4ebf0ff Mon Sep 17 00:00:00 2001 From: Stephenie Harris Date: Mon, 10 Jun 2019 17:26:59 -0600 Subject: [PATCH 07/10] Toggle bar highlight for multiple data set charts. --- .../Classes/ViewRelated/Stats/Charts/PeriodChart.swift | 4 ++-- .../ViewRelated/Stats/Charts/StatsBarChartView.swift | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Stats/Charts/PeriodChart.swift b/WordPress/Classes/ViewRelated/Stats/Charts/PeriodChart.swift index c0dc66519783..456beb969ca8 100644 --- a/WordPress/Classes/ViewRelated/Stats/Charts/PeriodChart.swift +++ b/WordPress/Classes/ViewRelated/Stats/Charts/PeriodChart.swift @@ -137,9 +137,9 @@ private final class PeriodChartDataTransformer { let horizontalAxisFormatter = HorizontalAxisFormatter(initialDateInterval: firstDateInterval, period: data.period) let chartStyling: [BarChartStyling] = [ ViewsPeriodChartStyling(primaryBarColor: primaryBarColor(forCount: totalViews), - secondaryBarColor: secondaryBarColor(forCount: totalViews), + secondaryBarColor: secondaryBarColor(forCount: totalVisitors), primaryHighlightColor: primaryHighlightColor(forCount: totalViews), - secondaryHighlightColor: secondaryHighlightColor(forCount: totalViews), + secondaryHighlightColor: secondaryHighlightColor(forCount: totalVisitors), xAxisValueFormatter: horizontalAxisFormatter), DefaultPeriodChartStyling(primaryBarColor: primaryBarColor(forCount: totalVisitors), primaryHighlightColor: primaryHighlightColor(forCount: totalVisitors), diff --git a/WordPress/Classes/ViewRelated/Stats/Charts/StatsBarChartView.swift b/WordPress/Classes/ViewRelated/Stats/Charts/StatsBarChartView.swift index 62a91fbe919d..bedeed15c53d 100644 --- a/WordPress/Classes/ViewRelated/Stats/Charts/StatsBarChartView.swift +++ b/WordPress/Classes/ViewRelated/Stats/Charts/StatsBarChartView.swift @@ -221,9 +221,13 @@ private extension StatsBarChartView { primaryDataSet.colors = [ styling.primaryBarColor ] primaryDataSet.drawValuesEnabled = false - primaryDataSet.highlightAlpha = Constants.highlightAlpha if let initialHighlightColor = styling.primaryHighlightColor { + primaryDataSet.highlightAlpha = Constants.highlightAlpha primaryDataSet.highlightColor = initialHighlightColor + primaryDataSet.highlightEnabled = true + } else { + primaryDataSet.highlightEnabled = false + highlightPerTapEnabled = false } // Secondary From 3e01f368c1017b5371eff7e799e8ab33b6cafbac Mon Sep 17 00:00:00 2001 From: Stephenie Harris Date: Mon, 10 Jun 2019 18:25:18 -0600 Subject: [PATCH 08/10] Persist to core data after Likes Summary received since it typically comes in well after the other summary data. --- WordPress/Classes/Stores/StatsPeriodStore.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/WordPress/Classes/Stores/StatsPeriodStore.swift b/WordPress/Classes/Stores/StatsPeriodStore.swift index 4a17b1c049e0..9563066a0d90 100644 --- a/WordPress/Classes/Stores/StatsPeriodStore.swift +++ b/WordPress/Classes/Stores/StatsPeriodStore.swift @@ -764,6 +764,7 @@ private extension StatsPeriodStore { state.summary = newSummary } + persistToCoreData() } func receivedPostsAndPages(_ postsAndPages: StatsTopPostsTimeIntervalData?, _ error: Error?) { From c4652d7d980dcf70862cf8577b0c446b2f7d807d Mon Sep 17 00:00:00 2001 From: Stephenie Harris Date: Mon, 10 Jun 2019 18:26:32 -0600 Subject: [PATCH 09/10] Update the current chart data if it's been updated. Fixes an issue where Likes was not updated after the query finished. --- .../Stats/Period Stats/SiteStatsPeriodViewModel.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/WordPress/Classes/ViewRelated/Stats/Period Stats/SiteStatsPeriodViewModel.swift b/WordPress/Classes/ViewRelated/Stats/Period Stats/SiteStatsPeriodViewModel.swift index 8febd512a3f1..6120de6cf47f 100644 --- a/WordPress/Classes/ViewRelated/Stats/Period Stats/SiteStatsPeriodViewModel.swift +++ b/WordPress/Classes/ViewRelated/Stats/Period Stats/SiteStatsPeriodViewModel.swift @@ -118,6 +118,10 @@ private extension SiteStatsPeriodViewModel { if mostRecentChartData == nil { mostRecentChartData = periodSummary + } else if let mostRecentChartData = mostRecentChartData, + let periodSummary = periodSummary, + mostRecentChartData.periodEndDate == periodSummary.periodEndDate { + self.mostRecentChartData = periodSummary } else if let periodSummary = periodSummary, let chartData = mostRecentChartData, periodSummary.periodEndDate > chartData.periodEndDate { mostRecentChartData = chartData } From dad0b67f6208908bdf97eadafc671e36288460da Mon Sep 17 00:00:00 2001 From: Stephenie Harris Date: Mon, 10 Jun 2019 18:39:29 -0600 Subject: [PATCH 10/10] Removing this call to persistToCoreData. I don't believe it's necessary. --- WordPress/Classes/Stores/StatsPeriodStore.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/WordPress/Classes/Stores/StatsPeriodStore.swift b/WordPress/Classes/Stores/StatsPeriodStore.swift index 9563066a0d90..4a17b1c049e0 100644 --- a/WordPress/Classes/Stores/StatsPeriodStore.swift +++ b/WordPress/Classes/Stores/StatsPeriodStore.swift @@ -764,7 +764,6 @@ private extension StatsPeriodStore { state.summary = newSummary } - persistToCoreData() } func receivedPostsAndPages(_ postsAndPages: StatsTopPostsTimeIntervalData?, _ error: Error?) {