This is an automated email from the ASF dual-hosted git repository.
ovilia pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/echarts-custom-series.git
The following commit(s) were added to refs/heads/main by this push:
new a6527aa chore: setup build scripts and templates
a6527aa is described below
commit a6527aac562ae7c0ca770cf33cb361f3f6abf355
Author: Ovilia <[email protected]>
AuthorDate: Tue Sep 3 15:23:33 2024 +0800
chore: setup build scripts and templates
---
.gitignore | 2 +-
LICENSE | 201 +++++++++++++++++++++
README.md | 25 ++-
custom-series/violin/dist/index.d.ts | 1 +
custom-series/violin/dist/index.js | 125 +++++++++++++
custom-series/violin/dist/index.js.map | 1 +
custom-series/violin/package-lock.json | 2 +-
custom-series/violin/package.json | 4 +-
custom-series/violin/src/index.ts | 21 ++-
custom-series/violin/tsconfig.json | 24 ---
package-lock.json | 29 +++
package.json | 22 +++
scripts/build.js | 75 ++++++++
scripts/create.js | 71 ++++++++
.../violin => scripts/template}/package.json | 6 +-
scripts/template/src/index.ts | 36 ++++
16 files changed, 601 insertions(+), 44 deletions(-)
diff --git a/.gitignore b/.gitignore
index 491fc35..fd4f2b0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,2 @@
node_modules
-lib
+.DS_Store
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..261eeb9
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,201 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/README.md b/README.md
index 154449b..1833d64 100644
--- a/README.md
+++ b/README.md
@@ -6,15 +6,32 @@ This repo provides some custom series for [Apache
ECharts](https://github.com/ap
TODO
+## Create A New Custom Series
+
+```bash
+npm run create <series-name>
+```
+
+The generated files are in `custom-series/<series-name>`.
+
## Build
-Each of the directories in `custom-series/` is a custom series. You can `cd`
to that path and build them by running:
+Each of the directories in `custom-series/` is a custom series.
+
+### Build All
```bash
-npm install
npm run build
```
-The built files will be in the `lib/` directory.
+### Build One
-> Note: There is no bundling step for now.
+```bash
+npm run build <series-name>
+```
+
+For example, to build `custom-series/violin`, run:
+
+```bash
+npm run build violin
+```
diff --git a/custom-series/violin/dist/index.d.ts
b/custom-series/violin/dist/index.d.ts
new file mode 100644
index 0000000..cb0ff5c
--- /dev/null
+++ b/custom-series/violin/dist/index.d.ts
@@ -0,0 +1 @@
+export {};
diff --git a/custom-series/violin/dist/index.js
b/custom-series/violin/dist/index.js
new file mode 100644
index 0000000..877879e
--- /dev/null
+++ b/custom-series/violin/dist/index.js
@@ -0,0 +1,125 @@
+"use strict";
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+Object.defineProperty(exports, "__esModule", { value: true });
+var tslib_1 = require("tslib");
+var echarts_1 = tslib_1.__importDefault(require("echarts"));
+function epanechnikovKernel(u) {
+ return Math.abs(u) <= 1 ? 0.75 * (1 - u * u) : 0;
+}
+function kernelDensityEstimator(kernel, bandwidth, data) {
+ return function (x) {
+ var sum = 0;
+ for (var i = 0; i < data.length; i++) {
+ sum += kernel((x - data[i]) / bandwidth);
+ }
+ return sum / (data.length * bandwidth);
+ };
+}
+var renderItem = function (params, api) {
+ var violins = {};
+ if (params.context.violins == null) {
+ params.context.violins = [];
+ violins = params.context.violins;
+ var cnt = params.dataInsideLength;
+ for (var i_1 = 0; i_1 < cnt; ++i_1) {
+ var xIndex = api.value(0, i_1);
+ if (violins[xIndex] == null) {
+ violins[xIndex] = {
+ firstDataIndex: i_1,
+ data: [],
+ };
+ }
+ violins[xIndex].data.push(api.value(1, i_1));
+ }
+ }
+ var symbolSize = params.itemPayload.symbolSize;
+ var xValue = api.value(0);
+ var yValue = api.value(1);
+ var coord = api.coord([xValue, yValue]);
+ var bandWidthScale = params.itemPayload.bandWidthScale;
+ var bandWidth = (api.coord([1, 0])[0] - api.coord([0, 0])[0]) *
+ (bandWidthScale == null ? 1 : bandWidthScale);
+ var violin = violins[xValue];
+ var violinPath = null;
+ if (violin && violin.firstDataIndex === params.dataIndex) {
+ var kde_1 = kernelDensityEstimator(epanechnikovKernel, 1, violin.data);
+ var binCount = params.itemPayload.binCount || 100;
+ var xRange = [];
+ for (var i = 0; i < binCount; i++) {
+ xRange.push(i * (10 / (binCount - 1)));
+ }
+ var density = xRange.map(function (x) { return [x, kde_1(x)]; });
+ var epsilonDensity = 0.001;
+ var polylines_1 = [];
+ var points_1 = [];
+ var pushToPolylines = function () {
+ if (points_1.length > 1) {
+ for (var j = points_1.length - 1; j >= 0; --j) {
+ points_1.push([coord[0] * 2 - points_1[j][0],
points_1[j][1]]);
+ }
+ var areaOpacity = params.itemPayload.areaOpacity;
+ polylines_1.push({
+ type: 'polygon',
+ shape: {
+ points: points_1.slice(),
+ },
+ style: {
+ fill: api.visual('color'),
+ opacity: areaOpacity == null ? 0.5 : areaOpacity,
+ },
+ });
+ }
+ points_1.length = 0;
+ };
+ for (var i_2 = 0; i_2 < density.length; ++i_2) {
+ var coord_1 = api.coord([xValue, density[i_2][0]]);
+ if (density[i_2][1] < epsilonDensity) {
+ pushToPolylines();
+ continue;
+ }
+ points_1.push([coord_1[0] + (bandWidth / 2) * density[i_2][1],
coord_1[1]]);
+ }
+ pushToPolylines();
+ violinPath = {
+ type: 'group',
+ children: polylines_1,
+ silent: true,
+ };
+ }
+ var scatter = {
+ type: 'circle',
+ shape: {
+ cx: coord[0],
+ cy: coord[1],
+ r: symbolSize == null ? 5 : symbolSize,
+ },
+ style: {
+ fill: api.visual('color'),
+ },
+ };
+ return violinPath
+ ? {
+ type: 'group',
+ children: [scatter, violinPath],
+ }
+ : scatter;
+};
+echarts_1.default.registerCustomSeries('violin', renderItem);
+//# sourceMappingURL=index.js.map
\ No newline at end of file
diff --git a/custom-series/violin/dist/index.js.map
b/custom-series/violin/dist/index.js.map
new file mode 100644
index 0000000..9423d4f
--- /dev/null
+++ b/custom-series/violin/dist/index.js.map
@@ -0,0 +1 @@
+{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;AAEH,4DAA0D;AAM1D,SAAS,kBAAkB,CAAC,CAAS;IACnC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACnD,CAAC;AAED,SAAS,sBAAsB,CAC7B,MAA6B,EAC7B,SAAiB,EACjB,IAAc;IAEd,OAAO,UAAU,CAAS;QACxB,IAAI,GAAG,GAAG,CAAC,CAAC;QACZ,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EA
[...]
\ No newline at end of file
diff --git a/custom-series/violin/package-lock.json
b/custom-series/violin/package-lock.json
index 943d4e1..aab4037 100644
--- a/custom-series/violin/package-lock.json
+++ b/custom-series/violin/package-lock.json
@@ -7,7 +7,7 @@
"": {
"name": "echarts-violin",
"version": "1.0.0",
- "license": "ISC",
+ "license": "Apache-2.0",
"dependencies": {
"echarts": "github:apache/echarts#v6"
},
diff --git a/custom-series/violin/package.json
b/custom-series/violin/package.json
index 30f592c..6ea24d5 100644
--- a/custom-series/violin/package.json
+++ b/custom-series/violin/package.json
@@ -1,6 +1,6 @@
{
"name": "echarts-violin",
- "version": "1.0.0",
+ "version": "0.0.1-beta",
"description": "",
"main": "index.js",
"scripts": {
@@ -8,7 +8,7 @@
},
"keywords": [],
"author": "",
- "license": "ISC",
+ "license": "Apache-2.0",
"dependencies": {
"echarts": "github:apache/echarts#v6"
},
diff --git a/custom-series/violin/src/index.ts
b/custom-series/violin/src/index.ts
index 17fda98..856d68e 100644
--- a/custom-series/violin/src/index.ts
+++ b/custom-series/violin/src/index.ts
@@ -18,7 +18,10 @@
*/
import echarts, { CustomSeriesRenderItem } from 'echarts';
-import type { CustomPathOption } from
'echarts/types/src/chart/custom/CustomSeries';
+import type {
+ CustomPathOption,
+ CustomRootElementOption,
+} from 'echarts/types/src/chart/custom/CustomSeries.d.ts';
function epanechnikovKernel(u: number) {
return Math.abs(u) <= 1 ? 0.75 * (1 - u * u) : 0;
@@ -42,7 +45,8 @@ const renderItem = (
params: echarts.CustomSeriesRenderItemParams,
api: echarts.CustomSeriesRenderItemAPI
) => {
- let violins: { [key: number]: { firstDataIndex: number; data: number[] } };
+ let violins: { [key: number]: { firstDataIndex: number; data: number[] } } =
+ {};
if (params.context.violins == null) {
params.context.violins = [];
violins = params.context.violins as any;
@@ -68,14 +72,14 @@ const renderItem = (
(bandWidthScale == null ? 1 : bandWidthScale);
const violin = violins[xValue];
- let violinPath = null;
+ let violinPath: CustomRootElementOption | null = null;
if (violin && violin.firstDataIndex === params.dataIndex) {
const kde = kernelDensityEstimator(epanechnikovKernel, 1, violin.data);
const binCount = (params.itemPayload.binCount as number) || 100;
- const xRange = Array.from(
- { length: binCount },
- (_, i) => i * (10 / (binCount - 1))
- );
+ const xRange: number[] = [];
+ for (var i = 0; i < binCount; i++) {
+ xRange.push(i * (10 / (binCount - 1)));
+ }
const density = xRange.map((x) => [x, kde(x)]);
const epsilonDensity = 0.001;
const polylines: CustomPathOption[] = [];
@@ -100,7 +104,6 @@ const renderItem = (
}
points.length = 0;
};
- const x = coord[0];
for (let i = 0; i < density.length; ++i) {
const coord = api.coord([xValue, density[i][0]]);
if (density[i][1] < epsilonDensity) {
@@ -114,7 +117,7 @@ const renderItem = (
violinPath = {
type: 'group',
children: polylines,
- // silent: true // 因为这里实际是用该 x 对应的第一个数据显示的,如果不 silent,tooltip 里会显示第一个数据的值
+ silent: true,
};
}
diff --git a/custom-series/violin/tsconfig.json
b/custom-series/violin/tsconfig.json
deleted file mode 100644
index 76fee21..0000000
--- a/custom-series/violin/tsconfig.json
+++ /dev/null
@@ -1,24 +0,0 @@
-{
- "compilerOptions": {
- "target": "es2015",
-
- "noImplicitAny": true,
- "noImplicitThis": true,
- "strictBindCallApply": true,
- "removeComments": false,
- "sourceMap": true,
-
- "moduleResolution": "node",
- "esModuleInterop": true,
-
- "declaration": true,
- "declarationMap": false,
-
- "importHelpers": true,
-
- "pretty": true,
-
- "outDir": "lib"
- },
- "include": ["src/**/*.ts"]
-}
diff --git a/package-lock.json b/package-lock.json
new file mode 100644
index 0000000..02ab8c0
--- /dev/null
+++ b/package-lock.json
@@ -0,0 +1,29 @@
+{
+ "name": "echarts-custom-series",
+ "version": "1.0.0",
+ "lockfileVersion": 3,
+ "requires": true,
+ "packages": {
+ "": {
+ "name": "echarts-custom-series",
+ "version": "1.0.0",
+ "license": "Apache-2.0",
+ "devDependencies": {
+ "typescript": "^5.5.4"
+ }
+ },
+ "node_modules/typescript": {
+ "version": "5.5.4",
+ "resolved":
"https://registry.npmjs.org/typescript/-/typescript-5.5.4.tgz",
+ "integrity":
"sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==",
+ "dev": true,
+ "bin": {
+ "tsc": "bin/tsc",
+ "tsserver": "bin/tsserver"
+ },
+ "engines": {
+ "node": ">=14.17"
+ }
+ }
+ }
+}
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..e7da31b
--- /dev/null
+++ b/package.json
@@ -0,0 +1,22 @@
+{
+ "name": "echarts-custom-series",
+ "version": "1.0.0",
+ "description": "Custom Series for Apache ECharts",
+ "scripts": {
+ "build": "node scripts/build.js",
+ "create": "node scripts/create.js"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/apache/echarts-custom-series.git"
+ },
+ "author": "",
+ "license": "Apache-2.0",
+ "bugs": {
+ "url": "https://github.com/apache/echarts/issues"
+ },
+ "homepage": "https://github.com/apache/echarts-custom-series#readme",
+ "devDependencies": {
+ "typescript": "^5.5.4"
+ }
+}
diff --git a/scripts/build.js b/scripts/build.js
new file mode 100644
index 0000000..a02a4f1
--- /dev/null
+++ b/scripts/build.js
@@ -0,0 +1,75 @@
+const fs = require('fs');
+const path = require('path');
+const { execSync } = require('child_process');
+
+/**
+ * Install dependencies before build if needed.
+ * If no `node_modules` directory, run `npm install`
+ *
+ * @param {string} dirName directory name under ./custom-series/
+ */
+function beforeBuild(dirName) {
+ const seriesPath = path.join(__dirname, '../custom-series', dirName);
+ const nodeModulesPath = path.join(seriesPath, 'node_modules');
+ if (!fs.existsSync(nodeModulesPath)) {
+ console.log(`Installing dependencies for custom series ${dirName}...`);
+ execSync(`npm install`, { cwd: seriesPath });
+ }
+}
+
+/**
+ * Build one custom series
+ *
+ * @param {string} dirName directory name under ./custom-series/
+ */
+function buildCustomSeries(dirName) {
+ const seriesPath = path.join(__dirname, '../custom-series', dirName);
+ if (!fs.existsSync(seriesPath)) {
+ console.error(`Custom series ${dirName} does not exist`);
+ return;
+ }
+
+ beforeBuild(dirName);
+
+ console.log(`Building custom series ${dirName}...`);
+
+ // Execute `tsc index.ts` to build custom series
+ const tscPath = path.join(__dirname, '../node_modules/.bin/tsc');
+ execSync(
+ `${tscPath} ${seriesPath}/src/index.ts \
+ --outDir ${seriesPath}/dist \
+ --target ES3 \
+ --noImplicitAny \
+ --noImplicitThis \
+ --strictBindCallApply \
+ --removeComments false \
+ --sourceMap \
+ --moduleResolution node \
+ --esModuleInterop \
+ --declaration \
+ --declarationMap false \
+ --importHelpers \
+ --pretty \
+ --ignoreDeprecations 5.0`
+ );
+}
+
+/**
+ * `npm run build` to build all
+ * `npm run build <series-name>` to build one custom series
+ */
+function build() {
+ const args = process.argv.slice(2);
+ if (args.length === 0) {
+ // Build all custom series
+ fs.readdirSync(path.join(__dirname, '../custom-series')).forEach(
+ buildCustomSeries
+ );
+ } else {
+ // Build custom series from args
+ args.forEach(buildCustomSeries);
+ }
+ console.log('Build successfully.');
+}
+
+build();
diff --git a/scripts/create.js b/scripts/create.js
new file mode 100644
index 0000000..5f6feb8
--- /dev/null
+++ b/scripts/create.js
@@ -0,0 +1,71 @@
+const fs = require('fs');
+const path = require('path');
+
+/**
+ * Create a new custom series based on template
+ */
+function create(name) {
+ // Copy the files under ./template to ./custom-series/<name>
+ const templatePath = path.join(__dirname, './template');
+ const seriesPath = path.join(__dirname, '../custom-series', name);
+ if (fs.existsSync(seriesPath)) {
+ console.error(`Custom series ${name} already exists`);
+ return;
+ }
+
+ fs.mkdirSync(seriesPath);
+ copyDirectory(templatePath, seriesPath);
+
+ // Replace $$$ in package.json with <name>
+ const packageJsonPath = path.join(seriesPath, 'package.json');
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
+ packageJson.name = `echarts-${name}`;
+ fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
+
+ // Run `npm install`
+ console.log(`Installing dependencies for custom series ${name}...`);
+ require('child_process').execSync(`npm install`, { cwd: seriesPath });
+
+ console.log(`Custom series ${name} created successfully`);
+ console.log(`Run "npm run build ${name}" to build the custom series`);
+}
+
+function copyDirectory(src, dest) {
+ // Check if source directory exists
+ if (!fs.existsSync(src)) {
+ console.error(`Source directory "${src}" does not exist.`);
+ return;
+ }
+
+ // Create the destination directory if it does not exist
+ if (!fs.existsSync(dest)) {
+ fs.mkdirSync(dest, { recursive: true });
+ }
+
+ // Read all files and directories in the source directory
+ const items = fs.readdirSync(src);
+
+ // Iterate over each item in the directory
+ items.forEach((item) => {
+ const srcPath = path.join(src, item);
+ const destPath = path.join(dest, item);
+ const stats = fs.statSync(srcPath);
+
+ if (stats.isDirectory()) {
+ // If the item is a directory, recursively copy its contents
+ copyDirectory(srcPath, destPath);
+ } else {
+ // If the item is a file, copy it to the destination
+ fs.copyFileSync(srcPath, destPath);
+ }
+ });
+}
+
+const names = process.argv.slice(2);
+if (names.length === 0) {
+ console.error(
+ 'Please specify the name of the custom series. For example: npm run create
my-series'
+ );
+} else {
+ names.forEach(create);
+}
diff --git a/custom-series/violin/package.json b/scripts/template/package.json
similarity index 76%
copy from custom-series/violin/package.json
copy to scripts/template/package.json
index 30f592c..cdcea7d 100644
--- a/custom-series/violin/package.json
+++ b/scripts/template/package.json
@@ -1,6 +1,6 @@
{
- "name": "echarts-violin",
- "version": "1.0.0",
+ "name": "echarts-$$$",
+ "version": "0.0.1",
"description": "",
"main": "index.js",
"scripts": {
@@ -8,7 +8,7 @@
},
"keywords": [],
"author": "",
- "license": "ISC",
+ "license": "Apache-2.0",
"dependencies": {
"echarts": "github:apache/echarts#v6"
},
diff --git a/scripts/template/src/index.ts b/scripts/template/src/index.ts
new file mode 100644
index 0000000..154f721
--- /dev/null
+++ b/scripts/template/src/index.ts
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import echarts, { CustomSeriesRenderItem } from 'echarts';
+import type { CustomRootElementOption } from
'echarts/types/src/chart/custom/CustomSeries.d.ts';
+
+const renderItem = (
+ params: echarts.CustomSeriesRenderItemParams,
+ api: echarts.CustomSeriesRenderItemAPI
+) => {
+ return {
+ type: 'group',
+ children: [],
+ } as CustomRootElementOption;
+};
+
+echarts.registerCustomSeries(
+ 'violin',
+ renderItem as unknown as CustomSeriesRenderItem
+);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]