Conversation
eventually. It allows configurability of density of ticks with the `Width`, and aims to be legible on a per-inch basis. Normally, if you set Width to be the same width you render the graph with, things should look good.
axis.go
Outdated
| } | ||
|
|
||
| if count > 20 { | ||
| os.Exit(0) |
There was a problem hiding this comment.
that's pretty ugly :)
at the very least, this should be a panic("plot: run away procedure").
There was a problem hiding this comment.
perhaps just return nil and document?
There was a problem hiding this comment.
woohaahh! that was just for debugging :) sorry it went through.. should just take that out.. if you have a sane time range, you won't be hitting that.
|
ok, first pass done :) looks interesting, thanks! |
axis.go
Outdated
|
|
||
| // Inspired by https://github.com/d3/d3-scale/blob/master/src/time.js | ||
| var tickIntervals = []tickRule{ | ||
| {time.Millisecond, |
There was a problem hiding this comment.
Don't break these over two lines.
|
Folks I'm so sorry to have submitted a half-baked PR like this. I was in a hurry and haven't gotten time to clean it up. I'll do it the moment things calm down over here. |
Simplified rules as timeWindow and durationPerInch were exactly the same in our implementation (it differed in d3's implementation, but we got rid of those diffs).
|
I am closing this, because we are cleaning up inactive pull requests. See https://groups.google.com/d/topic/gonum-dev/Dr8t8WdvB_4/discussion for more details. |
|
Folks, could we reopen this ? It's still valid.. don't know why it fell into the cracks.. I'm still using that and I'd be grateful to have it upstream ! |
kortschak
left a comment
There was a problem hiding this comment.
I think this probably wants an example.
| // adjust the number of ticks according to the specified Width. If | ||
| // not specified, Width defaults to 10 centimeters. | ||
| type TimeTicks struct { | ||
| // Width is the width of the underlying graph, used to calculate |
| {10 * year, "2006", "", "2006"}, | ||
| } | ||
|
|
||
| const month = 31 * 24 * time.Hour |
There was a problem hiding this comment.
These can be in a const block. Also, I'm sort of troubled by the choice of length of month; the marginally closer length is 30 days.
| // shown each time the timestamp goes over a certain boundary | ||
| // (verified through `watchFormat`). This way you can show `Sep 2, | ||
| // 12pm` when you pass midnight after `11pm` on `Sep 1`. | ||
| type tickRule struct { |
There was a problem hiding this comment.
This type does not need to exist. You can define tickRules on the anonymous struct.
| func (t TimeTicks) Ticks(min, max float64) []Tick { | ||
| width := t.Width | ||
| if width == 0 { | ||
| width = 10 * vg.Centimeter |
| // (verified through `watchFormat`). This way you can show `Sep 2, | ||
| // 12pm` when you pass midnight after `11pm` on `Sep 1`. | ||
| type tickRule struct { | ||
| durationPerInch time.Duration // use this rule for a maximum Duration per inch, it is also used as an interval per ticks. |
| durationPerInch := maxT.Sub(minT) / time.Duration(width/vg.Inch) | ||
|
|
||
| lastElement := len(tickRules) - 1 | ||
| rule := tickRules[lastElement] |
There was a problem hiding this comment.
Just use rule := tickRules[len(tickRules)-1] and similarly in the range.
| var ticks []Tick | ||
| for { | ||
| if delta > 0 { | ||
| // Count in Months now |
| if lastWatch == newWatch { | ||
| label = start.Format(rule.shortFormat) | ||
| } else { | ||
| //TODO: overwrite the first tick with the long form if we |
There was a problem hiding this comment.
s|//TODO: o|// TODO(name): O|
| label = start.Format(rule.shortFormat) | ||
| } else { | ||
| //TODO: overwrite the first tick with the long form if we | ||
| // haven't shown a lonform at all.. instead of always |
| want: []string{"2017", "2022", "2027", "2032", "2037", "2042", "2047"}, | ||
| }, | ||
| } { | ||
| //fmt.Println("For dates", test.min, test.max) |
Could probably be the default eventually.
It allows configurability of density of ticks with the
Width, and aimsto be legible on a per-inch basis. Normally, if you set Width to be
the same width you render the graph with, things should look good.
Check tests for a feel of what it would look like once rendered (for 4 inch-wide graph).