d3-funnel icon indicating copy to clipboard operation
d3-funnel copied to clipboard

Change funnel orientation

Open rviquez opened this issue 10 years ago • 11 comments
trafficstars

Is there any way to change the funnel from a vertical view to a horizontal view? I haven't look into the code to check how that can be done but wanted to check first to see if there is any possibility to do this.

rviquez avatar Jul 16 '15 16:07 rviquez

There is no way to do this as it stands in the current implementation.

However, you can use SVG transformations to rotate the funnel. Assuming you wanted a left-to-right funnel, you could do the following after the funnel has been drawn:

d3.select('#funnel svg')
    .attr('transform', 'translate(0, ' + width + ')rotate(270)')
    .attr('width', height)
    .attr('height', width);

You can also rotate the labels such that they are oriented correctly. However, it's likely the text will overflow the block:

d3.selectAll('#funnel text').each(function () {
    var element = d3.select(this).attr(),
        x = element.attr('x'),
        y = element.attr('y');
    element.attr('transform', 'rotate(90, ' + x + ', ' + y + ')');
});

See complete example below:

https://jsfiddle.net/w8ch2c41/

jakezatecky avatar Jul 17 '15 00:07 jakezatecky

I am thinking about adding an option in a future release, such as the following:

{
    orientation: 'top-to-bottom',  // Default
    orientation: 'right-to-left',  // Opposite of most horizontal funnels
    orientation: 'bottom-to-top',  // Equivalent to `isInverted` option
    orientation: 'left-to-right'   // Most horizontal funnels
}

It might make sense to also allow a rotation degree (0 - 360). This would naturally complicate some of the math that goes on.

jakezatecky avatar Jul 17 '15 00:07 jakezatecky

Any word on the progress of this?

dearsaturn avatar Nov 25 '15 01:11 dearsaturn

@dearsaturn No recent progress on this. It is one of the more "doable" outstanding issues, so I might pick it up in the coming holidays when I have more availability.

jakezatecky avatar Nov 25 '15 03:11 jakezatecky

:100: happy holidays!

dearsaturn avatar Nov 25 '15 06:11 dearsaturn

While I could do a scale() then rotate(), that would really screw the dimensions of the text and look very bad. Will need to construct the resulting trapezoids according to a new paradigm and rotate the text as appropriate.

jakezatecky avatar Jan 16 '16 06:01 jakezatecky

Is there any way to divide funnel horizontally and vertically both? Please check the funnel digram designed by me. is this possible with d3. https://drive.google.com/file/d/0ByB4z_WuoNl0Wl9Kd2FINklJOUU/view?usp=sharing

amitb009 avatar Apr 21 '17 10:04 amitb009

@amitb009 That is a very interesting visualization. It could be supported in a future version, but is not quite on the horizon. It is a bit different than this issue, though, so it might make sense to create a new issue allowing for block partitions.

jakezatecky avatar Apr 24 '17 03:04 jakezatecky

Dear Jake, Thanks for the very nice work. However, I am not sure I understand - does the funnel chart already support orientation change or not?

iftahb avatar Oct 22 '18 13:10 iftahb

No, it does not. It is a high priority enhancement, however, and will be included in the next feature release (whenever that is).

jakezatecky avatar Oct 22 '18 17:10 jakezatecky