css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <link href='https://fonts.googleapis.com/css?family=Roboto:400,400italic&subset=latin,latin-ext,greek-ext,greek,cyrillic-ext,cyrillic,vietnamese' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Merriweather:400,400italic&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Alegreya+Sans+SC:400,400italic&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Yanone+Kaffeesatz:400&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Tillana:400&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Source+Code+Pro:400,400italic&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Comfortaa:400,&subset=latin,latin-ext,greek,cyrillic-ext,cyrillic' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Inknut+Antiqua:400&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Roboto+Slab:400,400italic&subset=latin,latin-ext,greek-ext,greek,cyrillic-ext,cyrillic,vietnamese' rel='stylesheet' type='text/css'>
<link href="https://fonts.googleapis.com/css?family=Krona+One&amp;subset=latin-ext" rel="stylesheet" type='text/css'>
<link href="https://fonts.googleapis.com/css?family=Seymour+One&amp;subset=latin-ext" rel="stylesheet" type='text/css'>

	<h2> Simple line chart with microtext </h2>
	<small>Each line is labeled with microtext in multiple languages. Data, fonts and colors are semi-random, refresh page to re-run.</small></p>
<button onclick="actualLines.attr('visibility','hidden');"> Line off </button>
<button onclick="actualLines.attr('visibility','normal');"> Line on </button>
<button onclick="actualLines.attr('stroke-width',linewidth++);"> Fatter </button>
<button onclick="actualLines.attr('stroke-width',linewidth--);"> Thinner </button>
 ||
<button onclick="microText.attr('visibility','hidden'); "> Text off </button>
<button onclick="microText.attr('visibility','normal'); "> Text on </button>
<button onclick="fontsize++; microText.attr('font-size',fontsize); "> Bigger </button>
<button onclick="fontsize--; microText.attr('font-size',fontsize); "> Smaller </button> 
<br>
	
            
          
!
            
              		h2 {
			font-family: "Roboto Slab";
			font-weight: 700;
			color: #222277;
		}
            
          
!
            
              //fonts loaded
fontlist=["Roboto", "Merriweather", "Roboto Slab", "Alegreya Sans SC", "Yanone Kaffeesatz", "Tillana", "Source Code Pro", "Comfortaa", "Inknut Antiqua", "Krona One", "Seymour One"];
	
//SAMPLE DATASET, 16 countries
dataset = [
		  {
			"ID":4,
			"Country":"Canada",
			"ISO":"CAN",
			"French":"Canada",
			"German":"Kanada",
      "Timeseries": []
		  },
		  {
			"ID":5,
			"Country":"Chile",
			"ISO":"CHL",
			"French":"Chili",
			"German":"Chile",
      "Timeseries": []
		  },
		  {
			"ID":6,
			"Country":"Czech Republic",
			"ISO":"CZE",
			"French":"République tchèque",
			"German":"Tschechische Republik",
			"Timeseries":[]
		  },
		  {
			"ID":10,
			"Country":"France",
			"ISO":"FRA",
			"French":"France",
			"German":"Frankreich",
			"Timeseries":[]
		  },
		  {
			"ID":11,
			"Country":"Germany",
			"ISO":"DEU",
			"French":"Allemagne",
			"German":"Deutschland",
			"Timeseries":[]
		  },
		  {
			"ID":12,
			"Country":"Greece",
			"ISO":"GRC",
			"French":"Grèce",
			"German":"Griechenland",
			"Timeseries":[]
		  },
		  {
			"ID":15,
			"Country":"Ireland",
			"ISO":"IRL",
			"French":"Irlande",
			"German":"Irland",
			"Timeseries":[]
		  },
		  {
			"ID":16,
			"Country":"Israel",
			"ISO":"ISR",
			"French":"Israël",
			"German":"Israel",
			"Timeseries":[]
		  },
		  {
			"ID":17,
			"Country":"Italy",
			"ISO":"ITA",
			"French":"Italie",
			"German":"Italien",
			"Timeseries":[]
		  },
		  {
			"ID":18,
			"Country":"Japan",
			"ISO":"JPN",
			"French":"Japon",
			"German":"Japan",
			"Timeseries":[]
		  },
		  {
			"ID":19,
			"Country":"Korea",
			"ISO":"KOR",
			"French":"Corée du Sud",
			"German":"Republik Korea",
			"Timeseries":[]
		  },
		  {
			"ID":21,
			"Country":"Mexico",
			"ISO":"MEX",
			"French":"Mexique",
			"German":"Mexiko",
			"Timeseries":[]
		  },
		  {
			"ID":22,
			"Country":"Netherlands",
			"ISO":"NLD",
			"French":"Pays-Bas",
			"German":"Niederlande",
			"Timeseries":[]
		  },
		  {
			"ID":24,
			"Country":"Norway",
			"ISO":"NOR",
			"French":"Norvège",
			"German":"Norwegen",
			"Timeseries":[]
		  },
		  {
			"ID":25,
			"Country":"Poland",
			"ISO":"POL",
			"French":"Pologne",
			"German":"Polen",
			"Timeseries":[]
		  },
		  {
			"ID":29,
			"Country":"Spain",
			"ISO":"ESP",
			"French":"Espagne",
			"German":"Spanien",
			"Timeseries":[]
		  }
		];
  		
//DATA PREP
var timeseriesMaxLen = Math.floor(Math.random()*60)+15;
var timeseriesVolatility = Math.random()*5.0;
var timeseriesMin = 9999; timeseriesMax = -9999;
var hexlist = '0123456789ABCDEF';
// make random data for the timeseries instead of the preset data
for (var i=1;i<dataset.length; i++) {
	// initial value is random, subsequent values based off prior value
	dataset[i].Timeseries[0] = Math.random()*1;
	for (var j=1;j<timeseriesMaxLen; j++) {
		dataset[i].Timeseries[j] = dataset[i].Timeseries[j-1] + 
			(Math.random()-0.5)*(Math.random()*0.5)*timeseriesVolatility;
	}
  
	// get min/max/length of series
	timeseriesMin = Math.min( timeseriesMin, d3.min( dataset[i].Timeseries ) );
	timeseriesMax = Math.max( timeseriesMax, d3.max( dataset[i].Timeseries ) );
	// pick a font for this line
	dataset[i].fontfamily = fontlist[Math.floor(Math.random() * fontlist.length)];
	// create the string to use for the line
	dataset[i].microstring=" \00 " + dataset[i].Country;
	for (var j=0; j<50; j++) {
		prevmicro = dataset[i].microstring;
		dataset[i].microstring = prevmicro
					+ "--" + dataset[i].French
					+ "--" + dataset[i].German
					+ "--" + dataset[i].Country;
	}
	// generate a random color for this line
	dataset[i].clr = "#";
	for (var j = 0; j < 6; j++) {
		  dataset[i].clr += hexlist[Math.floor(Math.random() * 16)];
	}						
}


// set up the drawing area
var w = 1000,
		h = 600,
		margin = 50;
fontsize = 8; linewidth = .1; letterspace = 1;
y = d3.scale.linear().domain([timeseriesMin, timeseriesMax]).range([0 + margin, h - margin]);
x = d3.scale.linear().domain([0, timeseriesMaxLen]).range([0 + margin, w - margin]);
			
var vis = d3.select("body")
			    .append("svg:svg")
			    .attr("width", w)
			    .attr("height", h);

var g = vis.append("svg:g")
			    .attr("transform", "translate(0, " + h + ")");

//TODO DELETE ME
g.append("circle").attr("radius",20).attr("fill","blue");

// parent (group) object for the lines and the text. 
// both the line and the microtext will inherit data from the parent	
var lineGroup = g.selectAll("lineGroup").data(dataset);
var lineObjects = lineGroup.enter()
				.append("g")
				.classed("lineGroup",true);
			
// this is the line generation function - See Bostock d3.svg.line (i.e. paths)
var line = d3.svg.line()
		    .x(function(d,i) { return x(i); })
		    .y(function(d) { return -1 * y(d+ Math.random()*.01 ); })	
				.interpolate("cardinal");
			
// the actual line geometry that get drawn
var actualLines = lineObjects
			.append("svg:path")
        // each line needs a unique id so we can associate the microtext with
				.attr("id", function(d,i) { return "path_"+ d.ISO; })
				.attr("stroke",function(d,i) { return d.clr; }) 
				.attr("stroke-width", linewidth)
				.attr("fill","none")
				.attr("visibility","normal")
				.attr("d",function(d) { return line(d.Timeseries); });
				   
// the microtext
var microText = lineObjects
      .append("text")
		  .append("textPath")
        // cross-reference to the line to put the text on the linepath
        // see also https://www.w3.org/TR/SVG/text.html#TextOnAPath
				.attr("xlink:href", function(d) { return "#path_" + d.ISO; })
				.attr("fill",   function(d,i) { return d.clr; })
				.attr("font-size",fontsize)
				.attr("letter-spacing", letterspace)
				.attr("startOffset", function(d,i) { return -i*3.5; }) 
				.attr("font-family", function(d) { return d.fontfamily; })
				.text( function(d) { return d.microstring });
	
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console