简体   繁体   English

Neovis.js 在 Salesforce Lightning Web 组件中未完全呈现

[英]Neovis.js not rendering completely in Salesforce Lightning Web Component

I've spent about a week or so on this, and there's very little documentation online so I figured I'd come on here to see if anyone could potentially help out.我花了大约一个星期左右的时间,网上的文档很少,所以我想我会来这里看看是否有人可以提供帮助。 So the top level summary is that I'm trying to use an external library (neovis.js) to visualize a neo4j graph database in a Salesforce Lightning web component.所以顶级总结是我正在尝试使用外部库(neovis.js)在 Salesforce Lightning web 组件中可视化 neo4j 图形数据库。 I've already explored d3.js (which is compatible with Salesforces locker service) and a few other visualization libraries, but neovis.js would be the most viable option for my use case.我已经探索了 d3.js(与 Salesforce 储物柜服务兼容)和其他一些可视化库,但对于我的用例,neovis.js 将是最可行的选择。 I've made some slight modifications shown in the code below to avoid using Document.getElementById in the neovis.js library to select the element and append the canvas to the page.我在下面的代码中显示了一些细微的修改,以避免使用 Neovis.js 库中的 Document.getElementById 到 select 元素和 append 到页面。

However, once the canvas is drawn to the page, none of the canvas elements (nodes and edges) are shown on the screen.但是,一旦将 canvas 绘制到页面上,屏幕上就不会显示任何 canvas 元素(节点和边)。 Here's the weird part though, I can still hover over where the nodes should be on the canvas, and the popup which displays specific information for each node appears on screen with the correct information for each node.这是奇怪的部分,我仍然可以 hover 超过节点应该在 canvas 上的位置,并且显示每个节点的特定信息的弹出窗口出现在屏幕上,并显示每个节点的正确信息。 I am not super familiar with how the canvas element works, but it seems to me as if some css property is not being applied because of Salesforce's locker service, which causes to elements to be rendered invisibly.我不太熟悉 canvas 元素的工作原理,但在我看来,由于 Salesforce 的储物柜服务,某些 css 属性没有被应用,这会导致元素以不可见的方式呈现。

I've gone through a good chunk of the neovis.js library (which is just a library built on top of vis.js), and I've looked for places where perhaps styles aren't being applied to the canvas element;我已经浏览了大部分 neovis.js 库(它只是一个构建在 vis.js 之上的库),并且我寻找了 styles 可能没有应用于 canvas 元素的地方; however up to now I've had no luck.但是到目前为止,我还没有运气。

Here's the code I've used so far:这是我到目前为止使用的代码:

index.html索引.html

<template>
    <lightning-card title="Neovis" icon-name="custom:custom19">
        <div class="slds-m-around_medium">
            <div id="neovisContainerViz" class="neoVizClass" lwc:dom="manual" style="height: 700px; width: 400px;">
            </div>
        </div>
    </lightning-card>
</template>

index.js index.js

drawNeovis() {


        const config = {
            container_id: "",
            server_url: "bolt://neo4j.het.io:7687", //This is a publicly available neo4j database that I'm using for testing purposes. 
            server_user: "",
            server_password: "",
            labels: {

            },
            relationships: {

            },
            initial_cypher: "MATCH (node:Disease {name: 'lung cancer'}) RETURN node"
        }

        const parent = this.template.querySelector('div.neoVizClass');
        const container = document.createElement('DIV');
        container.className = 'neoViz';
        parent.appendChild(container);

        const viz = new NeoVis.default(config);
        viz._container = container; //This is a property inside of the NeoVis library. This property is normally set by using the document.getElementById method, however I've replaced it with my predefined container to get around the Salesforce Locker Service.
        viz.render();
    }

Here is exactly what is rendered onto the Salesforce App page:这正是在 Salesforce 应用页面上呈现的内容:

<div class="slds-card__body">
    <slot>
        <div class="slds-m-around_medium">
            <div id="neovisContainerViz-67" class="neoVizClass" style="height: 700px; width: 400px;">
                <div class="neovis">
                    <div class="vis-network" tabindex="900" style="position: relative; overflow: hidden; touch-action: pan-y; user-select: none; -webkit-user-drag: none; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); width: 100%; height: 100%;">
                        <canvas width="200" height="200" style="position: relative; touch-action: none; user-select: none; -webkit-user-drag: none; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); width: 100%; height: 100%;">

                        </canvas>
                        <div class="vis-tooltip" style="left: 5px; top: 5px; visibility: hidden;">
                            <strong>
                                license:
                            </strong> 
                            CC BY 3.0
                            <br>
                            <strong>identifier:</strong> 
                            DOID:1324
                            <br>
                            <strong>name:</strong> 
                            lung cancer
                            <br>
                            <strong>source:</strong> 
                            Disease Ontology
                            <br>
                            <strong>url:</strong> 
                            http://purl.obolibrary.org/obo/DOID_1324
                            <br>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </slot>
</div>

The canvas and the tooltip are appended to the DOM, AND the tooltip dynamically updates when I hover over where the canvas elements should be displayed. canvas 和工具提示被附加到 DOM,并且当我 hover 超过应该显示 canvas 元素的位置时,工具提示会动态更新。 However none of the nodes or edges are visible on the screen.但是,屏幕上看不到任何节点或边缘。

All in all, I am not very familiar with how the canvas element actually functions, and am hoping that someone can give me some tips on how to trouble shoot this issue and get the elements on the canvas to display.总而言之,我对 canvas 元件的实际功能不是很熟悉,我希望有人能给我一些关于如何解决这个问题并让 canvas 上的元件显示的提示。

Thank you all!谢谢你们!

I was able to finally figure this out incase anyone else is running into similar issues.我终于能够弄清楚这一点,以防其他人遇到类似问题。 I wouldn't say this is the preferred answer, but it works (for now).我不会说这是首选答案,但它(目前)有效。 Basically I injected an iframe into Salesforce, and inside of the iframe I injected the neovis.js library and generated the graph, works perfectly now.基本上我将iframe注入到 Salesforce 中,在 iframe 内部我注入了 neovis.js 库并生成了图形,现在可以完美运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM