forked from MapComplete/MapComplete
Refactoring: switch specialVis constructor to an object
This commit is contained in:
parent
6bb33771b4
commit
1bd226a6fa
38 changed files with 369 additions and 563 deletions
|
|
@ -1,11 +1,6 @@
|
|||
import {
|
||||
SpecialVisualization,
|
||||
SpecialVisualizationState,
|
||||
SpecialVisualizationSvelte,
|
||||
} from "../SpecialVisualization"
|
||||
import { SpecialVisualisationParams, SpecialVisualization, SpecialVisualizationSvelte } from "../SpecialVisualization"
|
||||
import { HistogramViz } from "./HistogramViz"
|
||||
import { Store, UIEventSource } from "../../Logic/UIEventSource"
|
||||
import { Feature } from "geojson"
|
||||
import { Store } from "../../Logic/UIEventSource"
|
||||
import BaseUIElement from "../BaseUIElement"
|
||||
import SvelteUIElement from "../Base/SvelteUIElement"
|
||||
import DirectionIndicator from "../Base/DirectionIndicator.svelte"
|
||||
|
|
@ -20,15 +15,15 @@ import NextChangeViz from "../OpeningHours/NextChangeViz.svelte"
|
|||
import { Unit } from "../../Models/Unit"
|
||||
import AllFeaturesStatistics from "../Statistics/AllFeaturesStatistics.svelte"
|
||||
import { LanguageElement } from "./LanguageElement/LanguageElement"
|
||||
import LayerConfig from "../../Models/ThemeConfig/LayerConfig"
|
||||
import { QuestionableTagRenderingConfigJson } from "../../Models/ThemeConfig/Json/QuestionableTagRenderingConfigJson"
|
||||
import { And } from "../../Logic/Tags/And"
|
||||
import TagRenderingConfig from "../../Models/ThemeConfig/TagRenderingConfig"
|
||||
import TagRenderingEditable from "./TagRendering/TagRenderingEditable.svelte"
|
||||
import AllTagsPanel from "./AllTagsPanel/AllTagsPanel.svelte"
|
||||
import CollectionTimes from "../CollectionTimes/CollectionTimes.svelte"
|
||||
import Tr from "../Base/Tr.svelte"
|
||||
|
||||
class DirectionIndicatorVis extends SpecialVisualization {
|
||||
class DirectionIndicatorVis extends SpecialVisualizationSvelte {
|
||||
funcName = "direction_indicator"
|
||||
args = []
|
||||
|
||||
|
|
@ -36,13 +31,8 @@ class DirectionIndicatorVis extends SpecialVisualization {
|
|||
"Gives a distance indicator and a compass pointing towards the location from your GPS-location. If clicked, centers the map on the object"
|
||||
group = "data"
|
||||
|
||||
constr(
|
||||
state: SpecialVisualizationState,
|
||||
tagSource: UIEventSource<Record<string, string>>,
|
||||
argument: string[],
|
||||
feature: Feature
|
||||
): BaseUIElement {
|
||||
return new SvelteUIElement(DirectionIndicator, { state, feature })
|
||||
constr(params: SpecialVisualisationParams): SvelteUIElement {
|
||||
return new SvelteUIElement(DirectionIndicator, params)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -65,17 +55,15 @@ class DirectionAbsolute extends SpecialVisualization {
|
|||
]
|
||||
group = "data"
|
||||
|
||||
constr(
|
||||
state: SpecialVisualizationState,
|
||||
tagSource: UIEventSource<Record<string, string>>,
|
||||
args: string[]
|
||||
): BaseUIElement {
|
||||
constr({
|
||||
tags,
|
||||
args,
|
||||
}: SpecialVisualisationParams): BaseUIElement {
|
||||
const key = args[0] === "" ? "_direction:centerpoint" : args[0]
|
||||
const offset = args[1] === "" ? 0 : Number(args[1])
|
||||
|
||||
return new VariableUiElement(
|
||||
tagSource
|
||||
.map((tags) => {
|
||||
tags.map((tags) => {
|
||||
console.log("Direction value", tags[key], key)
|
||||
return tags[key]
|
||||
})
|
||||
|
|
@ -117,14 +105,12 @@ class OpeningHoursTableVis extends SpecialVisualizationSvelte {
|
|||
example =
|
||||
"A normal opening hours table can be invoked with `{opening_hours_table()}`. A table for e.g. conditional access with opening hours can be `{opening_hours_table(access:conditional, no @ &LPARENS, &RPARENS)}`"
|
||||
|
||||
constr(state, tagSource: UIEventSource<any>, args) {
|
||||
constr({ tags, args }: SpecialVisualisationParams): SvelteUIElement {
|
||||
const [key, prefix, postfix] = args
|
||||
const openingHoursStore: Store<opening_hours | "error" | undefined> =
|
||||
OH.CreateOhObjectStore(tagSource, key, prefix, postfix)
|
||||
OH.CreateOhObjectStore(tags, key, prefix, postfix)
|
||||
return new SvelteUIElement(OpeningHoursWithError, {
|
||||
tags: tagSource,
|
||||
key,
|
||||
opening_hours_obj: openingHoursStore,
|
||||
tags, key, opening_hours_obj: openingHoursStore,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -152,11 +138,7 @@ class OpeningHoursState extends SpecialVisualizationSvelte {
|
|||
},
|
||||
]
|
||||
|
||||
constr(
|
||||
state: SpecialVisualizationState,
|
||||
tags: UIEventSource<Record<string, string>>,
|
||||
args: string[]
|
||||
): SvelteUIElement {
|
||||
constr({ state, tags, args }: SpecialVisualisationParams): SvelteUIElement {
|
||||
const keyToUse = args[0]
|
||||
const prefix = args[1]
|
||||
const postfix = args[2]
|
||||
|
|
@ -187,10 +169,10 @@ class Canonical extends SpecialVisualization {
|
|||
},
|
||||
]
|
||||
|
||||
constr(state, tagSource, args) {
|
||||
constr({ state, tags, args }: SpecialVisualisationParams) {
|
||||
const key = args[0]
|
||||
return new VariableUiElement(
|
||||
tagSource
|
||||
tags
|
||||
.map((tags) => tags[key])
|
||||
.map((value) => {
|
||||
if (value === undefined) {
|
||||
|
|
@ -203,7 +185,7 @@ class Canonical extends SpecialVisualization {
|
|||
if (unit === undefined) {
|
||||
return value
|
||||
}
|
||||
const getCountry = () => tagSource.data._country
|
||||
const getCountry = () => tags.data._country
|
||||
return unit.asHumanLongValue(value, getCountry)
|
||||
})
|
||||
)
|
||||
|
|
@ -217,26 +199,23 @@ class StatisticsVis extends SpecialVisualizationSvelte {
|
|||
"Show general statistics about all the elements currently in view. Intended to use on the `current_view`-layer. They will be split per layer"
|
||||
args = []
|
||||
|
||||
constr(state) {
|
||||
return new SvelteUIElement(AllFeaturesStatistics, { state })
|
||||
constr(params: SpecialVisualisationParams) {
|
||||
return new SvelteUIElement(AllFeaturesStatistics, params)
|
||||
}
|
||||
}
|
||||
|
||||
class PresetDescription extends SpecialVisualization {
|
||||
class PresetDescription extends SpecialVisualizationSvelte {
|
||||
funcName = "preset_description"
|
||||
docs =
|
||||
"Shows the extra description from the presets of the layer, if one matches. It will pick the most specific one (e.g. if preset `A` implies `B`, but `B` does not imply `A`, it'll pick B) or the first one if no ordering can be made. Might be empty"
|
||||
args = []
|
||||
|
||||
constr(
|
||||
state: SpecialVisualizationState,
|
||||
tagSource: UIEventSource<Record<string, string>>
|
||||
): BaseUIElement {
|
||||
const translation = tagSource.map((tags) => {
|
||||
constr({ state, tags }: SpecialVisualisationParams): SvelteUIElement {
|
||||
const translation = tags.map((tags) => {
|
||||
const layer = state.theme.getMatchingLayer(tags)
|
||||
return layer?.getMostMatchingPreset(tags)?.description
|
||||
})
|
||||
return new VariableUiElement(translation)
|
||||
return new SvelteUIElement(Tr, { t: translation })
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -245,13 +224,7 @@ class PresetTypeSelect extends SpecialVisualizationSvelte {
|
|||
docs = "An editable tag rendering which allows to change the type"
|
||||
args = []
|
||||
|
||||
constr(
|
||||
state: SpecialVisualizationState,
|
||||
tags: UIEventSource<Record<string, string>>,
|
||||
argument: string[],
|
||||
selectedElement: Feature,
|
||||
layer: LayerConfig
|
||||
): SvelteUIElement {
|
||||
constr({ state, tags, feature, layer }: SpecialVisualisationParams,): SvelteUIElement {
|
||||
const t = Translations.t.preset_type
|
||||
if (layer._basedOn !== layer.id) {
|
||||
console.warn("Trying to use the _original_ layer")
|
||||
|
|
@ -277,7 +250,7 @@ class PresetTypeSelect extends SpecialVisualizationSvelte {
|
|||
return new SvelteUIElement(TagRenderingEditable, {
|
||||
config,
|
||||
tags,
|
||||
selectedElement,
|
||||
selectedElement: feature,
|
||||
state,
|
||||
layer,
|
||||
})
|
||||
|
|
@ -290,8 +263,8 @@ class AllTagsVis extends SpecialVisualizationSvelte {
|
|||
args = []
|
||||
group = "data"
|
||||
|
||||
constr(state, tags: UIEventSource<Record<string, string>>, _, __, layer: LayerConfig) {
|
||||
return new SvelteUIElement(AllTagsPanel, { tags, layer })
|
||||
constr(params: SpecialVisualisationParams) {
|
||||
return new SvelteUIElement(AllTagsPanel, params)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -308,18 +281,12 @@ class PointsInTimeVis extends SpecialVisualization {
|
|||
},
|
||||
]
|
||||
|
||||
constr(
|
||||
state: SpecialVisualizationState,
|
||||
tagSource: UIEventSource<Record<string, string>>,
|
||||
args: string[],
|
||||
feature: Feature,
|
||||
layer: LayerConfig
|
||||
): BaseUIElement {
|
||||
constr( {tags, args}: SpecialVisualisationParams): BaseUIElement {
|
||||
const key = args[0]
|
||||
const points_in_time = tagSource.map((tags) => tags[key])
|
||||
const points_in_time = tags.map((tags) => tags[key])
|
||||
const times = points_in_time.map(
|
||||
(times) => OH.createOhObject(<any>tagSource.data, times, tagSource.data["_country"], 1),
|
||||
[tagSource]
|
||||
(times) => OH.createOhObject(<any>tags.data, times, tags.data["_country"], 1),
|
||||
[tags]
|
||||
)
|
||||
return new VariableUiElement(
|
||||
times.map((times) => new SvelteUIElement(CollectionTimes, { times }))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue