Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Stats Refresh] Set empty chart bar height to chart height #11971

Merged
merged 1 commit into from
Jun 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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