handsontable icon indicating copy to clipboard operation
handsontable copied to clipboard

Rewrite custom borders to use SVGs insead of DIVs

Open wojciechczerniak opened this issue 5 years ago • 23 comments

Description

Refactor DIV based border renderer to SVG one. The main reason behind this change is the performance of Handsontable instance with multiple cell borders. As a side effect, we've fixed a few long-standing issues with custom borders.

Oh, and they are now beautiful: obraz

This was huge and the results are amazing. Multiple tests were added. Tested on all popular web browsers.

Epic. Work was done within smaller issues.

To Do

  • [ ] New documentation for SVG borders, including styling
  • [ ] Migration guide from DIV borders to SVG ones, including styling/printing
  • [ ] Document all the breaking changes for release notes and blog post

Related issues

We should check those

  • [x] handsontable/handsontable#4142 Custom border on fixed row
  • [ ] ~#4859 Merged Cells + selection causes improper merge cell highlight~ (related to mergeCells)
  • [x] handsontable/handsontable#4940 The selection doesn't work with merged cells with fixed overlays
  • [x] handsontable/dev-handsontable#48 The fragmentSelection doesn't draw all the borders in some cases
  • [ ] ~#5245 More custom border styles~ (feature request, not included)
  • [x] handsontable/handsontable#5298 Printing custom borders
  • [x] handsontable/handsontable#5568 CustomBorders draws borders of width 2px+ incorrectly
  • [x] handsontable/handsontable#6052 Custom borders plugin hook calls grow exponentially with data size
  • [ ] ~#6063 Borders after insert row are not movedown~ (related to cellMeta handsontable/handsontable#6274)
  • [x] handsontable/handsontable#6064 Custom borders create many elements and operations in DOM
  • [ ] handsontable/handsontable#6392 If the table fits well within the viewport, border line is not drawn on an edge of an overlay
  • [ ] handsontable/handsontable#6453 Border priority of borders of the same size
  • [ ] handsontable/handsontable#6588 iOS: Borders are missing while editing a cell
  • [ ] handsontable/dev-handsontable#176 When we select half-shown columns the viewport does not scroll to the exact place to show all borders

Checklist

  • [x] Various widths: 1px, 2px, ..., 5px?
  • [x] Various colours
  • [x] Various combinations, thick with thin, vertical, horizontal
  • [x] Is it possible to print the border?
  • [x] Border spanned across rows / columns
  • [x] Each cell border different
  • [ ] Put the performance at test, create as many borders as possible
  • [x] Creating/removing borders from context menu
  • [x] Creating/removing borders from API
  • [x] How does it work with updateSettings?
  • [x] Can we change the styles with CSS?
  • [x] Do we have prformance lab test?
  • [x] How does it look like on Firefox, Safari, Chrome, Edge and IE
  • [ ] Performance with and without autoColumnSize
  • [ ] With different setting of scroll (System Preferences/General on MacOs)
  • [x] scrolling with the fixedBottomRows

wojciechczerniak avatar Nov 13 '19 21:11 wojciechczerniak

It should be easier to test the feature/PR with this related issue list and checklist @aninde. If you have anything to add/remove feel free.

CC @AMBudnik @warpech

wojciechczerniak avatar Nov 13 '19 21:11 wojciechczerniak

I would also add

  • resizing associated cells (+dbclick - quick resize)
  • undo/redo after scrolling /filtering /moving / resizing
  • in window scenarios (iframe)

and remember to check all the browsers and go locally ;)

AMBudnik avatar Nov 20 '19 14:11 AMBudnik

@wojciechczerniak @AMBudnik thank you very much for preparing the checklist. Also, I would like to check custom borders with:

  • overlapping customBorders
  • intersection customBorders
  • fixed/frozen rows/columns
  • contextMenu
  • dropdownMenu - expanded dropdown list
  • autofill
  • various overlays - top, left and all
  • nested rows and headers
  • collapsible columns
  • IME (Internationalization)
  • on iPad & on mobile

aninde avatar Nov 26 '19 13:11 aninde

Due to better readability I will report bugs related to svg branch here, not in PR. I use during testing Mac Magic Mouse with the ability to vertical and horizontal scrolling or laptop's trackpad with the same feature I don't click on the scrollbar, I don't want to lost focus on selection.

Case 1

Jumping selection https://github.com/handsontable/handsontable/pull/6157#issuecomment-559401554

Case 2

Leaking fill handle in overlay

Chrome, Safari, Firefox / MacOs Pro, Regression. Use the same setting as in demo https://jsfiddle.net/aninde/f30rjd6u/ cut fillhandle Firefox

Steps to reproduction

  1. Select fixed column B.
  2. Set viewport to be narrow to see horizontal and vertical scroll.
  3. Scroll it horizontally.

Result Notice that the blue square of fileHandle is rectangle, not square and is cutted while scrolling Expected result Should work as in 7.2.2. Should be square and stay with border of fixed column during scrolling.

Case 3

Overlaying right border on frozen columns while scrolling. Occurs on Chrome, Firefox, Opera, Microsoft Dev Edge / MacOs and very fast on safari, so it's hard to notice.

SVG Branch - Firefox 70, locally left-border-ff-svg

7.2.2 Firefox, jsfiddle selection7 2 2

Steps to reproduction

  1. Set viewport to be narrow to see horizontal and vertical scroll.
  2. Select one cell from column C, maybe C11.
  3. Scroll it horizontally with changed speed to the right and back to the left the faster when you are close to the end of the left margin of the site.

Result: Pink, the right border is overlaying fixed columns. Selection is doubled and moved. Expected result: Fixed/frozen columns should be on top.

Case 4

Overlaying top border on frozen rows while scrolling.

It works worst in the Firefox, but even in Chrome and Safari doesn't look good.

  1. Comment fixedColumnsLeft, uncomment fixedRowsTow in settings.
  2. Scroll it vertically with a trackpad, without clicking to change focus.
  3. The result is similar to the bug connected to fixedColumnsLeft/frozen columns.

Firefox SVG Branch fixedrowstop-ff-svg

Chrome SVG Branch fixedrowsTop-chrome-svg

EDIT: All cases described in this comment also occurs on IE/Real Edge/Firefox on Windows 10. This bug can be reproduced without a trackpad, only with a mouse with scroll-roundel by click and hold on scroll-roundel. scroll-mouse-ff

aninde avatar Nov 28 '19 10:11 aninde

Case 5

Border colors with spaces

customBorders are not rendering in any browser when there is space in color name https://jsfiddle.net/aninde/bfckronw/ 7.2.2 with svg borders

aninde avatar Dec 02 '19 12:12 aninde

Case 6

Border color order

https://github.com/handsontable/handsontable/issues/6453#issuecomment-560371785 the color order is not preserved.

aninde avatar Dec 02 '19 12:12 aninde

I'm not sure about the assumption with zooming and blurriness. On PR description was: The borders should looks sharp in every browser at 100% zoom level. They might be blurry at other zoom levels that are not multiplies of 100. I'm not sure that we met that assumption.

I wear glasses so I need someone with healthy eyes to look at it too. @jansiegel @budnix @AMBudnik can you double-check how selection and customBorders looks on zoom 125%, 150% and 200% on Chrome, Firefox, Safari, IE and Microsoft Edge? https://jsfiddle.net/aninde/6c2znt15/2/

Below, I paste print screens on the 150% zoom in and zoom into those print to see details. Sadly the blurriness is worse on Windows. Here is example from Edge. Screenshot 2019-12-02 at 15 49 27

Chrome/Mac OS 150% zoom chrome-150-svg Screenshot 2019-12-02 at 15 07 31

chrome-150-latest Screenshot 2019-12-02 at 15 07 03

aninde avatar Dec 02 '19 14:12 aninde

@aninde

The borders should looks sharp in every browser at 100% zoom level. They might be blurry at other zoom levels that are not multiplies of 100.

can you double-check how selection and customBorders looks on zoom 125%, 150% and 200% on Chrome, Firefox, Safari, IE and Microsoft Edge?

To me they look sharp at multiplies of 100, and a little blurry on other levels, just as @warpech stated in handsontable/handsontable#6157, at least on Chrome, Firefox and Safari.

jansiegel avatar Dec 02 '19 15:12 jansiegel

Summary of testing

Found:

  • [ ] https://github.com/handsontable/handsontable/pull/6157#issuecomment-559401554 Case 1: Jumping selection
  • [ ] https://github.com/handsontable/handsontable/issues/6467#issuecomment-559440649 ~Case 2: Leaking fill handle in overlay~ not regression
  • [ ] https://github.com/handsontable/handsontable/issues/6467#issuecomment-559440649 Case 3: Overlaying right border on frozen columns while scrolling
  • [ ] https://github.com/handsontable/handsontable/issues/6467#issuecomment-559440649 Case 4: Overlaying top border on frozen rows while scrolling
  • [ ] https://github.com/handsontable/handsontable/issues/6467#issuecomment-560370346 Case 5: Border colors with spaces
  • [ ] https://github.com/handsontable/handsontable/issues/6467#issuecomment-560372097 Case 6: Border color order

Fixed issues that they need to add tests to:

  • [ ] handsontable/handsontable#4142 Custom border on fixed row
  • [ ] handsontable/handsontable#4940 The selection doesn't work with merged cells with fixed overlays
  • [ ] handsontable/handsontable#5298 Printing custom borders with bootstrap css
  • [ ] handsontable/handsontable#5568 CustomBorders draws borders of width 2px+ incorrectly
  • [x] handsontable/dev-handsontable#48 The fragmentSelection doesn't draw all the borders in some cases

aninde avatar Dec 04 '19 09:12 aninde

@krzysztofspilka asked me for estimate how much time is needed to finish. Here are my pessimistic estimates (total: up to 9 days).

  • https://github.com/handsontable/handsontable/pull/6157#issuecomment-559401554 Case 1: Jumping selection
  • https://github.com/handsontable/handsontable/issues/6467#issuecomment-559440649 Case 3: Overlaying right border on frozen columns while scrolling
  • https://github.com/handsontable/handsontable/issues/6467#issuecomment-559440649 Case 4: Overlaying top border on frozen rows while scrolling

These are the occurences of the same problem: There is a race condition between border rendering and overlay positioning when main window serves as a scroll container. Additional problem, that seems to be related: in some Walkontable tests, I must call Walkontable.draw() twice to get the desired rendering. Work in progress to fix this is on the branch https://github.com/handsontable/handsontable/commits/feature/issue-6064-touch-overlays, but the further I get, the more I get entangled in quirks of overlay rendering. I might need 2-3 days for this.

  • https://github.com/handsontable/handsontable/issues/6467#issuecomment-559440649 Case 2: Leaking fill handle in overlay

This might take 1 day.

  • https://github.com/handsontable/handsontable/issues/6467#issuecomment-560370346 Case 5: Border colors with spaces

This might take 1 day.

  • https://github.com/handsontable/handsontable/issues/6467#issuecomment-560372097 Case 6: Border color order

This might take 1 day.

Fixed issues that they need to add tests to:

  • handsontable/handsontable#4142 Custom border on fixed row
  • handsontable/handsontable#4940 The selection doesn't work with merged cells with fixed overlays
  • handsontable/handsontable#5298 Printing custom borders with bootstrap css
  • handsontable/handsontable#5568 CustomBorders draws borders of width 2px+ incorrectly

Can we please move this out of scope of the PR https://github.com/handsontable/handsontable/pull/6157. My rough estimate is that it might take 1 day of work for each test.

warpech avatar Dec 04 '19 14:12 warpech

As said in point 2 of https://github.com/handsontable/handsontable/pull/6157 OP, the feature/issue-6064 branch removes the only way to restyle borders using CSS. Meaning: it will no longer be possible to set the border colors of current selection, area selection and fill area using CSS (demo: https://jsfiddle.net/kayw7e20/1/).

I am not sure of the severity of this. Was such possibility ever advertised in the docs? Are our customers using it? If yes, then I think we need to add a proper API for selection customization and explain the migration.

@wojciechczerniak, @krzysztofspilka WDYT?

warpech avatar Dec 16 '19 12:12 warpech

@warpech the demo in your comment is in the stable version 7.2.2 Screenshot 2019-12-16 at 14 43 09

This is how selection looks on your PR with changed CSS. Only square is changed. Is this in line with the assumptions? 7.2.2. v. with svg, 29.11.19 build. https://jsfiddle.net/aninde/4zkrvqgs/ Screenshot 2019-12-16 at 14 39 15

aninde avatar Dec 16 '19 13:12 aninde

This is how selection looks on your PR with changed CSS. Only square is changed. Is this in line with the assumptions?

It is in line with my assumptions, yes. I changed the CSS API of the "borders" but did not change the CSS API of the "corners".

warpech avatar Dec 16 '19 14:12 warpech

I am not sure of the severity of this. Was such possibility ever advertised in the docs? Are our customers using it? If yes, then I think we need to add a proper API for selection customization and explain the migration.

It was: https://handsontable.com/docs/1.17.0/tutorial-styling.html and was removed.

I don't have evidence for this, but it might be an important part of the customization process. Everything that is a part of the UI should be customizable in terms of color at least. In handsontable/handsontable#6538 @AMBudnik proposes a feature to keep this feature. I've found one question about it handsontable/handsontable#2487

wojciechczerniak avatar Dec 16 '19 14:12 wojciechczerniak

I don't have evidence for this, but it might be an important part of the customization process. Everything that is a part of the UI should be customizable in terms of color at least.

I made a small PR that implements this: https://github.com/handsontable/handsontable/pull/6593. However there is one pitfall (see in the PR's first comment).

warpech avatar Jan 02 '20 09:01 warpech

I made a big PR that fixes "Case 1", "Case 3" and "Case 4" explained in this issue: https://github.com/handsontable/handsontable/pull/6594

"Case 5" and "Case 6" were fixed in early December in https://github.com/handsontable/handsontable/pull/6157

@aninde are you sure that "Case 2" is a regression in the SVG borders branch? I think I can reproduce the same problem with 7.2.2 and 7.3.0.

warpech avatar Jan 02 '20 09:01 warpech

@warpech you are correct. "Case 2" it is not regression, it can be reproduced on 7+ version, my mistake.

aninde avatar Jan 02 '20 10:01 aninde

New issue explaining a problem discovered in the PR: https://github.com/handsontable/handsontable/issues/6626 (Selection on printed Handsontable)

aninde avatar Jan 08 '20 13:01 aninde

  1. ~The bottom border is doubled, it emerges from under the customBorder. This occurs when fixed rows are enabled.~ EDIT: This is out of Svg-borders scope, because it is not a regression. It's official bug, that I will report. testing 7.3.0.pdf

Screenshot 2020-01-08 at 14 21 30

without fixed rows this bug do not occur. Lack of the bottom border of colHeader is also in version 7.3.0, which is why I don't report it here. Screenshot 2020-01-08 at 14 25 40

aninde avatar Jan 08 '20 13:01 aninde

Excel does not print them. IMHO, it should not be visible on the print in Handsontable.

+1 on that. We should hide the rest of the selection and white rectangle that covers the grid.

But it's out of the scope so up to you.

Edit: not only custom border is doubled at the bottom:

obraz

wojciechczerniak avatar Jan 08 '20 14:01 wojciechczerniak

Keep in mind that the problem still exists that we cannot set custom styles for area selection, until the area selection was used. It is explained in more details in https://github.com/handsontable/handsontable/pull/6593#issue-358600499 (OP and the first comment by @aninde).

Edit: There's a new issue for that: https://github.com/handsontable/handsontable/issues/6656

Edit 2: https://github.com/handsontable/handsontable/issues/6656 is done.

warpech avatar Jan 15 '20 13:01 warpech

I closed the SVG borders PR https://github.com/handsontable/handsontable/pull/6157, becuase it got largely outdated. At some point, we will reimplement this on a fresh branch.

warpech avatar Jan 13 '22 14:01 warpech

Inform ZD

adrianszymanski89 avatar May 05 '22 14:05 adrianszymanski89