jointjs实现可拖动移动的时间轴大事记代码

代码语言:html

所属分类:其他

代码描述:jointjs实现可拖动移动的时间轴大事记代码

代码标签: jointjs 拖动 移动 时间轴 大事记 代码

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/lodash.4.17.21.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/backbone-min.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/joint.3.7.2.js"></script>
<style>
#paper-container {
  position: absolute;
  right: 0;
  top: 0;
  left: 0;
  bottom: 0;
  overflow: scroll;
}

#logo {
  position: absolute;
  bottom: 20px;
  right: 20px;
  padding: 5px;
}
</style>


  
  
</head>

<body translate="no">
  <div id="paper-container"></div>


      <script  >
const { dia, util, shapes: defaultShapes } = joint;

const chevronCount = 40;
const chevronHeight = 8;
const chevronWidth = 3;
const timelineColor = '#fff';
const backgroundColor = '#444';
const padding = 10;
const gap = 70;
const timelineY = 300;
const timelineXMin = 140;
const timelineXMax = 1100;

const timelineEventJSONMarkup = util.svg`
    <ellipse @selector="body"/>
    <text @selector="title"/>
    <text @selector="subtitle"/>
    <text @selector="description"/>
`;

class TimelineEvent extends dia.Element {

  defaults() {
    return {
      ...super.defaults,
      type: 'TimelineEvent',
      attrs: {
        root: {
          magnetSelector: 'body' },

        body: {
          stroke: 'none',
          cx: 'calc(w/2)',
          cy: 'calc(h/2)',
          rx: 'calc(w/2)',
          ry: 'calc(h/2)' },

        title: {
          text: 'Label Inside',
          fontSize: 18,
          fontFamily: 'sans-serif',
          fill: timelineColor,
          textVerticalAnchor: 'top',
          textAnchor: 'end',
          x: 'calc(w)',
          y: 'calc(h + 10)' },

        subtitle: {
          text: 'Subtitle',
          fontSize: 14,
          fontFamily: 'sans-serif',
          fontWeight: 'bold',
          fill: timelineColor,
          textVerticalAnchor: 'top',
          textAnchor: 'end',
          x: 'calc(w)',
          y: 'calc(h + 40)' },

        description: {
          text: 'Description',
          fontSize: 11,
          fontFamily: 'sans-serif',
          fill: timelineColor,
          textVerticalAnchor: 'top',
          textAnchor: 'end',
          x: 'calc(w)',
          y: 'calc(h + 60)' } } };




  }

  preinitialize() {
    this.markup = timelineEventJSONMarkup;
  }

  positionLabels() {
    if (this.position().y > timelineY) {
      if (this.attr('title/y') === 'calc(h + 10)') return;
      this.attr({
        title: {
          y: 'calc(h + 10)',
          textVerticalAnchor: 'top' },

        subtitle: {
          y: 'calc(h + 40)',
          textVerticalAnchor: 'top' },

        description: {
          y: 'calc(h + 60)',
          textVerticalAnchor: 'top' } });


    } else {
      if (this.attr('title/y') === -10) return;
      this.attr({
        title: {
          y: -10,
          textVerticalAnchor: 'bottom' },

        subtitle: {
          y: -40,
          textVerticalAnchor: 'bottom' },

        description: {
          y: -60,
          textVerticalAnchor: 'bottom' } });


    }
  }}


const shapes = { ...defaultShapes, TimelineEvent };

const graph = new dia.Graph({}, {
  cellNamespace: shapes });


const paper = new dia.Paper({
  width: "100%",
  height: "100%&q.........完整代码请登录后点击上方下载按钮下载查看

网友评论0