From 97ed7b7381deaef60348a1c978520f9bd20c773d Mon Sep 17 00:00:00 2001 From: Daniel Cothran <daniel@andile.co> Date: Mon, 8 Jan 2018 15:50:22 -0500 Subject: [PATCH] Issue #2879200 by Grimreaper: Improve installation of JS chart libraries --- README.txt | 37 ++------ modules/charts_c3/.gitignore | 2 - modules/charts_c3/README.txt | 52 +++++++++++ modules/charts_c3/charts_c3.libraries.yml | 10 +- modules/charts_c3/composer.json | 56 ------------ .../charts_c3/src/Charts/C3ChartsRender.php | 2 +- modules/charts_google/.gitignore | 2 - modules/charts_google/README.txt | 37 ++++++++ .../charts_google/charts_google.libraries.yml | 2 +- modules/charts_google/composer.json | 35 ------- .../src/Charts/GoogleChartsRender.php | 2 +- modules/charts_highcharts/.gitignore | 2 - modules/charts_highcharts/README.txt | 91 +++++++++++++++++++ .../charts_highcharts.libraries.yml | 9 +- modules/charts_highcharts/composer.json | 74 --------------- .../src/Charts/HighchartsChartsRender.php | 5 +- src/Charts/ModuleSelector.php | 1 - src/Util/Util.php | 12 +-- 18 files changed, 210 insertions(+), 221 deletions(-) delete mode 100644 modules/charts_c3/.gitignore create mode 100644 modules/charts_c3/README.txt delete mode 100644 modules/charts_c3/composer.json delete mode 100644 modules/charts_google/.gitignore create mode 100644 modules/charts_google/README.txt delete mode 100644 modules/charts_google/composer.json delete mode 100644 modules/charts_highcharts/.gitignore create mode 100644 modules/charts_highcharts/README.txt delete mode 100644 modules/charts_highcharts/composer.json diff --git a/README.txt b/README.txt index f70eb5a..05732d0 100644 --- a/README.txt +++ b/README.txt @@ -37,24 +37,16 @@ particular advantages and disadvantages. Installing Libraries --------------------- -The 8.x version of Charts is designed to be used with Composer. After you -enable a sub-module (charts_c3, charts_google, or charts_highcharts), you need -to download the library. Here's how I would do it for C3 (starting in my Drupal -root directory: +Using Composer: -cd modules/charts/modules/charts_c3 -composer install - -This will set up the following directory structure within your charts_c3 -directory: - -vendor - - cthree - - css - - c3.min.css - - c3.min.js - - dthree - - d3.v3.min.js +1: Ensure that you have the `composer/installers` package installed. +2: Ensure you have an installer-paths for the drupal-library type. Such as in + the composer.json of + https://github.com/drupal-composer/drupal-project/blob/8.x/composer.json +3: In each sub-module, there is a README.txt file that you can use to copy the + info inside the composer.json of your project. +4: Run 'composer install' or 'composer update' or the 'composer require' command + specified in each README.txt on your project composer.json. There are numerous tutorials on Drupal.org and elsewhere on the web if you are looking for more information about how to use Composer with Drupal 8. @@ -103,17 +95,6 @@ A major difference between the Drupal 7 and Drupal 8 versions of this module is that the Drupal 8 module uses a Chart Attachment plugin for creating a separate chart series that can be attached to a parent display. -As of the -alpha release, there is a lot of work needed here. The following are -identified questions/issues, which we would like your help with: - -1) Is a Chart Attachment (previously Chart Add-on) display still needed with -the improvements made to the module in Drupal 8? -2) Todo: determine how to respect the "Create Secondary Axis" option on the -Chart Attachment -3) Todo: determine how to respect the selection of a different chart type (for -example, the display could be a bar graph and the attachment could be a line -graph) - Support ------- diff --git a/modules/charts_c3/.gitignore b/modules/charts_c3/.gitignore deleted file mode 100644 index 4f4acd3..0000000 --- a/modules/charts_c3/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -vendor/ -composer.lock \ No newline at end of file diff --git a/modules/charts_c3/README.txt b/modules/charts_c3/README.txt new file mode 100644 index 0000000..019c40c --- /dev/null +++ b/modules/charts_c3/README.txt @@ -0,0 +1,52 @@ +Installation using Composer (recommended) +======================================== + +If you use Composer to manage dependencies, edit "/composer.json" as follows. + + 1. Run "composer require --prefer-dist composer/installers" to ensure that you + have the "composer/installers" package installed. This package facilitates + the installation of packages into directories other than "/vendor" (e.g. + "/libraries") using Composer. + + 2. Add the following to the "installer-paths" section of "composer.json": + +"libraries/{$name}": ["type:drupal-library"], + + 3. Add the following to the "repositories" section of "composer.json": + + { + "type": "package", + "package": { + "name": "c3js/c3", + "version": "v0.4.18", + "type": "drupal-library", + "extra": { + "installer-name": "c3" + }, + "dist": { + "url": "https://github.com/c3js/c3/archive/v0.4.18.zip", + "type": "zip" + } + } + }, + { + "type": "package", + "package": { + "name": "d3/d3", + "version": "v3.5.17", + "type": "drupal-library", + "extra": { + "installer-name": "d3" + }, + "dist": { + "url": "https://github.com/d3/d3/archive/v3.5.17.zip", + "type": "zip" + }, + "require": { + "composer/installers": "~1.0" + } + } + } + +4. Run "composer require --prefer-dist c3js/c3:0.4.18 d3/d3:3.5.17" - you should find that new directories have been created +under "/libraries" diff --git a/modules/charts_c3/charts_c3.libraries.yml b/modules/charts_c3/charts_c3.libraries.yml index f9bbac2..cc5cad4 100644 --- a/modules/charts_c3/charts_c3.libraries.yml +++ b/modules/charts_c3/charts_c3.libraries.yml @@ -14,19 +14,19 @@ d3: url: 'https://en.wikipedia.org/wiki/BSD_licenses' gpl-compatible: false js: - vendor/dthree/d3.v3.min.js: { } + /libraries/d3/d3.min.js: { } c3: - remote: 'https://cdnjs.cloudflare.com/ajax/libs/c3/0.4.11/c3.min.js' - version: 0.4.11 + remote: 'https://cdnjs.cloudflare.com/ajax/libs/c3/0.4.18/c3.min.js' + version: 0.4.18 license: name: MIT url: 'https://opensource.org/licenses/MIT' gpl-compatible: true css: theme: - vendor/cthree/css/c3.min.css: { } + /libraries/c3/c3.min.css: { } js: - vendor/cthree/c3.min.js: { } + /libraries/c3/c3.min.js: { } dependencies: - charts_c3/charts_c3 - charts_c3/d3 diff --git a/modules/charts_c3/composer.json b/modules/charts_c3/composer.json deleted file mode 100644 index b7068fb..0000000 --- a/modules/charts_c3/composer.json +++ /dev/null @@ -1,56 +0,0 @@ -{ - "name": "charts_cthree", - "version": "0.0.1", - "require": { - "dthree": "*", - "cthree": "*", - "cthree/css": "*" - }, - "repositories": [ - { - "type": "package", - "package": { - "name": "dthree", - "version": "3", - "type": "dthree", - "dist": { - "url": "https://d3js.org/d3.v3.min.js", - "type": "file" - } - } - }, - { - "type": "package", - "package": { - "name": "cthree", - "version": "0.4.11", - "type": "cthree", - "dist": { - "url": "https://cdnjs.cloudflare.com/ajax/libs/c3/0.4.11/c3.min.js", - "type": "file" - } - } - }, - { - "type": "package", - "package": { - "name": "cthree/css", - "version": "0.4.11", - "type": "css", - "dist": { - "url": "https://cdnjs.cloudflare.com/ajax/libs/c3/0.4.11/c3.min.css", - "type": "file" - } - } - } - ], - "extra": { - "assets": { - "packages": { - "dthree": "*", - "cthree": "*", - "cthree/css": "*" - } - } - } -} diff --git a/modules/charts_c3/src/Charts/C3ChartsRender.php b/modules/charts_c3/src/Charts/C3ChartsRender.php index 062a434..786291b 100644 --- a/modules/charts_c3/src/Charts/C3ChartsRender.php +++ b/modules/charts_c3/src/Charts/C3ChartsRender.php @@ -20,7 +20,7 @@ class C3ChartsRender implements ChartsRenderInterface { * Construct. */ public function __construct() { - Util::checkMissingLibrary('charts_c3', '/vendor/cthree/c3.min.js'); + Util::checkMissingLibrary('libraries/c3/c3.min.js'); } /** diff --git a/modules/charts_google/.gitignore b/modules/charts_google/.gitignore deleted file mode 100644 index 4f4acd3..0000000 --- a/modules/charts_google/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -vendor/ -composer.lock \ No newline at end of file diff --git a/modules/charts_google/README.txt b/modules/charts_google/README.txt new file mode 100644 index 0000000..7479349 --- /dev/null +++ b/modules/charts_google/README.txt @@ -0,0 +1,37 @@ +Installation using Composer (recommended) +======================================== + +If you use Composer to manage dependencies, edit "/composer.json" as follows. + + 1. Run "composer require --prefer-dist composer/installers" to ensure that you + have the "composer/installers" package installed. This package facilitates + the installation of packages into directories other than "/vendor" (e.g. + "/libraries") using Composer. + + 2. Add the following to the "installer-paths" section of "composer.json": + +"libraries/{$name}": ["type:drupal-library"], + + 3. Add the following to the "repositories" section of "composer.json": + + { + "type": "package", + "package": { + "name": "google/charts", + "version": "45", + "type": "drupal-library", + "extra": { + "installer-name": "google_charts" + }, + "dist": { + "url": "https://www.gstatic.com/charts/loader.js", + "type": "file" + }, + "require": { + "composer/installers": "~1.0" + } + } + } + +4. Run "composer require --prefer-dist google/charts:45" - you should find that new directories have been created +under "/libraries" diff --git a/modules/charts_google/charts_google.libraries.yml b/modules/charts_google/charts_google.libraries.yml index 8641261..0a340c7 100644 --- a/modules/charts_google/charts_google.libraries.yml +++ b/modules/charts_google/charts_google.libraries.yml @@ -14,6 +14,6 @@ google: url: 'http://www.apache.org/licenses/LICENSE-2.0' gpl-compatible: false js: - vendor/google/loader.js: { } + /libraries/google_charts/loader.js: { } dependencies: - charts_google/charts_google diff --git a/modules/charts_google/composer.json b/modules/charts_google/composer.json deleted file mode 100644 index 1f1934c..0000000 --- a/modules/charts_google/composer.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "name": "charts_google", - "version": "0.0.1", - "require": { - "google": "*" - }, - "repositories": [ - { - "type": "package", - "package": { - "name": "google", - "version": "45", - "type": "google", - "dist": { - "url": "https://www.gstatic.com/charts/loader.js", - "type": "file" - } - } - } - ], - "extra": { - "assets": { - "actions": [ - { - "type": "copy", - "target": "js", - "pattern": "\\.js$" - } - ], - "packages": { - "google": "*" - } - } - } -} diff --git a/modules/charts_google/src/Charts/GoogleChartsRender.php b/modules/charts_google/src/Charts/GoogleChartsRender.php index 7e10222..9bdb634 100644 --- a/modules/charts_google/src/Charts/GoogleChartsRender.php +++ b/modules/charts_google/src/Charts/GoogleChartsRender.php @@ -18,7 +18,7 @@ class GoogleChartsRender implements ChartsRenderInterface { * Construct. */ public function __construct() { - Util::checkMissingLibrary('charts_google', '/vendor/google/loader.js'); + Util::checkMissingLibrary('libraries/google_charts/loader.js'); } /** diff --git a/modules/charts_highcharts/.gitignore b/modules/charts_highcharts/.gitignore deleted file mode 100644 index 4f4acd3..0000000 --- a/modules/charts_highcharts/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -vendor/ -composer.lock \ No newline at end of file diff --git a/modules/charts_highcharts/README.txt b/modules/charts_highcharts/README.txt new file mode 100644 index 0000000..fb3facb --- /dev/null +++ b/modules/charts_highcharts/README.txt @@ -0,0 +1,91 @@ +Installation using Composer (recommended) +======================================== + +If you use Composer to manage dependencies, edit "/composer.json" as follows. + + 1. Run "composer require --prefer-dist composer/installers" to ensure that you + have the "composer/installers" package installed. This package facilitates + the installation of packages into directories other than "/vendor" (e.g. + "/libraries") using Composer. + + 2. Add the following to the "installer-paths" section of "composer.json": + +"libraries/{$name}": ["type:drupal-library"], + + 3. Add the following to the "repositories" section of "composer.json": + + { + "type": "package", + "package": { + "name": "highcharts/highcharts", + "version": "6.0.4", + "type": "drupal-library", + "extra": { + "installer-name": "highcharts" + }, + "dist": { + "url": "https://code.highcharts.com/6.0.4/highcharts.js", + "type": "file" + }, + "require": { + "composer/installers": "~1.0" + } + } + }, + { + "type": "package", + "package": { + "name": "highcharts/exporting", + "version": "6.0.4", + "type": "drupal-library", + "extra": { + "installer-name": "highcharts_exporting" + }, + "dist": { + "url": "https://code.highcharts.com/6.0.4/modules/exporting.js", + "type": "file" + }, + "require": { + "composer/installers": "~1.0" + } + } + }, + { + "type": "package", + "package": { + "name": "highcharts/export-data", + "version": "6.0.4", + "type": "drupal-library", + "extra": { + "installer-name": "highcharts_export-data" + }, + "dist": { + "url": "https://code.highcharts.com/6.0.4/modules/export-data.js", + "type": "file" + }, + "require": { + "composer/installers": "~1.0" + } + } + }, + { + "type": "package", + "package": { + "name": "highcharts/accessibility", + "version": "6.0.4", + "type": "drupal-library", + "extra": { + "installer-name": "highcharts_accessibility" + }, + "dist": { + "url": "https://code.highcharts.com/6.0.4/modules/accessibility.js", + "type": "file" + }, + "require": { + "composer/installers": "~1.0" + } + } + } + +4. Run "composer require --prefer-dist highcharts/highcharts:6.0.4 highcharts/exporting:6.0.4 highcharts/export-data:6.0.4 highcharts/accessibility:6.0.4" - you should find that new directories have been created +under "/libraries" diff --git a/modules/charts_highcharts/charts_highcharts.libraries.yml b/modules/charts_highcharts/charts_highcharts.libraries.yml index 841a7b9..64e4f47 100644 --- a/modules/charts_highcharts/charts_highcharts.libraries.yml +++ b/modules/charts_highcharts/charts_highcharts.libraries.yml @@ -15,10 +15,9 @@ highcharts: url: https://creativecommons.org/licenses/by-nc/3.0/ gpl-compatible: false js: - vendor/highcharts/highcharts.js: {} - vendor/exporting/exporting.js: {} - vendor/export-data/export-data.js: {} - vendor/accessibility/accessibility.js: {} - + /libraries/highcharts/highcharts.js: {} + /libraries/highcharts_exporting/exporting.js: {} + /libraries/highcharts_export-data/export-data.js: {} + /libraries/highcharts_accessibility/accessibility.js: {} dependencies: - charts_highcharts/charts_highcharts diff --git a/modules/charts_highcharts/composer.json b/modules/charts_highcharts/composer.json deleted file mode 100644 index 45fb1d1..0000000 --- a/modules/charts_highcharts/composer.json +++ /dev/null @@ -1,74 +0,0 @@ -{ - "name": "charts_highcharts", - "version": "0.0.1", - "require": { - "highcharts": "*", - "exporting": "*", - "export-data": "*", - "accessibility": "*" - }, - "repositories": [ - { - "type": "package", - "package": { - "name": "highcharts", - "version": "5.0.7", - "type": "highcharts", - "dist": { - "url": "https://code.highcharts.com/highcharts.js", - "type": "file" - } - } - }, - { - "type": "package", - "package": { - "name": "exporting", - "version": "5.0.7", - "type": "highcharts", - "dist": { - "url": "https://code.highcharts.com/modules/exporting.js", - "type": "file" - } - } - }, - { - "type": "package", - "package": { - "name": "export-data", - "version": "5.0.7", - "type": "highcharts", - "dist": { - "url": "https://code.highcharts.com/modules/export-data.js", - "type": "file" - } - } - }, - { - "type": "package", - "package": { - "name": "accessibility", - "version": "5.0.7", - "type": "highcharts", - "dist": { - "url": "https://code.highcharts.com/modules/accessibility.js", - "type": "file" - } - } - } - ], - "extra": { - "assets": { - "actions": [ - { - "type": "copy", - "target": "js", - "pattern": "\\.js$" - } - ], - "packages": { - "highcharts": "*" - } - } - } -} diff --git a/modules/charts_highcharts/src/Charts/HighchartsChartsRender.php b/modules/charts_highcharts/src/Charts/HighchartsChartsRender.php index d6f848a..22e76ee 100644 --- a/modules/charts_highcharts/src/Charts/HighchartsChartsRender.php +++ b/modules/charts_highcharts/src/Charts/HighchartsChartsRender.php @@ -29,7 +29,10 @@ class HighchartsChartsRender implements ChartsRenderInterface { * Construct. */ public function __construct() { - Util::checkMissingLibrary('charts_highcharts', '/vendor/highcharts/highcharts.js'); + Util::checkMissingLibrary('libraries/highcharts/highcharts.js'); + Util::checkMissingLibrary('libraries/highcharts_accessibility/accessibility.js'); + Util::checkMissingLibrary('libraries/highcharts_export-data/export-data.js'); + Util::checkMissingLibrary('libraries/highcharts_exporting/exporting.js'); } /** diff --git a/src/Charts/ModuleSelector.php b/src/Charts/ModuleSelector.php index a677e7c..32fd56e 100644 --- a/src/Charts/ModuleSelector.php +++ b/src/Charts/ModuleSelector.php @@ -8,7 +8,6 @@ namespace Drupal\charts\Charts; class ModuleSelector { private $library; - private $assetLocation = '/vendor/'; private $assetName; private $categories; private $seriesData; diff --git a/src/Util/Util.php b/src/Util/Util.php index 7ea0c5b..450d890 100644 --- a/src/Util/Util.php +++ b/src/Util/Util.php @@ -106,16 +106,14 @@ class Util { /** * Checks for missing libraries necessary for data visualization. * - * @param string $moduleName - * Module name. * @param string $libraryPath * Library Path. */ - public static function checkMissingLibrary($moduleName = '', $libraryPath = '') { - $module_path = drupal_get_path('module', $moduleName); - if (!file_exists($module_path . $libraryPath)) { - $text = 'Charting libraries for ' . $moduleName . ' might not be installed. Run \'composer install\' for ' . $moduleName . ' sub-module.'; - drupal_set_message(t($text), 'error'); + public static function checkMissingLibrary($libraryPath = '') { + if (!file_exists(DRUPAL_ROOT . DIRECTORY_SEPARATOR . $libraryPath)) { + drupal_set_message(t('Charting libraries might not be installed at the location @libraryPath.', [ + '@libraryPath' => $libraryPath, + ]), 'error'); } } -- GitLab