mirror of
https://github.com/tiennm99/ghstats.git
synced 2026-05-16 20:58:49 +00:00
cb502f2aa2
- Productive time is now a 24-hour bar chart with axes and nice tick labels instead of a 7x24 heatmap. Model Productive field reshaped from [7][24]int to [24]int. - Language cards render as donut charts with a left-side legend instead of a stacked bar. Slices beyond top-6 collapse into an "Other" row. - Add niceTicks helper (1/2/5 * 10^k ladder, d3-style) for axis ticks. - Legacy language_bar.go removed.
43 lines
990 B
Go
43 lines
990 B
Go
package card
|
||
|
||
import (
|
||
"math"
|
||
"strconv"
|
||
)
|
||
|
||
// niceTicks returns evenly-spaced tick values in [0, max] such that the step
|
||
// is a 1/2/5/10 × 10^k number and the tick count is roughly targetTicks.
|
||
//
|
||
// Mirrors d3.scaleLinear().nice() / d3.axisLeft().ticks(n) so charts built
|
||
// on top look visually consistent with the d3 reference.
|
||
func niceTicks(max float64, targetTicks int) []float64 {
|
||
if max <= 0 || targetTicks <= 0 {
|
||
return []float64{0}
|
||
}
|
||
rough := max / float64(targetTicks)
|
||
exp := math.Pow(10, math.Floor(math.Log10(rough)))
|
||
frac := rough / exp
|
||
var step float64
|
||
switch {
|
||
case frac < 1.5:
|
||
step = 1 * exp
|
||
case frac < 3:
|
||
step = 2 * exp
|
||
case frac < 7:
|
||
step = 5 * exp
|
||
default:
|
||
step = 10 * exp
|
||
}
|
||
|
||
out := []float64{}
|
||
for v := 0.0; v <= max+step/1e9; v += step {
|
||
out = append(out, v)
|
||
}
|
||
return out
|
||
}
|
||
|
||
// formatTick renders a float tick label. Integer-valued ticks drop decimals.
|
||
func formatTick(v float64) string {
|
||
return strconv.FormatFloat(v, 'f', -1, 64)
|
||
}
|