Implement equally sized bars#4994
Conversation
When `barThickness: undefined|null` (default), we compute an optimal sample size based on the smallest tick interval reduced to prevent any bar to overlap (bar equally sized). Also added support for a special `barThickness: 'flex'` value (previous default) that globally arranges bars side by side to prevent any gap when percentage options are 1 (variable bar sizes).
7e0ca21 to
98227b1
Compare
src/controllers/controller.bar.js
Outdated
| function computeFitSampleRange(index, ruler, options) { | ||
| var thickness = options.barThickness; | ||
| var count = ruler.stackCount; | ||
| var pixels = ruler.pixels; |
There was a problem hiding this comment.
You could probably inline pixels and curr since they are only used once. I think that should actually result in smaller minified code too
src/controllers/controller.bar.js
Outdated
| } | ||
|
|
||
| /** | ||
| * Computes the "ideal" sample range based on the absolute bar thickness or, if undefined or |
There was a problem hiding this comment.
It would help to explain what a sample range is and potentially why there are different fit and flex sample ranges
There was a problem hiding this comment.
Relates to the description from the docs, but that's actually not "sample" but "category". It was initially a range, but after some refactor, it's not anymore one: I will rename these 2 methods compute*CategoryTraits (though, I don't like the "category" term here).
|
Woohoo! This is awesome!! I think this will be the most exciting part of 2.8. Pretty great to kill 7 birds with 1 stone :-) |
|
Pulled and working as expected! Per my thread, I was working with financial data so I've got gaps for the weekend in time-series data. As you can see, there are appropriate spaces in the data, and the remaining bars are all equal sized. ... Edit for an additional test. So I added |
|
@btumbleson Thanks, good to hear that it solves your issue.
|
etimberg
left a comment
There was a problem hiding this comment.
Looks good to me. I think I can follow how it works. I haven't tested it yet to see all the cases
src/controllers/controller.bar.js
Outdated
| var prev, curr, i, ilen; | ||
|
|
||
| for (i = 0, ilen = pixels.length; i < ilen; ++i) { | ||
| min = i > 0 ? Math.min(min, pixels[i] - pixels[i - 1]) : min; |
There was a problem hiding this comment.
I think we can start this loop at 1 and then the ternary condition goes away
There was a problem hiding this comment.
Good catch, that was originally part of this loop (that's why i > 0), but forgot after moving it into a separate method.
|
I decided to go for image based unit tests because expectations are now more complicated to calculate and it doesn't seem a good practice to have complex logic in unit tests since this logic can also be bugged. |
|
Looks like Code Climate introduced a new maintainability check: Cognitive Complexity (never seen it before, maybe I missed it). Most of the codebase doesn't pass this check, I'm going to increase its threshold in another PR to align with the Cyclomatic Complexity (10 instead of 5). |
|
Good call on the image tests. |
|
@simonbrunel wow that's great!
When I have input data, say 1 per day, is it possible to fix bar thickness to |
|
It's not possible to explicitly set barThickness to 'day' (that would be a new feature). The bar thickness is computed based on the tick interval, so you will need to set |
When `barThickness: undefined|null` (default), we compute an optimal sample size based on the smallest tick interval reduced to prevent any bar to overlap (bar equally sized). Also added support for a special `barThickness: 'flex'` value (previous default) that globally arranges bars side by side to prevent any gap when percentage options are 1 (variable bar sizes).
|
Please also consider the issues I am having here as well. Thank you. |
|
Are the changes discussed above available publicly yet? |
|
You can build the master branch, its wfm |
|
I build it myself and worked perfectly. Here you can find how: Be sure, if on Windows, to run your Command Prompt as administrator! And install node and npm (npm is bundled with node) first if you don't have it already: |
When `barThickness: undefined|null` (default), we compute an optimal sample size based on the smallest tick interval reduced to prevent any bar to overlap (bar equally sized). Also added support for a special `barThickness: 'flex'` value (previous default) that globally arranges bars side by side to prevent any gap when percentage options are 1 (variable bar sizes).


When
barThickness: undefined|null(default), we compute an optimal sample size based on the smallest tick interval reduced to prevent any bar to overlap (bar equally sized). Added support for a specialbarThickness: 'flex'value (previous default) that globally arranges bars side by side to prevent any gap when percentage options are 1 (variable bar sizes).Tests: I didn't update failing ones yet since it's not trivial to adjust (computed) expectations with the new implementation. Will do it as soon as we reviewed and validated this PR.
@benmccann @Darkrender @GTDunk @btumbleson @eele94 @weequ @DurgpalSingh: can you guys checkout and test this PR with your specific use cases, and confirm that it works as expected.
/cc @nagix
Fixes #4666
Fixes #4745
Fixes #4758
Fixes #4825
Fixes #4855
Fixes #4907
Fixes #4983
Fixes #4938