App-Netdisco

 view release on metacpan or  search on metacpan

share/public/javascripts/d3-force-network-chart.js  view on Meta::CPAN

     *
     *     example.maxZoomFactor(10);
     * @see {@link module:API.minZoomFactor}
     * @param {number} [value=5] - The new config value.
     * @returns {(number|Object)} The current config value if no parameter is given or the graph object for method chaining.
     */
    graph.maxZoomFactor = function(value) {
        if (!arguments.length) {
            return v.conf.maxZoomFactor;
        }
        v.conf.maxZoomFactor = value;
        if (v.status.graphReady) {
            graph.zoomMode(v.conf.zoomMode);
        }
        return graph;
    };

    /**
     * If the graph option `zoomMode` is set to true, then the graph is centered to the given position and scaled to the calculated scale factor (effective graph with / viewportWidth). The reason to have a viewportWidth instead of a scale factor is, ...
     *
     *     var node = example.nodeDataById('9999');
     *     example.zoom(node.x, node.y, node.radius * 6);
     * @see {@link module:API.zoomMode}
     * @see {@link module:API.zoomSmooth}
     * @see {@link module:API.minZoomFactor}
     * @see {@link module:API.maxZoomFactor}
     * @see {@link module:API.transform}
     * @param {number} [centerX=graph width / 2] - The horizontal center position.
     * @param {number} [centerY=graph height / 2] - The vertical center position.
     * @param {number} [viewportWidth=graph width] - The desired viewport width.
     * @returns {Object} The graph object for method chaining.
     */
    graph.zoom = function(centerX, centerY, viewportWidth) {
        graph.zoomSmooth(centerX, centerY, viewportWidth, 0);
        return graph;
    };

    /**
     * This method does the same as the zoom method - the difference is, that the zoom is animated in a nice way and there is a optional fourth parameter for the duration of the transition, which defaults to 1500ms. No `render` or `resume` call neede...
     *
     *     var node = example.nodeDataById('8888');
     *     example.zoomSmooth(node.x, node.y, node.radius * 6); // default duration of 1500ms
     *
     *     var node = example.nodeDataById('9999');
     *     example.zoomSmooth(node.x, node.y, node.radius * 6, 3000); // duration of 3000ms
     * @see {@link module:API.zoomMode}
     * @see {@link module:API.zoom}
     * @see {@link module:API.minZoomFactor}
     * @see {@link module:API.maxZoomFactor}
     * @see {@link module:API.transform}
     * @param {number} [centerX=graph width / 2] - The horizontal center position.
     * @param {number} [centerY=graph height / 2] - The vertical center position.
     * @param {number} [viewportWidth=graph width] - The desired viewport width.
     * @param {number} [duration=1500] - the duration of the transition
     * @returns {Object} The graph object for method chaining.
     */
    graph.zoomSmooth = function(centerX, centerY, viewportWidth, duration) {
        // http://bl.ocks.org/linssen/7352810
        var x, y, scale;
        var width = v.tools.getGraphWidth(); // could be different then configured (responsive)
        centerX = (isNaN(centerX) ? width / 2 : parseInt(centerX));
        centerY = (isNaN(centerY) ? v.conf.height / 2 : parseInt(centerY));
        viewportWidth = (isNaN(viewportWidth) ? width : parseInt(viewportWidth));
        duration = (isNaN(duration) ? 1500 : parseInt(duration));
        scale = width / viewportWidth;
        x = width / 2 - centerX * scale;
        y = v.conf.height / 2 - centerY * scale;
        v.main.interpolateZoom([x, y], scale, duration);
        return graph;
    };

    /**
     * Behaves like a normal getter/setter (the `zoom` and `zoomSmooth` methods implements only setters) and can be used in the conf object to initialize the graph with different translate values/scale factors than [0,0]/1. Works only, if the `zoomMo...
     *
     *     //example.zoomMode(true);
     *     example.transform({"translate":[100,100],"scale":0.5});
     * @see {@link module:API.zoomMode}
     * @see {@link module:API.zoom}
     * @see {@link module:API.zoomSmooth}
     * @param {Object} [transform={“translate”:[0,0],“scale”:1}] - The new config value.
     * @returns {Object} The current config value if no parameter is given or the graph object for method chaining.
     */
    graph.transform = function(transform) {
        if (!arguments.length) {
            return {
                "translate": v.main.zoom.translate(),
                "scale": v.main.zoom.scale()
            };
        } else {
            v.main.interpolateZoom(transform.translate, transform.scale, 0);
        }
        return graph;
    };

    /**
     * Helper/Command method - automatically zoom, so that the whole graph is visible and optimal sized. No `render` or `resume` call needed to take into effect:
     *
     *     example.zoomToFit();
     * @see {@link module:API.zoomMode}
     * @see {@link module:API.zoomSmooth}
     * @see {@link module:API.minZoomFactor}
     * @see {@link module:API.maxZoomFactor}
     * @see {@link module:API.transform}
     * @see {@link module:API.zoomToFitOnForceEnd}
     * @param {number} [duration=500] - The transition duration in milliseconds.
     * @returns {Object} The graph object for method chaining.
     */
    graph.zoomToFit = function(duration) {
        var svg = {},
            graph_, padding = 10,
            x, y, scale;
        duration = (isNaN(duration) ? 500 : parseInt(duration));
        svg.width = v.tools.getGraphWidth();
        svg.height = v.conf.height;
        graph_ = v.dom.graph.node().getBBox();
        scale = Math.min((svg.height - 2 * padding) / graph_.height,
            (svg.width - 2 * padding) / graph_.width);
        x = (svg.width - graph_.width * scale) / 2 - graph_.x * scale;
        y = (svg.height - graph_.height * scale) / 2 - graph_.y * scale;
        v.main.interpolateZoom([x, y], scale, duration);
        return graph;
    };

    /**
     * Automatically zoom at force end, so that the whole graph is visible and optimal sized. Needs a `resume` call to take into effect or must be set at initialization (before the graph starts). If enabled it fires at every force end event. If you o...
     *
     *     //running graph: change config
     *     example.zoomToFitOnForceEnd(true).resume();
     *     //alternative way without a resume call
     *     example.zoomToFitOnForceEnd(true).zoomToFit();
     *
     *     //running graph: resize only once
     *     example.zoomToFit();
     * @see {@link module:API.zoomMode}
     * @see {@link module:API.zoomSmooth}
     * @see {@link module:API.minZoomFactor}
     * @see {@link module:API.maxZoomFactor}
     * @see {@link module:API.transform}
     * @see {@link module:API.zoomToFit}
     * @param {boolean} [value=false] - The new config value.
     * @returns {(boolean|Object)} The current config value if no parameter is given or the graph object for method chaining.
     */
    graph.zoomToFitOnForceEnd = function(value) {
        if (!arguments.length) {
            return v.conf.zoomToFitOnForceEnd;
        }
        v.conf.zoomToFitOnForceEnd = value;
        if (v.status.graphStarted) {
            v.tools.createCustomizeWizardIfNotRendering();
        }
        return graph;
    };

    /**
     * If true, a loading indicator is shown when used as a APEX plugin during the AJAX calls. If you want to show the loading indicator in a standalone implementation you can show and hide the loading indicator directly with the API method `showLoad...
     *
     *     example.showLoadingIndicatorOnAjaxCall(false);
     * @see {@link module:API.showLoadingIndicator}
     * @param {boolean} [value=true] - The new config value.
     * @returns {(boolean|Object)} The current config value if no parameter is given or the graph object for method chaining.
     */
    graph.showLoadingIndicatorOnAjaxCall = function(value) {
        if (!arguments.length) {
            return v.conf.showLoadingIndicatorOnAjaxCall;
        }
        v.conf.showLoadingIndicatorOnAjaxCall = value;
        return graph;
    };

    /**
     * Helper method to directly show or hide a loading indicator. The APEX plugin do this implicitly on AJAX calls when the option `showLoadingIndicatorOnAjaxCall` is set to true. No `render` or `resume` call needed to take into effect:
     *



( run in 0.597 second using v1.01-cache-2.11-cpan-437f7b0c052 )