forked from MapComplete/MapComplete
Small fixes to OH visualization
This commit is contained in:
parent
4db1997ed6
commit
c9478c100a
5 changed files with 55 additions and 13 deletions
|
@ -27,7 +27,11 @@ export default class OpeningHoursVisualization extends UIElement {
|
|||
|
||||
const values = [[], [], [], [], [], [], []];
|
||||
|
||||
const iterator = oh.getIterator(from);
|
||||
const start = new Date(from);
|
||||
// We go one day more into the past, in order to force rendering of holidays in the start of the period
|
||||
start.setDate(from.getDate() - 1);
|
||||
|
||||
const iterator = oh.getIterator(start);
|
||||
|
||||
let prevValue = undefined;
|
||||
while (iterator.advance(to)) {
|
||||
|
@ -51,6 +55,10 @@ export default class OpeningHoursVisualization extends UIElement {
|
|||
// simply closed, nothing special here
|
||||
continue;
|
||||
}
|
||||
|
||||
if(value.startDate < from){
|
||||
continue;
|
||||
}
|
||||
// Get day: sunday is 0, monday is 1. We move everything so that monday == 0
|
||||
values[(value.startDate.getDay() + 6) % 7].push(value);
|
||||
}
|
||||
|
@ -233,11 +241,13 @@ export default class OpeningHoursVisualization extends UIElement {
|
|||
|
||||
let innerContent: string[] = [];
|
||||
|
||||
// Add the lines
|
||||
for (const changeMoment of changeHours) {
|
||||
const offset = 100 * (changeMoment - earliestOpen) / availableArea;
|
||||
innerContent.push(new FixedUiElement("").SetStyle(`left:${offset}%;`).SetClass("ohviz-line").Render())
|
||||
}
|
||||
|
||||
// Add the actual ranges
|
||||
for (const range of dayRanges) {
|
||||
if (!range.isOpen && !range.isSpecial) {
|
||||
innerContent.push(
|
||||
|
@ -256,6 +266,7 @@ export default class OpeningHoursVisualization extends UIElement {
|
|||
new FixedUiElement(range.comment).SetStyle(`left:${startPercentage}%; width:${width}%`).SetClass("ohviz-range").Render())
|
||||
}
|
||||
|
||||
// Add line for 'now'
|
||||
if (now >= 0 && now <= 100) {
|
||||
innerContent.push(new FixedUiElement("").SetStyle(`left:${now}%;`).SetClass("ohviz-now").Render())
|
||||
}
|
||||
|
|
|
@ -4,13 +4,26 @@ import {UIEventSource} from "../Logic/UIEventSource";
|
|||
|
||||
export default class SpecialVisualizations {
|
||||
|
||||
public static specialVisualizations: { funcName: string, constr: ((tagSource: UIEventSource<any>, argument: string) => UIElement) }[] =
|
||||
public static specialVisualizations: {
|
||||
funcName: string,
|
||||
constr: ((tagSource: UIEventSource<any>, argument: string[]) => UIElement),
|
||||
docs: string,
|
||||
args: {name: string, defaultValue: string, doc: string}[]
|
||||
}[] =
|
||||
|
||||
[{
|
||||
funcName: "opening_hours_table",
|
||||
constr: (tagSource: UIEventSource<any>, keyname) => {
|
||||
docs: "Creates an opening-hours table. Usage: {opening_hours_table(opening_hours)} to create a table of the tag 'opening_hours'.",
|
||||
args:[{name:"key", defaultValue: "opening_hours", doc: "The tag from which the table is constructed"}],
|
||||
constr: (tagSource: UIEventSource<any>, args) => {
|
||||
let keyname = args[0];
|
||||
if (keyname === undefined || keyname === "") {
|
||||
keyname = keyname ?? "opening_hours"
|
||||
}
|
||||
return new OpeningHoursVisualization(tagSource, keyname)
|
||||
}
|
||||
}]
|
||||
},
|
||||
|
||||
]
|
||||
|
||||
}
|
|
@ -518,7 +518,7 @@ export class TagRendering extends UIElement implements TagDependantUIElement {
|
|||
const knownSpecials : {funcName: string, constr: ((arg: string) => UIElement)}[]= SpecialVisualizations.specialVisualizations.map(
|
||||
special => ({
|
||||
funcName: special.funcName,
|
||||
constr: arg => special.constr(this.currentTags, arg)
|
||||
constr: arg => special.constr(this.currentTags, arg.split(","))
|
||||
})
|
||||
)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue