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 includes JSX processing.

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

Packages

Add Packages

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.

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

              
                <script src="https://cdn.rawgit.com/fnando/sparkline/master/dist/sparkline.js
"></script>
<h2>Smart Flanders demo</h2>
<strong>This demo automatically discovers live and historic off-street parking site availabilities in cities across Flanders.</strong> ― <a href="https://smart.flanders.be/piloten/parkeren.html">read more (Dutch)</a>
<p>
  Pick a city: <select id="stad" name="stad" value="kies een stad" onChange="processGemeente()"></select></p>
<div>
<p>And pick a parking site <select name="parking" id="parking" onChange="processParking()"></select></p>
<p>
  This parking site has <span id="plaatsen"><i>...</i></span>
<svg class="parking-sparkline" width="50" height="20" stroke-width="2" stroke="blue" fill="rgba(0, 0, 255, .2)"></svg> <span class="tooltip" hidden="true"></span> vacant parking spaces.</p></div> 

 <svg style="display: inline-block;  vertical-align: middle; height: 40px;  width: 25px;  margin: 0;  fill: #333332;">
    
  <path data-name="Logo Vlaanderen" d="M19.61 16c-1.08-.82-1.59 0-2.27 0s-1.12-1-1.56-.75c-.85.43.34 2 .86 2.27a12.51 12.51 0 0 0 1.18.59 1.72 1.72 0 0 1 1 1.55 3 3 0 0 1 0 .75c-.31 1.32-2.64 2.52-4 1.61a3 3 0 0 1-1.4-2c-.36-1.73-1.62-3-2-4.7-.25-1-.43-2.12-.7-3.15S10.17 10 9.94 9A27.44 27.44 0 0 0 9 5.92C7.71 2.61 7.14 2.85 7.14 2.85s.46.92 2.15 9A47.8 47.8 0 0 0 10.42 17c.16.42.44 1.32.62 1.72.54 1.16 2 2.92 2.05 4.51.05.92.16 1.68.18 2.37a7.37 7.37 0 0 0 .24 1.4c.35 1 3.14 4.09 6.1 4.09v-2.41a10.88 10.88 0 0 1-5.79-1.82 6.37 6.37 0 0 1 .35-1.7 2.78 2.78 0 0 1 2.39-1.94 17.91 17.91 0 0 1 3 .31V16zM6.82 7.36c-.11 1.77-2.87 4.2-3.73 5.75A11.43 11.43 0 0 0 2 15.95a7.53 7.53 0 0 0 .62 4.67c.91 2.18-.12 3 .59 2.54.88-.72.75-2.39.68-3.43a14.77 14.77 0 0 1 0-2.82 13.29 13.29 0 0 1 2.41-5.33 4.84 4.84 0 0 0 .52-4.22m.56 5s.29 1.4-1 5c-3.26 9.45 3 10.34 4.74 12.56 0 0 .69-1-2.14-4-1-1.12-2-3.6-1.15-7.15 1.17-5.13-.5-6.39-.5-6.39M1.21 6.2A4.53 4.53 0 0 1 1 4.7c.2-2.22 2.23-3.12 2.73-3.45A2.7 2.7 0 0 0 4.76 0a3 3 0 0 1-1.21 3.67A6.06 6.06 0 0 0 1.21 6.2m5.11-2.15c.11.23 1 1.45-2.48 4.27s-2.36 4.84-2.36 4.84-3.66-2 .56-5.53 3.35-4.2 3.35-4.2a1.05 1.05 0 0 1 .93.63m4.46 1.08c.59.08 1 1.92 2.35 2.32 1 .29 2.08.13 2.32.74a.52.52 0 0 0 .37.92c.39-1.12.58-5.24-5.03-3.98zm1.86.86c0-.13.12 0 .27-.12a1.66 1.66 0 0 1 .59-.48 1 1 0 0 1 .62 0c.12 0 0 .33 0 .4s-.74-.09-.74.32c0 .67.91 0 1.38 0 .23 1.64-2.48 1.19-2.08-.16z"></path></svg>
<small>This demo is part of <a href="https://smart.flanders.be">Smart Flanders</a>: a support program for publishing real-time Open Data in Flanders.</small>
              
            
!

CSS

              
                body {
  padding: 50px;
}

div {
  position: relative;
  display: inline;
}

*[hidden] {
  display: none;
}

.sparkline--cursor {
  stroke: orange;
}

.sparkline--spot {
  fill: red;
  stroke: red;
}
              
            
!

JS

              
                // This library reads any serialization, and extract the Linked Data facts from it, which are returned.
// You can find it over here: https://github.com/pietercolpaert/ldfetch
var ldfetch = new window.ldfetch();
// This URL is our starting point, and the only location we use that is hard coded
// It is the data catalog that we maintain of references to all datasets relevant to our use case
// It follows the W3C DCAT standard (and European DCAT-AP)
// We can imagine private parties creating their own controlled list of datasets they trust. (the generation of this list can of course in its turn be automated)
var url = "https://datapiloten.be/parking/catalog.ttl";

// This is the first Linked Data helper function:
// It takes the list of triples as an argument, and returns a summary of everything we know about a certain subject in one object
var triplesToObjects = function(triples) {
	var objects = {};
	for (var index in triples) {
		var triple = triples[index];
		if (!objects[triple.subject.value]) {
			objects[triple.subject.value] = {};
		}
		objects[triple.subject.value][triple.predicate.value] = triple.object.value;

		if (triple.predicate.value === "http://www.w3.org/ns/prov#generatedAtTime") {
			objects[triple.subject.value][triple.predicate.value] = new Date(
				objects[triple.subject.value][triple.predicate.value]
			);
		}
	}
	return objects;
};

// This is the second helper function:
// It takes the list of triples, with their context, as an argument, and returns a summary of everything we know about a certain subject in one object, but also first group them by their context. E.g., for time series, the context indicated through a generatedAtTime property the time at which the value is true.
var quadsToObjects = function(quads) {
	var graphs = {};
	for (var index in quads) {
		var quad = quads[index];
		if (!graphs[quad.graph.value]) {
			graphs[quad.graph.value] = {};
		}
		var objects = graphs[quad.graph.value];
		if (!objects[quad.subject.value]) {
			objects[quad.subject.value] = {};
		}
    objects[quad.subject.value][quad.predicate.value] = quad.object.value;
		graphs[quad.graph.value] = objects;
	}
	return graphs;
};

//At start-up, we will download the DCAT catalog of parkings and populate a drop-down menu
ldfetch.get(url).then(response => {
	//Filter the results and select the dct:title
	var objects = triplesToObjects(response.triples);
  
	//Filter the results and populate the gemeente-selector
	var options = "<option/>"; //start with an empty value
	for (var subject in objects) {
		var entity = objects[subject];
    //Select all objects that are a Dataset
		if (
			entity["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"] ===
			"http://www.w3.org/ns/dcat#Dataset"
		) {
			//populate gemeente-selector
			options +=
				'<option value="' +
				entity["http://www.w3.org/ns/dcat#distribution"] +
				'">' +
				entity["http://purl.org/dc/terms/title"] +
				"</option>";
		}
	}
	document.getElementById("stad").innerHTML = options;
});

var timeseries = [];

// When a Gemeente is selected, we will download the data from that gemeente
var processGemeente = async function() {
	document.getElementById("plaatsen").innerHTML = "X";
	var gemeente = document.getElementById("stad").value;
	var response = await ldfetch.get(gemeente);
  //this will squash all named graphs together, useful for extracting basic information across all triples
  var responsetriples = response.triples;
	var objects = triplesToObjects(responsetriples);

  // If a previous page link exists, let’s also process this previous page to have a good amount of data in our visualization.
  // Now, we’ll be lazy and only check whether there’s a hydra:previous predicate attached to the current page URL. We will extend this in the future if it gets properly standardized in Flanders/Europe/W3C -- From then on, this will become a convenience function in LDFetch
  if (objects[response.url] && objects[response.url]["http://www.w3.org/ns/hydra/core#previous"]) {
    var response2 = await ldfetch.get(objects[response.url]["http://www.w3.org/ns/hydra/core#previous"]);
    //put all triples in one pile
    responsetriples = response.triples.concat(response2.triples);
    //and we need to run this again
    objects = triplesToObjects(responsetriples);
  }
  
  //this will categorize the objects per named graph, useful for extracting the precise information per measurement
	var graphs = quadsToObjects(responsetriples);
		//now, create an overview of the timeseries per parking site
		for (var graphname in graphs) {
			for (var subject in graphs[graphname]) {
				var parkingObservation = graphs[graphname][subject];
				if (parkingObservation["http://vocab.datex.org/terms#parkingNumberOfVacantSpaces"]) {
					var observation = {};
					observation.time = objects[graphname]["http://www.w3.org/ns/prov#generatedAtTime"];
					observation.subject = subject;
					observation.value =
						parkingObservation["http://vocab.datex.org/terms#parkingNumberOfVacantSpaces"];
					observation.max =
						objects[subject]["http://vocab.datex.org/terms#parkingNumberOfSpaces"];
					timeseries.push(observation);
				}
			}
		}
		//You cannot trust the server to send you ordered measurements, so let’s order them here
		timeseries.sort((a, b) => a.time.getTime() - b.time.getTime());
		var options = "<option selected/>";
		for (var subject in objects) {
			var entity = objects[subject];
			if (
				entity["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"] ===
				"http://vocab.datex.org/terms#UrbanParkingSite"
			) {
				options +=
					'<option value="' +
					subject +
					'">' +
					entity["http://www.w3.org/2000/01/rdf-schema#label"] +
					"</option>";
			}
		}
		document.getElementById("parking").innerHTML = options;
};

//Put only the most recent value in the page
var processParking = function() {
	var parkingid = document.getElementById("parking").value;
	var observations = timeseries.filter(obj => {
		return obj.subject === parkingid;
	});
	var latest = observations[observations.length -1];
	document.getElementById("plaatsen").innerHTML =
		latest.value +
		"/" +
		latest.max +
		"";
  observations = observations.map((obj) => {
    return {
      name : obj.subject,
      value : parseInt(obj.value),
      date : obj.time
    }
  });
  sparkline.sparkline(document.querySelector(".parking-sparkline"), observations, options);
};

//The rest is helper code to create the sparkline with the nice mouse-over:
// Generating sparklines with https://github.com/fnando/sparkline

function findClosest(target, tagName) {
  if (target.tagName === tagName) {
    return target;
  }

  while ((target = target.parentNode)) {
    if (target.tagName === tagName) {
      break;
    }
  }
  return target;
}

var options = {
  onmousemove(event, datapoint) {
    var svg = findClosest(event.target, "svg");
    var tooltip = svg.nextElementSibling;
    var date = (new Date(datapoint.date)).toLocaleString('nl-BE', { hour12: false, 
                                             hour: "numeric", 
                                             minute: "numeric"});

    tooltip.hidden = false;
    tooltip.textContent = `${date} ― ${datapoint.value} spots available`;
    tooltip.style.top = `${event.offsetY}px`;
    tooltip.style.left = `${event.offsetX + 20}px`;
  },

  onmouseout(event) {
    var svg = findClosest(event.target, "svg");
    var tooltip = svg.nextElementSibling;

    tooltip.hidden = true;
  }
};


              
            
!
999px

Console