Skip to content

Commit c522d6b

Browse files
authored
Add TimeScale and TimeTicks to allow building linear time charts (#116)
* feat: add TimeScale and TimeTicks to allow building linear time charts * chore: codestyle Fixes #90
1 parent f08a95d commit c522d6b

File tree

4 files changed

+188
-0
lines changed

4 files changed

+188
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright © 2023 XDEV Software (https://xdev.software)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package software.xdev.chartjs.model.options.scales;
17+
18+
/**
19+
* Options for adapter for external date library if that adapter needs or supports options.
20+
*/
21+
public class ScaleAdapters
22+
{
23+
protected Object date;
24+
25+
public Object getDate()
26+
{
27+
return this.date;
28+
}
29+
30+
public ScaleAdapters setDate(final Object date)
31+
{
32+
this.date = date;
33+
return this;
34+
}
35+
}

chartjs-java-model/src/main/java/software/xdev/chartjs/model/options/scales/Time.java

+24
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ public class Time
7777
*/
7878
protected String unit;
7979

80+
/**
81+
* Default {@code 'millisecond'}
82+
*
83+
* @see #setMinUnit(String)
84+
*/
85+
protected String minUnit;
86+
8087
/**
8188
* Default {@code 1}
8289
*
@@ -222,6 +229,23 @@ public Time setUnit(final String unit)
222229
return this;
223230
}
224231

232+
/**
233+
* @see #setMinUnit(String)
234+
*/
235+
public String getMinUnit()
236+
{
237+
return this.minUnit;
238+
}
239+
240+
/**
241+
* The minimum display format to be used for a time unit.
242+
*/
243+
public Time setMinUnit(final String minUnit)
244+
{
245+
this.minUnit = minUnit;
246+
return this;
247+
}
248+
225249
/**
226250
* @see #setUnitStepSize(BigDecimal)
227251
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Copyright © 2023 XDEV Software (https://xdev.software)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package software.xdev.chartjs.model.options.scales;
17+
18+
import software.xdev.chartjs.model.options.ticks.TimeTicks;
19+
20+
21+
public class TimeScale extends Scale<TimeTicks, TimeScale>
22+
{
23+
/**
24+
* Default {@code "time"}
25+
*
26+
* @see #setType(String type)
27+
*/
28+
protected String type = "time";
29+
30+
protected Time time;
31+
32+
protected ScaleAdapters adapters;
33+
34+
/**
35+
* @see #setType(String type)
36+
*/
37+
public String getType()
38+
{
39+
return this.type;
40+
}
41+
42+
/**
43+
* As defined in Scales. Could be {@code "time"} or {@code "timeseries"}.
44+
*/
45+
public TimeScale setType(final String type)
46+
{
47+
this.type = type;
48+
return this;
49+
}
50+
51+
/**
52+
* @see #setTime(Time)
53+
*/
54+
public Time getTime()
55+
{
56+
return time;
57+
}
58+
59+
/**
60+
* As defined in Time.
61+
*/
62+
public TimeScale setTime(final Time time)
63+
{
64+
this.time = time;
65+
return this;
66+
}
67+
68+
/**
69+
* @see #setAdapters(ScaleAdapters)
70+
*/
71+
public ScaleAdapters getAdapters()
72+
{
73+
return adapters;
74+
}
75+
76+
/**
77+
* Options for adapter for external date library if that adapter needs or supports options.
78+
*/
79+
public TimeScale setAdapters(final ScaleAdapters adapters)
80+
{
81+
this.adapters = adapters;
82+
return this;
83+
}
84+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright © 2023 XDEV Software (https://xdev.software)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package software.xdev.chartjs.model.options.ticks;
17+
18+
public class TimeTicks extends Ticks<TimeTicks>
19+
{
20+
/**
21+
* Default {@code "auto"}
22+
*
23+
* @see #setSource(String type)
24+
*/
25+
protected String source;
26+
27+
/**
28+
* @see #setSource(String)
29+
*/
30+
public String getSource()
31+
{
32+
return this.source;
33+
}
34+
35+
/**
36+
* How ticks are generated, possible values are: 'auto' - generates "optimal" ticks based on scale size and time
37+
* options; 'data' - generates ticks from data (including labels from data {x|y} objects); 'labels' - generates
38+
* ticks from user given labels ONLY
39+
*/
40+
public TimeTicks setSource(final String source)
41+
{
42+
this.source = source;
43+
return this;
44+
}
45+
}

0 commit comments

Comments
 (0)