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

Set max width of the graph #193

Closed
jk171505 opened this issue Dec 19, 2015 · 2 comments
Closed

Set max width of the graph #193

jk171505 opened this issue Dec 19, 2015 · 2 comments

Comments

@jk171505
Copy link

Is this possible to set max width of the graph?

@thoussem
Copy link

any updates ??

@JensJI
Copy link

JensJI commented Jun 12, 2020

I had to implement this behaviour myself.
I needed to stretch the edges to the width of my "canvas".

Maybe you can be inspired by my code:

fitToScreenWithStretch() {
    let vm = this

    if (angular.element('#canvas').width() > vm.gWidth && vm.fitToScreen) {
    let uniqueX = []
    vm.g.nodes().forEach(function (node) {
        if (uniqueX.indexOf(vm.g.node(node).x) === -1) {
        uniqueX.push(vm.g.node(node).x)
        }
    })
    uniqueX.sort(function(a, b) {
        return a - b;
    })

    // Calcuate how much extra margin each node must have
    const extraMargin = (angular.element('#canvas').width() - vm.gWidth) / uniqueX.length
    vm.g.nodes().forEach(function (node) {
        if (angular.element('#' + node).attr('data-orig-left') === undefined) {
        angular.element('#' + node).attr('data-orig-left', parseInt($('#' + node).css('left')))
        }
        angular.element('#' + node).css(
        'left',
        parseInt(angular.element('#' + node).attr('data-orig-left'))+(extraMargin*uniqueX.indexOf(vm.g.node(node).x))
        )
    })
    } else {
    vm.g.nodes().forEach(function (node) {
        if (angular.element('#' + node).attr('data-orig-left') !== undefined) {
        angular.element('#' + node).css('left', parseInt(angular.element('#' + node).attr('data-orig-left')))
        }
    })

    }
    vm.instance.repaintEverything()
}

@jk171505 jk171505 closed this as completed Dec 4, 2021
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