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

Use ResizeObserver and MutationObserver to detect detach/attach/resize #7104

Merged
merged 4 commits into from
Feb 17, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions docs/getting-started/integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,3 @@ require(['moment'], function() {
});
});
```

## Content Security Policy

By default, Chart.js injects CSS directly into the DOM. For webpages secured using [Content Security Policy (CSP)](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP), this requires to allow `style-src 'unsafe-inline'`. For stricter CSP environments, where only `style-src 'self'` is allowed, the following CSS file needs to be manually added to your webpage:

```html
<link rel="stylesheet" type="text/css" href="path/to/chartjs/dist/Chart.min.css">
```

And the style injection must be turned off **before creating the first chart**:

```javascript
// Disable automatic style injection
Chart.platform.disableCSSInjection = true;
```
4 changes: 3 additions & 1 deletion docs/getting-started/v3-migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Chart.js 3.0 introduces a number of breaking changes. Chart.js 2.0 was released
* Completely rewritten animation system
* Rewritten filler plugin with numerous bug fixes
* API Documentation generated and verified by TypeScript
* No more CSS injection
* Tons of bug fixes

## End user migration
Expand Down Expand Up @@ -88,6 +89,7 @@ Animation system was completely rewritten in Chart.js v3. Each property can now
* `Chart.chart.chart`
* `Chart.Controller`
* `Chart.prototype.generateLegend`
* `Chart.platform`. It only contained `disableCSSInjection`. CSS is never injected in v3.
* `Chart.types`
* `Chart.Tooltip` is now provided by the tooltip plugin. The positioners can be accessed from `tooltipPlugin.positioners`
* `DatasetController.addElementAndReset`
Expand Down Expand Up @@ -253,6 +255,6 @@ Animation system was completely rewritten in Chart.js v3. Each property can now

#### Platform

* `Chart.platform` is no longer the platform object used by charts. It contains only a single configuration option, `disableCSSInjection`. Every chart instance now has a separate platform instance.
* `Chart.platform` is no longer the platform object used by charts. Every chart instance now has a separate platform instance.
* `Chart.platforms` is an object that contains two usable platform classes, `BasicPlatform` and `DomPlatform`. It also contains `BasePlatform`, a class that all platforms must extend from.
* If the canvas passed in is an instance of `OffscreenCanvas`, the `BasicPlatform` is automatically used.
23 changes: 6 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"@babel/plugin-transform-object-assign": "^7.8.3",
"@babel/preset-env": "^7.8.4",
"babel-preset-es2015-rollup": "^3.0.0",
"clean-css": "^4.2.3",
"coveralls": "^3.0.9",
"eslint": "^6.8.0",
"eslint-config-chartjs": "^0.2.0",
Expand Down Expand Up @@ -66,6 +65,7 @@
"merge-stream": "^1.0.1",
"moment": "^2.10.2",
"pixelmatch": "^5.0.0",
"resize-observer-polyfill": "^1.5.1",
"rollup": "^1.31.0",
"rollup-plugin-babel": "^4.3.3",
"rollup-plugin-cleanup": "^3.1.1",
Expand Down
21 changes: 4 additions & 17 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const babel = require('rollup-plugin-babel');
const cleanup = require('rollup-plugin-cleanup');
const terser = require('rollup-plugin-terser').terser;
const optional = require('./rollup.plugins').optional;
const stylesheet = require('./rollup.plugins').stylesheet;
const pkg = require('./package.json');

const input = 'src/index.js';
Expand All @@ -29,13 +28,12 @@ module.exports = [
resolve(),
commonjs(),
babel(),
stylesheet({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should add something to the migration guide about the stylesheet and disableCSSInjection flag no longer being available?

extract: true
}),
optional({
include: ['moment']
}),
cleanup(),
cleanup({
sourcemap: true
kurkle marked this conversation as resolved.
Show resolved Hide resolved
})
],
output: {
name: 'Chart',
Expand All @@ -60,10 +58,6 @@ module.exports = [
optional({
include: ['moment']
}),
stylesheet({
extract: true,
minify: true
}),
terser({
output: {
preamble: banner
Expand Down Expand Up @@ -93,10 +87,7 @@ module.exports = [
resolve(),
commonjs(),
babel(),
stylesheet({
extract: true
}),
cleanup(),
cleanup()
],
output: {
name: 'Chart',
Expand All @@ -118,10 +109,6 @@ module.exports = [
resolve(),
commonjs(),
babel(),
stylesheet({
extract: true,
minify: true
}),
terser({
output: {
preamble: banner
Expand Down
56 changes: 3 additions & 53 deletions rollup.plugins.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/* eslint-env es6 */
const cleancss = require('clean-css');
const path = require('path');

/* eslint-disable import/no-commonjs */
const UMD_WRAPPER_RE = /(\(function \(global, factory\) \{)((?:\s.*?)*)(\}\(this,)/;
const CJS_FACTORY_RE = /(module.exports = )(factory\(.*?\))( :)/;
const AMD_FACTORY_RE = /(define\()(.*?, factory)(\) :)/;
Expand All @@ -24,7 +21,7 @@ function optional(config = {}) {
let factory = (CJS_FACTORY_RE.exec(content) || [])[2];
let updated = false;

for (let lib of chunk.imports) {
for (const lib of chunk.imports) {
if (!include || include.indexOf(lib) !== -1) {
const regex = new RegExp(`require\\('${lib}'\\)`);
if (!regex.test(factory)) {
Expand Down Expand Up @@ -58,53 +55,6 @@ function optional(config = {}) {
};
}

// https://github.com/chartjs/Chart.js/issues/5208
function stylesheet(config = {}) {
const minifier = new cleancss();
const styles = [];

return {
name: 'stylesheet',
transform(code, id) {
// Note that 'id' can be mapped to a CJS proxy import, in which case
// 'id' will start with 'commonjs-proxy', so let's first check if we
// are importing an existing css file (i.e. startsWith()).
if (!id.startsWith(path.resolve('.')) || !id.endsWith('.css')) {
return;
}

if (config.minify) {
code = minifier.minify(code).styles;
}

// keep track of all imported stylesheets (already minified)
styles.push(code);

return {
code: 'export default ' + JSON.stringify(code)
};
},
generateBundle(opts, bundle) {
if (!config.extract) {
return;
}

const entry = Object.keys(bundle).find(v => bundle[v].isEntry);
const name = (entry || '').replace(/\.js$/i, '.css');
if (!name) {
this.error('failed to guess the output file name');
}

this.emitFile({
type: 'asset',
source: styles.filter(v => !!v).join(''),
fileName: name
});
}
};
}

module.exports = {
optional,
stylesheet
optional
};
20 changes: 0 additions & 20 deletions samples/advanced/content-security-policy.css

This file was deleted.

27 changes: 0 additions & 27 deletions samples/advanced/content-security-policy.html

This file was deleted.

53 changes: 0 additions & 53 deletions samples/advanced/content-security-policy.js

This file was deleted.

3 changes: 0 additions & 3 deletions samples/samples.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,6 @@
items: [{
title: 'Progress bar',
path: 'advanced/progress-bar.html'
}, {
title: 'Content Security Policy',
path: 'advanced/content-security-policy.html'
}, {
title: 'Polar Area Radial Gradient',
path: 'advanced/radial-gradient.html'
Expand Down
Loading