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

Resizing a chart with huge legend draws the legend beyond the chart area #2650

Closed
creage opened this issue Apr 22, 2022 · 3 comments
Closed

Comments

@creage
Copy link

creage commented Apr 22, 2022

Description

When a legend has too many items (like 20, 30 etc.) - resizing a chart doesn't calculate the position/dimensions of the legend correctly, drawing it outside of the chart container.

Steps to check or reproduce

var chart = bb.generate({
  data: {
    columns: [
	["data1", 30, 200, 100, 400, 150, 250],
	["data2", 30, 200, 100, 400, 150, 250],
	["data3", 30, 200, 100, 400, 150, 250],
	["data4", 30, 200, 100, 400, 150, 250],
	["data5", 30, 200, 100, 400, 150, 250],
	["data6", 30, 200, 100, 400, 150, 250],
	["data7", 30, 200, 100, 400, 150, 250],
	["data8", 30, 200, 100, 400, 150, 250],
	["data9", 30, 200, 100, 400, 150, 250],
	["data10", 30, 200, 100, 400, 150, 250],
	["data11", 30, 200, 100, 400, 150, 250],
	["data12", 30, 200, 100, 400, 150, 250],
	["data13", 30, 200, 100, 400, 150, 250],
	["data14", 30, 200, 100, 400, 150, 250],
	["data15", 30, 200, 100, 400, 150, 250],
	["data16", 30, 200, 100, 400, 150, 250],
	["data17", 30, 200, 100, 400, 150, 250],
	["data18", 30, 200, 100, 400, 150, 250],
	["data19", 30, 200, 100, 400, 150, 250],
	["data20", 30, 200, 100, 400, 150, 250],
	["data21", 30, 200, 100, 400, 150, 250],
	["data22", 30, 200, 100, 400, 150, 250],
	["data23", 30, 200, 100, 400, 150, 250],
	["data24", 30, 200, 100, 400, 150, 250],
	["data25", 30, 200, 100, 400, 150, 250],
	["data26", 30, 200, 100, 400, 150, 250],
	["data27", 30, 200, 100, 400, 150, 250],
	["data28", 30, 200, 100, 400, 150, 250],
	["data29", 30, 200, 100, 400, 150, 250],
	["data30", 30, 200, 100, 400, 150, 250],
	["data31", 30, 200, 100, 400, 150, 250],
	["data32", 30, 200, 100, 400, 150, 250],
	["data33", 30, 200, 100, 400, 150, 250],
	["data34", 30, 200, 100, 400, 150, 250],
	["data35", 30, 200, 100, 400, 150, 250],
	["data36", 30, 200, 100, 400, 150, 250],
	["data37", 30, 200, 100, 400, 150, 250],
	["data38", 30, 200, 100, 400, 150, 250],
	["data39", 30, 200, 100, 400, 150, 250],
	["data40", 30, 200, 100, 400, 150, 250]
    ],
    type: "bar", // for ESM specify as: bar()
  },
  bar: {
    width: {
      ratio: 0.5
    }
  },
  bindto: "#barChart_1"
});
  • Try to resize window multiple times

Expected: Chart re-draws properly, according to window size
Actual: Sometimes legend overflows, leading to crops - on the screenshot below only first 31 legend items are drawn, the rest is not visible.
image

IMPORTANT: Redrawing the chart (destroying old one, and generating new) renders it as expected.

@netil netil added the question label Apr 26, 2022
@creage
Copy link
Author

creage commented Apr 27, 2022

@netil Any comments on that issue? Or maybe suggestions on how can we workaround it other than re-creating the widget entirely?

@netil
Copy link
Member

netil commented Apr 28, 2022

Hi @creage, IMO there're 2 issues here.

  • A. Buggy on determining legend area height during resize if has huge legend items.
  • B. Even the first(A) issue solved, when the viewport narrowed down, the chart area will shrink. Hence the chart isn't visible, which isn't a proper way to visualize data.

My recommendation is, if need to deal huge legend items, try use of legend.template.
This will make chart visible in any circumstances, and also make legend to be visible correctly.

Here is the example:

@creage
Copy link
Author

creage commented Apr 29, 2022

@netil I just wonder why does re-creating of the chart renders both chart and legend as expected, and resize - breaks the rendering. Can we have that part fixed please?

I don't want to render the legend manually - it puts another effort for calculating the legend dims.

@netil netil added bug and removed question labels May 4, 2022
netil added a commit to netil/billboard.js that referenced this issue Jun 2, 2022
Implement resize.timer option, where to give alternative option
for controlling timer trigger delay and use requestCallbackIdle()
instead.

Ref naver#2650
netil added a commit to netil/billboard.js that referenced this issue Jun 2, 2022
Implement resize.timer option, where to give alternative option
for controlling timer trigger delay and use requestIdleCallback()
instead.

Ref naver#2650
netil added a commit that referenced this issue Jun 2, 2022
Implement resize.timer option, where to give alternative option
for controlling timer trigger delay and use requestIdleCallback()
instead.

Ref #2650
netil added a commit to netil/billboard.js that referenced this issue Jun 7, 2022
Fix legend not resized properly during resize events

Ref naver#2650
netil added a commit to netil/billboard.js that referenced this issue Jun 8, 2022
Fix legend not resized properly during resize events

Ref naver#2650
@netil netil closed this as completed in 7df949b Jun 8, 2022
github-actions bot pushed a commit that referenced this issue Jun 9, 2022
# [3.5.0-next.1](3.4.1...3.5.0-next.1) (2022-06-09)

### Bug Fixes

* **bar:** fix bar radius for zero value ([9aa7579](9aa7579)), closes [#2642](#2642)
* **build:** Fix this keyword transpile ([b65531a](b65531a)), closes [#2671](#2671) [#2664](#2664) [#2665](#2665) [#2666](#2666) [#2667](#2667)
* **data:** Fix data label position on inverted axis ([b024d83](b024d83)), closes [#2700](#2700)
* **grid:** Fix y grid to show for log axis type ([d0b8cbd](d0b8cbd)), closes [#2710](#2710)
* **plugin:** fix sparkline dimension & tooltip ([79e1ab7](79e1ab7)), closes [#2682](#2682)
* **plugin:** fix stanford tooltip formatting ([9a87464](9a87464)), closes [#2657](#2657)
* **resize:** Fix legend resize ([7df949b](7df949b)), closes [#2650](#2650)
* **scale:** fix getting tickOffset ([3091677](3091677)), closes [#2669](#2669)
* **size.axis:** fix truncated axis when has no data ([40f4b66](40f4b66)), closes [#2675](#2675)
* **types:** Fix `Chart.load({ json })` typing ([1bd4f4a](1bd4f4a)), closes [#2711](#2711)
* **types:** Fix the signature of the tick format callback for timeseries ([c9c76e5](c9c76e5)), closes [#2676](#2676)
* **types:** Fix the type for options.data.names ([e64f6bd](e64f6bd)), closes [#2677](#2677)
* **types:** Fix types for the tooltip contents callback ([a0c0355](a0c0355)), closes [#2693](#2693)
* **zoom:** fix wheel zoom feeling "stuck" when panning past the edge ([50ed640](50ed640)), closes [#2588](#2588) [#2648](#2648)

### Features

* **data:** Intent to ship data.labels.rotate ([7b7ee08](7b7ee08)), closes [#2662](#2662)
* **module:** Support dual CJS/ESM package ([437c007](437c007)), closes [#2202](#2202)
* **plugin:** Intent to ship TableView plugin ([215b611](215b611)), closes [#1873](#1873)
* **resize:** Intent to ship resize.timer ([#2712](#2712)) ([0a07de0](0a07de0)), closes [#2650](#2650)
github-actions bot pushed a commit that referenced this issue Jun 30, 2022
# [3.5.0](3.4.1...3.5.0) (2022-06-30)

### Bug Fixes

* **bar:** fix bar radius for zero value ([9aa7579](9aa7579)), closes [#2642](#2642)
* **build:** Fix this keyword transpile ([b65531a](b65531a)), closes [#2671](#2671) [#2664](#2664) [#2665](#2665) [#2666](#2666) [#2667](#2667)
* **data:** Fix data label position on inverted axis ([b024d83](b024d83)), closes [#2700](#2700)
* **grid:** Fix y grid to show for log axis type ([d0b8cbd](d0b8cbd)), closes [#2710](#2710)
* **option:** Fix onresize/onresized call context ([3ef9684](3ef9684)), closes [#2726](#2726)
* **plugin, type:** fix TextOverlap type definition ([80cc3b7](80cc3b7))
* **plugin:** fix sparkline dimension & tooltip ([79e1ab7](79e1ab7)), closes [#2682](#2682)
* **plugin:** fix stanford tooltip formatting ([9a87464](9a87464)), closes [#2657](#2657)
* **resize:** Fix legend resize ([7df949b](7df949b)), closes [#2650](#2650)
* **scale:** fix getting tickOffset ([3091677](3091677)), closes [#2669](#2669)
* **size.axis:** fix truncated axis when has no data ([40f4b66](40f4b66)), closes [#2675](#2675)
* **types:** Fix `Chart.load({ json })` typing ([1bd4f4a](1bd4f4a)), closes [#2711](#2711)
* **types:** Fix the signature of the tick format callback for timeseries ([c9c76e5](c9c76e5)), closes [#2676](#2676)
* **types:** Fix the type for options.data.names ([e64f6bd](e64f6bd)), closes [#2677](#2677)
* **types:** Fix types for the tooltip contents callback ([a0c0355](a0c0355)), closes [#2693](#2693)
* **zoom:** fix wheel zoom feeling "stuck" when panning past the edge ([50ed640](50ed640)), closes [#2588](#2588) [#2648](#2648)

### Features

* **area:** add option to render area below line ([cf60291](cf60291)), closes [#2740](#2740) [#2741](#2741)
* **data:** Intent to ship data.labels.rotate ([7b7ee08](7b7ee08)), closes [#2662](#2662)
* **option:** Intent to ship boost.useCssRule ([4a060d6](4a060d6)), closes [#2716](#2716)
* **option:** Intent to ship boost.useWorker ([eeaf8bd](eeaf8bd))
* **resize:** Intent to ship resize.timer ([#2712](#2712)) ([0a07de0](0a07de0)), closes [#2650](#2650)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants