Merge 10a60e072a into d25a827706
This commit is contained in:
commit
60588e9f8a
3 changed files with 99 additions and 0 deletions
File diff suppressed because one or more lines are too long
|
|
@ -72,6 +72,7 @@ type SeriesLabel struct {
|
||||||
// {b}: the name of a data item.
|
// {b}: the name of a data item.
|
||||||
// {c}: the value of a data item.
|
// {c}: the value of a data item.
|
||||||
// {d}: the percent of a data item(pie chart).
|
// {d}: the percent of a data item(pie chart).
|
||||||
|
// {e}: the value with commas of a data item
|
||||||
Formatter string
|
Formatter string
|
||||||
// The color for label
|
// The color for label
|
||||||
Color Color
|
Color Color
|
||||||
|
|
@ -306,6 +307,7 @@ func NewLabelFormatter(seriesNames []string, layout string) LabelFormatter {
|
||||||
percentText = humanize.FtoaWithDigits(percent*100, 2) + "%"
|
percentText = humanize.FtoaWithDigits(percent*100, 2) + "%"
|
||||||
}
|
}
|
||||||
valueText := humanize.FtoaWithDigits(value, 2)
|
valueText := humanize.FtoaWithDigits(value, 2)
|
||||||
|
valueTextWithCommas := humanize.CommafWithDigits(value, 2)
|
||||||
name := ""
|
name := ""
|
||||||
if len(seriesNames) > index {
|
if len(seriesNames) > index {
|
||||||
name = seriesNames[index]
|
name = seriesNames[index]
|
||||||
|
|
@ -313,6 +315,7 @@ func NewLabelFormatter(seriesNames []string, layout string) LabelFormatter {
|
||||||
text := strings.ReplaceAll(layout, "{c}", valueText)
|
text := strings.ReplaceAll(layout, "{c}", valueText)
|
||||||
text = strings.ReplaceAll(text, "{d}", percentText)
|
text = strings.ReplaceAll(text, "{d}", percentText)
|
||||||
text = strings.ReplaceAll(text, "{b}", name)
|
text = strings.ReplaceAll(text, "{b}", name)
|
||||||
|
text = strings.ReplaceAll(text, "{e}", valueTextWithCommas)
|
||||||
return text
|
return text
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -86,4 +86,9 @@ func TestFormatter(t *testing.T) {
|
||||||
"a",
|
"a",
|
||||||
"b",
|
"b",
|
||||||
}, "")(0, 10, 0.12))
|
}, "")(0, 10, 0.12))
|
||||||
|
|
||||||
|
assert.Equal("10,000.01", NewLabelFormatter([]string{
|
||||||
|
"a",
|
||||||
|
"b",
|
||||||
|
}, "{e}")(0, 10000.01, 0))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue