Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
mtgibbs committed Feb 1, 2016
1 parent e4c3427 commit 5164e95
Showing 1 changed file with 60 additions and 2 deletions.
62 changes: 60 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ var defaultOptions = {
x: 2,
y: 4
},
labelPositionFnc: undefined,
startAtBase: undefined,
textAnchor: 'start',
showZeroLabels: false,
includeIndexClass: false,
thresholdPercentage: 30,
thresholdOptions: {
percentage: 30,
belowLabelClass: 'ct-label-below',
aboveLabelClass: 'ct-label-above'
}
Expand All @@ -43,17 +45,73 @@ var defaultOptions = {
x: 0,
y: -2
},
labelPositionFnc: undefined,
startAtBase: undefined,
textAnchor: 'middle',
showZeroLabels: false,
includeIndexClass: false,
thresholdPercentage: 30,
thresholdOptions: {
percentage: 30,
belowLabelClass: 'ct-label-below',
aboveLabelClass: 'ct-label-above'
}
}
```

##### Label Position Function

The label position function can be used to conditionally influence the location of the label relative to the bar. The function has some bar data being passed to it in this format:

```javascript
{
high: number; // the highest value in the chart or the defined high in the options
value: number; // the value of the bar that the label will belong to
threshold: number; // the percentage threshold defined in the options
}
```

The function must return labelOffset and textAnchor data otherwise when this data is undefined it will fall back on the default offsets.

```javascript
{
labelOffset: {
x: number // the offset to the label on the X axis
y: number // the offset to the label on the Y axis
},
textAnchor: string // the css text-anchor value
}

```

The plugin comes with a default example.

```javascript
Chartist.plugins.ctBarLabels.InsetLabelsPositionHorizontal = function(data) {

if (data.high && data.value && data.threshold) {
var aboveThreshold = (data.value / data.high * 100 > data.threshold);

if (aboveThreshold) {
return {
labelOffset: {
x: -2,
y: 4
},
textAnchor: 'end'
}
} else {
return {
labelOffset: {
x: 2,
y: 4
},
textAnchor: 'start'
};
}
}
};
```

##### Example Script

```javascript
Expand Down

0 comments on commit 5164e95

Please sign in to comment.