vega-embed icon indicating copy to clipboard operation
vega-embed copied to clipboard

Full screen action

Open domoritz opened this issue 7 years ago • 6 comments

It would be great to have an action to open a chart in full screen.

domoritz avatar Mar 01 '19 18:03 domoritz

I tried to develop this functionality for a project but I am not sure I chose the right solution. I first tried with addSignalListener but after couple of hours searching for examples did not succeed (I always receive an Unrecognized signal name error message). I then opted for an addEventListener and now my figure re-sizes when I double click on it.

  • Here is my html file <div #dsHist id="distanceHistogram"></div>

  • and the corresponding Angular code

ngAfterViewInit()   
{  
        let el: string = "#distanceHistogram";  
        let data: Array<{ distance_km: number }> = [];  
        for (let i = 0; i < 10000; i++) {  
            data.push({ distance_km: Math.floor(Math.random() * 100) });  
        }
       embed.default(el, {
            data: { values: data },
            mark: "bar",
            encoding: {
                x: {
                    field: "distance_km",
                    type: "quantitative",
                    title: "Distance (km)"
                },
                y: {
                    aggregate: "count",
                    type: "quantitative"
                }
            }
        })
            .then((res: embed.Result) => {    
                let view: vega.View = res.view;
                view.width(FullScreenTry02Component.WIDTH_PX);
                view.height(FullScreenTry02Component.HEIGHT_PX);

                view.addEventListener("dblclick", function (name, value) {
                    this._fullScreen = !this._fullScreen;
                    if (this._fullScreen) {
                        view.width(FullScreenTry02Component.WIDTH_PX_FULL_SCREEN);
                        view.height(FullScreenTry02Component.HEIGHT_PX_FULL_SCREEN);
                    }
                    else {
                        view.width(FullScreenTry02Component.WIDTH_PX);
                        view.height(FullScreenTry02Component.HEIGHT_PX);
                    }
                })
                return res.view.runAsync();
            })
            .then(v => {
                let view: vega.View = v;
            })
            .catch(function (err) {
                throw new Error(err);
            })
}

Now the figure re-sizes correctly when I double-click but I am not sure at all the solution I propose is correct. What's more I still do not know how to add a full screen icon as displayed in the figure below (peraphs should I use layers) ?

image

Any feedback will be greatly appreciated !

jmaFinistereVar avatar Apr 29 '19 15:04 jmaFinistereVar

My idea was to add another action to the Vega-Embed actions, which is independent of Vega signals. See https://github.com/vega/vega-embed/blob/1fcb4389fd95e6025fc308a6b5af6b3c92660c97/src/embed.ts#L323

domoritz avatar Apr 29 '19 21:04 domoritz

Closing since noone has asked for this yet.

domoritz avatar May 09 '20 01:05 domoritz

Doh; Apparently I missed the boat on this! I think this is a great idea, and would definitely use it! Please consider reopening.

Thanks!

metasoarous avatar Oct 04 '21 17:10 metasoarous

Wanna send a pull request? I'm happy to help with reviews.

domoritz avatar Oct 04 '21 18:10 domoritz

Maybe; LOL. It's not high priority for me right now, but I might consider working on it at some point.

How do you feel about reopening so that folks interested in contributing can find it more easily?

Thanks as always

metasoarous avatar Oct 04 '21 23:10 metasoarous