Skip to content
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 3 commits into from Nov 9, 2021

Conversation

il3ven
Copy link
Contributor

@il3ven il3ven commented Nov 6, 2021

Fixes #33

Solution:

The idea is to change the offsetX variable to the width of the yLabel instead of using a fixed value. This width is not in absolute pixel but relative to the given viewBox.

The function getWidth is based on the assumption that the font-size is 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 getWidth function holds. (See Tim's comment)

Note

Due to this line we cannot specify the fontSize in em, cm or px. 1.5px will throw an error.
https://github.com/il3ven/svg-line-chart/blob/813b3d02812a968975d0eab28a6b006af0c2e146/src/index.mjs#L405

Do we need to normalize 1.5px to 1.5 instead of throwing an error?

This width is used to calculate the start of yAxis and things right to it.
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')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@il3ven
Copy link
Contributor Author

il3ven commented Nov 7, 2021 via email

@TimDaub
Copy link
Member

TimDaub commented Nov 8, 2021

I took a few screenshots to document the behavior under different conditions
Screen Shot 2021-11-08 at 15 56 18
Screen Shot 2021-11-08 at 15 56 38
Screen Shot 2021-11-08 at 15 57 30
Screen Shot 2021-11-08 at 15 57 43
Screen Shot 2021-11-08 at 15 59 50
Screen Shot 2021-11-08 at 15 58 56

I think it's a good approach. I'm happy if we continue with it.

@il3ven il3ven marked this pull request as ready for review November 8, 2021 20:42
Copy link
Member

@TimDaub TimDaub left a 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.

src/index.mjs Outdated Show resolved Hide resolved
src/index.mjs Outdated Show resolved Hide resolved
@TimDaub TimDaub merged commit 6027419 into rugpullindex:master Nov 9, 2021
2 checks passed
@il3ven il3ven deleted the whitespace branch November 9, 2021 10:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

chart reserves too much unnecessary space on the left side
2 participants