From 05076e973f59af11c4eac4a6d0d57c2e75acbd44 Mon Sep 17 00:00:00 2001 From: Stephenie Harris Date: Fri, 21 Jun 2019 17:04:38 -0600 Subject: [PATCH] Set height of bars in empty charts to empty chart height. --- RELEASE-NOTES.txt | 3 ++- .../ViewRelated/Stats/Charts/PeriodChart.swift | 12 ++++++------ .../Classes/ViewRelated/Stats/Charts/PostChart.swift | 4 +--- .../ViewRelated/Stats/Charts/StatsBarChartView.swift | 7 +++++-- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index 4d91b6e11097..b29dd1109708 100644 --- a/RELEASE-NOTES.txt +++ b/RELEASE-NOTES.txt @@ -6,7 +6,8 @@ * Stats Insights: New two-column layout for This Year stats. * Stats Insights: added details option for This Year stats. * Stats Insights: New two-column layout for Most Popular Time stats. -* Post preview: Fixed issue with preview for self hosted sites not working. +* Post preview: Fixed issue with preview for self hosted sites not working. +* Stats: modified appearance of empty charts. 12.7 ----- diff --git a/WordPress/Classes/ViewRelated/Stats/Charts/PeriodChart.swift b/WordPress/Classes/ViewRelated/Stats/Charts/PeriodChart.swift index 456beb969ca8..05dc271f6fb3 100644 --- a/WordPress/Classes/ViewRelated/Stats/Charts/PeriodChart.swift +++ b/WordPress/Classes/ViewRelated/Stats/Charts/PeriodChart.swift @@ -1,6 +1,4 @@ - import Foundation - import Charts // MARK: - StatsPeriodFilterDimension @@ -84,6 +82,7 @@ private final class PeriodChartDataTransformer { var visitorEntries = [BarChartDataEntry]() var likeEntries = [BarChartDataEntry]() var commentEntries = [BarChartDataEntry]() + for datum in summaryData { let dateInterval = datum.periodStartDate.timeIntervalSince1970 let offset = dateInterval - firstDateInterval @@ -91,10 +90,11 @@ private final class PeriodChartDataTransformer { let x = offset // 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) + let emptyChartBarHeight = StatsBarChartView.emptyChartBarHeight + let viewEntry = BarChartDataEntry(x: x, y: totalViews > 0 ? Double(datum.viewsCount) : emptyChartBarHeight) + let visitorEntry = BarChartDataEntry(x: x, y: totalVisitors > 0 ? Double(datum.visitorsCount) : emptyChartBarHeight) + let likeEntry = BarChartDataEntry(x: x, y: totalLikes > 0 ? Double(datum.likesCount) : emptyChartBarHeight) + let commentEntry = BarChartDataEntry(x: x, y: totalComments > 0 ? Double(datum.commentsCount) : emptyChartBarHeight) viewEntries.append(viewEntry) visitorEntries.append(visitorEntry) diff --git a/WordPress/Classes/ViewRelated/Stats/Charts/PostChart.swift b/WordPress/Classes/ViewRelated/Stats/Charts/PostChart.swift index 0aaa34a7ee1d..a1e9efd7df3f 100644 --- a/WordPress/Classes/ViewRelated/Stats/Charts/PostChart.swift +++ b/WordPress/Classes/ViewRelated/Stats/Charts/PostChart.swift @@ -1,6 +1,4 @@ - import Foundation - import Charts // MARK: - PostChartType @@ -110,7 +108,7 @@ private final class PostChartDataTransformer { let x = offset // If the chart has no data, show "stub" bars - let y = totalViews > 0 ? Double(datum.viewsCount) : 1.0 + let y = totalViews > 0 ? Double(datum.viewsCount) : StatsBarChartView.emptyChartBarHeight let entry = BarChartDataEntry(x: x, y: y) entries.append(entry) diff --git a/WordPress/Classes/ViewRelated/Stats/Charts/StatsBarChartView.swift b/WordPress/Classes/ViewRelated/Stats/Charts/StatsBarChartView.swift index bedeed15c53d..3ba5df52e77b 100644 --- a/WordPress/Classes/ViewRelated/Stats/Charts/StatsBarChartView.swift +++ b/WordPress/Classes/ViewRelated/Stats/Charts/StatsBarChartView.swift @@ -1,6 +1,4 @@ - import UIKit - import Charts // MARK: - StatsBarChartViewDelegate @@ -32,6 +30,11 @@ class StatsBarChartView: BarChartView { static let verticalAxisLabelCount = 5 } + /// Height for "stub" bars when a chart is empty, which is the height of the default chart. + /// The value is just shy of the default height to prevent the chart height from automatically expanding. + /// + static let emptyChartBarHeight = Double(Constants.verticalAxisLabelCount - 1) - 0.01 + /// This adapts the data set for presentation by the Charts framework. /// private let barChartData: BarChartDataConvertible