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 support for inline plugins #137

Merged
merged 1 commit into from
Jul 3, 2017

Conversation

kurbar
Copy link

@kurbar kurbar commented Jul 3, 2017

Implementation for feature #130

Possibility to add inline plugins to individual charts.

A plugin can be added in the class which extends any of the charts before rendering,

this.addPlugin({
  id: 'kwhWeek',
  beforeDraw(chart) {
    const width = chart.chart.width;
    const height = chart.chart.height;
    const ctx = chart.chart.ctx;
    ctx.restore();
    const fontSize = (height / 114).toFixed(2);
    ctx.font = `${fontSize}em sans-serif`;
    ctx.textBaseline = 'middle';
    const text = '4511kWh';
    const textX = Math.round((width - ctx.measureText(text).width) / 2);
    const textY = height / 2;
    ctx.fillText(text, textX, textY);
    ctx.save();
  },
});

It supports all methods available in the docs http://www.chartjs.org/docs/latest/developers/plugins.html

@kurbar kurbar changed the title Add support for inline plugins (feature #130) Add support for inline plugins Jul 3, 2017
@codecov
Copy link

codecov bot commented Jul 3, 2017

Codecov Report

Merging #137 into develop will decrease coverage by 7.76%.
The diff coverage is 0%.

@@             Coverage Diff             @@
##           develop     #137      +/-   ##
===========================================
- Coverage      100%   92.23%   -7.77%     
===========================================
  Files           11       11              
  Lines           95      103       +8     
===========================================
  Hits            95       95              
- Misses           0        8       +8
Impacted Files Coverage Δ
src/BaseCharts/HorizontalBar.js 90% <0%> (-10%) ⬇️
src/BaseCharts/Doughnut.js 90% <0%> (-10%) ⬇️
src/BaseCharts/Radar.js 90% <0%> (-10%) ⬇️
src/BaseCharts/Bubble.js 90% <0%> (-10%) ⬇️
src/BaseCharts/PolarArea.js 90% <0%> (-10%) ⬇️
src/BaseCharts/Bar.js 90% <0%> (-10%) ⬇️
src/BaseCharts/Pie.js 90% <0%> (-10%) ⬇️
src/BaseCharts/Line.js 90% <0%> (-10%) ⬇️

@apertureless apertureless merged commit 362639c into apertureless:develop Jul 3, 2017
@apertureless apertureless added this to the 2.7.0 milestone Jul 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants