将滚动条添加到svg容器

12 jquery getorgchart

我正在使用GetOrgChart为我的公司制作组织结构图,但我遇到了一个小问题.

如果SVG它比容器大,我们希望添加一个滚动条,以便您可以使用它滚动,因为这比用鼠标拖动它要快得多.

我试过这个例子但是无法使它工作.

有没有办法实现我正在寻找的东西?

下面的示例比我们的实际图表小,但它应该足以表示问题.

var peopleElement = document.getElementById("people");
var orgChart = new getOrgChart(peopleElement, {
  primaryFields: ["name", "title", "phone", "mail"],
  photoFields: ["image"],
  scale: 0.4,
  dataSource: [{
      id: 1,
      parentId: null,
      name: "Amber McKenzie",
      title: "CEO",
      phone: "678-772-470",
      mail: "lemmons@jourrapide.com",
      adress: "Atlanta, GA 30303",
      image: "images/f-11.jpg"
    },
    {
      id: 2,
      parentId: 1,
      name: "Ava Field",
      title: "Paper goods machine setter",
      phone: "937-912-4971",
      mail: "anderson@jourrapide.com",
      image: "images/f-10.jpg"
    },
    {
      id: 3,
      parentId: 1,
      name: "Evie Johnson",
      title: "Employer relations representative",
      phone: "314-722-6164",
      mail: "thornton@armyspy.com",
      image: "images/f-9.jpg"
    },
    {
      id: 4,
      parentId: 1,
      name: "Paul Shetler",
      title: "Teaching assistant",
      phone: "330-263-6439",
      mail: "shetler@rhyta.com",
      image: "images/f-5.jpg"
    },
    {
      id: 11,
      parentId: 1,
      name: "Paul Shetler",
      title: "Teaching assistant",
      phone: "330-263-6439",
      mail: "shetler@rhyta.com",
      image: "images/f-5.jpg"
    },
    {
      id: 12,
      parentId: 1,
      name: "Paul Shetler",
      title: "Teaching assistant",
      phone: "330-263-6439",
      mail: "shetler@rhyta.com",
      image: "images/f-5.jpg"
    },
    {
      id: 5,
      parentId: 2,
      name: "Rebecca Francis",
      title: "Welding machine setter",
      phone: "408-460-0589",
      image: "images/f-4.jpg"
    },
    {
      id: 6,
      parentId: 2,
      name: "Rebecca Randall",
      title: "Optometrist",
      phone: "801-920-9842",
      mail: "JasonWGoodman@armyspy.com",
      image: "images/f-8.jpg"
    },
    {
      id: 7,
      parentId: 2,
      name: "Spencer May",
      title: "System operator",
      phone: "Conservation scientist",
      mail: "hodges@teleworm.us",
      image: "images/f-7.jpg"
    },
    {
      id: 8,
      parentId: 6,
      name: "Max Ford",
      title: "Budget manager",
      phone: "989-474-8325",
      mail: "hunter@teleworm.us",
      image: "images/f-6.jpg"
    },
    {
      id: 9,
      parentId: 7,
      name: "Riley Bray",
      title: "Structural metal fabricator",
      phone: "479-359-2159",
      image: "images/f-3.jpg"
    },
    {
      id: 10,
      parentId: 7,
      name: "Callum Whitehouse",
      title: "Radar controller",
      phone: "847-474-8775",
      image: "images/f-2.jpg"
    }
  ]
});

$('.get-left,.get-down,.get-up,.get-right').remove();

$(document).ready(function() {
  $(".get-oc-c").css("overflow","scroll");
})
Run Code Online (Sandbox Code Playgroud)
#people {
  width: 90%;
  height: 90%;
  border:1px solid #000;
}
Run Code Online (Sandbox Code Playgroud)
<link href="http://www.getorgchart.com/GetOrgChart/getorgchart/getorgchart.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://www.getorgchart.com/GetOrgChart/getorgchart/getorgchart.js"></script>
<div id="people"></div>
Run Code Online (Sandbox Code Playgroud)

Con*_*Fan 7

你可以看看这个jsfiddle..get-oc-c如果需要,容器会显示滚动条:

.get-oc-c {
  overflow: auto !important;
}
Run Code Online (Sandbox Code Playgroud)

并且SVG图表元素被包装在一个div中,该div被调整大小以容纳整个图表:

function wrapChart() {
  ...
  $("svg").wrap("<div id='svgContainer'></div>");
  ...
}

#svgContainer {
  overflow: visible;
}
Run Code Online (Sandbox Code Playgroud)

wrapChart方法在updatedEvent.中调用.禁用图表移动选项以删除侧面的箭头并防止平移:

var orgChart = new getOrgChart(peopleElement, {
  enableMove: false,
  ...
});
Run Code Online (Sandbox Code Playgroud)

原始显示似乎有效但是为包装元素获取正确的大小值很困难(jsfiddle中使用的表达式非常经验),当窗口调整大小,链接展开/折叠时,它变得更加复杂当图表缩放时.一些调整大小使用动画,因此计算必须考虑到获得最终值之前的延迟.

jsfiddle显示了一些简单的代码,用于在展开/折叠节点后恢复滚动位置,但是需要对其进行改进.我没有编写代码来解释窗口大小调整和缩放.

考虑到使滚动条表现正常所需的工作量,最好使用组件提供的平移和移动功能.您还可以联系组件的创建者并要求他们添加滚动条选项.