0.1.0 • Published 8 years ago

rope-chart v0.1.0

Weekly downloads
2
License
ISC
Repository
github
Last release
8 years ago

ropeChart

The rope chart provides a simplified visualization of where a particular value lies within a group.

Getting Started

For now, you must use a script tag to include ropeChart. D3 must be available in the global namespace as well. Download ropeChart.js, put something like the following in your and you should be good to go.

<script src="d3.js" charset="utf-8"></script>
<script src="ropeChart.js" charset="utf-8"></script>

Example

HTML would look something like this

<!DOCTYPE html>
<html lang="en-US">
	<head>
		<script src="d3.js" charset="utf-8"></script>
		<script src="ropeChart.js" charset="utf-8"></script>
		
	</head>
	<body>
		<div id="myRopeChart"></div>	
	</body>
	<script src="index.js"></script>
</html>

And the index.js here would contain something like this

var data = {
  min: {value: 5, label: 'Country A'},
  max: {value: 95, label: 'Country B'},
  threshold: {value: 60, label: 'Region Average'},
  focus: {value: 45, label: 'Mongolia'}
}

var myRopeChart = ropeChart('div#myRopeChart');
	.data(data)
	.width(250)
	.height(250)
	.ropeWidth(10)
	.knotRadius(10)
	.render();

API Reference

ropeChart

Kind: global class

new ropeChart(selection)

Rope chart implementation.

Returns: ropeChart - s

ParamTypeDescription
selectionStringany valid d3 selector. This selector is used to place the chart.

ropeChart.render(data) ⇒ ropeChart

Render the ropeChart instance. Simply renders chart when called with no parameter. Updates data, then renders, if called with parameter

Kind: instance method of ropeChart

ParamType
dataObject

ropeChart.data(data) ⇒ Object | ropeChart

Get/set the data for the ropeChart instance

Kind: instance method of ropeChart
Returns: Object - Acts as getter if called with no parameterropeChart - Acts as setter if called with parameter

ParamType
dataObject

ropeChart.width() ⇒ Object | ropeChart

Get/set the name/key used to access the "focus" item for the chart. The "focus" is the member of the data set that you want to compare to the rest of the group.

Kind: instance method of ropeChart
Returns: Object - Acts as getter if called with no parameter. Returns a record from your data set.ropeChart - Acts as setter if called with parameter

ParamType
recordName - should be the value of the name property for the record you want as your focus.String

ropeChart.width(width) ⇒ Integer | ropeChart

Get/set the width of the chart SVG

Kind: instance method of ropeChart
Returns: Integer - Acts as getter if called with no parameterropeChart - Acts as setter if called with parameter

ParamTypeDefault
widthInteger500

ropeChart.height(height) ⇒ Integer | ropeChart

Get/set the height of the chart SVG

Kind: instance method of ropeChart
Returns: Integer - Acts as getter if called with no parameterropeChart - Acts as setter if called with parameter

ParamTypeDefault
heightInteger500

ropeChart.knotRadius(knotRadius) ⇒ Integer | ropeChart

Get/set the radius of "knot" circles at max, min, and focus value positions.

Kind: instance method of ropeChart
Returns: Integer - Acts as getter if called with no parameterropeChart - Acts as setter if called with parameter

ParamTypeDefault
knotRadiusInteger20

ropeChart.ropeWidth(ropeWidth) ⇒ Integer | ropeChart

Get/set the width of the "rope" rectangle.

Kind: instance method of ropeChart
Returns: Integer - Acts as getter if called with no parameterropeChart - Acts as setter if called with parameter

ParamTypeDefault
ropeWidthInteger20

ropeChart.threshLineLength(threshLineLength) ⇒ Integer | ropeChart

Get/set the length of the horizontal "threshold" line.

Kind: instance method of ropeChart
Returns: Integer - Acts as getter if called with no parameterropeChart - Acts as setter if called with parameter

ParamTypeDefault
threshLineLengthInteger20

ropeChart.goodColor(goodColor) ⇒ String | ropeChart

Get/set the color used on the "good" side of the threshold.

Kind: instance method of ropeChart
Returns: String - Acts as getter if called with no parameterropeChart - Acts as setter if called with parameter

ParamTypeDefault
goodColorStringgreen

ropeChart.badColor(goodColor) ⇒ String | ropeChart

Get/set the color used on the "bad" side of the threshold.

Kind: instance method of ropeChart
Returns: String - Acts as getter if called with no parameterropeChart - Acts as setter if called with parameter

ParamTypeDefault
goodColorStringred

ropeChart.flipDirection(flipDirection) ⇒ Boolean | ropeChart

Get/set boolean that "flips direction" of the "good"/"bad" sides of threshold. By default the top section is "good" (green). If flipDirection is true, then top section becomes "bad" (red).

Kind: instance method of ropeChart
Returns: Boolean - Acts as getter if called with no parameterropeChart - Acts as setter if called with parameter

ParamTypeDefault
flipDirectionBooleanfalse

ropeChart.showAverage(showAverage) ⇒ Boolean | ropeChart

Get/set boolean that toggles display of a "knot" for the group average.

Kind: instance method of ropeChart
Returns: Boolean - Acts as getter if called with no parameterropeChart - Acts as setter if called with parameter

ParamTypeDefault
showAverageBooleanfalse

ropeChart.averageLabel(averageLabel) ⇒ String | ropeChart

Get/set label for average knot location.

Kind: instance method of ropeChart
Returns: String - Acts as getter if called with no parameterropeChart - Acts as setter if called with parameter

ParamTypeDefault
averageLabelString"Average"

ropeChart.labelMargin(labelMargin) ⇒ Integer | ropeChart

Get/set the margin between labels and "knot" circles.

Kind: instance method of ropeChart
Returns: Integer - Acts as getter if called with no parameterropeChart - Acts as setter if called with parameter

ParamTypeDefault
labelMarginInteger5

ropeChart.valueAccessor(valueAccessorFunction) ⇒ function | ropeChart

Get/set function used to access "value" property from each data record. Defaults to:

function (d){ return d.value; }

Kind: instance method of ropeChart
Returns: function - Acts as getter if called with no parameterropeChart - Acts as setter if called with parameter

ParamType
valueAccessorFunctionfunction

ropeChart.nameAccessor(nameAccessorFunction) ⇒ function | ropeChart

Get/set function used to access "name" property from each data record. Defaults to:

function (d){ return d.name; }

Kind: instance method of ropeChart
Returns: function - Acts as getter if called with no parameterropeChart - Acts as setter if called with parameter

ParamType
nameAccessorFunctionfunction
0.1.0

8 years ago