The visible range of the timeline is limited in this demo.
<h:form id="form">
<p:timeline value="#{limitTimelineRangeView.model}"
min="#{limitTimelineRangeView.min}"
max="#{limitTimelineRangeView.max}"
zoomMin="#{limitTimelineRangeView.zoomMin}"
zoomMax="#{limitTimelineRangeView.zoomMax}"
height="180px" />
</h:form>
package org.primefaces.showcase.view.data.timeline;
import jakarta.annotation.PostConstruct;
import jakarta.faces.view.ViewScoped;
import jakarta.inject.Named;
import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalDateTime;
import io.quarkus.runtime.annotations.RegisterForReflection;
import org.primefaces.model.timeline.TimelineEvent;
import org.primefaces.model.timeline.TimelineModel;
@Named("limitTimelineRangeView")
@ViewScoped
@RegisterForReflection(serialization = true)
public class LimitTimelineRangeView implements Serializable {
private TimelineModel<String, ?> model;
private LocalDateTime min;
private LocalDateTime max;
private long zoomMin;
private long zoomMax;
@PostConstruct
public void init() {
model = new TimelineModel<>();
model.add(TimelineEvent.<String>builder().data("First").startDate(LocalDate.of(2015, 5, 25)).build());
model.add(TimelineEvent.<String>builder().data("Last").startDate(LocalDate.of(2015, 5, 26)).build());
// lower limit of visible range
min = LocalDate.of(2015, 1, 1).atStartOfDay();
// upper limit of visible range
max = LocalDate.of(2015, 12, 31).atStartOfDay();
// one day in milliseconds for zoomMin
zoomMin = 1000L * 60 * 60 * 24;
// about three months in milliseconds for zoomMax
zoomMax = 1000L * 60 * 60 * 24 * 31 * 3;
}
public TimelineModel<String, ?> getModel() {
return model;
}
public LocalDateTime getMin() {
return min;
}
public LocalDateTime getMax() {
return max;
}
public long getZoomMin() {
return zoomMin;
}
public long getZoomMax() {
return zoomMax;
}
}