Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hoverColor option #141

Merged
merged 5 commits into from
Oct 23, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ To configure the annotations plugin, you can simply add new config options to yo
```javascript
{
annotation: {
// Set this to false to hide all annotations (events will still trigger)
display: true, // (default)

// Defines when the annotations are drawn.
// This allows positioning of the annotation relative to the other
// elements of the graph.
Expand All @@ -40,6 +43,7 @@ To configure the annotations plugin, you can simply add new config options to yo
// Array of annotation configuration objects
// See below for detailed descriptions of the annotation options
annotations: [{
display: true, // (default)
drawTime: 'afterDraw', // overrides annotation.drawTime if set
id: 'a-line-1', // optional
type: 'line',
Expand Down
3 changes: 2 additions & 1 deletion src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ module.exports = function(Chart) {
function initConfig(config) {
config = chartHelpers.configMerge(Chart.Annotation.defaults, config);
if (chartHelpers.isArray(config.annotations)) {
config.annotations.forEach(function(annotation) {
config.annotations = config.annotations.map(function(annotation) {
annotation.label = chartHelpers.configMerge(Chart.Annotation.labelDefaults, annotation.label);
return chartHelpers.configMerge(Chart.Annotation.annotationDefaults, annotation);
kurkle marked this conversation as resolved.
Show resolved Hide resolved
});
}
return config;
Expand Down
5 changes: 5 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@ Chart.Annotation.drawTimeOptions = {
};

Chart.Annotation.defaults = {
display: true,
drawTime: 'afterDatasetsDraw',
dblClickSpeed: 350, // ms
events: [],
annotations: []
};

Chart.Annotation.annotationDefaults = {
display: true
};

Chart.Annotation.labelDefaults = {
backgroundColor: 'rgba(0,0,0,0.8)',
fontFamily: Chart.defaults.global.defaultFontFamily,
Expand Down
14 changes: 10 additions & 4 deletions src/types/box.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,16 @@ module.exports = function(Chart) {
model.right = right;
model.bottom = bottom;

// Stylistic options
model.borderColor = options.borderColor;
model.borderWidth = options.borderWidth;
model.backgroundColor = options.backgroundColor;
// Hide if display disabled
if(options.display && chartInstance.annotation.options.display) {
benmccann marked this conversation as resolved.
Show resolved Hide resolved
model.borderColor = options.borderColor;
model.borderWidth = options.borderWidth;
model.backgroundColor = options.backgroundColor;
} else {
model.borderColor = 'rgba(0,0,0,0)';
model.borderWidth = 0;
model.backgroundColor = 'rgba(0,0,0,0)';
}
},
inRange: function(mouseX, mouseY) {
var model = this._model;
Expand Down
7 changes: 7 additions & 0 deletions src/types/line.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,13 @@ module.exports = function(Chart) {
model.borderWidth = options.borderWidth;
model.borderDash = options.borderDash || [];
model.borderDashOffset = options.borderDashOffset || 0;

// Hide if display is disabled
if(!options.display || !chartInstance.annotation.options.display) {
benmccann marked this conversation as resolved.
Show resolved Hide resolved
model.labelEnabled = false;
model.borderColor = 'rgba(0,0,0,0)';
model.borderWidth = 0;
}
},
inRange: function(mouseX, mouseY) {
var model = this._model;
Expand Down