HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<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>
<job v-for="node in nodes" :key="node.id" :status="node.state" :ref="node.id"></job>
<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>
#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);
}
}
}
// 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>`
})
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) {
const jobForThisNode = window.vm.$refs[data.id][0]
if (Object.hasOwnProperty.call(jobForThisNode, '$el')) {
return jobForThisNode.$el.outerHTML
}
return ''
}
}
])
}
});
// 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
Also see: Tab Triggers