Skip to content

Commit c43f4d3

Browse files
committed
Add properties for Legend
Fixes #146
1 parent 9a2cd9f commit c43f4d3

File tree

3 files changed

+278
-8
lines changed

3 files changed

+278
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Add ``PointStyle#rectRounded`` #143 (@aripddev)
44
* Add ``BubbleDataset#pointStyle`` #144 (@aripddev)
55
* ``reverse`` property should be on the ``Scale`` object #145
6+
* Added all available properties for ``Legend``
67

78
## 1.3.0
89
* Allows creation of mixed charts #128

chartjs-java-model/src/main/java/software/xdev/chartjs/model/options/Legend.java

Lines changed: 173 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,18 @@ public class Legend
2626
{
2727
protected Boolean display;
2828
protected Position position;
29-
protected Boolean fullWidth;
29+
protected String align;
30+
protected Integer maxHeight;
31+
protected Integer maxWidth;
32+
protected Boolean fullSize;
3033
protected JavaScriptFunction onClick;
34+
protected JavaScriptFunction onHover;
35+
protected JavaScriptFunction onLeave;
36+
protected Boolean reverse;
3137
protected LegendLabels labels;
38+
protected Boolean rtl;
39+
protected String textDirection;
40+
protected LegendTitle title;
3241

3342
/**
3443
* @see #setDisplay(Boolean)
@@ -69,21 +78,74 @@ public Legend setPosition(final Legend.Position position)
6978
}
7079

7180
/**
72-
* @see #setFullWidth(Boolean)
81+
* @see #setAlign(String)
7382
*/
74-
public Boolean getFullWidth()
83+
public String getAlign()
7584
{
76-
return this.fullWidth;
85+
return this.align;
86+
}
87+
88+
/**
89+
* Default 'center'.
90+
* <p>
91+
* Alignment of the legend
92+
*/
93+
public Legend setAlign(final String align)
94+
{
95+
this.align = align;
96+
return this;
97+
}
98+
99+
/**
100+
* @see #setMaxHeight(Integer)
101+
*/
102+
public Integer getMaxHeight()
103+
{
104+
return this.maxHeight;
105+
}
106+
107+
/**
108+
* Maximum height of the legend, in pixels
109+
*/
110+
public Legend setMaxHeight(final Integer maxHeight)
111+
{
112+
this.maxHeight = maxHeight;
113+
return this;
114+
}
115+
116+
/**
117+
* @see #setMaxWidth(Integer)
118+
*/
119+
public Integer getMaxWidth()
120+
{
121+
return this.maxWidth;
122+
}
123+
124+
/**
125+
* Maximum width of the legend, in pixels
126+
*/
127+
public Legend setMaxWidth(final Integer maxWidth)
128+
{
129+
this.maxWidth = maxWidth;
130+
return this;
131+
}
132+
133+
/**
134+
* @see #setFullSize(Boolean)
135+
*/
136+
public Boolean getFullSize()
137+
{
138+
return this.fullSize;
77139
}
78140

79141
/**
80142
* Default {@code true}
81143
* <p>
82144
* Marks that this box should take the full width of the canvas (pushing down other boxes)
83145
*/
84-
public Legend setFullWidth(final Boolean fullWidth)
146+
public Legend setFullSize(final Boolean fullSize)
85147
{
86-
this.fullWidth = fullWidth;
148+
this.fullSize = fullSize;
87149
return this;
88150
}
89151

@@ -96,8 +158,6 @@ public JavaScriptFunction getOnClick()
96158
}
97159

98160
/**
99-
* Default {@code function(event, legendItem) {}}
100-
* <p>
101161
* A callback that is called when a click is registered on top of a label item
102162
*/
103163
public Legend setOnClick(final JavaScriptFunction onClick)
@@ -106,6 +166,59 @@ public Legend setOnClick(final JavaScriptFunction onClick)
106166
return this;
107167
}
108168

169+
/**
170+
* @see #setOnHover(JavaScriptFunction)
171+
*/
172+
public JavaScriptFunction getOnHover()
173+
{
174+
return this.onHover;
175+
}
176+
177+
/**
178+
* A callback that is called when a 'mousemove' event is registered on top of a label item
179+
*/
180+
public Legend setOnHover(final JavaScriptFunction onHover)
181+
{
182+
this.onHover = onHover;
183+
return this;
184+
}
185+
186+
/**
187+
* @see #setOnLeave(JavaScriptFunction)
188+
*/
189+
public JavaScriptFunction getOnLeave()
190+
{
191+
return this.onLeave;
192+
}
193+
194+
/**
195+
* A callback that is called when a 'mousemove' event is registered outside of a previously hovered label item
196+
*/
197+
public Legend setOnLeave(final JavaScriptFunction onLeave)
198+
{
199+
this.onLeave = onLeave;
200+
return this;
201+
}
202+
203+
/**
204+
* @see #setReverse(Boolean)
205+
*/
206+
public Boolean getReverse()
207+
{
208+
return this.reverse;
209+
}
210+
211+
/**
212+
* Default <code>false</code>
213+
* <p>
214+
* Legend will show datasets in reverse order
215+
*/
216+
public Legend setReverse(final Boolean reverse)
217+
{
218+
this.reverse = reverse;
219+
return this;
220+
}
221+
109222
/**
110223
* @see #setLabels(LegendLabels)
111224
*/
@@ -125,6 +238,58 @@ public Legend setLabels(final LegendLabels labels)
125238
return this;
126239
}
127240

241+
/**
242+
* @see #setRtl(Boolean)
243+
*/
244+
public Boolean getRtl()
245+
{
246+
return this.rtl;
247+
}
248+
249+
/**
250+
* <code>true</code> for rendering the legends from right to left
251+
*/
252+
public Legend setRtl(final Boolean rtl)
253+
{
254+
this.rtl = rtl;
255+
return this;
256+
}
257+
258+
/**
259+
* @see #setTextDirection(String)
260+
*/
261+
public String getTextDirection()
262+
{
263+
return this.textDirection;
264+
}
265+
266+
/**
267+
* This will force the text direction 'rtl' or 'ltr' on the canvas for rendering the legend, regardless of the css
268+
* specified on the canvas
269+
*/
270+
public Legend setTextDirection(final String textDirection)
271+
{
272+
this.textDirection = textDirection;
273+
return this;
274+
}
275+
276+
/**
277+
* @see #setTitle(LegendTitle)
278+
*/
279+
public LegendTitle getTitle()
280+
{
281+
return this.title;
282+
}
283+
284+
/**
285+
* @see LegendTitle
286+
*/
287+
public Legend setTitle(final LegendTitle title)
288+
{
289+
this.title = title;
290+
return this;
291+
}
292+
128293
public enum Position
129294
{
130295
TOP,
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package software.xdev.chartjs.model.options;
2+
3+
import software.xdev.chartjs.model.color.Color;
4+
import software.xdev.chartjs.model.options.layout.Padding;
5+
import software.xdev.chartjs.model.options.scales.Font;
6+
7+
8+
public class LegendTitle
9+
{
10+
protected Color color;
11+
protected Boolean display;
12+
protected Font font;
13+
protected Padding padding;
14+
protected String text;
15+
16+
/**
17+
* @see #setColor(Color)
18+
*/
19+
public Color getColor()
20+
{
21+
return this.color;
22+
}
23+
24+
/**
25+
* Default <code>Chart.defaults.color</code>
26+
* <p/>
27+
* Color of text
28+
*/
29+
public LegendTitle setColor(final Color color)
30+
{
31+
this.color = color;
32+
return this;
33+
}
34+
35+
/**
36+
* @see #setDisplay(Boolean)
37+
*/
38+
public Boolean getDisplay()
39+
{
40+
return this.display;
41+
}
42+
43+
/**
44+
* Default <code>false</code>
45+
* <p/>
46+
* Is the legend title displayed?
47+
*/
48+
public LegendTitle setDisplay(final Boolean display)
49+
{
50+
this.display = display;
51+
return this;
52+
}
53+
54+
/**
55+
* @see #setFont(Font)
56+
*/
57+
public Font getFont()
58+
{
59+
return this.font;
60+
}
61+
62+
/**
63+
* Default <code>Chart.defaults.font</code>
64+
*/
65+
public LegendTitle setFont(final Font font)
66+
{
67+
this.font = font;
68+
return this;
69+
}
70+
71+
/**
72+
* @see #setPadding(Padding)
73+
*/
74+
public Padding getPadding()
75+
{
76+
return this.padding;
77+
}
78+
79+
/**
80+
* Padding around the title
81+
*/
82+
public LegendTitle setPadding(final Padding padding)
83+
{
84+
this.padding = padding;
85+
return this;
86+
}
87+
88+
/**
89+
* @see #setText(String)
90+
*/
91+
public String getText()
92+
{
93+
return this.text;
94+
}
95+
96+
/**
97+
* The string title
98+
*/
99+
public LegendTitle setText(final String text)
100+
{
101+
this.text = text;
102+
return this;
103+
}
104+
}

0 commit comments

Comments
 (0)