Skip to content

Instantly share code, notes, and snippets.

@ckothari
ckothari / centers.csv
Last active March 19, 2016 13:21
Plots center of countries
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
iso lat long name
AD 42.546245 1.601554 Andorra
AE 23.424076 53.847818 United Arab Emirates
AF 33.93911 67.709953 Afghanistan
AG 17.060816 -61.796428 Antigua and Barbuda
AI 18.220554 -63.068615 Anguilla
AL 41.153332 20.168331 Albania
AM 40.069099 45.038189 Armenia
AN 12.226079 -69.060087 Netherlands Antilles
AO -11.202692 17.873887 Angola
@ckothari
ckothari / normalize.js
Created March 19, 2016 13:19
Normalize value
/**
* Normalizes a value given scale : [minRange, maxRange],
* valueRange: [minValue, maxValue] and the number: value
*
* Adapted from http://mathforum.org/library/drmath/view/60433.html
* @param value
* @param minRange
* @param maxRange
* @param minValue
* @param maxValue
@ckothari
ckothari / bubbleMap.js
Last active August 6, 2016 07:20
Bubble map with Pack layout
var BubbleMap = (function(){
function BubbleMap(data, elem, width, height, minRadius, maxRadius){
this.width = width;
this.height = height;
this.elem = elem[0];
this.data = data;
this.minRadius = minRadius;
this.maxRadius = maxRadius;
this.init();
this.drawCountries();
@ckothari
ckothari / README.md
Last active July 11, 2023 19:45 — forked from cbjuan/LICENSE.md
Stacked Bar Chart with Legend, Text Labels and Tooltips

Simple example of a Stacked Bar Chart in D3.js with legend, text labels, tooltips and word wrapping for X axis. Legend based on Susie Lu's library D3 Legend http://d3-legend.susielu.com/

@ckothari
ckothari / index.html
Last active August 6, 2016 11:29
Data Join v-3.5
<html>
<head>
<script type="application/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.17/d3.js"></script>
<!--<script type="application/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.2.1/d3.js"></script>-->
<style>
svg {
width: 100%;
height: 100%;
}
@ckothari
ckothari / index.html
Created August 6, 2016 11:41
Data Joins in v-4
<html>
<head>
<!--<script type="application/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.17/d3.js"></script>-->
<script type="application/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.2.1/d3.js"></script>
<style>
svg {
width: 100%;
height: 100%;
}
@ckothari
ckothari / index.html
Created August 9, 2016 14:21
Bar chart with data joins
<html>
<head>
<!--<script type="application/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.17/d3.js"></script>-->
<script type="application/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.2.1/d3.js"></script>
</head>
<body>
<!-- Visualization Placeholder -->
@ckothari
ckothari / index.html
Last active August 11, 2016 14:29
Lets make bar chart-2.1
<html>
<head>
<!--<script type="application/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.17/d3.js"></script>-->
<script type="application/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.2.1/d3.js"></script>
</head>
<body>
<!-- Visualization Placeholder -->
<div id="bar-chart"></div>
We couldn’t find that file to show.
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
iso lat long name
US 37.09024 -95.712891 United States
ZA -30.559482 22.937506 South Africa