Fix onwheels statistics, fix #1850

This commit is contained in:
Pieter Vander Vennet 2024-03-28 03:39:46 +01:00
parent e5d9e253ef
commit df0b43ba41
4 changed files with 56 additions and 40 deletions

View file

@ -17,7 +17,8 @@ export default class Title extends BaseUIElement {
constructor(embedded: string | BaseUIElement, level: number = 3) { constructor(embedded: string | BaseUIElement, level: number = 3) {
super() super()
if (embedded === undefined) { if (embedded === undefined) {
throw "A title should have some content. Undefined is not allowed" console.warn("A title should have some content. Undefined is not allowed")
embedded = ""
} }
if (typeof embedded === "string") { if (typeof embedded === "string") {
this.title = new FixedUiElement(embedded) this.title = new FixedUiElement(embedded)

View file

@ -17,14 +17,17 @@ export default class StatisticsForLayerPanel extends VariableUiElement {
return new Loading("Loading data") return new Loading("Loading data")
} }
if (features.length === 0) { if (features.length === 0) {
return "No elements in view" return new Combine([
"No elements in view for layer ",
layer.id
]).SetClass("block")
} }
const els: BaseUIElement[] = [] const els: BaseUIElement[] = []
const featuresForLayer = features const featuresForLayer = features
if (featuresForLayer.length === 0) { if (featuresForLayer.length === 0) {
return return
} }
els.push(new Title(layer.name.Clone(), 1).SetClass("mt-8")) els.push(new Title(layer.name, 1).SetClass("mt-8"))
const layerStats = [] const layerStats = []
for (const tagRendering of layer?.tagRenderings ?? []) { for (const tagRendering of layer?.tagRenderings ?? []) {

View file

@ -8,7 +8,9 @@ import { OsmFeature } from "../../Models/OsmFeature"
export interface TagRenderingChartOptions { export interface TagRenderingChartOptions {
groupToOtherCutoff?: 3 | number groupToOtherCutoff?: 3 | number
sort?: boolean sort?: boolean,
hideUnkown?: boolean,
hideNotApplicable?: boolean
} }
export class StackedRenderingChart extends ChartJs { export class StackedRenderingChart extends ChartJs {
@ -19,12 +21,16 @@ export class StackedRenderingChart extends ChartJs {
period: "day" | "month" period: "day" | "month"
groupToOtherCutoff?: 3 | number groupToOtherCutoff?: 3 | number
// If given, take the sum of these fields to get the feature weight // If given, take the sum of these fields to get the feature weight
sumFields?: string[] sumFields?: string[],
hideUnknown?: boolean,
hideNotApplicable?: boolean
} }
) { ) {
const { labels, data } = TagRenderingChart.extractDataAndLabels(tr, features, { const { labels, data } = TagRenderingChart.extractDataAndLabels(tr, features, {
sort: true, sort: true,
groupToOtherCutoff: options?.groupToOtherCutoff, groupToOtherCutoff: options?.groupToOtherCutoff,
hideNotApplicable: options?.hideNotApplicable,
hideUnkown: options?.hideUnknown
}) })
if (labels === undefined || data === undefined) { if (labels === undefined || data === undefined) {
console.error( console.error(
@ -36,7 +42,6 @@ export class StackedRenderingChart extends ChartJs {
) )
throw "No labels or data given..." throw "No labels or data given..."
} }
// labels: ["cyclofix", "buurtnatuur", ...]; data : [ ["cyclofix-changeset", "cyclofix-changeset", ...], ["buurtnatuur-cs", "buurtnatuur-cs"], ... ]
for (let i = labels.length; i >= 0; i--) { for (let i = labels.length; i >= 0; i--) {
if (data[i]?.length != 0) { if (data[i]?.length != 0) {
@ -116,13 +121,13 @@ export class StackedRenderingChart extends ChartJs {
datasets.push({ datasets.push({
data: countsPerDay, data: countsPerDay,
backgroundColor, backgroundColor,
label, label
}) })
} }
const perDayData = { const perDayData = {
labels: trimmedDays, labels: trimmedDays,
datasets, datasets
} }
const config = <ChartConfiguration>{ const config = <ChartConfiguration>{
@ -131,17 +136,17 @@ export class StackedRenderingChart extends ChartJs {
options: { options: {
responsive: true, responsive: true,
legend: { legend: {
display: false, display: false
}, },
scales: { scales: {
x: { x: {
stacked: true, stacked: true
}, },
y: { y: {
stacked: true, stacked: true
}, }
}, }
}, }
} }
super(config) super(config)
} }
@ -194,7 +199,7 @@ export default class TagRenderingChart extends Combine {
"rgba(255, 206, 86, 0.2)", "rgba(255, 206, 86, 0.2)",
"rgba(75, 192, 192, 0.2)", "rgba(75, 192, 192, 0.2)",
"rgba(153, 102, 255, 0.2)", "rgba(153, 102, 255, 0.2)",
"rgba(255, 159, 64, 0.2)", "rgba(255, 159, 64, 0.2)"
] ]
public static readonly borderColors = [ public static readonly borderColors = [
@ -203,7 +208,7 @@ export default class TagRenderingChart extends Combine {
"rgba(255, 206, 86, 1)", "rgba(255, 206, 86, 1)",
"rgba(75, 192, 192, 1)", "rgba(75, 192, 192, 1)",
"rgba(153, 102, 255, 1)", "rgba(153, 102, 255, 1)",
"rgba(255, 159, 64, 1)", "rgba(255, 159, 64, 1)"
] ]
/** /**
@ -239,12 +244,12 @@ export default class TagRenderingChart extends Combine {
const borderColor = [ const borderColor = [
TagRenderingChart.unkownBorderColor, TagRenderingChart.unkownBorderColor,
TagRenderingChart.otherBorderColor, TagRenderingChart.otherBorderColor,
TagRenderingChart.notApplicableBorderColor, TagRenderingChart.notApplicableBorderColor
] ]
const backgroundColor = [ const backgroundColor = [
TagRenderingChart.unkownColor, TagRenderingChart.unkownColor,
TagRenderingChart.otherColor, TagRenderingChart.otherColor,
TagRenderingChart.notApplicableColor, TagRenderingChart.notApplicableColor
] ]
while (borderColor.length < data.length) { while (borderColor.length < data.length) {
@ -276,17 +281,17 @@ export default class TagRenderingChart extends Combine {
backgroundColor, backgroundColor,
borderColor, borderColor,
borderWidth: 1, borderWidth: 1,
label: undefined, label: undefined
}, }
], ]
}, },
options: { options: {
plugins: { plugins: {
legend: { legend: {
display: !barchartMode, display: !barchartMode
}, }
}, }
}, }
} }
const chart = new ChartJs(config).SetClass(options?.chartclasses ?? "w-32 h-32") const chart = new ChartJs(config).SetClass(options?.chartclasses ?? "w-32 h-32")
@ -297,7 +302,7 @@ export default class TagRenderingChart extends Combine {
super([ super([
options?.includeTitle ? tagRendering.question.Clone() ?? tagRendering.id : undefined, options?.includeTitle ? tagRendering.question.Clone() ?? tagRendering.id : undefined,
chart, chart
]) ])
this.SetClass("block") this.SetClass("block")
@ -386,20 +391,26 @@ export default class TagRenderingChart extends Combine {
} }
} }
const labels = [ const labels = []
"Unknown", const data: T[][] = []
"Other",
"Not applicable", if (!options.hideUnkown) {
data.push(unknownCount)
labels.push("Unknown")
}
data.push(otherGrouped)
labels.push("Other")
if (!options.hideNotApplicable) {
data.push(notApplicable)
labels.push(
"Not applicable"
)
}
data.push(...categoryCounts,
...otherData)
labels.push(
...(mappings?.map((m) => m.then.txt) ?? []), ...(mappings?.map((m) => m.then.txt) ?? []),
...otherLabels, ...otherLabels)
]
const data: T[][] = [
unknownCount,
otherGrouped,
notApplicable,
...categoryCounts,
...otherData,
]
return { labels, data } return { labels, data }
} }

View file

@ -1153,10 +1153,11 @@ export default class SpecialVisualizations {
constr: (state) => { constr: (state) => {
return new Combine( return new Combine(
state.layout.layers state.layout.layers
.filter((l) => l.name !== null) .filter((l) => l.name !== null && l.title && state.perLayer.get(l.id) !== undefined )
.map( .map(
(l) => { (l) => {
const fs = state.perLayer.get(l.id) const fs = state.perLayer.get(l.id)
console.log(">>>", l.id, fs)
const bbox = state.mapProperties.bounds const bbox = state.mapProperties.bounds
const fsBboxed = new BBoxFeatureSourceForLayer(fs, bbox) const fsBboxed = new BBoxFeatureSourceForLayer(fs, bbox)
return new StatisticsPanel(fsBboxed) return new StatisticsPanel(fsBboxed)