fix: introduce individual spacing constant for legend
Legends need to use their individual text spacing - not use the Tick spacing. For vertical lists it looks a lot better to use a spacing of 10 instead of 20. Prior to this commit this couldn't be set in the defaults without also manipulating the axis tick spacing. Using their own constant, this can be now easily configured.
This commit is contained in:
parent
1288c8d48d
commit
6eff5912ca
2 changed files with 12 additions and 7 deletions
|
@ -58,6 +58,11 @@ const (
|
|||
// DefaultMinimumTickVerticalSpacing is the minimum distance between vertical ticks.
|
||||
DefaultMinimumTickVerticalSpacing = 20
|
||||
|
||||
// DefaultLegendHorizontalSpacing is the minimum distance between two horizontal elements in the legend.
|
||||
DefaultLegendHorizontalSpacing = 20
|
||||
// DefaultLegendVerticalSpacing is the minimum distance between two vertical elements in the legend.
|
||||
DefaultLegendVerticalSpacing = 10
|
||||
|
||||
// DefaultDateFormat is the default date format.
|
||||
DefaultDateFormat = "2006-01-02"
|
||||
// DefaultDateHourFormat is the date format for hour timestamp formats.
|
||||
|
|
14
legend.go
14
legend.go
|
@ -64,7 +64,7 @@ func Legend(c *Chart, userDefaults ...Style) Renderable {
|
|||
if len(labels[x]) > 0 {
|
||||
tb := r.MeasureText(labels[x])
|
||||
if labelCount > 0 {
|
||||
legendContent.Bottom += DefaultMinimumTickVerticalSpacing
|
||||
legendContent.Bottom += DefaultLegendVerticalSpacing
|
||||
}
|
||||
legendContent.Bottom += tb.Height()
|
||||
right := legendContent.Left + tb.Width() + lineTextGap + lineLengthMinimum
|
||||
|
@ -89,7 +89,7 @@ func Legend(c *Chart, userDefaults ...Style) Renderable {
|
|||
label = labels[x]
|
||||
if len(label) > 0 {
|
||||
if legendCount > 0 {
|
||||
ycursor += DefaultMinimumTickVerticalSpacing
|
||||
ycursor += DefaultLegendVerticalSpacing
|
||||
}
|
||||
|
||||
tb := r.MeasureText(label)
|
||||
|
@ -179,7 +179,7 @@ func LegendLineLeft(c *Chart, userDefaults ...Style) Renderable {
|
|||
if len(labels[x]) > 0 {
|
||||
tb := r.MeasureText(labels[x])
|
||||
if labelCount > 0 {
|
||||
legendContent.Bottom += DefaultMinimumTickVerticalSpacing
|
||||
legendContent.Bottom += DefaultLegendVerticalSpacing
|
||||
}
|
||||
legendContent.Bottom += tb.Height()
|
||||
right := legendContent.Left + tb.Width() + lineTextGap + lineLengthMinimum
|
||||
|
@ -204,7 +204,7 @@ func LegendLineLeft(c *Chart, userDefaults ...Style) Renderable {
|
|||
label = labels[x]
|
||||
if len(label) > 0 {
|
||||
if legendCount > 0 {
|
||||
ycursor += DefaultMinimumTickVerticalSpacing
|
||||
ycursor += DefaultLegendVerticalSpacing
|
||||
}
|
||||
|
||||
// Calculate text dimensions
|
||||
|
@ -329,7 +329,7 @@ func LegendThin(c *Chart, userDefaults ...Style) Renderable {
|
|||
r.LineTo(lx+lineLengthMinimum, ly)
|
||||
r.Stroke()
|
||||
|
||||
tx += textBox.Width() + DefaultMinimumTickHorizontalSpacing + lineTextGap + lineLengthMinimum
|
||||
tx += textBox.Width() + DefaultLegendHorizontalSpacing + lineTextGap + lineLengthMinimum
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -395,7 +395,7 @@ func LegendLeft(c *Chart, userDefaults ...Style) Renderable {
|
|||
if len(labels[x]) > 0 {
|
||||
tb := r.MeasureText(labels[x])
|
||||
if labelCount > 0 {
|
||||
legendContent.Bottom += DefaultMinimumTickVerticalSpacing
|
||||
legendContent.Bottom += DefaultLegendVerticalSpacing
|
||||
}
|
||||
legendContent.Bottom += tb.Height()
|
||||
right := legendContent.Left + tb.Width() + lineTextGap + lineLengthMinimum
|
||||
|
@ -420,7 +420,7 @@ func LegendLeft(c *Chart, userDefaults ...Style) Renderable {
|
|||
label = labels[x]
|
||||
if len(label) > 0 {
|
||||
if legendCount > 0 {
|
||||
ycursor += DefaultMinimumTickVerticalSpacing
|
||||
ycursor += DefaultLegendVerticalSpacing
|
||||
}
|
||||
|
||||
tb := r.MeasureText(label)
|
||||
|
|
Loading…
Reference in a new issue