public set configuration()

in packages/network-navigator/src/NetworkNavigator.ts [206:272]


    public set configuration(newConfig: INetworkNavigatorConfiguration) {
        newConfig = $.extend(true, {}, this._configuration, newConfig);
        if (this.force) {
            let runStart: boolean;

            /**
             * Updates the config value if necessary, and returns true if it was updated
             */
            const updateForceConfig = (name: string, config: { default: number, min: number, max: number }) => {
                const { default: defaultValue, min, max } = config;
                if (newConfig[name] !== this._configuration[name]) {
                    let newValue = max ? Math.min(newConfig[name], max) : newConfig[name];
                    newValue = min ? Math.max(newValue, min) : newValue;
                    this.force[name](newValue || defaultValue);
                    return true;
                }
            };

            // Bound all of the settings to their appropriate min/maxes
            const { charge, linkDistance, linkStrength, gravity } = CONSTANTS;
            runStart = updateForceConfig("linkDistance", linkDistance) || runStart;
            runStart = updateForceConfig("linkStrength", linkStrength) || runStart;
            runStart = updateForceConfig("charge", charge) || runStart;
            runStart = updateForceConfig("gravity", gravity) || runStart;

            // If the zoom has changed at all, then let the zoom behavior know
            if ((newConfig.minZoom !== this._configuration.minZoom ||
                newConfig.maxZoom !== this._configuration.maxZoom) &&
                this.zoom) {
                this.zoom.scaleExtent([newConfig.minZoom, newConfig.maxZoom]);
            }

            if (newConfig.animate) {
                // If we are rerunning start or if we weren't animated, but now we are, then start the force
                if (runStart || !this.configuration.animate) {
                    this.force.start();
                }
            } else {
                this.force.stop();
                if (runStart) {
                    this.reflow(this.vis.selectAll(".link"), this.vis.selectAll(".node"));
                }
            }

            // Rerender the labels if necessary
            if (newConfig.labels !== this._configuration.labels) {
                this.vis.selectAll(".node text")
                    /* tslint:disable */
                    .style("display", newConfig.labels ? null : "none");
                    /* tslint:enable */
            }

            //
            if (newConfig.caseInsensitive !== this._configuration.caseInsensitive) {
                this.filterNodes(this.element.find(".search-filter-box").val());
            }

            if (newConfig.fontSizePT !== this._configuration.fontSizePT) {
                newConfig.fontSizePT = newConfig.fontSizePT || 8;
                this.vis.selectAll(".node text")
                    .attr("font-size", () => `${newConfig.fontSizePT}pt`);
            }
        }

        this._configuration = newConfig;
        this.redraw();
    }