Show a full-screen graph on click

This commit is contained in:
pietervdvn 2022-07-20 15:04:51 +02:00
parent a90fa5cd63
commit e25c904aa3
3 changed files with 37 additions and 12 deletions

View file

@ -39,7 +39,9 @@ export default class TagRenderingChart extends Combine {
*/ */
constructor(features: OsmFeature[], tagRendering: TagRenderingConfig, options?: { constructor(features: OsmFeature[], tagRendering: TagRenderingConfig, options?: {
chartclasses?: string, chartclasses?: string,
chartstyle?: string chartstyle?: string,
includeTitle?: boolean,
groupToOtherCutoff?: 3 | number
}) { }) {
const mappings = tagRendering.mappings ?? [] const mappings = tagRendering.mappings ?? []
@ -79,9 +81,7 @@ export default class TagRenderingChart extends Combine {
const mapping = mappings[i]; const mapping = mappings[i];
if (TagUtils.MatchesMultiAnswer( mapping.if, props)) { if (TagUtils.MatchesMultiAnswer( mapping.if, props)) {
categoryCounts[i]++ categoryCounts[i]++
if(categoryCounts[i] > 3){ foundMatchingMapping = true
foundMatchingMapping = true
}
} }
} }
} }
@ -89,7 +89,6 @@ export default class TagRenderingChart extends Combine {
if (tagRendering.freeform?.key !== undefined && props[tagRendering.freeform.key] !== undefined) { if (tagRendering.freeform?.key !== undefined && props[tagRendering.freeform.key] !== undefined) {
const otherValue = props[tagRendering.freeform.key] const otherValue = props[tagRendering.freeform.key]
otherCounts[otherValue] = (otherCounts[otherValue] ?? 0) + 1 otherCounts[otherValue] = (otherCounts[otherValue] ?? 0) + 1
barchartMode = true ;
} else { } else {
unknownCount++ unknownCount++
} }
@ -107,13 +106,14 @@ export default class TagRenderingChart extends Combine {
const otherData : number[] = [] const otherData : number[] = []
for (const v in otherCounts) { for (const v in otherCounts) {
const count = otherCounts[v] const count = otherCounts[v]
if(count > 2){ if(count >= (options.groupToOtherCutoff ?? 3)){
otherLabels.push(v) otherLabels.push(v)
otherData.push(otherCounts[v]) otherData.push(otherCounts[v])
}else{ }else{
otherGrouped++; otherGrouped++;
} }
} }
const labels = ["Unknown", "Other", "Not applicable", ...mappings?.map(m => m.then.txt) ?? [], ...otherLabels] const labels = ["Unknown", "Other", "Not applicable", ...mappings?.map(m => m.then.txt) ?? [], ...otherLabels]
const data = [unknownCount, otherGrouped, notApplicable, ...categoryCounts, ... otherData] const data = [unknownCount, otherGrouped, notApplicable, ...categoryCounts, ... otherData]
@ -136,9 +136,10 @@ export default class TagRenderingChart extends Combine {
} }
} }
if (tagRendering.id === undefined) { if(labels.length > 9){
console.log(tagRendering) barchartMode = true;
} }
const config = <ChartConfiguration>{ const config = <ChartConfiguration>{
type: barchartMode ? 'bar' : 'doughnut', type: barchartMode ? 'bar' : 'doughnut',
data: { data: {
@ -168,7 +169,7 @@ export default class TagRenderingChart extends Combine {
super([ super([
tagRendering.question ?? tagRendering.id, options?.includeTitle ? (tagRendering.question.Clone() ?? tagRendering.id) : undefined,
chart]) chart])
this.SetClass("block") this.SetClass("block")

View file

@ -29,6 +29,7 @@ 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"; import BackToIndex from "./BigComponents/BackToIndex";
import Locale from "./i18n/Locale";
export default class DashboardGui { export default class DashboardGui {
@ -128,7 +129,7 @@ export default class DashboardGui {
continue continue
} }
const activeFilters: FilterState[] = Array.from(filtered.appliedFilters.data.values()); const activeFilters: FilterState[] = Array.from(filtered.appliedFilters.data.values());
if (activeFilters.some(filter => !filter?.currentFilter?.matchesProperties(element.properties))) { if (!activeFilters.every(filter => filter?.currentFilter === undefined || filter?.currentFilter?.matchesProperties(element.properties))) {
continue continue
} }
const center = GeoOperations.centerpointCoordinates(element); const center = GeoOperations.centerpointCoordinates(element);
@ -257,14 +258,33 @@ export default class DashboardGui {
for (const tagRendering of layer.tagRenderings) { for (const tagRendering of layer.tagRenderings) {
const chart = new TagRenderingChart(featuresForLayer, tagRendering, { const chart = new TagRenderingChart(featuresForLayer, tagRendering, {
chartclasses: "w-full", chartclasses: "w-full",
chartstyle: "height: 60rem" chartstyle: "height: 60rem",
includeTitle: true
}) })
const full = new Lazy(() =>
new TagRenderingChart(featuresForLayer, tagRendering, {
chartstyle: "max-height: calc(100vh - 10rem)",
groupToOtherCutoff: 0
})
)
chart.onClick(() => {
const current = self.currentView.data
full.onClick(() => {
self.currentView.setData(current)
})
self.currentView.setData(
{
title: new Title(tagRendering.question.Clone() ?? tagRendering.id),
contents: full
})
}
)
layerStats.push(chart.SetClass("w-full lg:w-1/3")) layerStats.push(chart.SetClass("w-full lg:w-1/3"))
} }
els.push(new Combine(layerStats).SetClass("flex flex-wrap")) els.push(new Combine(layerStats).SetClass("flex flex-wrap"))
} }
return new Combine(els) return new Combine(els)
})) }, [Locale.language]))
new Combine([ new Combine([

View file

@ -1110,6 +1110,10 @@ video {
height: 12rem; height: 12rem;
} }
.max-h-screen {
max-height: 100vh;
}
.max-h-7 { .max-h-7 {
max-height: 1.75rem; max-height: 1.75rem;
} }