-
Notifications
You must be signed in to change notification settings - Fork 334
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
Enable different fonts and colors configuration on multiline labels #801
Merged
Merged
Changes from all commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
962ee4b
Add element diagrams to the annotation types guide
stockiNail 05e619c
Merge branch 'master' of https://github.com/chartjs/chartjs-plugin-an…
stockiNail 22a3aa3
Merge branch 'master' of https://github.com/chartjs/chartjs-plugin-an…
stockiNail f5186fe
Merge branch 'master' of https://github.com/chartjs/chartjs-plugin-an…
stockiNail 6d87201
Merge branch 'master' of https://github.com/chartjs/chartjs-plugin-an…
stockiNail 84366b3
Merge branch 'master' of https://github.com/chartjs/chartjs-plugin-an…
stockiNail ec3a554
Merge branch 'master' of https://github.com/chartjs/chartjs-plugin-an…
stockiNail 1324e43
Merge branch 'master' of https://github.com/chartjs/chartjs-plugin-an…
stockiNail 693e84d
Merge branch 'master' of https://github.com/chartjs/chartjs-plugin-an…
stockiNail 30b5941
Merge branch 'master' of https://github.com/chartjs/chartjs-plugin-an…
stockiNail b30c95e
Merge branch 'master' of https://github.com/chartjs/chartjs-plugin-an…
stockiNail ff2a323
Merge branch 'master' of https://github.com/chartjs/chartjs-plugin-an…
stockiNail 1c5cbf2
Enable different fonts and colors configuration on multiline labels
stockiNail 340a3e8
updates type definitions
stockiNail b2a5edc
fixes CC
stockiNail 30d56bf
documentation
stockiNail ea14c2f
fixes check for font as array
stockiNail d2ff540
adds sample
stockiNail a522271
fixes CC
stockiNail b686c7a
Merge branch 'master' of https://github.com/chartjs/chartjs-plugin-an…
stockiNail 30446eb
Merge branch 'master' of https://github.com/chartjs/chartjs-plugin-an…
stockiNail 63e01f8
Merge branch 'master' of https://github.com/chartjs/chartjs-plugin-an…
stockiNail 235712c
Merge branch 'master' of https://github.com/chartjs/chartjs-plugin-an…
stockiNail db39263
changes font and color as indexable
stockiNail 5114654
Merge branch 'master' of https://github.com/chartjs/chartjs-plugin-an…
stockiNail 6f32004
Merge remote-tracking branch 'origin/master' into fontsColors
stockiNail e43a62e
Merge branch 'master' of https://github.com/chartjs/chartjs-plugin-an…
stockiNail 5069380
Merge branch 'master' of https://github.com/chartjs/chartjs-plugin-an…
stockiNail d7723e6
Merge branch 'master' of
stockiNail f9835e1
Merge branch 'master' of https://github.com/chartjs/chartjs-plugin-an…
stockiNail f8cc9c6
Merge branch 'master' of https://github.com/chartjs/chartjs-plugin-an…
stockiNail ba80172
Merge remote-tracking branch 'origin/master' into fontsColors
stockiNail 65c55ec
Merge branch 'master' of https://github.com/chartjs/chartjs-plugin-an…
stockiNail 358b44c
Merge branch 'master' into fontsColors
stockiNail fad03a4
add tolerance
stockiNail 7a940ab
add tolerance 2
stockiNail 2996473
add tolerance 3
stockiNail 8b3857c
add tolerance 4
stockiNail 5a80feb
add tolerance 4
stockiNail 127e093
fallback tolerance changes
stockiNail 006a3bb
Test with new registered fixtures
stockiNail 05b50ec
Another test if adjust is passed
stockiNail bf0f8ad
additional test with a label fixture
stockiNail e04e475
add new fixture for polygon to test if works
stockiNail f634ce8
add new fixtures for ellipse from FF
stockiNail af0d85d
fallback tests on fixtures
stockiNail c552b5a
Merge branch 'master' of https://github.com/chartjs/chartjs-plugin-an…
stockiNail 7ad86ca
Merge remote-tracking branch 'origin/master' into fontsColors
stockiNail 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
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
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,152 @@ | ||
# Fonts and colors | ||
|
||
```js chart-editor | ||
// <block:setup:5> | ||
const DATA_COUNT = 12; | ||
const MIN = 0; | ||
const MAX = 100; | ||
|
||
const numberCfg = {count: DATA_COUNT, min: MIN, max: MAX}; | ||
|
||
const data = { | ||
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], | ||
datasets: [{ | ||
data: Utils.numbers(numberCfg) | ||
}] | ||
}; | ||
// </block:setup> | ||
|
||
// <block:annotation1:1> | ||
const annotation1 = { | ||
type: 'label', | ||
backgroundColor: 'rgba(0,0,0,0.2)', | ||
borderRadius: 6, | ||
borderWidth: 0, | ||
callout: { | ||
display: true | ||
}, | ||
color: ['black,', 'black', 'green'], | ||
content: ['March', 'is', 'annotated'], | ||
font: [{size: 16, weight: 'bold'}, {family: 'courier'}], | ||
position: { | ||
x: 'center', | ||
y: 'end' | ||
}, | ||
xValue: 'March', | ||
yAdjust: (ctx) => yOffset(ctx, 'March'), | ||
yValue: (ctx) => yValue(ctx, 'March') | ||
}; | ||
// </block:annotation1> | ||
|
||
// <block:annotation2:2> | ||
const annotation2 = { | ||
type: 'label', | ||
backgroundColor: 'rgba(0,0,0,0.2)', | ||
borderRadius: 6, | ||
borderWidth: 0, | ||
callout: { | ||
display: true | ||
}, | ||
color: ['black,', 'black', 'green'], | ||
content: ['June', 'is', 'annotated'], | ||
font: [{size: 16, weight: 'bold'}, {family: 'courier'}], | ||
position: { | ||
x: 'center', | ||
y: 'end' | ||
}, | ||
xValue: 'June', | ||
yAdjust: (ctx) => yOffset(ctx, 'June'), | ||
yValue: (ctx) => yValue(ctx, 'June') | ||
}; | ||
// </block:annotation2> | ||
|
||
// <block:annotation3:3> | ||
const annotation3 = { | ||
type: 'label', | ||
backgroundColor: 'rgba(0,0,0,0.2)', | ||
borderRadius: 6, | ||
borderWidth: 0, | ||
callout: { | ||
display: true | ||
}, | ||
color: ['black,', 'black', 'green'], | ||
content: ['October', 'is', 'annotated'], | ||
font: [{size: 16, weight: 'bold'}, {family: 'courier'}], | ||
position: { | ||
x: 'center', | ||
y: 'end' | ||
}, | ||
xValue: 'October', | ||
yAdjust: (ctx) => yOffset(ctx, 'October'), | ||
yValue: (ctx) => yValue(ctx, 'October') | ||
}; | ||
// </block:annotation3> | ||
|
||
// <block:utils:4> | ||
function yValue(ctx, label) { | ||
const chart = ctx.chart; | ||
const dataset = chart.data.datasets[0]; | ||
return dataset.data[chart.data.labels.indexOf(label)]; | ||
} | ||
|
||
function yOffset(ctx, label) { | ||
const value = yValue(ctx, label); | ||
const chart = ctx.chart; | ||
const scale = chart.scales.y; | ||
const y = scale.getPixelForValue(value); | ||
const lblPos = scale.getPixelForValue(100); | ||
return lblPos - y - 5; | ||
} | ||
|
||
// </block:utils> | ||
|
||
/* <block:config:0> */ | ||
const config = { | ||
type: 'bar', | ||
data, | ||
options: { | ||
scales: { | ||
y: { | ||
beginAtZero: true, | ||
max: 130, | ||
min: 0, | ||
grid: { | ||
color: (ctx)=> ctx.tick.value <= 100 ? | ||
ctx.chart.scales.x.options.grid.color : | ||
undefined | ||
}, | ||
ticks: { | ||
callback: (value) => value > 100 ? '' : value | ||
} | ||
} | ||
}, | ||
plugins: { | ||
annotation: { | ||
annotations: { | ||
annotation1, | ||
annotation2, | ||
annotation3 | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
/* </block:config> */ | ||
|
||
const actions = [ | ||
{ | ||
name: 'Randomize', | ||
handler: function(chart) { | ||
chart.data.datasets.forEach(function(dataset, i) { | ||
dataset.data = dataset.data.map(() => Utils.rand(MIN, MAX)); | ||
}); | ||
chart.update(); | ||
} | ||
} | ||
]; | ||
|
||
module.exports = { | ||
actions: actions, | ||
config: config, | ||
}; | ||
``` |
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
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
Oops, something went wrong.
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.
This should be in the plugin descriptors, unless it does not work there?
For example:
https://github.com/chartjs/Chart.js/blob/cfe8e0311bca46e43d5630e91bf82f470df3f56d/src/plugins/plugin.tooltip.js#L1322-L1335
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.
@kurkle it is in element because is also used in element code: https://github.com/chartjs/chartjs-plugin-annotation/pull/801/files#diff-4e8835b7cdbc98ff051ec4984253e2a838ff262a5ec9e3ecf469aa0569cd8429R132
Putting it in annotation and exported to element, we have a cycle in the "import"
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.
@kurkle what do you think? Is it acceptable or do you think I must move in annotation.js ?