Small tweaks

This commit is contained in:
pietervdvn 2022-01-24 00:19:01 +01:00
parent 3a158a6155
commit 141d5330a7

View file

@ -14,10 +14,10 @@ import CheckBoxes from "../Input/Checkboxes";
/** /**
* Shows the data to import on a map, asks for the correct layer to be selected * Shows the data to import on a map, asks for the correct layer to be selected
*/ */
export class PreviewPanel extends Combine implements FlowStep<{ features: { properties: any, geometry: { coordinates: [number, number] } }[] }>{ export class PreviewPanel extends Combine implements FlowStep<{ features: { properties: any, geometry: { coordinates: [number, number] } }[] }> {
public readonly IsValid: UIEventSource<boolean>; public readonly IsValid: UIEventSource<boolean>;
public readonly Value: UIEventSource< { features: { properties: any, geometry: { coordinates: [number, number] } }[] }> public readonly Value: UIEventSource<{ features: { properties: any, geometry: { coordinates: [number, number] } }[] }>
constructor( constructor(
state: UserRelatedState, state: UserRelatedState,
geojson: { features: { properties: any, geometry: { coordinates: [number, number] } }[] }) { geojson: { features: { properties: any, geometry: { coordinates: [number, number] } }[] }) {
@ -29,70 +29,82 @@ export class PreviewPanel extends Combine implements FlowStep<{ features: { prop
for (const f of geojson.features) { for (const f of geojson.features) {
Object.keys(f.properties).forEach(key => propertyKeys.add(key)) Object.keys(f.properties).forEach(key => propertyKeys.add(key))
} }
const attributeOverview : BaseUIElement[] = [] const attributeOverview: BaseUIElement[] = []
const n = geojson.features.length; const n = geojson.features.length;
for (const key of Array.from(propertyKeys)) { for (const key of Array.from(propertyKeys)) {
const values = Utils.NoNull(geojson.features.map(f => f.properties[key])) const values = Utils.NoNull(geojson.features.map(f => f.properties[key]))
console.log("There are ",values.length,"features with attribute",key, "namely",values)
const allSame = !values.some(v => v !== values[0]) const allSame = !values.some(v => v !== values[0])
if(allSame){ let countSummary: BaseUIElement
attributeOverview.push(new Title(key+"="+values[0])) if (values.length === n) {
if(values.length === n){ countSummary = t.allAttributesSame
attributeOverview.push(t.allAttributesSame) } else {
}else{ countSummary = t.someHaveSame.Subs({
attributeOverview.push(t.someHaveSame.Subs({count: values.length, percentage: Math.floor(100 * values.length / n)})) count: values.length,
} percentage: Math.floor(100 * values.length / n)
})
}
if (allSame) {
attributeOverview.push(new Title(key + "=" + values[0]))
attributeOverview.push(countSummary)
continue continue
} }
const uniqueCount = new Set(values).size const uniqueCount = new Set(values).size
if(uniqueCount !== values.length){ if (uniqueCount !== values.length) {
attributeOverview.push() attributeOverview.push()
// There are some overlapping values: histogram time! // There are some overlapping values: histogram time!
let hist : BaseUIElement = new Histogram( let hist: BaseUIElement =
new UIEventSource<string[]>(values), new Combine([
"Value", countSummary,
"Occurence", new Histogram(
{ new UIEventSource<string[]>(values),
sortMode: "count-rev" "Value",
} "Occurence",
{
) sortMode: "count-rev"
})
const title = new Title(key+"=*") ]).SetClass("flex flex-col")
if(uniqueCount > 15){
hist = new Toggleable(title,
const title = new Title(key + "=*")
if (uniqueCount > 15) {
hist = new Toggleable(title,
hist.SetClass("block") hist.SetClass("block")
).Collapse() ).Collapse()
}else{ } else {
attributeOverview.push(title) attributeOverview.push(title)
} }
attributeOverview.push(hist) attributeOverview.push(hist)
continue continue
} }
// All values are different, we add a boring (but collapsable) list // All values are different, we add a boring (but collapsable) list
attributeOverview.push(new Toggleable( attributeOverview.push(new Toggleable(
new Title(key+"=*"), new Title(key + "=*"),
new Combine([
countSummary,
new List(values) new List(values)
) ) ])
))
} }
const confirm = new CheckBoxes([t.inspectLooksCorrect]) const confirm = new CheckBoxes([t.inspectLooksCorrect])
super([ super([
new Title(t.inspectDataTitle.Subs({count:geojson.features.length })), new Title(t.inspectDataTitle.Subs({count: geojson.features.length})),
...attributeOverview, ...attributeOverview,
confirm confirm
]); ]);
this.Value = new UIEventSource<{features: {properties: any; geometry: {coordinates: [number, number]}}[]}>(geojson) this.Value = new UIEventSource<{ features: { properties: any; geometry: { coordinates: [number, number] } }[] }>(geojson)
this.IsValid = confirm.GetValue().map(selected => selected.length == 1) this.IsValid = confirm.GetValue().map(selected => selected.length == 1)
} }
} }