Search in sources :

Example 1 with D3Behavior

use of org.opennms.features.topology.app.internal.gwt.client.d3.D3Behavior in project opennms by OpenNMS.

the class VTopologyComponent method initialize.

private void initialize() {
    super.onLoad();
    consoleLog("onLoad");
    ServiceRegistry serviceRegistry = new DefaultServiceRegistry();
    serviceRegistry.register(vertexClickHandler(), new HashMap<String, String>() {

        {
            put("handlerType", "vertexClick");
        }
    }, Handler.class);
    serviceRegistry.register(vertexDblClickHandler(), new HashMap<String, String>() {

        {
            put("handlerType", "vertexDblClick");
        }
    }, Handler.class);
    serviceRegistry.register(vertexContextMenuHandler(), new HashMap<String, String>() {

        {
            put("handlerType", "vertexContextMenu");
        }
    }, Handler.class);
    serviceRegistry.register(edgeContextHandler(), new HashMap<String, String>() {

        {
            put("handlerType", "edgeContextMenu");
        }
    }, Handler.class);
    serviceRegistry.register(edgeClickHandler(), new HashMap<String, String>() {

        {
            put("handlerType", "edgeClick");
        }
    }, Handler.class);
    m_topologyView = new TopologyViewImpl();
    m_topologyView.setPresenter(this);
    m_componentHolder.setSize("100%", "100%");
    m_componentHolder.add(m_topologyView.asWidget());
    m_svgDragHandlerManager = new DragHandlerManager();
    m_svgDragHandlerManager.addDragBehaviorHandler(PanHandler.DRAG_BEHAVIOR_KEY, new PanHandler(this));
    m_svgDragHandlerManager.addDragBehaviorHandler(MarqueeSelectHandler.DRAG_BEHAVIOR_KEY, new MarqueeSelectHandler(this, m_topologyView));
    m_svgDragHandlerManager.setCurrentDragHandler(PanHandler.DRAG_BEHAVIOR_KEY);
    setupDragBehavior(m_topologyView.getSVGElement(), m_svgDragHandlerManager);
    D3 svgElement = D3.d3().select(m_topologyView.getSVGElement());
    //        svgElement.on("dblclick", new Handler<Void>() {
    //
    //            @Override
    //            public void call(Void t, int index) {
    //                JsArrayInteger pos = D3.getMouse(m_topologyView.getSVGElement());
    //                onBackgroundDoubleClick(m_topologyView.getPoint(pos.get(0), pos.get(1)));
    //            }
    //
    //		})
    svgElement.on(D3Events.CONTEXT_MENU.event(), new Handler<Void>() {

        @Override
        public void call(Void aVoid, int index) {
            NativeEvent event = D3.getEvent();
            if (D3.eventDefaultPrevented()) {
                return;
            }
            if (!isMarqueeSelected()) {
                EventTarget target = event.getEventTarget();
                if (target.equals(m_topologyView.getSVGElement())) {
                    onContextMenu(null, event.getClientX(), event.getClientY(), "map");
                }
            }
            event.preventDefault();
            event.stopPropagation();
        }
    });
    svgElement.on(D3Events.CLICK.event(), new Handler<Void>() {

        @Override
        public void call(Void aVoid, int index) {
            NativeEvent event = D3.getEvent();
            if (D3.eventDefaultPrevented()) {
                return;
            }
            if (!isMarqueeSelected() && event.getButton() == NativeEvent.BUTTON_LEFT && event.getEventTarget().equals(m_topologyView.getSVGElement())) {
                onBackgroundClick();
            }
            event.preventDefault();
            event.stopPropagation();
        }
    });
    svgElement.on(D3Events.MOUSE_WHEEL.event(), new Handler<Void>() {

        @Override
        public void call(Void t, int index) {
            double scrollVal = (double) D3.getEvent().getMouseWheelVelocityY() / 30.0;
            SVGPoint centerPos = m_topologyView.getCenterPos(m_graph.getBoundingBox());
            onMouseWheel(scrollVal, (int) centerPos.getX(), (int) centerPos.getY());
        }
    });
    D3Behavior dragBehavior = new D3Behavior() {

        @Override
        public D3 run(D3 selection) {
            D3Drag drag = D3.getDragBehavior();
            drag.on(D3Events.DRAG_START.event(), vertexDragStartHandler());
            drag.on(D3Events.DRAG.event(), vertexDragHandler());
            drag.on(D3Events.DRAG_END.event(), vertexDragEndHandler());
            selection.call(drag);
            return selection;
        }
    };
    m_graphDrawer = new SVGGraphDrawer(dragBehavior, serviceRegistry);
    m_graphDrawerNoTransition = new SVGGraphDrawerNoTransition(dragBehavior, serviceRegistry);
    setTopologyViewRenderer(m_graphDrawer);
    m_updatePhysicalDimensionTimer.scheduleRepeating(UPDATE_PHYSICAL_DIMENSIONS_TIMER_PERIOD_MILLIS);
}
Also used : PanHandler(org.opennms.features.topology.app.internal.gwt.client.handler.PanHandler) D3Behavior(org.opennms.features.topology.app.internal.gwt.client.d3.D3Behavior) SVGPoint(org.opennms.features.topology.app.internal.gwt.client.svg.SVGPoint) Point(com.google.gwt.touch.client.Point) D3(org.opennms.features.topology.app.internal.gwt.client.d3.D3) SVGPoint(org.opennms.features.topology.app.internal.gwt.client.svg.SVGPoint) DefaultServiceRegistry(org.opennms.features.topology.app.internal.gwt.client.service.support.DefaultServiceRegistry) DragHandlerManager(org.opennms.features.topology.app.internal.gwt.client.handler.DragHandlerManager) DefaultServiceRegistry(org.opennms.features.topology.app.internal.gwt.client.service.support.DefaultServiceRegistry) ServiceRegistry(org.opennms.features.topology.app.internal.gwt.client.service.ServiceRegistry) D3Drag(org.opennms.features.topology.app.internal.gwt.client.d3.D3Drag) EventTarget(com.google.gwt.dom.client.EventTarget) MarqueeSelectHandler(org.opennms.features.topology.app.internal.gwt.client.handler.MarqueeSelectHandler) NativeEvent(com.google.gwt.dom.client.NativeEvent)

Example 2 with D3Behavior

use of org.opennms.features.topology.app.internal.gwt.client.d3.D3Behavior in project opennms by OpenNMS.

the class GWTVertex method draw.

public static D3Behavior draw() {
    return new D3Behavior() {

        @Override
        public D3 run(D3 selection) {
            final D3 iconContainer = selection.select(".icon-container");
            iconContainer.attr("transform", normalizeSVGIcon()).attr("opacity", getVertexOpacity());
            iconContainer.select(".vertex .activeIcon").attr("opacity", selectionFilter());
            selection.select(".svgIconOverlay").attr("width", calculateOverlayWidth()).attr("height", calculateOverlayHeight()).attr("x", calculateOverlayXPos()).attr("y", calculateOverlayYPos());
            selection.select(".status").attr("width", calculateOverlayWidth()).attr("height", calculateOverlayHeight()).attr("x", calculateOverlayXPos()).attr("y", calculateOverlayYPos()).attr("class", getStatusClass());
            selection.select(".status-counter").text(getStatusCountText());
            selection.select(".node-status-counter").attr("transform", statusCounterPos()).style("opacity", showStatusCount()).select("rect").attr("class", getStatusClass()).attr("width", calculateStatusCounterWidth());
            selection.select(".status-badge-container").attr("transform", statusBadgePos()).attr("class", getStatusClass("status-badge-container")).select(".status-badge").text(getBadgeStatusText());
            selection.select(".navigate-to .text").style("opacity", showNavigateToIndicator());
            return selection.attr("class", GWTVertex.getClassName()).attr("transform", GWTVertex.getTranslation()).select("text.vertex-label").text(label()).attr("y", textLabelPlacement());
        }
    };
}
Also used : D3Behavior(org.opennms.features.topology.app.internal.gwt.client.d3.D3Behavior) D3(org.opennms.features.topology.app.internal.gwt.client.d3.D3)

Example 3 with D3Behavior

use of org.opennms.features.topology.app.internal.gwt.client.d3.D3Behavior in project opennms by OpenNMS.

the class GWTVertex method create.

public static D3Behavior create() {
    return new D3Behavior() {

        @Override
        public D3 run(D3 selection) {
            D3 vertex = selection.append("g").attr("class", "vertex");
            vertex.attr("opacity", 1e-6).style("cursor", "pointer");
            vertex.append("svg:rect").attr("class", "status").attr("fill", "none").attr("stroke-width", 5).attr("stroke-location", "outside").attr("stroke", "blue").attr("opacity", 0);
            D3 svgIconContainer = vertex.append("g").attr("class", "icon-container").attr("opacity", 0);
            D3 svgIcon = svgIconContainer.append("use");
            D3 svgIconRollover = svgIconContainer.append("use");
            D3 svgIconActive = svgIconContainer.append("use");
            D3 statusCounter = vertex.append("g");
            D3 statusBadge = vertex.append("g");
            D3 textSelection = vertex.append("text");
            D3 navigateTo = vertex.append("g").attr("class", "navigate-to");
            vertex.append("svg:rect").attr("class", "svgIconOverlay").attr("width", 100).attr("height", 100).attr("opacity", 0).call(new D3Behavior() {

                @Override
                public D3 run(D3 selection) {
                    return selection.on("mouseover", new D3Events.Handler<Object>() {

                        @Override
                        public void call(Object o, int index) {
                            NativeEvent event = D3.getEvent();
                            SVGRect element = event.getCurrentEventTarget().cast();
                            SVGGElement parent = element.getParentElement().cast();
                            D3 selection = D3.d3().select(parent);
                            selection.select(".overIcon").attr("opacity", 1);
                        }
                    }).on("mouseout", new D3Events.Handler<Object>() {

                        @Override
                        public void call(Object o, int index) {
                            NativeEvent event = D3.getEvent();
                            SVGRect element = event.getCurrentEventTarget().cast();
                            SVGGElement parent = element.getParentElement().cast();
                            D3 selection = D3.d3().select(parent);
                            selection.select(".overIcon").attr("opacity", 0);
                        }
                    });
                }
            });
            svgIcon.attr("xlink:href", svgIconId("")).attr("class", "upIcon");
            svgIconRollover.attr("xlink:href", svgIconId("_rollover")).attr("class", "overIcon").attr("opacity", 0);
            svgIconActive.attr("xlink:href", svgIconId("_active")).attr("class", "activeIcon").attr("opacity", 0);
            // Status Counter
            statusCounter.attr("class", "node-status-counter").append("svg:rect").attr("height", 20).attr("width", 20).attr("rx", 10).attr("ry", 10);
            statusCounter.append("text").attr("x", "6px").attr("y", "14px").attr("class", "status-counter");
            // Status Badge
            statusBadge.attr("class", "status-badge-container");
            statusBadge.append("text").attr("x", "0px").attr("y", "0px").attr("class", "status-badge");
            // Navigate To indicator
            navigateTo.append("text").attr("class", "text").attr("opacity", 1).attr("x", -23).attr("y", 23).text(// ion-record
            "");
            textSelection.text(label()).attr("class", "vertex-label").attr("x", "0px").attr("text-anchor", "middle").attr("alignment-baseline", "text-before-edge");
            vertex.call(draw());
            return vertex;
        }
    };
}
Also used : D3Events(org.opennms.features.topology.app.internal.gwt.client.d3.D3Events) SVGGElement(org.opennms.features.topology.app.internal.gwt.client.svg.SVGGElement) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) D3Behavior(org.opennms.features.topology.app.internal.gwt.client.d3.D3Behavior) SVGRect(org.opennms.features.topology.app.internal.gwt.client.svg.SVGRect) D3(org.opennms.features.topology.app.internal.gwt.client.d3.D3) NativeEvent(com.google.gwt.dom.client.NativeEvent)

Aggregations

D3 (org.opennms.features.topology.app.internal.gwt.client.d3.D3)3 D3Behavior (org.opennms.features.topology.app.internal.gwt.client.d3.D3Behavior)3 NativeEvent (com.google.gwt.dom.client.NativeEvent)2 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)1 EventTarget (com.google.gwt.dom.client.EventTarget)1 Point (com.google.gwt.touch.client.Point)1 D3Drag (org.opennms.features.topology.app.internal.gwt.client.d3.D3Drag)1 D3Events (org.opennms.features.topology.app.internal.gwt.client.d3.D3Events)1 DragHandlerManager (org.opennms.features.topology.app.internal.gwt.client.handler.DragHandlerManager)1 MarqueeSelectHandler (org.opennms.features.topology.app.internal.gwt.client.handler.MarqueeSelectHandler)1 PanHandler (org.opennms.features.topology.app.internal.gwt.client.handler.PanHandler)1 ServiceRegistry (org.opennms.features.topology.app.internal.gwt.client.service.ServiceRegistry)1 DefaultServiceRegistry (org.opennms.features.topology.app.internal.gwt.client.service.support.DefaultServiceRegistry)1 SVGGElement (org.opennms.features.topology.app.internal.gwt.client.svg.SVGGElement)1 SVGPoint (org.opennms.features.topology.app.internal.gwt.client.svg.SVGPoint)1 SVGRect (org.opennms.features.topology.app.internal.gwt.client.svg.SVGRect)1