-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
yaxis tick formatters #9065
yaxis tick formatters #9065
Conversation
I can't get the The currency formatting functionality is confusing. I can't get the example in the screenshot to work and the spec for toLocaleString says you need to know the 3 letter ISO 4217 currency code. Perhaps specifying the symbol, as in the screenshot, is a non-standard thing implemented in some other browser than Chrome? |
for currency you need to provide 3 letter ISO code that's correct. i changed that from original implementation. so to get euros i fixed the custom format. |
Should probably note in the help text for the |
i like that currency also adds the commas on the thousands and limits decimal places to 2 ... i'll add the information to help text. |
'bits/s': function (val, axis) { | ||
var labels = ['b/s','kb/s','mb/s','gb/s','tb/s','pb/s']; | ||
var index = 0; | ||
while (val > 1000 && index < labels.length) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The bit above lead me to another issue. When using the The logic for the 2nd chart can be cribbed from https://github.com/whatbox/jquery.flot.byte/blob/master/jquery.flot.byte.js I wouldn't necessarily use that plugin, but it does the right thing. |
i took the logic for generating byte ticks from the plugin you pointed me to. i kept just the basic part we need. |
Yay - thanx @ppisljar :) |
You need to take Also, as @simianhacker noted to me, you can get rid of all of the code in |
if (!tickFormatters[unitTokens[0]]) { | ||
throw new Error (`${units} is not a supported unit type.`); | ||
} | ||
myAxis.units = unitTokens; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the sake of API consistency and readability of the returned object, I'd rather see this returned as
{
"type": "someType",
"prefix": "foo",
"suffix": "bar"
}
return base * Math.floor(n / base); | ||
} | ||
|
||
function generateTicks(axis) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Break this function out and write tests for it
@@ -218,6 +260,16 @@ module.exports = function timechartFn(Private, config, $rootScope, timefilter, $ | |||
// best you can do is an empty string. Deal with it. | |||
if (objVal == null) return srcVal; | |||
}); | |||
|
|||
_.forEach(options.yaxes, yaxis => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This breaks 2nd y-axis functionality
i fixed most things you brought up but:
|
timelion doesnt have any tests for the browser part does it ? |
Timelion doesn't have tests for the browser stuff, but pulling out that function and adding tests for it shouldn't be much work. If you take it out of the file you can test it in isolation. There's a fair amount of logic there. edit: I see you added tests, solid. |
hey @rashidkpc yes tests are there, also i fixed the axis (its still partly broken due to that bug, but its not completely broken .... so this PR doesnt break it additionally, and once that bug is fixed it should work correctly). with numeral.js i don't seem to be able to do bits, bits/s, bytes/s and currency (in a way i do it now, where you just submit ISO currency code and it will auto format to match ... with numeral you can just add a sign there (which is tricky for chinese for example ... where on my keyboard is CNY sign ? ) ) or am i just not getting something ? |
This now seems to be broken completely unless I call at least one series with Also the currency formatter is currently broken. The On a side note, its funny you mention the Chinese yuan, since its an excellent example of lack of prefix standardization in currency. In China you would see ¥10.00, however the rest of the world uses '¥' to refer to the Japanese yen. The official name of the yuan is of course the renminbi, and you'll often see it abbreviated as RMB outside of China, eg RMB10.00. With this code we get Javascript's In any case, ISO 4217 provides a standard for something, so it'll have to do. |
Everything about this looks fine, with one exception. I'd like it to throw an error if the currency isn't either null (thus defaults to USD) or a 3 letter code, eg |
const threeLetterCode = /^[A-Za-z]{3}$/; | ||
const currency = unitTokens[1]; | ||
if (currency && !threeLetterCode.test(currency)) { | ||
throw new Error('Currency must be a three letter code'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a test
61e3c41
to
205df1c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got the following error on the server-console, when specifying a non-existant unit type:
Unhandled rejection Error: time is not a supported unit type.
at /home/thomas/repos/kibana/src/core_plugins/timelion/server/series_functions/yaxis.js:80:17
at /home/thomas/repos/kibana/src/core_plugins/timelion/server/lib/alter.js:22:17
at arrayMap (/home/thomas/repos/kibana/node_modules/lodash/index.js:1406:25)
at map (/home/thomas/repos/kibana/node_modules/lodash/index.js:6710:14)
at interceptor (/home/thomas/repos/kibana/node_modules/lodash/index.js:12240:26)
at thru (/home/thomas/repos/kibana/node_modules/lodash/index.js:5927:26)
at baseWrapperValue (/home/thomas/repos/kibana/node_modules/lodash/index.js:2768:30)
at LazyWrapper.lazyValue [as value] (/home/thomas/repos/kibana/node_modules/lodash/index.js:1077:16)
at baseWrapperValue (/home/thomas/repos/kibana/node_modules/lodash/index.js:2761:25)
at LodashWrapper.wrapperValue (/home/thomas/repos/kibana/node_modules/lodash/index.js:6124:14)
at /home/thomas/repos/kibana/src/core_plugins/timelion/server/lib/alter.js:23:18
at tryCatcher (/home/thomas/repos/kibana/node_modules/bluebird/js/main/util.js:26:23)
at Promise._settlePromiseFromHandler (/home/thomas/repos/kibana/node_modules/bluebird/js/main/promise.js:503:31)
at Promise._settlePromiseAt (/home/thomas/repos/kibana/node_modules/bluebird/js/main/promise.js:577:18)
at Promise._settlePromiseAtPostResolution (/home/thomas/repos/kibana/node_modules/bluebird/js/main/promise.js:244:10)
at Async._drainQueue (/home/thomas/repos/kibana/node_modules/bluebird/js/main/async.js:128:12)
at Async._drainQueues (/home/thomas/repos/kibana/node_modules/bluebird/js/main/async.js:133:10)
at Immediate.Async.drainQueues (/home/thomas/repos/kibana/node_modules/bluebird/js/main/async.js:15:14)
The problem is, I can no longer reproduce. These errors are usually gracefully handled (correctly IMO, I don't think we should spam the server with these types of errors).
Perhaps there is an edge-case slipping through the cracks somehow?
Otherwise, LGTM.
@thomasneirynck i cant reproduce it either. i followed the same pattern rest of timelion uses to throw errors and they usually don't show up in server log but in the client. @rashidkpc can you reproduce with static line ? something like |
eda3a0f
to
9852048
Compare
@ppisljar You happened to pick one of the rare values that doesn't cause the issue: I'm not sure if this is even fixable, but shipping with this bug seems really bad since it happens with 0, which is pretty common |
i was able to reproduce the bug ... but funny, not with same numbers as you ... for example with 0 it works for me. what about removing the custom option ? (its the only one causing the issue) |
9852048
to
f8c5b42
Compare
its fixed now @rashidkpc please take another look. |
f8c5b42
to
a338a1f
Compare
a338a1f
to
1928e6f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Backports PR #9065 **Commit 1:** yaxis tick formatters * Original sha: af24338 * Authored by ppisljar <[email protected]> on 2016-11-14T14:38:12Z **Commit 2:** fixing custom format * Original sha: 21dc660 * Authored by ppisljar <[email protected]> on 2016-11-14T18:21:59Z **Commit 3:** adding information to currency help text * Original sha: 6100b5f * Authored by ppisljar <[email protected]> on 2016-11-14T19:21:28Z **Commit 4:** fixing based on @rashidkpc review * Original sha: 2b07d6a * Authored by ppisljar <[email protected]> on 2016-11-15T09:23:10Z **Commit 5:** updating based on rashids comments * Original sha: 8bc012e * Authored by ppisljar <[email protected]> on 2016-11-17T09:06:51Z **Commit 6:** adding some tests * Original sha: cb8bfd5 * Authored by ppisljar <[email protected]> on 2016-11-17T10:06:02Z **Commit 7:** fixing broken yaxis * Original sha: c1a650c * Authored by ppisljar <[email protected]> on 2016-11-21T14:40:56Z **Commit 8:** fixing broken currency mode * Original sha: 38d5e12 * Authored by ppisljar <[email protected]> on 2016-11-21T14:41:16Z **Commit 9:** adding tick formatters tests * Original sha: f1f1847 * Authored by ppisljar <[email protected]> on 2016-11-21T14:43:18Z **Commit 10:** throw error if currency is not three letter code * Original sha: deaff2e * Authored by ppisljar <[email protected]> on 2016-11-23T10:10:45Z **Commit 11:** adding server side tests * Original sha: 1f900ac * Authored by ppisljar <[email protected]> on 2016-11-23T14:48:33Z **Commit 12:** fixing bytes mode * Original sha: ebe5a6a * Authored by ppisljar <[email protected]> on 2016-12-09T13:31:54Z **Commit 13:** rebasing on master and fixing linting * Original sha: f1c014d * Authored by ppisljar <[email protected]> on 2016-12-14T09:44:48Z **Commit 14:** fixing custom formatter behaviour. * Original sha: 1928e6f * Authored by ppisljar <[email protected]> on 2017-01-13T11:25:27Z
Backports PR #9065 **Commit 1:** yaxis tick formatters * Original sha: af24338 * Authored by ppisljar <[email protected]> on 2016-11-14T14:38:12Z **Commit 2:** fixing custom format * Original sha: 21dc660 * Authored by ppisljar <[email protected]> on 2016-11-14T18:21:59Z **Commit 3:** adding information to currency help text * Original sha: 6100b5f * Authored by ppisljar <[email protected]> on 2016-11-14T19:21:28Z **Commit 4:** fixing based on @rashidkpc review * Original sha: 2b07d6a * Authored by ppisljar <[email protected]> on 2016-11-15T09:23:10Z **Commit 5:** updating based on rashids comments * Original sha: 8bc012e * Authored by ppisljar <[email protected]> on 2016-11-17T09:06:51Z **Commit 6:** adding some tests * Original sha: cb8bfd5 * Authored by ppisljar <[email protected]> on 2016-11-17T10:06:02Z **Commit 7:** fixing broken yaxis * Original sha: c1a650c * Authored by ppisljar <[email protected]> on 2016-11-21T14:40:56Z **Commit 8:** fixing broken currency mode * Original sha: 38d5e12 * Authored by ppisljar <[email protected]> on 2016-11-21T14:41:16Z **Commit 9:** adding tick formatters tests * Original sha: f1f1847 * Authored by ppisljar <[email protected]> on 2016-11-21T14:43:18Z **Commit 10:** throw error if currency is not three letter code * Original sha: deaff2e * Authored by ppisljar <[email protected]> on 2016-11-23T10:10:45Z **Commit 11:** adding server side tests * Original sha: 1f900ac * Authored by ppisljar <[email protected]> on 2016-11-23T14:48:33Z **Commit 12:** fixing bytes mode * Original sha: ebe5a6a * Authored by ppisljar <[email protected]> on 2016-12-09T13:31:54Z **Commit 13:** rebasing on master and fixing linting * Original sha: f1c014d * Authored by ppisljar <[email protected]> on 2016-12-14T09:44:48Z **Commit 14:** fixing custom formatter behaviour. * Original sha: 1928e6f * Authored by ppisljar <[email protected]> on 2017-01-13T11:25:27Z
Ability to specify one of (bits,bits/s,bytes,bytes/s,currency,custom) unit formatters for y-axis labels.
based on elastic/timelion#99 thanks and credits to @pagenbag
Example below of :