Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="app">
  <p>These are the Job icons, created within the Vue.js app. We will link them with the node-html-labels. This way, reactivity is still happening, regardless of what happens in the graph.</p>
  <graph-node v-for="node in nodes" :key="node.id" :node="node" :ref="node.id"></graph-node>
  <p><i>NB: in a real app, these icons would be hidden here, but displayed only in the graph.</i></p>
  <network :elements="elements" />
</div>

              
            
!

CSS

              
                #cy {
  width: 600px;
  height: 600px;
  display: block;
}

// styles from the job component
.c-job {
  svg.job {
    /* scale the icon to the font-size */
    width: 1em;
    height: 1em;
    rect {
      /* if no job status display nothing */
      fill: transparent;
      stroke: transparent;
    }
    &.submitted rect {
      fill: rgb(125,207,212);
      stroke: rgb(125,207,212);
    }
    &.running rect {
      fill: rgb(106,164,241);
      stroke: rgb(106,164,241);
    }
    &.succeeded rect {
      fill: rgb(81,175,81);
      stroke: rgb(81,175,81);
    }
    &.failed rect {
      fill: rgb(207,72,72);
      stroke: rgb(207,72,72);
    }
    &.submit-failed rect {
      fill: rgb(190,106,192);
      stroke: rgb(190,106,192);
    }
  }
}
              
            
!

JS

              
                // data from gist with example response from cylc ui server: https://gist.github.com/kinow/a9a75ab9398e1207eeb08c52f84e1b48
const graphqlResponse = {
  "data": {
    "workflows": [
      {
        "id": "kinow|families2",
        "status": "running",
        "nodesEdges": {
          "nodes": [
            {
              "id": "kinow|families2|20651108T1515+13|foo",
              "label": "kinow|families2|20651108T1515+13|foo",
              "parent": {
                "id": "kinow|families2|20651108T1515+13|FAM3",
                "state": "succeeded"
              },
              "state": "succeeded",
              "isHeld": false,
              "cyclePoint": "20651108T1515+13",
              "task": {
                "name": "foo"
              },
              "jobs": [
                {
                  "id": "kinow|families2|20651108T1515+13|foo|1",
                  "batchSysName": "background",
                  "batchSysJobId": "4483",
                  "host": "localhost",
                  "startedTime": "2019-11-08T15:19:46+13:00",
                  "submittedTime": "2019-11-08T15:19:45+13:00",
                  "finishedTime": "2019-11-08T15:19:51+13:00",
                  "state": "succeeded",
                  "submitNum": 1
                }
              ]
            },
            {
              "id": "kinow|families2|20651108T1515+13|bar",
              "label": "kinow|families2|20651108T1515+13|bar",
              "parent": {
                "id": "kinow|families2|20651108T1515+13|FAM3",
                "state": "succeeded"
              },
              "state": "succeeded",
              "isHeld": false,
              "cyclePoint": "20651108T1515+13",
              "task": {
                "name": "bar"
              },
              "jobs": [
                {
                  "id": "kinow|families2|20651108T1515+13|bar|1",
                  "batchSysName": "background",
                  "batchSysJobId": "4482",
                  "host": "localhost",
                  "startedTime": "2019-11-08T15:19:46+13:00",
                  "submittedTime": "2019-11-08T15:19:45+13:00",
                  "finishedTime": "2019-11-08T15:19:51+13:00",
                  "state": "succeeded",
                  "submitNum": 1
                }
              ]
            },
            {
              "id": "kinow|families2|20651108T1515+13|qux",
              "label": "kinow|families2|20651108T1515+13|qux",
              "parent": {
                "id": "kinow|families2|20651108T1515+13|FAM6",
                "state": "running"
              },
              "state": "running",
              "isHeld": false,
              "cyclePoint": "20651108T1515+13",
              "task": {
                "name": "qux"
              },
              "jobs": [
                {
                  "id": "kinow|families2|20651108T1515+13|qux|1",
                  "batchSysName": "background",
                  "batchSysJobId": "4904",
                  "host": "localhost",
                  "startedTime": "2019-11-08T15:19:54+13:00",
                  "submittedTime": "2019-11-08T15:19:53+13:00",
                  "finishedTime": "",
                  "state": "running",
                  "submitNum": 1
                }
              ]
            },
            {
              "id": "kinow|families2|20661108T1515+13|foo",
              "label": "kinow|families2|20661108T1515+13|foo",
              "parent": {
                "id": "kinow|families2|20661108T1515+13|FAM3",
                "state": "succeeded"
              },
              "state": "succeeded",
              "isHeld": false,
              "cyclePoint": "20661108T1515+13",
              "task": {
                "name": "foo"
              },
              "jobs": [
                {
                  "id": "kinow|families2|20661108T1515+13|foo|1",
                  "batchSysName": "background",
                  "batchSysJobId": "4613",
                  "host": "localhost",
                  "startedTime": "2019-11-08T15:19:48+13:00",
                  "submittedTime": "2019-11-08T15:19:47+13:00",
                  "finishedTime": "2019-11-08T15:19:53+13:00",
                  "state": "succeeded",
                  "submitNum": 1
                }
              ]
            },
            {
              "id": "kinow|families2|20661108T1515+13|bar",
              "label": "kinow|families2|20661108T1515+13|bar",
              "parent": {
                "id": "kinow|families2|20661108T1515+13|FAM3",
                "state": "succeeded"
              },
              "state": "succeeded",
              "isHeld": false,
              "cyclePoint": "20661108T1515+13",
              "task": {
                "name": "bar"
              },
              "jobs": [
                {
                  "id": "kinow|families2|20661108T1515+13|bar|1",
                  "batchSysName": "background",
                  "batchSysJobId": "4612",
                  "host": "localhost",
                  "startedTime": "2019-11-08T15:19:48+13:00",
                  "submittedTime": "2019-11-08T15:19:47+13:00",
                  "finishedTime": "2019-11-08T15:19:53+13:00",
                  "state": "succeeded",
                  "submitNum": 1
                }
              ]
            },
            {
              "id": "kinow|families2|20661108T1515+13|qux",
              "label": "kinow|families2|20661108T1515+13|qux",
              "parent": {
                "id": "kinow|families2|20661108T1515+13|FAM6",
                "state": "running"
              },
              "state": "running",
              "isHeld": false,
              "cyclePoint": "20661108T1515+13",
              "task": {
                "name": "qux"
              },
              "jobs": [
                {
                  "id": "kinow|families2|20661108T1515+13|qux|1",
                  "batchSysName": "background",
                  "batchSysJobId": "4954",
                  "host": "localhost",
                  "startedTime": "2019-11-08T15:19:57+13:00",
                  "submittedTime": "2019-11-08T15:19:56+13:00",
                  "finishedTime": "",
                  "state": "running",
                  "submitNum": 1
                }
              ]
            },
            {
              "id": "kinow|families2|20671108T1515+13|foo",
              "label": "kinow|families2|20671108T1515+13|foo",
              "parent": {
                "id": "kinow|families2|20671108T1515+13|FAM3",
                "state": "ready"
              },
              "state": "ready",
              "isHeld": false,
              "cyclePoint": "20671108T1515+13",
              "task": {
                "name": "foo"
              },
              "jobs": [
                {
                  "id": "kinow|families2|20671108T1515+13|foo|1",
                  "batchSysName": "background",
                  "batchSysJobId": "",
                  "host": "localhost",
                  "startedTime": "",
                  "submittedTime": "",
                  "finishedTime": "",
                  "state": "ready",
                  "submitNum": 1
                }
              ]
            },
            {
              "id": "kinow|families2|20671108T1515+13|bar",
              "label": "kinow|families2|20671108T1515+13|bar",
              "parent": {
                "id": "kinow|families2|20671108T1515+13|FAM3",
                "state": "ready"
              },
              "state": "ready",
              "isHeld": false,
              "cyclePoint": "20671108T1515+13",
              "task": {
                "name": "bar"
              },
              "jobs": [
                {
                  "id": "kinow|families2|20671108T1515+13|bar|1",
                  "batchSysName": "background",
                  "batchSysJobId": "",
                  "host": "localhost",
                  "startedTime": "",
                  "submittedTime": "",
                  "finishedTime": "",
                  "state": "ready",
                  "submitNum": 1
                }
              ]
            },
            {
              "id": "kinow|families2|20671108T1515+13|qux",
              "label": "kinow|families2|20671108T1515+13|qux",
              "parent": {
                "id": "kinow|families2|20671108T1515+13|FAM6",
                "state": "waiting"
              },
              "state": "waiting",
              "isHeld": false,
              "cyclePoint": "20671108T1515+13",
              "task": {
                "name": "qux"
              },
              "jobs": []
            }
          ],
          "edges": [
            {
              "id": "kinow|families2|foo.20651108T1515+13|qux.20651108T1515+13",
              "source": "kinow|families2|20651108T1515+13|foo",
              "target": "kinow|families2|20651108T1515+13|qux",
              "label": "kinow|families2|foo.20651108T1515+13|qux.20651108T1515+13"
            },
            {
              "id": "kinow|families2|bar.20651108T1515+13|qux.20651108T1515+13",
              "source": "kinow|families2|20651108T1515+13|bar",
              "target": "kinow|families2|20651108T1515+13|qux",
              "label": "kinow|families2|bar.20651108T1515+13|qux.20651108T1515+13"
            },
            {
              "id": "kinow|families2|bar.20671108T1515+13|qux.20671108T1515+13",
              "source": "kinow|families2|20671108T1515+13|bar",
              "target": "kinow|families2|20671108T1515+13|qux",
              "label": "kinow|families2|bar.20671108T1515+13|qux.20671108T1515+13"
            },
            {
              "id": "kinow|families2|foo.20671108T1515+13|qux.20671108T1515+13",
              "source": "kinow|families2|20671108T1515+13|foo",
              "target": "kinow|families2|20671108T1515+13|qux",
              "label": "kinow|families2|foo.20671108T1515+13|qux.20671108T1515+13"
            },
            {
              "id": "kinow|families2|bar.20661108T1515+13|qux.20661108T1515+13",
              "source": "kinow|families2|20661108T1515+13|bar",
              "target": "kinow|families2|20661108T1515+13|qux",
              "label": "kinow|families2|bar.20661108T1515+13|qux.20661108T1515+13"
            },
            {
              "id": "kinow|families2|foo.20661108T1515+13|qux.20661108T1515+13",
              "source": "kinow|families2|20661108T1515+13|foo",
              "target": "kinow|families2|20661108T1515+13|qux",
              "label": "kinow|families2|foo.20661108T1515+13|qux.20661108T1515+13"
            }
          ]
        }
      }
    ]
  }
}

// job/task statuses
const statuses = ["running", "succeeded", "failed"]

// return a random status
function randomStatus () {
  return statuses[Math.floor(Math.random() * statuses.length)]
}

// let's modify the statuses every 3 seconds
setInterval(
  function () {
    const workflow = graphqlResponse.data.workflows[0]
    workflow.nodesEdges.nodes.map((node) => {
      if (Object.hasOwnProperty.call(node, 'state') && node.state !== undefined && node.state !== '') {
        node.state = randomStatus()
      }
    })
  }, 3000
)

// IMPORTANT: we must be able to use the following Job component in the graph, being able to also changing its status so that this is reflected in the graph

// simplified Job component from Cylc
const Job = Vue.component('job', {
  name: 'Job',
  props: {
    status: {
      type: String,
      required: true
    }
  },
  template: `<span
    class="c-job"
    style="display:inline-block; vertical-align:middle"
  >
    <svg
      class="job"
      v-bind:class="[status]"
      viewBox="0 0 100 100"
    >
      <rect
        x="10" y="10"
        width="80" height="80"
        rx="20" ry="20"
        stroke-width="10"
      />
    </svg>
  </span>`
})

const GraphNode = Vue.component('graph-node', {
  name: 'GraphNode',
  components: {
    job: Job
  },
  props: {
    node: {
      type: Object,
      required: true
    }
  },
  watch: {
    node: {
      immediate: true,
      deep: true,
      handler (newValue, oldValue) {
        const nodeElem = document.getElementById(newValue.id)
        const vm = this
        if (nodeElem) {
          Vue.nextTick(function () {
            nodeElem.innerHTML = vm.$mount().$el.outerHTML
          })
        }
      }
    }
  },
  template: `<span>
  <job :status="node.state" />
</span>`
})

Vue.component('network', {
  props: {
    elements: {
      type: Array,
      required: true
    }
  },
  template: '<div id="cy" class="cy"></div>',
  mounted: function () {
    const cy1 = cytoscape({
      container: document.getElementById("cy"),
      elements: this.elements,
      layout: {
        name: 'dagre'
      },
      style: [
        // what a node looks like?
        {
          selector: 'node',
          style: {
            'content': 'data(name)',
            'text-valign': 'center',
            'text-halign': 'right',
            'background-color': '#ededed'
          }
        },
        // what an edge looks like?
        {
          selector: 'edge',
          style: {
            'curve-style': 'bezier',
            'width': 1,
            'target-arrow-shape': 'triangle',
            'line-color': '#333333',
            'target-arrow-color': '#333333'
          }
        }
      ]
    });
    
    cy1.nodeHtmlLabel([
      {
        query: 'node',
        tpl: function (data) {
          return `<div id="${ data.id }"></div>`
        }
      }
    ])
  }
});

// le Vue app
const vm = new Vue({
  el: "#app",
  components: {
    'job': Job
  },
  data () {
    return {
      queryResponse: graphqlResponse
    }
  },
  computed: {
    workflow: function () {
      return this.queryResponse.data.workflows[0]
    },
    nodes: function () {
      return this.workflow.nodesEdges.nodes
    },
    elements: function () {
      // structure used by cytoscape
      const elements = {
        nodes: [],
        edges: []
      }

      // I thought nodes would contain all the valid nodes, but it looks like some are only
      // available in the edges section (as target/source), so we loop twice to populate
      // all the nodes
      this.workflow.nodesEdges.nodes.map((node) => {
        elements.nodes.push({
          data: {
            id: node.id,
            name: node.task.name, // used to display the value in the graph,
            status: node.state
          }
        })
      })
      this.workflow.nodesEdges.edges.map((edge) => {
        elements.nodes.push({
          data: {
            id: edge.source
          }
        })
        elements.nodes.push({
          data: {
            id: edge.target
          }
        })
      })

      // then we add all the edges
      this.workflow.nodesEdges.edges.map((edge) => {
        elements.edges.push(
          {
            data: {
              source: edge.source,
              target: edge.target
            }
          }
        )
      })
      return elements
    }
  }
})
window.vm = vm

              
            
!
999px

Console