Skip to content
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

feat: add grid lines #1179

Open
wants to merge 12 commits into
base: dev
Choose a base branch
from
Open

Conversation

JulienDeveaux
Copy link

Implements #837

image
This is a grid_line_type of day for an hours_to_show of 730

README.md Outdated Show resolved Hide resolved
src/main.js Outdated Show resolved Hide resolved
src/main.js Outdated Show resolved Hide resolved
src/main.js Outdated Show resolved Hide resolved
src/main.js Outdated Show resolved Hide resolved
src/main.js Outdated Show resolved Hide resolved
src/main.js Outdated
return svg`
<svg width='100%' height=${height !== 0 ? '100%' : 0} viewBox='0 0 500 ${height}'
@click=${e => e.stopPropagation()}>
<g>
${grid_line_type ? this.renderGridLines() : ''}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably next "layers" will "overlay" the grid & make it less visible. I am thinking about drawing the grid AFTER these layers. But let's leave it this way & test...

Copy link
Author

Choose a reason for hiding this comment

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

I tried to move it around, but I don't see any visual changes to that

Copy link
Collaborator

Choose a reason for hiding this comment

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

don't see any visual changes to that

OK, we'll test it together

src/main.js Outdated Show resolved Hide resolved
src/main.js Outdated
const lines = [];

for (let i = 0; i < numLines; i += 1) {
const x = xRatio * (i + 0.5);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Assume we have hours_to_show=2 & grid_line_type=hour.
Then numLines = 2 & xRatio = 250.
Then we will have 2 lines - for 125 & 375, i.e. for hour=0.5 & hour=1.5.
And the 1st line will be "thin" (0 % 2 === 0), the 2nd line will be "thick" (1 % 2 = 1).
Not nice.
ALternatively we can make "thin" lines for "hour=0.5" & "hour=1.5", and "thick" line for "hour=1".
What do you think?
Also, can we turn a "frequency" - that "2" value - into an option like grid_line_????? to define which lines should be "thin"?

Copy link
Author

Choose a reason for hiding this comment

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

done

Copy link
Collaborator

Choose a reason for hiding this comment

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

We still have an issue here.
If hours_to_show = 2, we will get the left picture (thick line on 125, thin on 375), but we need to get the right picture (thick line on 250):
image

Copy link
Author

Choose a reason for hiding this comment

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

yeah that's the 0.5 in this line const x = xRatio * (i + 0.5);
If I remove it the first line is kinda hidden in the border and I find it wierd, that's why there is an offset

Copy link
Collaborator

Choose a reason for hiding this comment

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

I am trying now to adapt the algorithm to a fractional hours_to_show. For int values already made it, but for fractional more difficult story.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please check my addition below (currently last comment in the thread).

Copy link
Author

Choose a reason for hiding this comment

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

refactored

src/main.js Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
src/main.js Outdated Show resolved Hide resolved
src/main.js Outdated Show resolved Hide resolved
src/main.js Outdated Show resolved Hide resolved
src/main.js Outdated Show resolved Hide resolved
src/main.js Outdated Show resolved Hide resolved
src/main.js Outdated Show resolved Hide resolved
src/main.js Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@ildar170975
Copy link
Collaborator

@JulienDeveaux
The most difficult part is left - the algorithm itself.
Need some more time for thinking.
Thanks a lot for your work!

README.md Outdated Show resolved Hide resolved
src/main.js Outdated Show resolved Hide resolved
@ildar170975
Copy link
Collaborator

ildar170975 commented Dec 13, 2024

@JulienDeveaux
Please take this C-like code and refactor to JS:

    float spanInHours;
    
    switch (grid_lines_type) {
      case "5minute":
        spanInHours = float(1/12);
        break;
      case "hour":
        spanInHours = 1;
        break;
      case "day":
        spanInHours = 24;
        break;
      case "week":
        spanInHours = 168;
        break;
      default:
        spanInHours = 1;
    }

    float numLines = hours_to_show / spanInHours;
    float spanFactor = ceil(hours_to_show / spanInHours) / (hours_to_show / spanInHours);
    float thickPart = containerWidth * spanFactor / ceil(numLines);
    float thinPart = thickPart / float(grid_lines_ratio + 1);
    numLines = numLines * (grid_lines_ratio + 1);

    for (int i = 0; i < numLines - 1; i++) {
      float x = containerWidth - thinPart * (i + 1);
      //float timeLabel = hours_to_show / numLines * (i + 1);
	
      if ((i + 1) % (grid_lines_ratio + 1) > 0) {
        // draw thin
      } else {
        // draw thick
      }
    }

The code was tested locally.
Leave the "float timeLabel" line commented - we may need it in future if decide to draw labels on X-axis.

The code should be placed after this line:

    const containerWidth = 500;

till this last line:

return lines;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants