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

Cancel open the node on click or make it can be controlled by click listener #182

Open
sliyoxn opened this issue Jul 14, 2021 · 3 comments

Comments

@sliyoxn
Copy link

sliyoxn commented Jul 14, 2021

update the zoom function in flamegraph.js

function zoom (d) {
        if (tooltip) tooltip.hide()
        const updateChart = () => {
            hideSiblings(d)
            show(d)
            fadeAncestors(d)
            update()
        }
        if (scrollOnZoom) {
            const chartOffset = svg._groups[0][0].parentNode.offsetTop
            const maxFrames = (window.innerHeight - chartOffset) / c
            const frameOffset = (d.height - maxFrames + 10) * c
            window.scrollTo({
                top: chartOffset + frameOffset,
                left: 0,
                behavior: 'smooth'
            })
        }
        if (typeof clickHandler === 'function') {
            if (clickHandler.length >= 2) {
                clickHandler(d, updateChart)
            } else {
                const res = clickHandler(d)
                if (res !== false) {
                    updateChart()
                }
            }
        } else {
            updateChart()
        }
    }

can use like this

var chart = flamegraph()
        .width(960)
        .cellHeight(18)
        .onClick(onClick);

function onClick(d, zoom) {

        if (window.event.ctrlKey) {
            history.pushState({id: d.id}, d.data.name, `#${d.id}`);
            zoom();
        } else {
            console.info(`Click on ${d.data.name}, id: "${d.id}"`, d);
        }

    }
@spiermar
Copy link
Owner

If I'm understanding this correctly, the goal for this is to make zoom optional? If that's the case, can you share more details about your use case. Zoom is a basic function for navigating flame graphs.

@Ilovetaxi
Copy link

update the zoom function in flamegraph.js


function zoom (d) {

        if (tooltip) tooltip.hide()

        const updateChart = () => {

            hideSiblings(d)

            show(d)

            fadeAncestors(d)

            update()

        }

        if (scrollOnZoom) {

            const chartOffset = svg._groups[0][0].parentNode.offsetTop

            const maxFrames = (window.innerHeight - chartOffset) / c

            const frameOffset = (d.height - maxFrames + 10) * c

            window.scrollTo({

                top: chartOffset + frameOffset,

                left: 0,

                behavior: 'smooth'

            })

        }

        if (typeof clickHandler === 'function') {

            if (clickHandler.length >= 2) {

                clickHandler(d, updateChart)

            } else {

                const res = clickHandler(d)

                if (res !== false) {

                    updateChart()

                }

            }

        } else {

            updateChart()

        }

    }

can use like this


var chart = flamegraph()

        .width(960)

        .cellHeight(18)

        .onClick(onClick);



function onClick(d, zoom) {



        if (window.event.ctrlKey) {

            history.pushState({id: d.id}, d.data.name, `#${d.id}`);

            zoom();

        } else {

            console.info(`Click on ${d.data.name}, id: "${d.id}"`, d);

        }



    }

@Ilovetaxi
Copy link

update the zoom function in flamegraph.js


function zoom (d) {

        if (tooltip) tooltip.hide()

        const updateChart = () => {

            hideSiblings(d)

            show(d)

            fadeAncestors(d)

            update()

        }

        if (scrollOnZoom) {

            const chartOffset = svg._groups[0][0].parentNode.offsetTop

            const maxFrames = (window.innerHeight - chartOffset) / c

            const frameOffset = (d.height - maxFrames + 10) * c

            window.scrollTo({

                top: chartOffset + frameOffset,

                left: 0,

                behavior: 'smooth'

            })

        }

        if (typeof clickHandler === 'function') {

            if (clickHandler.length >= 2) {

                clickHandler(d, updateChart)

            } else {

                const res = clickHandler(d)

                if (res !== false) {

                    updateChart()

                }

            }

        } else {

            updateChart()

        }

    }

can use like this


var chart = flamegraph()

        .width(960)

        .cellHeight(18)

        .onClick(onClick);



function onClick(d, zoom) {



        if (window.event.ctrlKey) {

            history.pushState({id: d.id}, d.data.name, `#${d.id}`);

            zoom();

        } else {

            console.info(`Click on ${d.data.name}, id: "${d.id}"`, d);

        }



    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants