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

onrendered event not (immediately) fired after resize #1969

Closed
tjohannto opened this issue Mar 4, 2021 · 5 comments
Closed

onrendered event not (immediately) fired after resize #1969

tjohannto opened this issue Mar 4, 2021 · 5 comments
Labels

Comments

@tjohannto
Copy link

I am using the chart onrendered event to create a custom legend including values and ratios for Pie-charts.
These charts are exported to PDF/PNG or PPTx using canvg. For this export the charts are upscaled to a higher resolution than used on screen. During this upscaling via bb.resize() the onrendered event does not seem to be fired immediately. Then the legend looks odd ;)

If have created a fiddle to show the issue:
https://jsfiddle.net/c3egh71u/
(click export to canvas)

Is there any way to prevent this or a better (and working) solution?

@netil netil added the question label Mar 5, 2021
@netil
Copy link
Member

netil commented Mar 5, 2021

Hi @tjohannto

One of the possibility to apply is turn off the animation by:

  transition: {
    duration: 0
  },

And to make a customized legend, legend.contents.template looks more adequate, because you can make your own legend. Also, consider using .export() API to export as image.

@tjohannto
Copy link
Author

This does not work within my example.
updated: https://jsfiddle.net/c3egh71u/23/
I have tried using the config option in bb.generate() as well as bbChart.config('transition_duration', 0);
I wanted to avoid the usage of custom legends because this would lead to a massive redesign of the current dashboards, but I'll have a look now.
.export() is worth having a look though. are custom legends included in .export()?

thank you.

@netil
Copy link
Member

netil commented Mar 9, 2021

I haven't looked in very detail, try modifying redrawLegend() and add it as the .load() done option.

for (var i = 0; i < columns.length; i++) {
  if (i > 0) {
    setTimeout(function(column) {
      chart.load({
        columns: [
          columnData[column],
        ],
	done: redrawLegend
      });
    }, (i * 5000 / columnData.length), i);
  }
}

function redrawLegend() {
	chart.$.legend.selectAll("text")
		.filter(function() {
			return !this.querySelector("tspan");
		})
		.each(function() {
			const [id, value, ratio] = this.innerHTML.split(';');

			this.innerHTML = `
				<tspan class='id-row' text-anchor='start'>${id}:</tspan>
				<tspan class='value-row' x='100' text-anchor='end'>${value} = </tspan>
				<tspan class='ratio-row' x='130' text-anchor='end'>${ratio}</tspan>`;

			this.parentNode.querySelector("rect").setAttribute("width", 190);
  		});
  }

@tjohannto
Copy link
Author

tjohannto commented Mar 16, 2021

thx @netil
The issue is not on loading but on resizing. After calling chart.resize({height: 800, width: 1200}); I clone the svg node for export. This cloning (var svgEl = d3.select(svgContainer).select('svg').node(); var svgCopyEl = svgEl.cloneNode(true);) is done after calling the resize() function and in C3js this did work, but not in BBjs.

well, the workaround is to call the redrawLegend() function directly after calling resize()

netil added a commit to netil/billboard.js that referenced this issue Mar 18, 2021
Make to accept option to specify in different size.

Ref naver#815, naver#1969
netil added a commit that referenced this issue Mar 19, 2021
Make to accept option to specify in different size.

Close #815
Fix #1969
github-actions bot pushed a commit that referenced this issue Mar 19, 2021
# [3.0.0-next.3](3.0.0-next.2...3.0.0-next.3) (2021-03-19)

### Bug Fixes

* **axis:** fix axis.x.max error throw ([de06361](de06361)), closes [#1981](#1981)
* **axis:** fix axis.x.tick.tooltip on rotated axis ([eed2f86](eed2f86)), closes [#1990](#1990)
* **axis:** remove x axis transition during resize ([a938681](a938681)), closes [#1949](#1949)
* **tooltip:** fix linked tooltip recursive call ([b6af8ec](b6af8ec)), closes [#1979](#1979)
* **zoom:** fix zoom on latest chrome ([37edc9b](37edc9b)), closes [/github.com/d3/d3-zoom/issues/231#issuecomment-802305692](https://github.com//github.com/d3/d3-zoom/issues/231/issues/issuecomment-802305692) [#1992](#1992)

### Features

* **api:** Enhance .export() option to specify size ([3c2de80](3c2de80)), closes [#815](#815) [#1969](#1969)
@netil
Copy link
Member

netil commented Mar 19, 2021

@tjohannto, added new feature to export image as desired size.
So, there's no need to clone the node and doing export image process via canvas.

chart.export({
    width: 1200,
    height: 800
});
// will return image dataURL string

To use new feature, it needs to install next v3 version (v3 needs d3.js v6)

# install the next tagged version
npm i billboard.js@next

github-actions bot pushed a commit that referenced this issue Mar 26, 2021
# [3.0.0](2.2.6...3.0.0) (2021-03-26)

### Bug Fixes

* **axis:** fix axis.x.max error throw ([de06361](de06361)), closes [#1981](#1981)
* **axis:** fix axis.x.tick.tooltip on rotated axis ([eed2f86](eed2f86)), closes [#1990](#1990)
* **subchart:** fix duplicated node generation on data load ([d9a5d9a](d9a5d9a)), closes [#2003](#2003)
* **zoom:** fix zoom on latest chrome ([37edc9b](37edc9b)), closes [/github.com/d3/d3-zoom/issues/231#issuecomment-802305692](https://github.com//github.com/d3/d3-zoom/issues/231/issues/issuecomment-802305692) [#1992](#1992)

### Features

* **all:** update for d3 v6 ([2752e55](2752e55)), closes [#1641](#1641)
* **api:** Enhance .export() option to specify size ([3c2de80](3c2de80)), closes [#815](#815) [#1969](#1969)
* **api:** Intent to ship subchart APIs ([5572dc9](5572dc9)), closes [#1993](#1993)
* **candlestick:** Intent to ship candlestick ([8d37bd8](8d37bd8)), closes [#76](#76) [#1167](#1167)
* **candlestick:** Intent to ship candlestick type ([42307cb](42307cb))

### BREAKING CHANGES

* **all:** - Update to work on d3 v6
- Added getPoint() to get event's position coordinate

https://github.com/d3/d3/blob/master/CHANGES.md
https://observablehq.com/d/f91cccf0cad5e9cb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants