@@ -106,6 +106,9 @@ private LegendPosition getLegendPosition() {
106
106
107
107
private static final int DPI_DEFAULT = 96 ;
108
108
109
+ private static final String INTERPOLATION_LINEAR = "linear" ;
110
+ private static final String INTERPOLATION_STEP = "step" ;
111
+
109
112
private final Logger logger = LoggerFactory .getLogger (DefaultChartProvider .class );
110
113
111
114
private final ItemUIRegistry itemUIRegistry ;
@@ -130,20 +133,21 @@ public String getName() {
130
133
@ Override
131
134
public BufferedImage createChart (@ Nullable String serviceId , @ Nullable String theme , ZonedDateTime startTime ,
132
135
ZonedDateTime endTime , int height , int width , @ Nullable String items , @ Nullable String groups ,
133
- @ Nullable Integer dpiValue , @ Nullable Boolean legend )
136
+ @ Nullable Integer dpiValue , @ Nullable String interpolation , @ Nullable Boolean legend )
134
137
throws ItemNotFoundException , IllegalArgumentException {
135
- return createChart (serviceId , theme , startTime , endTime , height , width , items , groups , dpiValue , null , legend );
138
+ return createChart (serviceId , theme , startTime , endTime , height , width , items , groups , dpiValue , null ,
139
+ interpolation , legend );
136
140
}
137
141
138
142
@ Override
139
143
public BufferedImage createChart (@ Nullable String serviceId , @ Nullable String theme , ZonedDateTime startTime ,
140
144
ZonedDateTime endTime , int height , int width , @ Nullable String items , @ Nullable String groups ,
141
- @ Nullable Integer dpiValue , @ Nullable String yAxisDecimalPattern , @ Nullable Boolean legend )
142
- throws ItemNotFoundException , IllegalArgumentException {
145
+ @ Nullable Integer dpiValue , @ Nullable String yAxisDecimalPattern , @ Nullable String interpolation ,
146
+ @ Nullable Boolean legend ) throws ItemNotFoundException , IllegalArgumentException {
143
147
logger .debug (
144
- "Rendering chart: service: '{}', theme: '{}', startTime: '{}', endTime: '{}', width: '{}', height: '{}', items: '{}', groups: '{}', dpi: '{}', yAxisDecimalPattern: '{}', legend: '{}'" ,
148
+ "Rendering chart: service: '{}', theme: '{}', startTime: '{}', endTime: '{}', width: '{}', height: '{}', items: '{}', groups: '{}', dpi: '{}', yAxisDecimalPattern: '{}', interpolation: '{}', legend: '{}'" ,
145
149
serviceId , theme , startTime , endTime , width , height , items , groups , dpiValue , yAxisDecimalPattern ,
146
- legend );
150
+ interpolation , legend );
147
151
148
152
// If a persistence service is specified, find the provider, or use the default provider
149
153
PersistenceService service = (serviceId == null ) ? persistenceServiceRegistry .getDefault ()
@@ -188,8 +192,8 @@ public BufferedImage createChart(@Nullable String serviceId, @Nullable String th
188
192
// axis
189
193
styler .setAxisTickLabelsFont (chartTheme .getAxisTickLabelsFont (dpi ));
190
194
styler .setAxisTickLabelsColor (chartTheme .getAxisTickLabelsColor ());
191
- styler .setXAxisMin (( double ) startTime .toInstant ().toEpochMilli ());
192
- styler .setXAxisMax (( double ) endTime .toInstant ().toEpochMilli ());
195
+ styler .setXAxisMin (startTime .toInstant ().toEpochMilli ());
196
+ styler .setXAxisMax (endTime .toInstant ().toEpochMilli ());
193
197
int yAxisSpacing = Math .max (height / 10 , chartTheme .getAxisTickLabelsFont (dpi ).getSize ());
194
198
if (yAxisDecimalPattern != null ) {
195
199
styler .setYAxisDecimalPattern (yAxisDecimalPattern );
@@ -219,7 +223,7 @@ public BufferedImage createChart(@Nullable String serviceId, @Nullable String th
219
223
for (String itemName : itemNames ) {
220
224
Item item = itemUIRegistry .getItem (itemName );
221
225
if (addItem (chart , persistenceService , startTime , endTime , item , seriesCounter , chartTheme , dpi ,
222
- legendPositionDecider )) {
226
+ interpolation , legendPositionDecider )) {
223
227
seriesCounter ++;
224
228
}
225
229
}
@@ -233,7 +237,7 @@ public BufferedImage createChart(@Nullable String serviceId, @Nullable String th
233
237
if (item instanceof GroupItem groupItem ) {
234
238
for (Item member : groupItem .getMembers ()) {
235
239
if (addItem (chart , persistenceService , startTime , endTime , member , seriesCounter , chartTheme ,
236
- dpi , legendPositionDecider )) {
240
+ dpi , interpolation , legendPositionDecider )) {
237
241
seriesCounter ++;
238
242
}
239
243
}
@@ -307,7 +311,7 @@ private double convertData(State state) {
307
311
308
312
private boolean addItem (XYChart chart , QueryablePersistenceService service , ZonedDateTime timeBegin ,
309
313
ZonedDateTime timeEnd , Item item , int seriesCounter , ChartTheme chartTheme , int dpi ,
310
- LegendPositionDecider legendPositionDecider ) {
314
+ @ Nullable String interpolation , LegendPositionDecider legendPositionDecider ) {
311
315
Color color = chartTheme .getLineColor (seriesCounter );
312
316
313
317
// Get the item label
@@ -358,7 +362,9 @@ private boolean addItem(XYChart chart, QueryablePersistenceService service, Zone
358
362
for (HistoricItem historicItem : result ) {
359
363
// For 'binary' states, we need to replicate the data
360
364
// to avoid diagonal lines
361
- if (state instanceof OnOffType || state instanceof OpenClosedType ) {
365
+ if (state != null && INTERPOLATION_STEP .equals (interpolation )
366
+ || ((state instanceof OnOffType || state instanceof OpenClosedType )
367
+ && !INTERPOLATION_LINEAR .equals (interpolation ))) {
362
368
xData .add (Date .from (historicItem .getInstant ().minus (1 , ChronoUnit .MILLIS )));
363
369
yData .add (convertData (state ));
364
370
}
0 commit comments