-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable applying of gradients and pattern on line segments (#11217)
* Enable applying of gradients and pattern on line segments * add test case * improve replacer
- Loading branch information
1 parent
aec1c6d
commit ee7e928
Showing
3 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const getGradient = (context) => { | ||
const {chart, p0, p1} = context; | ||
const ctx = chart.ctx; | ||
const {x: x0} = p0.getProps(['x'], true); | ||
const {x: x1} = p1.getProps(['x'], true); | ||
const gradient = ctx.createLinearGradient(x0, 0, x1, 0); | ||
gradient.addColorStop(0, p0.options.backgroundColor); | ||
gradient.addColorStop(1, p1.options.backgroundColor); | ||
return gradient; | ||
}; | ||
|
||
module.exports = { | ||
config: { | ||
type: 'line', | ||
data: { | ||
datasets: [{ | ||
data: [{x: 0, y: 0}, {x: 1, y: 1}, {x: 2, y: 2}, {x: 3, y: 3}, {x: 4, y: 4}, {x: 5, y: 5}, {x: 6, y: 6}], | ||
pointBackgroundColor: ['red', 'yellow', 'green', 'green', 'blue', 'pink', 'blue'], | ||
pointBorderWidth: 0, | ||
pointRadius: 10, | ||
borderWidth: 5, | ||
segment: { | ||
borderColor: getGradient, | ||
} | ||
}] | ||
}, | ||
options: { | ||
scales: { | ||
x: {type: 'linear', display: false}, | ||
y: {display: false} | ||
} | ||
} | ||
} | ||
}; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.