forked from chartjs/Chart.js
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
92 additions
and
2 deletions.
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Derived Axis Type - Log2 | ||
# Derived Axis Type | ||
|
||
```js chart-editor | ||
// <block:setup:1> | ||
|
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,46 @@ | ||
# Derived Chart Type | ||
|
||
```js chart-editor | ||
// <block:setup:1> | ||
const DATA_COUNT = 7; | ||
const NUMBER_CFG = {count: DATA_COUNT, min: -100, max: 100, rmin: 1, rmax: 20}; | ||
const data = { | ||
datasets: [ | ||
{ | ||
label: 'My First dataset', | ||
backgroundColor: Utils.transparentize(Utils.CHART_COLORS.blue, 0.5), | ||
borderColor: Utils.CHART_COLORS.blue, | ||
borderWidth: 1, | ||
boxStrokeStyle: 'red', | ||
data: Utils.bubbles(NUMBER_CFG) | ||
} | ||
], | ||
}; | ||
// </block:setup> | ||
|
||
// <block:config:0> | ||
const config = { | ||
type: 'derivedBubble', | ||
data: data, | ||
options: { | ||
responsive: true, | ||
plugins: { | ||
title: { | ||
display: true, | ||
text: 'Derived Chart Type' | ||
}, | ||
} | ||
} | ||
}; | ||
|
||
// </block:config> | ||
|
||
module.exports = { | ||
actions: [], | ||
config: config, | ||
}; | ||
``` | ||
|
||
## DerivedBubble Implementation | ||
|
||
<<< @/docs/scripts/derived-bubble.js |
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 @@ | ||
import {Chart, BubbleController} from 'chart.js'; | ||
|
||
class Custom extends BubbleController { | ||
draw() { | ||
// Call bubble controller method to draw all the points | ||
super.draw(arguments); | ||
|
||
// Now we can do some custom drawing for this dataset. | ||
// Here we'll draw a box around the first point in each dataset, | ||
// using `boxStrokeStyle` dataset option for color | ||
var meta = this.getMeta(); | ||
var pt0 = meta.data[0]; | ||
|
||
const {x, y} = pt0.getProps(['x', 'y']); | ||
const {radius} = pt0.options; | ||
|
||
var ctx = this.chart.ctx; | ||
ctx.save(); | ||
ctx.strokeStyle = this.options.boxStrokeStyle; | ||
ctx.lineWidth = 1; | ||
ctx.strokeRect(x - radius, y - radius, 2 * radius, 2 * radius); | ||
ctx.restore(); | ||
} | ||
} | ||
Custom.id = 'derivedBubble'; | ||
Custom.defaults = { | ||
// Custom defaults. Bubble defaults are inherited. | ||
boxStrokeStyle: 'red' | ||
}; | ||
// Overrides are only inherited, but not merged if defined | ||
// Custom.overrides = Chart.overrides.bubble; | ||
|
||
// Stores the controller so that the chart initialization routine can look it up | ||
Chart.register(Custom); |
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import {Chart, registerables} from '../../dist/chart.esm'; | ||
import Log2Axis from './log2'; | ||
import './derived-bubble'; | ||
|
||
Chart.register(...registerables); | ||
Chart.register(Log2Axis); |
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