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

convert SVG in PowerPoint to shapes for Polar Chart is very large and off the chart #15863

Open
rignaldspan opened this issue Jun 8, 2021 · 7 comments

Comments

@rignaldspan
Copy link

rignaldspan commented Jun 8, 2021

We are implementing the new highcharts and something we use is to convert SVG in PowerPoint to shapes.
This works for most Highchart graphs but we have an issue with the polar chart.

Live demo with steps to reproduce

https://www.highcharts.com/demo/polar
Export to SVG and paste in PowerPoint and convert to Shapes but then it looks not correct and one shape is too big.

Product version

Highcharts 9.1.1

@raf18seb
Copy link
Contributor

Hi @rignaldspan and thank you for reporting the issue.

This is caused by the axis labels group's height which is, in case of this demo, over 10.000px:
image

@raf18seb
Copy link
Contributor

After further investigation, the height is over 10.000 because the last label is hidden by setting its y to -9999. This is intended behavior and shouldn't be considered as a bug.

However, the workaround is very simple: in the PowerPoint, after converting to Shapes, find the highest element, ungroup it, go on top of a page, find the highest labels elements (texts) and delete them:
PowerPoint shapes

@rignaldspan
Copy link
Author

rignaldspan commented Jun 22, 2021 via email

@raf18seb
Copy link
Contributor

@TorsteinHonsi is it possible to implement a different solution for axis labels in polar so there are no DOM elements with such a big height?

@TorsteinHonsi
Copy link
Collaborator

Good question. The practice of setting y: -9999 is a bit hacky, it would be better if we were able to use regular .hide() and .show() calls, and if there are problems with that, implement the fix in those functions instead.

Minimal demo

I have created a demo where we loop over the SVG's first level child elements to verify that the bounding boxes are way off the chart (literally): https://jsfiddle.net/highcharts/eq0cwjvz/

The issue does not only apply to polar charts. There are other situation where we use the same trick to hide labels, like with overflowing data labels: https://jsfiddle.net/highcharts/eq0cwjvz/1/

Workaround

A drop-in workaround is to remove all these elements before creating the export:

// Workaround for #15863, elements far off the chart in export
// causing bounding box trouble in PowerPoint
Highcharts.wrap(Highcharts.Chart.prototype, 'getChartHTML', proceed => {
	[].forEach.call(
    	this.container.querySelectorAll('g[transform], *[y="-9999"]'),
        element => {
			if (
            	element.getAttribute('y') === '-9999' ||
            	element.transform.baseVal[0].matrix.f <= -9999 // translate Y
            ) {
                element.remove();
            }
        });
    return proceed.call(this);
});

See it in action on jsFiddle.

@raf18seb I think we should try to remove all these cases of setting 'y', as it is a counterintuitive of hiding an element. We should try to use .show() and .hide() instead. One caveat to look out for is that for each time we do hide, we need to add a show() if the same element should be shown again. That is new, because with the y: -9999 hack, the element would automatically become visible when a valid y position was set.

If it turns out that this approach has unforeseen consequences, we need to implement some form of the workaound above in the exporting module.

@pawelfus
Copy link
Contributor

pawelfus commented Dec 6, 2021

Let me check this.

List of current -9999 translations:

  • - scrollbar.group
  • - axis.title
  • - SVGElement.hide(true) - hides by translation
  • - Data Labels (alignDataLabel method)
  • - Flag Series (Data Labels)
  • - Stack Labels
  • - tick.label
  • - Gantt: tick.labelIcon
  • - SVGElement.fadeOut() - apparently used by Tooltip
  • - SeriesLabel module
  • - imgs in IE11:
                        // Special case for SVGs on IE11, the width is not
                        // accessible until the image is part of the DOM
                        // (#2854).
  • - AreaRange & Draggable points: resizers are placed at -999 if low or high is not defined
  • - RangeSelector hides HTML inputs and the dropdown this way
  • - Annotations: Circle, Ellipse, Image, Label, Path, Rect and ControlPoints
  • - 3D columns are placed that way when outside the extremes
  • - Pie Series (Data Labels)

@pawellysy
Copy link
Member

Maybe a good idea would be to split this issue into multiple tickets?
@pawelfus @TorsteinHonsi

pawellysy pushed a commit that referenced this issue Apr 4, 2022
pawellysy pushed a commit that referenced this issue Apr 6, 2022
pawellysy pushed a commit that referenced this issue Apr 8, 2022
TorsteinHonsi pushed a commit that referenced this issue Apr 8, 2022
@pawellysy pawellysy removed their assignment Aug 8, 2023
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

6 participants