-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
Introduce scriptable options (bubble chart) #4671
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -30,13 +30,13 @@ | |
utils.srand(110); | ||
|
||
function colorize(opaque, context) { | ||
var data = context.data; | ||
var x = data.x / 100; | ||
var y = data.y / 100; | ||
var value = context.dataset.data[context.dataIndex]; | ||
var x = value.x / 100; | ||
var y = value.y / 100; | ||
var r = x < 0 && y < 0 ? 250 : x < 0 ? 150 : y < 0 ? 50 : 0; | ||
var g = x < 0 && y < 0 ? 0 : x < 0 ? 50 : y < 0 ? 150 : 250; | ||
var b = x < 0 && y < 0 ? 0 : x > 0 && y > 0 ? 250 : 150; | ||
var a = opaque ? 1 : 0.5 * data.v / 1000; | ||
var a = opaque ? 1 : 0.5 * value.v / 1000; | ||
|
||
return 'rgba(' + r + ',' + g + ',' + b + ',' + a + ')'; | ||
} | ||
|
@@ -86,13 +86,14 @@ | |
}, | ||
|
||
hoverBorderWidth: function(context) { | ||
return Math.round(8 * context.data.v / 1000); | ||
var value = context.dataset.data[context.dataIndex]; | ||
return Math.round(8 * value.v / 1000); | ||
}, | ||
|
||
radius: function(context) { | ||
var data = context.data; | ||
var value = context.dataset.data[context.dataIndex]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @etimberg this is the way how to read the current value with the minimal context. What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks good 👍 |
||
var size = context.chart.width; | ||
var base = Math.abs(data.v) / 1000; | ||
var base = Math.abs(value.v) / 1000; | ||
return (size / 24) * base; | ||
} | ||
} | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is part of the public API, we need to be sure we want to expose all these properties.
Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm OK with these properties
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least, we need to expose
chart
,datasetIndex
anddataIndex
properties.The other values can be retrieved as follow:
datasetCount
:chart.data.datasets.length
dataset
:chart.data.datasets[datasetIndex]
dataCount
:chart.data.datasets[datasetIndex].data.length
data
:chart.data.datasets[datasetIndex].data[dataIndex]
dataset
is always needed to resolve options (since it contains some of them), so it would not cost more to include it to the context. I think most use cases of scriptable options will be to derive the data value, howeverdata
is (almost) never required to resolve options, so it's an additional cost to expose it to the context. I'm really not sure about exposing (right now)datasetCount
anddataCount
.If we expose only
chart
,datasetIndex
,dataIndex
anddataset
:datasetCount
:chart.data.datasets.length
dataCount
:dataset.data.length
data
:dataset.data[dataIndex]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
chart, datasetIndex, dataIndex and dataset
is the minimum. The only reason to include the other properties is to save users code if they want to get those values.I'm also OK with the minimal set of properties to keep our code smaller.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can start with the minimal set and add more if requested. Like that we limit probabilities of later deprecations.