This repository has been archived by the owner on Nov 17, 2022. It is now read-only.
fix: unnecessary space on the left side #34
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This width is used to calculate the start of yAxis and things right to it.
TimDaub
reviewed
Nov 7, 2021
src/index.mjs
Outdated
|
|
||
| function getWidth(fontSize, dataPoints) { | ||
| const characterHeight = Number(fontSize) // This height is relative to viewbox and not in px | ||
| if(isNan(characterHeight)) throw new Error('Invalid fontSize') |
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 don't think isNan exists: https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/isNaN
|
Yeah, I meant isNaN.
…On Sun, 7 Nov 2021, 15:49 Tim Daubenschütz, ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/index.mjs
<#34 (comment)>
:
> @@ -398,3 +400,11 @@ export function generateLabelRange(min, max, numLabels) {
return labels;
}
+
+function getWidth(fontSize, dataPoints) {
+ const characterHeight = Number(fontSize) // This height is relative to viewbox and not in px
+ if(isNan(characterHeight)) throw new Error('Invalid fontSize')
I don't think isNan exists:
https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/isNaN
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#34 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABBDAI2RSMS6MDCEBDAIYHDUKZHCRANCNFSM5HP54LPQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
TimDaub
reviewed
Nov 9, 2021
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.
Declare magic constants as variables.
I tend to prefer e.g calling the padding you added in the return by what it is const padding = 2 and then later in the return use it.
TimDaub
reviewed
Nov 9, 2021
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.






Fixes #33
Solution:
The idea is to change the
offsetXvariable to the width of theyLabelinstead of using a fixed value. This width is not in absolute pixel but relative to the givenviewBox.The function
getWidthis based on the assumption that thefont-sizeis kind of the height of the character and the width is proportional to the height. I couldn't find any spec for this but based on my tests I think it true at least for our use case.I have tried inputting different values and the
getWidthfunction holds. (See Tim's comment)Note
Due to this line we cannot specify the
fontSizein em, cm or px.1.5pxwill throw an error.https://github.com/il3ven/svg-line-chart/blob/813b3d02812a968975d0eab28a6b006af0c2e146/src/index.mjs#L405
Do we need to normalize
1.5pxto1.5instead of throwing an error?