Skip to content

Commit

Permalink
Add LabelSkipCount to the YAxisOption, plus more tweaks
Browse files Browse the repository at this point in the history
This adds the `LabelSkipCount` configuration as a way to reduce the amount of y axis labels, while maintaining the same `LabelCount` number of horizontal lines.

As part of testing around this change it was found that the Unit parameter was not handled in the best way possible.  A long comment in charts.go decribes the circular relationship between the axis range and label count (particularly if a unit is configured).
  • Loading branch information
jentfoo committed Feb 8, 2024
1 parent 0a2c45c commit 27aba6e
Show file tree
Hide file tree
Showing 13 changed files with 356 additions and 205 deletions.
45 changes: 22 additions & 23 deletions axis.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,21 @@ type AxisOption struct {
Unit float64
// LabelCount is the number of labels to show on the axis. Specify a smaller number to reduce writing collisions. This value takes priority over Unit.
LabelCount int
// LabelSkipCount specifies a number of lines between labels where there will be no label,
// but a horizontal line will still be drawn.
LabelSkipCount int
}

func (a *axisPainter) Render() (Box, error) {
opt := a.opt
if isFalse(opt.Show) {
return BoxZero, nil
}
top := a.p
theme := opt.Theme
if theme == nil {
theme = top.theme
}
if isFalse(opt.Show) {
return BoxZero, nil
}

strokeWidth := opt.StrokeWidth
if strokeWidth == 0 {
Expand All @@ -99,14 +102,13 @@ func (a *axisPainter) Render() (Box, error) {
strokeColor = theme.GetAxisStrokeColor()
}

data := opt.Data
formatter := opt.Formatter
if len(formatter) != 0 {
for index, text := range data {
data[index] = strings.ReplaceAll(formatter, "{value}", text)
for index, text := range opt.Data {
opt.Data[index] = strings.ReplaceAll(formatter, "{value}", text)
}
}
dataCount := len(data)
dataCount := len(opt.Data)

centerLabels := !isFalse(opt.BoundaryGap)
isVertical := opt.Position == PositionLeft ||
Expand All @@ -130,7 +132,7 @@ func (a *axisPainter) Render() (Box, error) {
if isTextRotation {
top.SetTextRotation(opt.TextRotation)
}
textMaxWidth, textMaxHeight := top.MeasureTextMaxWidthHeight(data)
textMaxWidth, textMaxHeight := top.MeasureTextMaxWidthHeight(opt.Data)
if isTextRotation {
top.ClearTextRotation()
}
Expand Down Expand Up @@ -200,11 +202,11 @@ func (a *axisPainter) Render() (Box, error) {
labelCount := opt.LabelCount
if labelCount <= 0 {
var maxLabelCount int
// Add 10px for some minimal extra padding and calculate more suitable display item count on text width
// Add 10px and remove one for some minimal extra padding so that letters don't collide
if orient == OrientVertical {
maxLabelCount = top.Height() / (textMaxHeight + 10)
maxLabelCount = (top.Height() / (textMaxHeight + 10)) - 1
} else {
maxLabelCount = top.Width() / (textMaxWidth + 10)
maxLabelCount = (top.Width() / (textMaxWidth + 10)) - 1
}
if opt.Unit > 0 {
multiplier := 1.0
Expand All @@ -218,10 +220,6 @@ func (a *axisPainter) Render() (Box, error) {
}
} else {
labelCount = maxLabelCount
if ((dataCount/(labelCount-1))%5 == 0) || ((dataCount/(labelCount-1))%2 == 0) {
// prefer %5 or %2 units if reasonable
labelCount--
}
}
}
if labelCount > dataCount {
Expand Down Expand Up @@ -263,14 +261,15 @@ func (a *axisPainter) Render() (Box, error) {
Top: labelPaddingTop,
Right: labelPaddingRight,
})).MultiText(MultiTextOption{
First: opt.FirstAxis,
Align: textAlign,
TextList: data,
Orient: orient,
LabelCount: labelCount,
CenterLabels: centerLabels,
TextRotation: opt.TextRotation,
Offset: opt.LabelOffset,
First: opt.FirstAxis,
Align: textAlign,
TextList: opt.Data,
Orient: orient,
LabelCount: labelCount,
LabelSkipCount: opt.LabelSkipCount,
CenterLabels: centerLabels,
TextRotation: opt.TextRotation,
Offset: opt.LabelOffset,
})

if opt.SplitLineShow { // show auxiliary lines
Expand Down
2 changes: 1 addition & 1 deletion bar_chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (b *barChart) render(result *defaultRenderResult, seriesList SeriesList) (B
opt := b.opt
seriesPainter := result.seriesPainter

xRange := NewRange(b.p, seriesPainter.Width(), len(opt.XAxis.Data), 0.0, 0.0, 0.0)
xRange := NewRange(b.p, seriesPainter.Width(), len(opt.XAxis.Data), 0.0, 0.0, 0.0, 0.0)
x0, x1 := xRange.GetRange(0)
width := int(x1 - x0)
// margin between each block
Expand Down
2 changes: 1 addition & 1 deletion chart_option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func TestHorizontalBarRender(t *testing.T) {
require.NoError(t, err)
data, err := p.Bytes()
require.NoError(t, err)
assertEqualSVG(t, "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"600\" height=\"400\">\\n<path d=\"M 0 0\nL 600 0\nL 600 400\nL 0 400\nL 0 0\" style=\"stroke-width:0;stroke:none;fill:rgba(255,255,255,1.0)\"/><path d=\"M 214 29\nL 244 29\" style=\"stroke-width:3;stroke:rgba(84,112,198,1.0);fill:rgba(84,112,198,1.0)\"/><circle cx=\"229\" cy=\"29\" r=\"5\" style=\"stroke-width:3;stroke:rgba(84,112,198,1.0);fill:rgba(84,112,198,1.0)\"/><path d=\"\" style=\"stroke-width:3;stroke:rgba(84,112,198,1.0);fill:rgba(84,112,198,1.0)\"/><text x=\"246\" y=\"35\" style=\"stroke-width:0;stroke:none;fill:rgba(70,70,70,1.0);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">2011</text><path d=\"M 301 29\nL 331 29\" style=\"stroke-width:3;stroke:rgba(145,204,117,1.0);fill:rgba(145,204,117,1.0)\"/><circle cx=\"316\" cy=\"29\" r=\"5\" style=\"stroke-width:3;stroke:rgba(145,204,117,1.0);fill:rgba(145,204,117,1.0)\"/><path d=\"\" style=\"stroke-width:3;stroke:rgba(145,204,117,1.0);fill:rgba(145,204,117,1.0)\"/><text x=\"333\" y=\"35\" style=\"stroke-width:0;stroke:none;fill:rgba(70,70,70,1.0);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">2012</text><text x=\"20\" y=\"35\" style=\"stroke-width:0;stroke:none;fill:rgba(70,70,70,1.0);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">World Population</text><path d=\"M 93 55\nL 98 55\" style=\"stroke-width:1;stroke:rgba(110,112,121,1.0);fill:none\"/><path d=\"M 93 104\nL 98 104\" style=\"stroke-width:1;stroke:rgba(110,112,121,1.0);fill:none\"/><path d=\"M 93 153\nL 98 153\" style=\"stroke-width:1;stroke:rgba(110,112,121,1.0);fill:none\"/><path d=\"M 93 202\nL 98 202\" style=\"stroke-width:1;stroke:rgba(110,112,121,1.0);fill:none\"/><path d=\"M 93 251\nL 98 251\" style=\"stroke-width:1;stroke:rgba(110,112,121,1.0);fill:none\"/><path d=\"M 93 300\nL 98 300\" style=\"stroke-width:1;stroke:rgba(110,112,121,1.0);fill:none\"/><path d=\"M 93 350\nL 98 350\" style=\"stroke-width:1;stroke:rgba(110,112,121,1.0);fill:none\"/><path d=\"M 98 55\nL 98 350\" style=\"stroke-width:1;stroke:rgba(110,112,121,1.0);fill:none\"/><text x=\"47\" y=\"86\" style=\"stroke-width:0;stroke:none;fill:rgba(70,70,70,1.0);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">World</text><text x=\"48\" y=\"135\" style=\"stroke-width:0;stroke:none;fill:rgba(70,70,70,1.0);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">China</text><text x=\"54\" y=\"184\" style=\"stroke-width:0;stroke:none;fill:rgba(70,70,70,1.0);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">India</text><text x=\"58\" y=\"233\" style=\"stroke-width:0;stroke:none;fill:rgba(70,70,70,1.0);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">USA</text><text x=\"20\" y=\"282\" style=\"stroke-width:0;stroke:none;fill:rgba(70,70,70,1.0);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">Indonesia</text><text x=\"49\" y=\"332\" style=\"stroke-width:0;stroke:none;fill:rgba(70,70,70,1.0);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">Brazil</text><text x=\"98\" y=\"375\" style=\"stroke-width:0;stroke:none;fill:rgba(70,70,70,1.0);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">0</text><text x=\"190\" y=\"375\" style=\"stroke-width:0;stroke:none;fill:rgba(70,70,70,1.0);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">142.99k</text><text x=\"282\" y=\"375\" style=\"stroke-width:0;stroke:none;fill:rgba(70,70,70,1.0);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">285.99k</text><text x=\"375\" y=\"375\" style=\"stroke-width:0;stroke:none;fill:rgba(70,70,70,1.0);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">428.99k</text><text x=\"467\" y=\"375\" style=\"stroke-width:0;stroke:none;fill:rgba(70,70,70,1.0);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">571.98k</text><text x=\"504\" y=\"375\" style=\"stroke-width:0;stroke:none;fill:rgba(70,70,70,1.0);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">714.98k</text><path d=\"M 190 55\nL 190 350\" style=\"stroke-width:1;stroke:rgba(224,230,242,1.0);fill:none\"/><path d=\"M 282 55\nL 282 350\" style=\"stroke-width:1;stroke:rgba(224,230,242,1.0);fill:none\"/><path d=\"M 375 55\nL 375 350\" style=\"stroke-width:1;stroke:rgba(224,230,242,1.0);fill:none\"/><path d=\"M 467 55\nL 467 350\" style=\"stroke-width:1;stroke:rgba(224,230,242,1.0);fill:none\"/><path d=\"M 560 55\nL 560 350\" style=\"stroke-width:1;stroke:rgba(224,230,242,1.0);fill:none\"/><path d=\"M 98 305\nL 109 305\nL 109 323\nL 98 323\nL 98 305\" style=\"stroke-width:0;stroke:none;fill:rgba(84,112,198,1.0)\"/><path d=\"M 98 256\nL 112 256\nL 112 274\nL 98 274\nL 98 256\" style=\"stroke-width:0;stroke:none;fill:rgba(84,112,198,1.0)\"/><path d=\"M 98 207\nL 115 207\nL 115 225\nL 98 225\nL 98 207\" style=\"stroke-width:0;stroke:none;fill:rgba(84,112,198,1.0)\"/><path d=\"M 98 158\nL 162 158\nL 162 176\nL 98 176\nL 98 158\" style=\"stroke-width:0;stroke:none;fill:rgba(84,112,198,1.0)\"/><path d=\"M 98 109\nL 179 109\nL 179 127\nL 98 127\nL 98 109\" style=\"stroke-width:0;stroke:none;fill:rgba(84,112,198,1.0)\"/><path d=\"M 98 60\nL 486 60\nL 486 78\nL 98 78\nL 98 60\" style=\"stroke-width:0;stroke:none;fill:rgba(84,112,198,1.0)\"/><path d=\"M 98 326\nL 109 326\nL 109 344\nL 98 344\nL 98 326\" style=\"stroke-width:0;stroke:none;fill:rgba(145,204,117,1.0)\"/><path d=\"M 98 277\nL 112 277\nL 112 295\nL 98 295\nL 98 277\" style=\"stroke-width:0;stroke:none;fill:rgba(145,204,117,1.0)\"/><path d=\"M 98 228\nL 117 228\nL 117 246\nL 98 246\nL 98 228\" style=\"stroke-width:0;stroke:none;fill:rgba(145,204,117,1.0)\"/><path d=\"M 98 179\nL 172 179\nL 172 197\nL 98 197\nL 98 179\" style=\"stroke-width:0;stroke:none;fill:rgba(145,204,117,1.0)\"/><path d=\"M 98 130\nL 180 130\nL 180 148\nL 98 148\nL 98 130\" style=\"stroke-width:0;stroke:none;fill:rgba(145,204,117,1.0)\"/><path d=\"M 98 81\nL 517 81\nL 517 99\nL 98 99\nL 98 81\" style=\"stroke-width:0;stroke:none;fill:rgba(145,204,117,1.0)\"/></svg>", string(data))
assertEqualSVG(t, "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"600\" height=\"400\">\\n<path d=\"M 0 0\nL 600 0\nL 600 400\nL 0 400\nL 0 0\" style=\"stroke-width:0;stroke:none;fill:rgba(255,255,255,1.0)\"/><path d=\"M 214 29\nL 244 29\" style=\"stroke-width:3;stroke:rgba(84,112,198,1.0);fill:rgba(84,112,198,1.0)\"/><circle cx=\"229\" cy=\"29\" r=\"5\" style=\"stroke-width:3;stroke:rgba(84,112,198,1.0);fill:rgba(84,112,198,1.0)\"/><path d=\"\" style=\"stroke-width:3;stroke:rgba(84,112,198,1.0);fill:rgba(84,112,198,1.0)\"/><text x=\"246\" y=\"35\" style=\"stroke-width:0;stroke:none;fill:rgba(70,70,70,1.0);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">2011</text><path d=\"M 301 29\nL 331 29\" style=\"stroke-width:3;stroke:rgba(145,204,117,1.0);fill:rgba(145,204,117,1.0)\"/><circle cx=\"316\" cy=\"29\" r=\"5\" style=\"stroke-width:3;stroke:rgba(145,204,117,1.0);fill:rgba(145,204,117,1.0)\"/><path d=\"\" style=\"stroke-width:3;stroke:rgba(145,204,117,1.0);fill:rgba(145,204,117,1.0)\"/><text x=\"333\" y=\"35\" style=\"stroke-width:0;stroke:none;fill:rgba(70,70,70,1.0);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">2012</text><text x=\"20\" y=\"35\" style=\"stroke-width:0;stroke:none;fill:rgba(70,70,70,1.0);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">World Population</text><path d=\"M 93 55\nL 98 55\" style=\"stroke-width:1;stroke:rgba(110,112,121,1.0);fill:none\"/><path d=\"M 93 104\nL 98 104\" style=\"stroke-width:1;stroke:rgba(110,112,121,1.0);fill:none\"/><path d=\"M 93 153\nL 98 153\" style=\"stroke-width:1;stroke:rgba(110,112,121,1.0);fill:none\"/><path d=\"M 93 202\nL 98 202\" style=\"stroke-width:1;stroke:rgba(110,112,121,1.0);fill:none\"/><path d=\"M 93 251\nL 98 251\" style=\"stroke-width:1;stroke:rgba(110,112,121,1.0);fill:none\"/><path d=\"M 93 300\nL 98 300\" style=\"stroke-width:1;stroke:rgba(110,112,121,1.0);fill:none\"/><path d=\"M 93 350\nL 98 350\" style=\"stroke-width:1;stroke:rgba(110,112,121,1.0);fill:none\"/><path d=\"M 98 55\nL 98 350\" style=\"stroke-width:1;stroke:rgba(110,112,121,1.0);fill:none\"/><text x=\"47\" y=\"86\" style=\"stroke-width:0;stroke:none;fill:rgba(70,70,70,1.0);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">World</text><text x=\"48\" y=\"135\" style=\"stroke-width:0;stroke:none;fill:rgba(70,70,70,1.0);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">China</text><text x=\"54\" y=\"184\" style=\"stroke-width:0;stroke:none;fill:rgba(70,70,70,1.0);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">India</text><text x=\"58\" y=\"233\" style=\"stroke-width:0;stroke:none;fill:rgba(70,70,70,1.0);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">USA</text><text x=\"20\" y=\"282\" style=\"stroke-width:0;stroke:none;fill:rgba(70,70,70,1.0);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">Indonesia</text><text x=\"49\" y=\"332\" style=\"stroke-width:0;stroke:none;fill:rgba(70,70,70,1.0);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">Brazil</text><text x=\"98\" y=\"375\" style=\"stroke-width:0;stroke:none;fill:rgba(70,70,70,1.0);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">0</text><text x=\"190\" y=\"375\" style=\"stroke-width:0;stroke:none;fill:rgba(70,70,70,1.0);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">142.99k</text><text x=\"282\" y=\"375\" style=\"stroke-width:0;stroke:none;fill:rgba(70,70,70,1.0);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">285.99k</text><text x=\"375\" y=\"375\" style=\"stroke-width:0;stroke:none;fill:rgba(70,70,70,1.0);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">428.99k</text><text x=\"467\" y=\"375\" style=\"stroke-width:0;stroke:none;fill:rgba(70,70,70,1.0);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">571.99k</text><text x=\"504\" y=\"375\" style=\"stroke-width:0;stroke:none;fill:rgba(70,70,70,1.0);font-size:15.3px;font-family:'Roboto Medium',sans-serif\">714.98k</text><path d=\"M 190 55\nL 190 350\" style=\"stroke-width:1;stroke:rgba(224,230,242,1.0);fill:none\"/><path d=\"M 282 55\nL 282 350\" style=\"stroke-width:1;stroke:rgba(224,230,242,1.0);fill:none\"/><path d=\"M 375 55\nL 375 350\" style=\"stroke-width:1;stroke:rgba(224,230,242,1.0);fill:none\"/><path d=\"M 467 55\nL 467 350\" style=\"stroke-width:1;stroke:rgba(224,230,242,1.0);fill:none\"/><path d=\"M 560 55\nL 560 350\" style=\"stroke-width:1;stroke:rgba(224,230,242,1.0);fill:none\"/><path d=\"M 98 305\nL 109 305\nL 109 323\nL 98 323\nL 98 305\" style=\"stroke-width:0;stroke:none;fill:rgba(84,112,198,1.0)\"/><path d=\"M 98 256\nL 112 256\nL 112 274\nL 98 274\nL 98 256\" style=\"stroke-width:0;stroke:none;fill:rgba(84,112,198,1.0)\"/><path d=\"M 98 207\nL 115 207\nL 115 225\nL 98 225\nL 98 207\" style=\"stroke-width:0;stroke:none;fill:rgba(84,112,198,1.0)\"/><path d=\"M 98 158\nL 162 158\nL 162 176\nL 98 176\nL 98 158\" style=\"stroke-width:0;stroke:none;fill:rgba(84,112,198,1.0)\"/><path d=\"M 98 109\nL 179 109\nL 179 127\nL 98 127\nL 98 109\" style=\"stroke-width:0;stroke:none;fill:rgba(84,112,198,1.0)\"/><path d=\"M 98 60\nL 486 60\nL 486 78\nL 98 78\nL 98 60\" style=\"stroke-width:0;stroke:none;fill:rgba(84,112,198,1.0)\"/><path d=\"M 98 326\nL 109 326\nL 109 344\nL 98 344\nL 98 326\" style=\"stroke-width:0;stroke:none;fill:rgba(145,204,117,1.0)\"/><path d=\"M 98 277\nL 112 277\nL 112 295\nL 98 295\nL 98 277\" style=\"stroke-width:0;stroke:none;fill:rgba(145,204,117,1.0)\"/><path d=\"M 98 228\nL 117 228\nL 117 246\nL 98 246\nL 98 228\" style=\"stroke-width:0;stroke:none;fill:rgba(145,204,117,1.0)\"/><path d=\"M 98 179\nL 172 179\nL 172 197\nL 98 197\nL 98 179\" style=\"stroke-width:0;stroke:none;fill:rgba(145,204,117,1.0)\"/><path d=\"M 98 130\nL 180 130\nL 180 148\nL 98 148\nL 98 130\" style=\"stroke-width:0;stroke:none;fill:rgba(145,204,117,1.0)\"/><path d=\"M 98 81\nL 517 81\nL 517 99\nL 98 99\nL 98 81\" style=\"stroke-width:0;stroke:none;fill:rgba(145,204,117,1.0)\"/></svg>", string(data))
}

func TestPieRender(t *testing.T) {
Expand Down
53 changes: 43 additions & 10 deletions charts.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const labelFontSize = 10
const smallLabelFontSize = 8
const defaultDotWidth = 2.0
const defaultStrokeWidth = 2.0
const defaultAxisLabelCount = 10
const defaultYAxisLabelCount = 10

var defaultChartWidth = 600
var defaultChartHeight = 400
Expand Down Expand Up @@ -160,28 +160,61 @@ func defaultRender(p *Painter, opt defaultRenderOption) (*defaultRenderResult, e
if len(opt.YAxisOptions) > index {
yAxisOption = opt.YAxisOptions[index]
}
padRange := 1.0
minPadRange, maxPadRange := 1.0, 1.0
if yAxisOption.RangeValuePaddingScale != nil {
minPadRange = *yAxisOption.RangeValuePaddingScale
maxPadRange = *yAxisOption.RangeValuePaddingScale
}
min, max := opt.SeriesList.GetMinMax(index)
if yAxisOption.Min != nil && *yAxisOption.Min < min {
padRange = 0.0
min = *yAxisOption.Min
minPadRange = 0.0
}
if yAxisOption.Max != nil && *yAxisOption.Max > max {
padRange = 0.0
max = *yAxisOption.Max
maxPadRange = 0.0
}
if yAxisOption.RangeValuePaddingScale != nil {
padRange = *yAxisOption.RangeValuePaddingScale
}

// Label counts and y-axis padding are linked together to produce a user-friendly graph.
// First when considering padding we want to prefer a zero axis start if reasonable, and add a slight
// padding to the max so there is a little space at the top of the graph. In addition, we want to pick
// a max value that will result in round intervals on the axis. These details are in range.go.
// But in order to produce round intervals we need to have an idea of how many intervals there are.
// In addition, if the user specified a `Unit` value we may need to adjust our label count calculation
// based on the padded range.
//
// In order to accomplish this, we estimate the label count (if necessary), pad the range, then precisely
// calculate the label count.
// TODO - label counts are also calculated in axis.go, for the X axis, ideally we unify these implementations
labelCount := yAxisOption.LabelCount
padLabelCount := labelCount
if padLabelCount < 1 {
if yAxisOption.Unit > 0 {
padLabelCount = int((max-min)/yAxisOption.Unit) + 1
} else {
padLabelCount = defaultYAxisLabelCount
}
}
// we call padRange directly because we need to do this padding before we can calculate the final labelCount for the axisRange
min, max = padRange(padLabelCount, min, max, minPadRange, maxPadRange)
if labelCount <= 0 {
if yAxisOption.Unit > 0 {
labelCount = int((max - min) / yAxisOption.Unit)
if yAxisOption.Max == nil {
max = math.Trunc(math.Ceil(max/yAxisOption.Unit) * yAxisOption.Unit)
}
labelCount = int((max-min)/yAxisOption.Unit) + 1
} else {
labelCount = defaultAxisLabelCount
labelCount = defaultYAxisLabelCount
}
yAxisOption.LabelCount = labelCount
}
r := axisRange{
p: p,
divideCount: labelCount,
min: min,
max: max,
size: rangeHeight,
}
r := NewRange(p, rangeHeight, labelCount, min, max, padRange)
result.axisRanges[index] = r

if yAxisOption.Theme == nil {
Expand Down
2 changes: 1 addition & 1 deletion horizontal_bar_chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (h *horizontalBarChart) render(result *defaultRenderResult, seriesList Seri
theme := opt.Theme

min, max := seriesList.GetMinMax(0)
xRange := NewRange(p, seriesPainter.Width(), len(seriesList[0].Data), min, max, 1.0)
xRange := NewRange(p, seriesPainter.Width(), len(seriesList[0].Data), min, max, 1.0, 1.0)
seriesNames := seriesList.Names()

rendererList := []Renderer{}
Expand Down
Loading

0 comments on commit 27aba6e

Please sign in to comment.