缩放比例为:自动的GetOrgChart渲染未居中

时间:2019-03-16 23:16:53

标签: javascript svg iframe visualforce getorgchart

我正在努力使getOrgChart在固定宽度的iframe中工作,以便可以显示组织结构图。 该功能确实可以正常工作,但是有一件事似乎无法正常工作,那就是缩放:自动实际上将组件居中:

这是我使用的主题:

size: [300, 370],
            toolbarHeight: 46,
            textPoints: [
                { x: 150, y: 50, width: 285 },
                { x: 150, y: 90, width: 285 },
                { x: 150, y: 120, width: 285 }

            ],
            textPointsNoImage: [
                { x: 150, y: 50, width: 285 },
                { x: 150, y: 90, width: 285 },
                { x: 150, y: 120, width: 285 }

            ],
            expandCollapseBtnRadius: 20,
            defs: '<filter id="f1" x="0" y="0" width="200%" height="200%"><feOffset result="offOut" in="SourceAlpha" dx="5" dy="5" /><feGaussianBlur result="blurOut" in="offOut" stdDeviation="5" /><feBlend in="SourceGraphic" in2="blurOut" mode="normal" /></filter>',
            box: '<rect x="0" y="0" height="370" width="300" rx="10" ry="10" class="myCustomTheme-box" filter="url(#f1)"  />',
            text: '<text text-anchor="middle" width="[width]" class="get-text get-text-[index]" x="[x]" y="[y]">[text]</text>',
            image: '<clipPath id="getMonicaClip"><circle cx="150" cy="235" r="85" /></clipPath><image preserveAspectRatio="xMidYMid slice" clip-path="url(#getMonicaClip)" xlink:href="[href]" x="65" y="130" height="190" width="170"/>',
            reporters: '<circle cx="80" cy="170" r="20" class="reporters"></circle><text class="reporters-text" text-anchor="middle" width="120" x="80" y="177">[reporters]</text>'

仅与演示2稍有不同。然后我更改了reports-text:

 .reporters-text {
   font-size: large;
   fill: #ffffff;
  }

但是,即使自定义主题改回原来的主题,使用我的数据集,我也总是得到相同的结果:

Rendering from loadout of iframe

这一切都发生在Salesforce开发组织的iframe内部。但是,我只在动态生成的数据上看到了这种情况,而演示中提供的固定数据集仍然显示了应有的状态。

它在Visualforce页面中渲染,而Visualforce页面又由Lightning组件打开,但是即使单独打开VF页面也可以得到相同的结果。

我很好奇这是怎么发生的,因为当我自己不生成数据而是获取一些预生成的数据时,渲染中心毫无问题:

Dummy Data center just fine

对节点列表进行排序也没有帮助,因为我已经对阵列进行了硬编码,但是svg仍然无法完全居中显示。

1 个答案:

答案 0 :(得分:1)

(从字面上看,过去几个小时都在处理此错误,直到在此处发布后不久才发现)

问题似乎是,只有名字带有记者的人在第二层级的中间。我在他和2级最左边的人之间切换了位置,瞧,它以某种方式认识到它应该再次正确居中。

对我来说,这意味着我将必须首先创建拥有最多管理者的节点,并从一侧到另一侧或仅从中心移开它们。

{ id: 1, parentId: null, name: "Test", title: "fancy", image:'available'},
                    { id: 2, parentId: 1, name: "Test", title: "fancy", image:'available'},
                    { id: 3, parentId: 1, name: "Test", title: "fancy", image:'available'},
                    { id: 4, parentId: 1, name: "Test", title: "fancy", image:'available'},
                    { id: 5, parentId: 3, name: "Test", title: "fancy", image:'available'},
                    { id: 6, parentId: 3, name: "Test", title: "fancy", image:'available'},
                    { id: 7, parentId: 3, name: "Test", title: "fancy", image:'available'},
                    { id: 8, parentId: 3, name: "Test", title: "fancy", image:'available'},
                    { id: 9, parentId: 3, name: "Test", title: "fancy", image:'available'},
                    { id: 10, parentId: 3, name: "Test", title: "fancy", image:'available'},
                    { id: 11, parentId: 3, name: "Test", title: "fancy", image:'available'},
                    { id: 12, parentId: 6, name: "Test", title: "fancy", image:'available'},
                    { id: 13, parentId: 6, name: "Test", title: "fancy", image:'available'},
                    { id: 14, parentId: 6, name: "Test", title: "fancy", image:'available'},
                    { id: 15, parentId: 6, name: "Test", title: "fancy", image:'available'},
                    { id: 16, parentId: 6, name: "Test", title: "fancy", image:'available'},
                    { id: 17, parentId: 10, name: "^Test", title: "fancy", image:'available'}

此数组在加载时导致此错误 Wrong alignment

该数组:

{ id: 1, parentId: null, name: "Test", title: "fancy", image:'available'},
                        { id: 2, parentId: 1, name: "Test", title: "fancy", image:'available'},
                        { id: 3, parentId: 1, name: "Test", title: "fancy", image:'available'},
                        { id: 4, parentId: 1, name: "Test", title: "fancy", image:'available'},
                        { id: 5, parentId: 2, name: "Test", title: "fancy", image:'available'},
                        { id: 6, parentId: 2, name: "Test", title: "fancy", image:'available'},
                        { id: 7, parentId: 2, name: "Test", title: "fancy", image:'available'},
                        { id: 8, parentId: 2, name: "Test", title: "fancy", image:'available'},
                        { id: 9, parentId: 2, name: "Test", title: "fancy", image:'available'},
                        { id: 10, parentId: 2, name: "Test", title: "fancy", image:'available'},
                        { id: 11, parentId: 2, name: "Test", title: "fancy", image:'available'},
                        { id: 12, parentId: 6, name: "Test", title: "fancy", image:'available'},
                        { id: 13, parentId: 6, name: "Test", title: "fancy", image:'available'},
                        { id: 14, parentId: 6, name: "Test", title: "fancy", image:'available'},
                        { id: 15, parentId: 6, name: "Test", title: "fancy", image:'available'},
                        { id: 16, parentId: 6, name: "Test", title: "fancy", image:'available'},
                        { id: 17, parentId: 10, name: "^Test", title: "fancy", image:'available'}

(注意,我将parentId更改为现在与2而不是3相关)

为此: enter image description here

当我将其更改为4而不是3时,发生了同样的事情。