forked from MapComplete/MapComplete
Finish dashboard mode
This commit is contained in:
parent
72f7bbd7db
commit
465497e6ca
2 changed files with 56 additions and 22 deletions
|
@ -3,6 +3,7 @@ import {OsmFeature} from "../../Models/OsmFeature";
|
||||||
import TagRenderingConfig from "../../Models/ThemeConfig/TagRenderingConfig";
|
import TagRenderingConfig from "../../Models/ThemeConfig/TagRenderingConfig";
|
||||||
import {ChartConfiguration} from 'chart.js';
|
import {ChartConfiguration} from 'chart.js';
|
||||||
import Combine from "../Base/Combine";
|
import Combine from "../Base/Combine";
|
||||||
|
import {TagUtils} from "../../Logic/Tags/TagUtils";
|
||||||
|
|
||||||
export default class TagRenderingChart extends Combine {
|
export default class TagRenderingChart extends Combine {
|
||||||
|
|
||||||
|
@ -47,12 +48,13 @@ export default class TagRenderingChart extends Combine {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let unknownCount = 0;
|
let unknownCount = 0;
|
||||||
let categoryCounts = mappings.map(_ => 0)
|
const categoryCounts = mappings.map(_ => 0)
|
||||||
let otherCount = 0;
|
const otherCounts: Record<string, number> = {}
|
||||||
let notApplicable = 0;
|
let notApplicable = 0;
|
||||||
|
let barchartMode = tagRendering.multiAnswer;
|
||||||
for (const feature of features) {
|
for (const feature of features) {
|
||||||
const props = feature.properties
|
const props = feature.properties
|
||||||
if(tagRendering.condition !== undefined && !tagRendering.condition.matchesProperties(props)){
|
if (tagRendering.condition !== undefined && !tagRendering.condition.matchesProperties(props)) {
|
||||||
notApplicable++;
|
notApplicable++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -62,34 +64,62 @@ export default class TagRenderingChart extends Combine {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let foundMatchingMapping = false;
|
let foundMatchingMapping = false;
|
||||||
|
if (!tagRendering.multiAnswer) {
|
||||||
for (let i = 0; i < mappings.length; i++) {
|
for (let i = 0; i < mappings.length; i++) {
|
||||||
const mapping = mappings[i];
|
const mapping = mappings[i];
|
||||||
if (mapping.if.matchesProperties(props)) {
|
if (mapping.if.matchesProperties(props)) {
|
||||||
categoryCounts[i]++
|
categoryCounts[i]++
|
||||||
foundMatchingMapping = true
|
foundMatchingMapping = true
|
||||||
if (!tagRendering.multiAnswer) {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
for (let i = 0; i < mappings.length; i++) {
|
||||||
|
const mapping = mappings[i];
|
||||||
|
if (TagUtils.MatchesMultiAnswer( mapping.if, props)) {
|
||||||
|
categoryCounts[i]++
|
||||||
|
if(categoryCounts[i] > 3){
|
||||||
|
foundMatchingMapping = true
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!foundMatchingMapping) {
|
||||||
if (tagRendering.freeform?.key !== undefined && props[tagRendering.freeform.key] !== undefined) {
|
if (tagRendering.freeform?.key !== undefined && props[tagRendering.freeform.key] !== undefined) {
|
||||||
otherCount++
|
const otherValue = props[tagRendering.freeform.key]
|
||||||
} else if (!foundMatchingMapping) {
|
otherCounts[otherValue] = (otherCounts[otherValue] ?? 0) + 1
|
||||||
|
barchartMode = true ;
|
||||||
|
} else {
|
||||||
unknownCount++
|
unknownCount++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (unknownCount + notApplicable === features.length) {
|
if (unknownCount + notApplicable === features.length) {
|
||||||
console.log("Totals:", features.length+" elements","tr:", tagRendering, "other",otherCount, "unkown",unknownCount, "na", notApplicable)
|
|
||||||
super(["No relevant data for ", tagRendering.id])
|
super(["No relevant data for ", tagRendering.id])
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const labels = ["Unknown", "Other", "Not applicable", ...mappings?.map(m => m.then.txt) ?? []]
|
let otherGrouped = 0;
|
||||||
const data = [unknownCount, otherCount, notApplicable,...categoryCounts]
|
const otherLabels: string[] = []
|
||||||
|
const otherData : number[] = []
|
||||||
|
for (const v in otherCounts) {
|
||||||
|
const count = otherCounts[v]
|
||||||
|
if(count > 2){
|
||||||
|
otherLabels.push(v)
|
||||||
|
otherData.push(otherCounts[v])
|
||||||
|
}else{
|
||||||
|
otherGrouped++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const labels = ["Unknown", "Other", "Not applicable", ...mappings?.map(m => m.then.txt) ?? [], ...otherLabels]
|
||||||
|
const data = [unknownCount, otherGrouped, notApplicable, ...categoryCounts, ... otherData]
|
||||||
const borderColor = [TagRenderingChart.unkownBorderColor, TagRenderingChart.otherBorderColor, TagRenderingChart.notApplicableBorderColor]
|
const borderColor = [TagRenderingChart.unkownBorderColor, TagRenderingChart.otherBorderColor, TagRenderingChart.notApplicableBorderColor]
|
||||||
const backgroundColor = [TagRenderingChart.unkownColor, TagRenderingChart.otherColor, TagRenderingChart.notApplicableColor]
|
const backgroundColor = [TagRenderingChart.unkownColor, TagRenderingChart.otherColor, TagRenderingChart.notApplicableColor]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
while (borderColor.length < data.length) {
|
while (borderColor.length < data.length) {
|
||||||
borderColor.push(...TagRenderingChart.borderColors)
|
borderColor.push(...TagRenderingChart.borderColors)
|
||||||
backgroundColor.push(...TagRenderingChart.backgroundColors)
|
backgroundColor.push(...TagRenderingChart.backgroundColors)
|
||||||
|
@ -108,7 +138,7 @@ export default class TagRenderingChart extends Combine {
|
||||||
console.log(tagRendering)
|
console.log(tagRendering)
|
||||||
}
|
}
|
||||||
const config = <ChartConfiguration>{
|
const config = <ChartConfiguration>{
|
||||||
type: tagRendering.multiAnswer ? 'bar' : 'doughnut',
|
type: barchartMode ? 'bar' : 'doughnut',
|
||||||
data: {
|
data: {
|
||||||
labels,
|
labels,
|
||||||
datasets: [{
|
datasets: [{
|
||||||
|
@ -122,7 +152,7 @@ export default class TagRenderingChart extends Combine {
|
||||||
options: {
|
options: {
|
||||||
plugins: {
|
plugins: {
|
||||||
legend: {
|
legend: {
|
||||||
display: !tagRendering.multiAnswer
|
display: !barchartMode
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ import Constants from "../Models/Constants";
|
||||||
import SimpleAddUI from "./BigComponents/SimpleAddUI";
|
import SimpleAddUI from "./BigComponents/SimpleAddUI";
|
||||||
import TagRenderingChart from "./BigComponents/TagRenderingChart";
|
import TagRenderingChart from "./BigComponents/TagRenderingChart";
|
||||||
import Loading from "./Base/Loading";
|
import Loading from "./Base/Loading";
|
||||||
|
import BackToIndex from "./BigComponents/BackToIndex";
|
||||||
|
|
||||||
|
|
||||||
export default class DashboardGui {
|
export default class DashboardGui {
|
||||||
|
@ -95,6 +96,7 @@ export default class DashboardGui {
|
||||||
private visibleElements(map: MinimapObj & BaseUIElement, layers: Record<string, LayerConfig>): { distance: number, center: [number, number], element: OsmFeature, layer: LayerConfig }[] {
|
private visibleElements(map: MinimapObj & BaseUIElement, layers: Record<string, LayerConfig>): { distance: number, center: [number, number], element: OsmFeature, layer: LayerConfig }[] {
|
||||||
const bbox = map.bounds.data
|
const bbox = map.bounds.data
|
||||||
if (bbox === undefined) {
|
if (bbox === undefined) {
|
||||||
|
console.warn("No bbox")
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
const location = map.location.data;
|
const location = map.location.data;
|
||||||
|
@ -278,14 +280,16 @@ export default class DashboardGui {
|
||||||
new VariableUiElement(elementsInview.map(elements => this.mainElementsView(elements).SetClass("block m-2")))
|
new VariableUiElement(elementsInview.map(elements => this.mainElementsView(elements).SetClass("block m-2")))
|
||||||
.SetClass("block shrink-2 overflow-x-auto h-full border-2 border-subtle rounded-lg"),
|
.SetClass("block shrink-2 overflow-x-auto h-full border-2 border-subtle rounded-lg"),
|
||||||
this.allDocumentationButtons(),
|
this.allDocumentationButtons(),
|
||||||
new LanguagePicker(Object.keys(state.layoutToUse.title.translations)).SetClass("mt-2")
|
new LanguagePicker(Object.keys(state.layoutToUse.title.translations)).SetClass("mt-2"),
|
||||||
|
new BackToIndex()
|
||||||
]).SetClass("w-1/2 m-4 flex flex-col shrink-0 grow-0"),
|
]).SetClass("w-1/2 m-4 flex flex-col shrink-0 grow-0"),
|
||||||
new VariableUiElement(this.currentView.map(({title, contents}) => {
|
new VariableUiElement(this.currentView.map(({title, contents}) => {
|
||||||
return new Combine([
|
return new Combine([
|
||||||
new Title(Translations.W(title), 2).SetClass("shrink-0 border-b-4 border-subtle"),
|
new Title(Translations.W(title), 2).SetClass("shrink-0 border-b-4 border-subtle"),
|
||||||
Translations.W(contents).SetClass("shrink-2 overflow-y-auto block")
|
Translations.W(contents).SetClass("shrink-2 overflow-y-auto block")
|
||||||
]).SetClass("flex flex-col h-full")
|
]).SetClass("flex flex-col h-full")
|
||||||
})).SetClass("w-1/2 m-4 p-2 border-2 border-subtle rounded-xl m-4 ml-0 mr-8 shrink-0 grow-0")
|
})).SetClass("w-1/2 m-4 p-2 border-2 border-subtle rounded-xl m-4 ml-0 mr-8 shrink-0 grow-0"),
|
||||||
|
|
||||||
]).SetClass("flex h-full")
|
]).SetClass("flex h-full")
|
||||||
.AttachTo("leafletDiv")
|
.AttachTo("leafletDiv")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue