forked from MapComplete/MapComplete
Improve statistics page
This commit is contained in:
parent
d04132d42c
commit
6200b420b3
6 changed files with 161 additions and 198 deletions
|
|
@ -18,6 +18,8 @@ export class StackedRenderingChart extends ChartJs {
|
|||
options?: {
|
||||
period: "day" | "month"
|
||||
groupToOtherCutoff?: 3 | number
|
||||
// If given, take the sum of these fields to get the feature weight
|
||||
sumFields?: string[]
|
||||
}
|
||||
) {
|
||||
const { labels, data } = TagRenderingChart.extractDataAndLabels(tr, features, {
|
||||
|
|
@ -78,7 +80,30 @@ export class StackedRenderingChart extends ChartJs {
|
|||
const countsPerDay: number[] = []
|
||||
for (let i = 0; i < trimmedDays.length; i++) {
|
||||
const day = trimmedDays[i]
|
||||
countsPerDay[i] = perDay[day]?.length ?? 0
|
||||
|
||||
const featuresForDay = perDay[day]
|
||||
if (!featuresForDay) {
|
||||
continue
|
||||
}
|
||||
if (options.sumFields !== undefined) {
|
||||
let sum = 0
|
||||
for (const featuresForDayElement of featuresForDay) {
|
||||
const props = featuresForDayElement.properties
|
||||
for (const key of options.sumFields) {
|
||||
if (!props[key]) {
|
||||
continue
|
||||
}
|
||||
const v = Number(props[key])
|
||||
if (isNaN(v)) {
|
||||
continue
|
||||
}
|
||||
sum += v
|
||||
}
|
||||
}
|
||||
countsPerDay[i] = sum
|
||||
} else {
|
||||
countsPerDay[i] = featuresForDay?.length ?? 0
|
||||
}
|
||||
}
|
||||
let backgroundColor =
|
||||
TagRenderingChart.borderColors[i % TagRenderingChart.borderColors.length]
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@
|
|||
let tags = state.featureProperties.getStore(properties.id) ?? new ImmutableStore(properties);
|
||||
|
||||
const favLayer = state.layerState.filteredLayers.get("favourite");
|
||||
const favConfig = favLayer.layerDef;
|
||||
const titleConfig = favConfig.title;
|
||||
const favConfig = favLayer?.layerDef;
|
||||
const titleConfig = favConfig?.title;
|
||||
|
||||
function center() {
|
||||
const [lon, lat] = GeoOperations.centerpointCoordinates(feature);
|
||||
|
|
@ -50,6 +50,7 @@
|
|||
|
||||
</script>
|
||||
|
||||
{#if favLayer !== undefined}
|
||||
<div class="px-1 my-1 border-2 border-dashed border-gray-300 rounded grid grid-cols-2 items-center no-weblate">
|
||||
<button class="cursor-pointer ml-1 m-0 link justify-self-start" on:click={() => select()}>
|
||||
<TagRenderingAnswer config={titleConfig} extraClasses="underline" layer={favConfig} selectedElement={feature}
|
||||
|
|
@ -81,3 +82,4 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import { VariableUiElement } from "./Base/VariableUIElement"
|
|||
import Loading from "./Base/Loading"
|
||||
import { Utils } from "../Utils"
|
||||
import Combine from "./Base/Combine"
|
||||
import { StackedRenderingChart } from "./BigComponents/TagRenderingChart"
|
||||
import TagRenderingChart, { StackedRenderingChart } from "./BigComponents/TagRenderingChart"
|
||||
import BaseUIElement from "./BaseUIElement"
|
||||
import Title from "./Base/Title"
|
||||
import { FixedUiElement } from "./Base/FixedUiElement"
|
||||
|
|
@ -150,11 +150,29 @@ class StatsticsForOverviewFile extends Combine {
|
|||
new Combine([
|
||||
new Title(tr.question ?? tr.id).SetClass("p-2"),
|
||||
total > 1 ? total + " unique value" : undefined,
|
||||
new Title("By number of changesets", 4).SetClass("p-2"),
|
||||
new StackedRenderingChart(tr, <any>overview._meta, {
|
||||
period: diffInDays <= 367 ? "day" : "month",
|
||||
groupToOtherCutoff:
|
||||
total > 50 ? 25 : total > 10 ? 3 : 0,
|
||||
}).SetStyle("width: 100%; height: 600px"),
|
||||
}).SetStyle("width: 75%; height: 600px"),
|
||||
new TagRenderingChart(<any>overview._meta, tr, {
|
||||
groupToOtherCutoff:
|
||||
total > 50 ? 25 : total > 10 ? 3 : 0,
|
||||
chartType: "doughnut",
|
||||
chartclasses: "w-8 h-8",
|
||||
sort: true,
|
||||
}).SetStyle("width: 25rem"),
|
||||
new Title("By number of modifications", 4).SetClass("p-2"),
|
||||
new StackedRenderingChart(
|
||||
tr,
|
||||
<any>Utils.Clone(overview._meta),
|
||||
{
|
||||
period: diffInDays <= 367 ? "day" : "month",
|
||||
groupToOtherCutoff: total > 50 ? 10 : 0,
|
||||
sumFields: valuesToSum,
|
||||
}
|
||||
).SetStyle("width: 100%; height: 600px"),
|
||||
]).SetClass("block border-2 border-subtle p-2 m-2 rounded-xl")
|
||||
)
|
||||
} catch (e) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue