Skip to content

Commit ef31c79

Browse files
committed
factor common stats display logic into StatsBreakdown
1 parent a13c869 commit ef31c79

18 files changed

+553
-467
lines changed

Assets/css/Main.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/css/Main.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/UnidocPages/Templates/Site.Docs.Culture.swift

Lines changed: 11 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -108,96 +108,24 @@ extension Site.Docs.Culture:ApplicationPage
108108
}
109109
content:
110110
{
111-
var breakdown:
112-
(
113-
unweighted:Pie<HTML.Stats.DeclPhylum>,
114-
weighted:Pie<HTML.Stats.DeclPhylum>
115-
) = ([], [])
116-
117-
for category:KeyPath<Record.Stats.Decl, Int> in
118-
[
119-
\.functions,
120-
\.operators,
121-
\.constructors,
122-
\.methods,
123-
\.subscripts,
124-
\.functors,
125-
\.protocols,
126-
\.requirements,
127-
\.witnesses,
128-
\.actors,
129-
\.classes,
130-
\.structures,
131-
\.typealiases,
132-
]
111+
$0[.div, { $0.class = "stats"}]
133112
{
134-
let unweighted:Int = self.master.census.unweighted.decls[keyPath: category]
135-
if unweighted > 0
136-
{
137-
breakdown.unweighted.values.append(.init(category,
138-
domain: "declarations in this module",
139-
weight: unweighted))
140-
}
141-
142-
let weighted:Int = self.master.census.weighted.decls[keyPath: category]
143-
if weighted > 0
144-
{
145-
breakdown.weighted.values.append(.init(category,
146-
domain: "symbols in this module",
147-
weight: weighted))
148-
}
149-
}
150-
151-
$0[.h2] = "Symbol Breakdown"
152-
153-
$0[.h3] = "Symbols"
154-
155-
$0 += breakdown.weighted
156-
157-
$0[.h3] = "Declarations"
113+
$0[.h2] = "Interface Breakdown"
158114

159-
$0 += breakdown.unweighted
115+
$0 += StatsBreakdown.init(
116+
unweighted: self.master.census.unweighted.decls,
117+
weighted: self.master.census.weighted.decls,
118+
domain: "this module").condensed
160119

161-
var coverage:
162-
(
163-
unweighted:Pie<HTML.Stats.Coverage>,
164-
weighted:Pie<HTML.Stats.Coverage>
165-
) = ([], [])
166120

167-
for category:KeyPath<Record.Stats.Coverage, Int> in
168-
[
169-
\.direct,
170-
\.indirect,
171-
\.undocumented,
172-
]
173-
{
174-
let unweighted:Int = self.master.census.unweighted.coverage[keyPath: category]
175-
if unweighted > 0
176-
{
177-
coverage.unweighted.values.append(.init(category,
178-
domain: "declarations in this module",
179-
weight: unweighted))
180-
}
121+
$0[.h2] = "Doc Coverage"
181122

182-
let weighted:Int = self.master.census.weighted.coverage[keyPath: category]
183-
if weighted > 0
184-
{
185-
coverage.weighted.values.append(.init(category,
186-
domain: "symbols in this module",
187-
weight: weighted))
188-
}
123+
$0 += StatsBreakdown.init(
124+
unweighted: self.master.census.unweighted.coverage,
125+
weighted: self.master.census.weighted.coverage,
126+
domain: "this module").condensed
189127
}
190128

191-
$0[.h2] = "Documentation Coverage"
192-
193-
$0[.h3] = "Symbols"
194-
195-
$0 += coverage.weighted
196-
197-
$0[.h3] = "Declarations"
198-
199-
$0 += coverage.unweighted
200-
201129
$0 ?= (self.master.details?.markdown).map(self.inliner.passage(_:))
202130
}
203131

Sources/UnidocPages/Templates/Site.Docs.Meta.swift

Lines changed: 9 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -156,95 +156,21 @@ extension Site.Docs.Meta:ApplicationPage
156156
}
157157
}
158158

159-
var breakdown:
160-
(
161-
unweighted:Pie<HTML.Stats.DeclPhylum>,
162-
weighted:Pie<HTML.Stats.DeclPhylum>
163-
) = ([], [])
159+
$0[.h2] = "Interface Breakdown"
164160

165-
for category:KeyPath<Record.Stats.Decl, Int> in
166-
[
167-
\.functions,
168-
\.operators,
169-
\.constructors,
170-
\.methods,
171-
\.subscripts,
172-
\.functors,
173-
\.protocols,
174-
\.requirements,
175-
\.witnesses,
176-
\.actors,
177-
\.classes,
178-
\.structures,
179-
\.typealiases,
180-
]
181-
{
182-
let unweighted:Int = self.master.census.unweighted.decls[keyPath: category]
183-
if unweighted > 0
184-
{
185-
breakdown.unweighted.values.append(.init(category,
186-
domain: "declarations in this package",
187-
weight: unweighted))
188-
}
189-
190-
let weighted:Int = self.master.census.weighted.decls[keyPath: category]
191-
if weighted > 0
192-
{
193-
breakdown.weighted.values.append(.init(category,
194-
domain: "symbols in this package",
195-
weight: weighted))
196-
}
197-
}
198-
199-
$0[.h2] = "Symbol Breakdown"
200-
201-
$0[.h3] = "Symbols"
202-
203-
$0 += breakdown.weighted
204-
205-
$0[.h3] = "Declarations"
161+
$0 += StatsBreakdown.init(
162+
unweighted: self.master.census.unweighted.decls,
163+
weighted: self.master.census.weighted.decls,
164+
domain: "this package")
206165

207-
$0 += breakdown.unweighted
208-
209-
var coverage:
210-
(
211-
unweighted:Pie<HTML.Stats.Coverage>,
212-
weighted:Pie<HTML.Stats.Coverage>
213-
) = ([], [])
214-
215-
for category:KeyPath<Record.Stats.Coverage, Int> in
216-
[
217-
\.direct,
218-
\.indirect,
219-
\.undocumented,
220-
]
221-
{
222-
let unweighted:Int = self.master.census.unweighted.coverage[keyPath: category]
223-
if unweighted > 0
224-
{
225-
coverage.unweighted.values.append(.init(category,
226-
domain: "declarations in this package",
227-
weight: unweighted))
228-
}
229-
230-
let weighted:Int = self.master.census.weighted.coverage[keyPath: category]
231-
if weighted > 0
232-
{
233-
coverage.weighted.values.append(.init(category,
234-
domain: "symbols in this package",
235-
weight: weighted))
236-
}
237-
}
238166

239167
$0[.h2] = "Documentation Coverage"
240168

241-
$0[.h3] = "Symbols"
242-
243-
$0 += coverage.weighted
244-
245-
$0[.h3] = "Declarations"
169+
$0 += StatsBreakdown.init(
170+
unweighted: self.master.census.unweighted.coverage,
171+
weighted: self.master.census.weighted.coverage,
172+
domain: "this package")
246173

247-
$0 += coverage.unweighted
248174

249175
$0[.h2] = "Snapshot Information"
250176

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
extension Site
2+
{
3+
@frozen public
4+
enum Stats
5+
{
6+
}
7+
}
8+
extension Site.Stats:FixedRoot
9+
{
10+
@inlinable public static
11+
var root:String { "stats" }
12+
}

Sources/UnidocPages/UI/Double (ext).swift

Lines changed: 0 additions & 11 deletions
This file was deleted.

Sources/UnidocPages/UI/HTML.Stats.Coverage.swift

Lines changed: 0 additions & 60 deletions
This file was deleted.

Sources/UnidocPages/UI/HTML.Stats.DeclPhylum.swift

Lines changed: 0 additions & 80 deletions
This file was deleted.

Sources/UnidocPages/UI/HTML.Stats.swift

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)