forked from MapComplete/MapComplete
Merge master
This commit is contained in:
commit
b61f930fea
39 changed files with 525 additions and 22753 deletions
|
|
@ -10,6 +10,9 @@
|
|||
import Tr from "../Base/Tr.svelte"
|
||||
import AccordionSingle from "../Flowbite/AccordionSingle.svelte"
|
||||
import Translations from "../i18n/Translations"
|
||||
import TagRenderingChart from "../BigComponents/TagRenderingChart"
|
||||
import ToSvelte from "../Base/ToSvelte.svelte"
|
||||
import type { TagRenderingConfigJson } from "../../Models/ThemeConfig/Json/TagRenderingConfigJson"
|
||||
|
||||
export let onlyShowUsername: string[]
|
||||
export let features: Feature[]
|
||||
|
|
@ -25,10 +28,13 @@
|
|||
key: string
|
||||
value?: string
|
||||
oldValue?: string
|
||||
step: OsmObject
|
||||
}[]
|
||||
> = allHistories.mapD((histories) => HistoryUtils.fullHistoryDiff(histories, usernames))
|
||||
|
||||
const trs = shared_questions.tagRenderings.map((tr) => new TagRenderingConfig(tr))
|
||||
const trs = shared_questions.tagRenderings.map(
|
||||
(tr) => new TagRenderingConfig(<TagRenderingConfigJson>tr)
|
||||
)
|
||||
|
||||
function detectQuestion(key: string): TagRenderingConfig {
|
||||
return trs.find((tr) => tr.freeform?.key === key)
|
||||
|
|
@ -40,17 +46,19 @@
|
|||
tr: TagRenderingConfig
|
||||
count: number
|
||||
values: { value: string; count: number }[]
|
||||
features: Feature[]
|
||||
}[]
|
||||
> = allDiffs.mapD((allDiffs) => {
|
||||
const keyCounts = new Map<string, Map<string, number>>()
|
||||
const keyCounts = new Map<string, Map<string, OsmObject[]>>()
|
||||
for (const diff of allDiffs) {
|
||||
const k = diff.key
|
||||
if (!keyCounts.has(k)) {
|
||||
keyCounts.set(k, new Map<string, number>())
|
||||
keyCounts.set(k, new Map<string, OsmObject[]>())
|
||||
}
|
||||
const valueCounts = keyCounts.get(k)
|
||||
const v = diff.value ?? ""
|
||||
valueCounts.set(v, 1 + (valueCounts.get(v) ?? 0))
|
||||
const oldFeaturesList = valueCounts.get(v) ?? []
|
||||
valueCounts.set(v, [...oldFeaturesList, diff.step])
|
||||
}
|
||||
|
||||
const perKey: {
|
||||
|
|
@ -58,19 +66,29 @@
|
|||
tr: TagRenderingConfig
|
||||
count: number
|
||||
values: { value: string; count: number }[]
|
||||
features: Feature[]
|
||||
}[] = []
|
||||
keyCounts.forEach((values, key) => {
|
||||
const keyTotal: { value: string; count: number }[] = []
|
||||
keyCounts.forEach((values: Map<string, OsmObject[]>, key: string) => {
|
||||
const keyTotal: { value: string; features: Feature[] }[] = []
|
||||
values.forEach((count, value) => {
|
||||
keyTotal.push({ value, count })
|
||||
keyTotal.push({ value, features: count.map((step) => step.asGeoJson()) })
|
||||
})
|
||||
let countForKey = 0
|
||||
for (const { count } of keyTotal) {
|
||||
countForKey += count
|
||||
let countForKey: Feature[] = []
|
||||
for (const { features } of keyTotal) {
|
||||
countForKey.push(...features)
|
||||
}
|
||||
keyTotal.sort((a, b) => b.count - a.count)
|
||||
keyTotal.sort((a, b) => b.features.length - a.features.length)
|
||||
const tr = detectQuestion(key)
|
||||
perKey.push({ count: countForKey, tr, key, values: keyTotal })
|
||||
perKey.push({
|
||||
count: countForKey.length,
|
||||
tr,
|
||||
key,
|
||||
values: keyTotal.map(({ value, features }) => ({
|
||||
value,
|
||||
count: features.length,
|
||||
})),
|
||||
features: countForKey,
|
||||
})
|
||||
})
|
||||
perKey.sort((a, b) => b.count - a.count)
|
||||
|
||||
|
|
@ -105,6 +123,19 @@
|
|||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
{#if diff.tr}
|
||||
<div class="h-48 w-48">
|
||||
<ToSvelte
|
||||
construct={new TagRenderingChart(diff.features, diff.tr, {
|
||||
groupToOtherCutoff: 0,
|
||||
chartType: "pie",
|
||||
sort: true,
|
||||
})}
|
||||
/>
|
||||
</div>
|
||||
{:else}
|
||||
Could not create a graph
|
||||
{/if}
|
||||
</AccordionSingle>
|
||||
{/each}
|
||||
{/if}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue