Skip to content

Commit

Permalink
Remove abbreviation from the percentage string
Browse files Browse the repository at this point in the history
  • Loading branch information
staskus committed Apr 3, 2024
1 parent 1cbd4c8 commit d8bdb39
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 19 deletions.
20 changes: 8 additions & 12 deletions WordPress/Classes/ViewRelated/Stats/Extensions/Double+Stats.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,8 @@ extension Double {
return formattedString
}

func abbreviatedPercentageString(forHeroNumber: Bool = false) -> String {
guard let numberWithPercentage = NumberFormatter.statsPercentage.string(from: .init(value: self)) else {
return abbreviatedString(forHeroNumber: forHeroNumber)
}

return numberWithPercentage.replacingOccurrences(of: "\(self)", with: self.abbreviatedString(forHeroNumber: forHeroNumber))
func percentageString() -> String {
return NumberFormatter.statsPercentage.string(from: .init(value: self))!
}

private func formatWithCommas() -> String {
Expand All @@ -166,8 +162,8 @@ extension NSNumber {
return self.doubleValue.abbreviatedString(forHeroNumber: forHeroNumber)
}

func abbreviatedPercentageString(forHeroNumber: Bool = false) -> String {
return self.doubleValue.abbreviatedPercentageString(forHeroNumber: forHeroNumber)
func percentageString() -> String {
return self.doubleValue.percentageString()
}
}

Expand All @@ -176,8 +172,8 @@ extension Float {
return Double(self).abbreviatedString(forHeroNumber: forHeroNumber)
}

func abbreviatedPercentageString(forHeroNumber: Bool = false) -> String {
return Double(self).abbreviatedPercentageString(forHeroNumber: forHeroNumber)
func percentageString(forHeroNumber: Bool = false) -> String {
return Double(self).percentageString()
}
}

Expand All @@ -186,7 +182,7 @@ extension Int {
return Double(self).abbreviatedString(forHeroNumber: forHeroNumber)
}

func abbreviatedPercentageString(forHeroNumber: Bool = false) -> String {
return Double(self).abbreviatedPercentageString(forHeroNumber: forHeroNumber)
func percentageString(forHeroNumber: Bool = false) -> String {
return Double(self).percentageString()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,8 @@ private extension SiteStatsInsightsViewModel {
return nil
}

let dayPercentage = String(format: MostPopularStats.viewPercentage, mostPopularStats.mostPopularDayOfWeekPercentage.abbreviatedPercentageString())
let hourPercentage = String(format: MostPopularStats.viewPercentage, mostPopularStats.mostPopularHourPercentage.abbreviatedPercentageString())
let dayPercentage = String(format: MostPopularStats.viewPercentage, mostPopularStats.mostPopularDayOfWeekPercentage.percentageString())
let hourPercentage = String(format: MostPopularStats.viewPercentage, mostPopularStats.mostPopularHourPercentage.percentageString())

return StatsMostPopularTimeData(mostPopularDayTitle: MostPopularStats.bestDay, mostPopularTimeTitle: MostPopularStats.bestHour, mostPopularDay: dayString, mostPopularTime: timeString.uppercased(), dayPercentage: dayPercentage, timePercentage: hourPercentage)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,9 @@ class StatsTotalInsightsCell: StatsBaseCell {

let differenceText: String = {
if difference > 0 {
return String(format: TextContent.differenceHigher, differencePrefix, difference.abbreviatedString(), percentage.abbreviatedPercentageString())
return String(format: TextContent.differenceHigher, differencePrefix, difference.abbreviatedString(), percentage.percentageString())
} else if difference < 0 {
return String(format: TextContent.differenceLower, differencePrefix, difference.abbreviatedString(), percentage.abbreviatedPercentageString())
return String(format: TextContent.differenceLower, differencePrefix, difference.abbreviatedString(), percentage.percentageString())
} else {
return TextContent.differenceSame
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ final class ViewsVisitorsChartMarker: MarkerView {
.paragraphStyle: paragraphStyle,
.foregroundColor: UIColor.white]

let topRowStr = NSMutableAttributedString(string: "\(differenceStr) (\(roundedPercentage.abbreviatedPercentageString()))\n", attributes: topRowAttributes)
let topRowStr = NSMutableAttributedString(string: "\(differenceStr) (\(roundedPercentage.percentageString()))\n", attributes: topRowAttributes)
let bottomRowStr = NSAttributedString(string: "\(yValue) \(name)", attributes: bottomRowAttributes)

topRowStr.append(bottomRowStr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ struct StatsSegmentedControlData {
stringFormat,
plusSign,
difference.abbreviatedString(),
differencePercent.abbreviatedPercentageString()
differencePercent.percentageString()
)
} else {
let stringFormat = NSLocalizedString(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct OverviewTabData: FilterTabBarItem, Hashable {
return String.localizedStringWithFormat(stringFormat,
difference < 0 ? "" : "+",
difference.abbreviatedString(),
differencePercent.abbreviatedPercentageString())
differencePercent.percentageString())
}

var differenceTextColor: UIColor {
Expand Down

0 comments on commit d8bdb39

Please sign in to comment.