All examples By author By category About

stephen101

Minimum Circle Example

#Minimum Circle

Calculates the centrepoint and radius of the smallest circle that encircles all the points provided as input. Drag the points around in the above vizualisation to see the circle update.

Source: https://github.com/stephen101/d3-plugins/tree/master/src/minimumCircle

Instantiation

First create the layout and pass in the data points you are working with

	var circle = minimumCircle()
	      			.data(points)

Then call the layout to calculate circle centre and radius, this allows you to change the underlying data and re-evaluate the function multiple times

    var circleData = circle()

##Rendering

To render the circle from the calculated data

	d3.select("svg")
		.append("circle")
		    .attr("r", circleData.r)
            .attr("cx", circleData.x)
            .attr("cy", circleData.y);