-
-
Notifications
You must be signed in to change notification settings - Fork 364
[ChartJs] chart.js v4 support #610
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
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f314d25
Add support for chart.js:^4.0
evertharmeling 768507e
Update CHANGELOG.md
evertharmeling 7a36a4f
Update devDependency for `chart.js`
evertharmeling 5cb0ee9
Exclude v3.9
evertharmeling 42fb419
Create controller per version
evertharmeling f86ba3b
Create test controller per version (WIP)
evertharmeling 2e8def6
Add support for 'low/high' dependency testing
evertharmeling 0799e87
Fix v4 import
evertharmeling 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 hidden or 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 hidden or 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 hidden or 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
144 changes: 144 additions & 0 deletions
144
src/Chartjs/assets/scripts/force-lowest-dependencies.js
This file contains hidden or 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,144 @@ | ||
/* | ||
* This file is part of the Symfony Webpack Encore package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const childProcess = require('child_process'); | ||
|
||
const packageFilePath = 'src/Chartjs/assets/package.json'; | ||
const chartJsLowVersion = '3.4.1'; | ||
|
||
/** | ||
* @param {string} dependency | ||
* @param {string} range | ||
* @return {Promise} | ||
*/ | ||
function getLowestVersion(dependency, range) { | ||
return new Promise((resolve, reject) => { | ||
if (range.startsWith('file:')) { | ||
resolve([dependency, range]); | ||
} | ||
|
||
childProcess.exec( | ||
`npm view "${dependency}@${range}" version`, | ||
{ encoding: 'utf-8' }, | ||
(error, stdout) => { | ||
if (error) { | ||
reject(`Could not retrieve versions list for "${dependency}@${range}"`); | ||
return; | ||
} | ||
|
||
const versions = stdout | ||
.split('\n') | ||
.filter(line => line); | ||
|
||
if (versions.length === 0) { | ||
reject(`Could not find a lowest version for "${dependency}@${range}"`); | ||
return; | ||
} | ||
|
||
const parts = versions[0].split(' '); | ||
|
||
// If there is only one version available that version | ||
// is directly printed as the output of npm view. | ||
if (parts.length === 1) { | ||
resolve([dependency, parts[0]]); | ||
return; | ||
} | ||
|
||
// If multiple versions are available then it outputs | ||
// multiple lines matching the following format: | ||
// <package>@<version> '<version>' | ||
if (parts.length === 2) { | ||
resolve([dependency, parts[1].replace(/'/g, '')]); | ||
return; | ||
} | ||
|
||
reject(`Unexpected response for "${dependency}@${range}": ${versions[0]}`); | ||
} | ||
); | ||
}); | ||
} | ||
|
||
fs.readFile(packageFilePath, (error, data) => { | ||
if (error) { | ||
throw error; | ||
} | ||
|
||
const packageInfo = JSON.parse(data); | ||
|
||
const dependencyPromises = []; | ||
if (packageInfo.dependencies) { | ||
for (const dependency in packageInfo.dependencies) { | ||
dependencyPromises.push(getLowestVersion( | ||
dependency, | ||
packageInfo.dependencies[dependency] | ||
)); | ||
} | ||
} | ||
|
||
const devDependencyPromises = []; | ||
if (packageInfo.devDependencies) { | ||
for (const devDependency in packageInfo.devDependencies) { | ||
devDependencyPromises.push(getLowestVersion( | ||
devDependency, | ||
packageInfo.devDependencies[devDependency] | ||
)); | ||
} | ||
} | ||
|
||
const dependenciesUpdate = Promise.all(dependencyPromises).then(versions => { | ||
versions.forEach(version => { | ||
packageInfo.dependencies[version[0]] = version[1]; | ||
}); | ||
}); | ||
|
||
const devDependenciesUpdate = Promise.all(devDependencyPromises).then(versions => { | ||
versions.forEach(version => { | ||
packageInfo.devDependencies[version[0]] = version[1]; | ||
}); | ||
}); | ||
|
||
// Once all the lowest versions have been resolved, update the | ||
// package.json file accordingly. | ||
Promise | ||
.all([dependenciesUpdate, devDependenciesUpdate]) | ||
.then(() => new Promise((resolve, reject) => { | ||
fs.writeFile(packageFilePath, JSON.stringify(packageInfo, null, 2), (error) => { | ||
if (error) { | ||
reject(error); | ||
return; | ||
} | ||
|
||
resolve(); | ||
}); | ||
})) | ||
.then(() => { | ||
console.log('Manually forcing chart.js to lowest version'); | ||
packageInfo.devDependencies['chart.js'] = chartJsLowVersion; | ||
}) | ||
.then(() => { | ||
console.log('Updated package.json file with lowest dependency versions: '); | ||
|
||
console.log('Dependencies:'); | ||
for (const dependency in packageInfo.dependencies) { | ||
console.log(` - ${dependency}: ${packageInfo.dependencies[dependency]}`); | ||
} | ||
|
||
console.log('Dev dependencies:'); | ||
for (const dependency in packageInfo.devDependencies) { | ||
console.log(` - ${dependency}: ${packageInfo.devDependencies[dependency]}`); | ||
} | ||
}) | ||
.catch(error => { | ||
console.error(error); | ||
process.exit(1); // eslint-disable-line | ||
}); | ||
}); |
This file contains hidden or 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 hidden or 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,20 @@ | ||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import AbstractChartController from './abstract_controller'; | ||
import Chart from 'chart.js/auto'; | ||
import { ChartConfiguration, ChartItem } from 'chart.js'; | ||
|
||
export default class extends AbstractChartController { | ||
createChart(canvasContext: ChartItem, payload: ChartConfiguration): any { | ||
return new Chart(canvasContext, payload); | ||
} | ||
} |
This file contains hidden or 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,20 @@ | ||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import AbstractChartController from './abstract_controller'; | ||
import Chart from 'chart.js/auto/auto.cjs'; | ||
import { ChartConfiguration, ChartItem } from 'chart.js'; | ||
|
||
export default class extends AbstractChartController { | ||
createChart(canvasContext: ChartItem, payload: ChartConfiguration): any { | ||
return new Chart(canvasContext, payload); | ||
} | ||
} | ||
This file contains hidden or 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,26 @@ | ||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import { Controller } from '@hotwired/stimulus' | ||
|
||
// Controller used to check the actual controller was properly booted | ||
export class CheckController extends Controller { | ||
connect() { | ||
this.element.addEventListener('chartjs:pre-connect', () => { | ||
this.element.classList.add('pre-connected'); | ||
}); | ||
|
||
this.element.addEventListener('chartjs:connect', (event) => { | ||
this.element.classList.add('connected'); | ||
this.element.chart = event.detail.chart; | ||
}); | ||
} | ||
} |
This file contains hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.