Skip to content

Commit

Permalink
Merge pull request #11971 from wordpress-mobile/feature/11876-empty_c…
Browse files Browse the repository at this point in the history
…hart_bar_height

[Stats Refresh] Set empty chart bar height to chart height
  • Loading branch information
ScoutHarris authored Jun 24, 2019
2 parents 3fb44df + 05076e9 commit b2b0181
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
3 changes: 2 additions & 1 deletion RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----
Expand Down
12 changes: 6 additions & 6 deletions WordPress/Classes/ViewRelated/Stats/Charts/PeriodChart.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

import Foundation

import Charts

// MARK: - StatsPeriodFilterDimension
Expand Down Expand Up @@ -84,17 +82,19 @@ 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

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)
Expand Down
4 changes: 1 addition & 3 deletions WordPress/Classes/ViewRelated/Stats/Charts/PostChart.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

import Foundation

import Charts

// MARK: - PostChartType
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

import UIKit

import Charts

// MARK: - StatsBarChartViewDelegate
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b2b0181

Please sign in to comment.