Built with blockbuilder.org
forked from sxywu's block: DS July: Code 1
forked from sxywu's block: DS July: Code 2
forked from sxywu's block: DS July: Code 3
forked from sxywu's block: DS July: Code 4
forked from sxywu's block: DS July: Code 5
forked from sxywu's block: DS July: Code 6
forked from sxywu's block: DS July: Code 7
forked from sxywu's block: Film Flowers, All
forked from anonymous's block: Film Flowers, Refactored
forked from sxywu's block: Film Flowers, Refactored
forked from sxywu's block: Film Flowers, Single Scaled Starter
forked from sxywu's block: Film Flowers, Single Starter
forked from mwehnert's block: Film Flowers, Single Starter
xxxxxxxxxx
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.13.1/lodash.js'></script>
<link href='https://fonts.googleapis.com/css?family=Libre+Baskerville:400,700' rel='stylesheet' type='text/css'>
<style>
svg {
width: 600px;
height: 20000px;
}
</style>
</head>
<body>
<svg></svg>
<script>
const width = 600;
const height = 600;
const petalPaths = [[
'M0,0',
'C50,40 50,70 20,100',
'L0,85',
'L-20,100',
'C-50,70 -50,40 0,0'
],
// ADD 3 MORE PETAL PATHS
[
// write your svg path here
'M0,0',
'C0,50 -50,50 -50,100',
'C-50,120 -35,120 -20,110',
'C-10,100 10,100 20,110',
'C 35,120 50,120 50,100',
'C 50,50 0,50 0,0'
]
];
// petal lookup for PG ratings
const pathLookup = {
G: petalPaths[0],
PG: petalPaths[1],
'PG-13': petalPaths[2],
R: petalPaths[3],
};
// grab svg
const svg = d3.select(' svg');
/*****************************************************
** get movie data
******************************************************/
d3.json('movies.json', function(movies) {
movies = _.map(movies, movie => {
return {
rating: ++movie.imdbRating,
votes: parseInt(movie.imdbVotes.replace(/\,/g, '')),
year: ++movie.Year,
title: movie.Title,
pg: movie.Rated,
}
});
const votesDomain = d3.extent(movies, data => data.votes);
const petalsNum = d3.scaleQuantize()
.domain(votesDomain)
.range([5, 15]);
// 1. create petal data for just the first movie
const movie = movies.filter((movie, index) => index === 0);
const petalData = [];
for (let i = 0; i < petalsNum(movie.votes); i++) {
petalData.push({
rotate: i/petalsNum(movie.votes)*360,
path: pathLookup[movies[0].pg]
});
}
// 2. draw the petals using d3's data-binding and enter-append
// (hint: use SVG transform for translation, rotation, and scale)
svg.selectAll('path')
.data(petalData)
.enter().append('path')
.attr('transform', data => `translate(200,200) rotate(${data.rotate})`)
.attr('d', data => data.path)
.attr('fill', 'lime')
.attr('stroke', '#000')
.attr('style', 'opacity:0.5;');
});
</script>
</body>
https://d3js.org/d3.v4.min.js
https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.13.1/lodash.js