This is an automated email from the ASF dual-hosted git repository. ovilia pushed a commit to branch feat-word-cloud in repository https://gitbox.apache.org/repos/asf/echarts-custom-series.git
commit 064e639d7590eb10035b3ca2e4f816502ed2c7fa Author: Ovilia <[email protected]> AuthorDate: Thu Dec 25 16:06:18 2025 +0800 feat: word cloud init --- custom-series/wordCloud/README.md | 111 ++++++++++++++++++++++++++++ custom-series/wordCloud/examples/index.html | 51 +++++++++++++ custom-series/wordCloud/examples/ssr.js | 67 +++++++++++++++++ custom-series/wordCloud/package-lock.json | 62 ++++++++++++++++ custom-series/wordCloud/package.json | 48 ++++++++++++ custom-series/wordCloud/src/index.ts | 56 ++++++++++++++ 6 files changed, 395 insertions(+) diff --git a/custom-series/wordCloud/README.md b/custom-series/wordCloud/README.md new file mode 100644 index 0000000..b8b2540 --- /dev/null +++ b/custom-series/wordCloud/README.md @@ -0,0 +1,111 @@ +# @echarts-x/custom-word-cloud + +`wordCloud` is a custom series for [Apache ECharts](https://github.com/apache/echarts). It's typically used to ... + + + +[Source Code](https://github.com/apache/echarts-custom-series/tree/main/custom-series/wordCloud) + +## Usage + +### Browser Environment + +For browser usage, use the auto-registration version that automatically installs the custom series when loaded: + +```html +<script src="./node_modules/echarts/dist/echarts.js"></script> +<script src="./node_modules/@echarts-x/custom-word-cloud/dist/word-cloud.auto.js"></script> +<script> + // No need to call echarts.use(), automatically registered + const chart = echarts.init(...); + const option = { + series: [{ + type: 'custom', + renderItem: 'wordCloud', + // ... + }] + } + chart.setOption(option); +</script> +``` + +See [examples](./examples) for more details. + +### UMD (Universal Module Definition) + +For environments that need manual registration or when using AMD/CommonJS loaders: + +```js +// CommonJS +const echarts = require('echarts'); +const wordCloudInstaller = require('@echarts-x/custom-word-cloud'); +echarts.use(wordCloudInstaller); +const chart = echarts.init(...); + +const option = { + series: [{ + type: 'custom', + renderItem: 'wordCloud', + // ... + }] +} +chart.setOption(option); +``` + +See [examples](./examples) for more details. + +### ESM (ES Modules) + +For modern module bundlers or native ES module environments: + +```bash +npm install @echarts-x/custom-word-cloud +``` + +```js +import * as echarts from 'echarts'; +import wordCloudCustomSeriesInstaller from '@echarts-x/custom-word-cloud'; + +echarts.use(wordCloudCustomSeriesInstaller); +const chart = echarts.init(...); + +const option = { + series: [{ + type: 'custom', + renderItem: 'wordCloud', + // ... + }] +} +chart.setOption(option); +``` + +See [examples](./examples) for more details. + +## API + +### series.data + +The data of the series is an array of arrays. Each sub-array represents ... + +```js +const data = []; +``` + +### series.itemPayload + +The `itemPayload` is an object that contains the following properties: + +| Property | Type | Default | Description | +| -------- | ---- | ------- | ----------- | + +### series.encode + +To make sure the value axis and tooltip take the correct range, `encode` should be set as follows: + +```js +encode: { + x: 0, + y: 1, + tooltip: 2 +} +``` diff --git a/custom-series/wordCloud/examples/index.html b/custom-series/wordCloud/examples/index.html new file mode 100644 index 0000000..62008eb --- /dev/null +++ b/custom-series/wordCloud/examples/index.html @@ -0,0 +1,51 @@ +<!DOCTYPE html> +<!-- + 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. +--> +<html lang="en"> + <head> + <meta charset="UTF-8" /> + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <title>Apache ECharts Custom Series Test</title> + </head> + + <body> + <div + id="main" + style="width: 1000px; height: 400px; border: 1px solid #ccc" + ></div> + + <script src="../node_modules/echarts/dist/echarts.js"></script> + <script src="../dist/word-cloud.auto.js"></script> + <script> + echarts.use(window.wordCloudCustomSeriesInstaller); + const chart = echarts.init(document.getElementById('main')); + + option = { + series: { + type: 'custom', + renderItem: 'wordCloud', + coordinateSystem: 'none', + itemPayload: {}, + }, + }; + + chart.setOption(option); + </script> + </body> +</html> diff --git a/custom-series/wordCloud/examples/ssr.js b/custom-series/wordCloud/examples/ssr.js new file mode 100644 index 0000000..60cc918 --- /dev/null +++ b/custom-series/wordCloud/examples/ssr.js @@ -0,0 +1,67 @@ +/* + * 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. + */ + +const echarts = require('echarts'); +const wordCloudInstaller = require('../dist/word-cloud.js'); + +echarts.use(wordCloudInstaller); + +const chart = echarts.init(null, null, { + renderer: 'svg', + ssr: true, + width: 600, + height: 400, +}); + +// Set up seeded random for consistent thumbnails +const seedrandom = require('seedrandom'); +const myRandom = new seedrandom('echarts-random'); +Math.random = function () { + return myRandom(); +}; + +// Sample data generation - customize this for your specific chart type +const sampleData = []; +// TODO: Generate appropriate sample data for wordCloud + +const option = { + animation: false, + tooltip: { + show: false, + }, + // TODO: Configure axes and other options specific to wordCloud + series: [ + { + type: 'custom', + renderItem: 'wordCloud', + data: sampleData, + silent: true, + itemPayload: { + // TODO: Add specific itemPayload properties for wordCloud + }, + }, + ], +}; + +chart.setOption(option); + +const svg = chart.renderToSVGString(); +console.log(svg); + +chart.dispose(); diff --git a/custom-series/wordCloud/package-lock.json b/custom-series/wordCloud/package-lock.json new file mode 100644 index 0000000..530ed3d --- /dev/null +++ b/custom-series/wordCloud/package-lock.json @@ -0,0 +1,62 @@ +{ + "name": "@echarts-x/custom-word-cloud", + "version": "1.0.0-beta.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "@echarts-x/custom-word-cloud", + "version": "1.0.0-beta.0", + "license": "Apache-2.0", + "devDependencies": { + "echarts": "^6.0.0", + "typescript": "^5.5.4" + }, + "peerDependencies": { + "echarts": "^6.0.0" + } + }, + "node_modules/echarts": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/echarts/-/echarts-6.0.0.tgz", + "integrity": "sha512-Tte/grDQRiETQP4xz3iZWSvoHrkCQtwqd6hs+mifXcjrCuo2iKWbajFObuLJVBlDIJlOzgQPd1hsaKt/3+OMkQ==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "tslib": "2.3.0", + "zrender": "6.0.0" + } + }, + "node_modules/tslib": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.0.tgz", + "integrity": "sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg==", + "dev": true, + "license": "0BSD" + }, + "node_modules/typescript": { + "version": "5.9.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", + "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, + "node_modules/zrender": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/zrender/-/zrender-6.0.0.tgz", + "integrity": "sha512-41dFXEEXuJpNecuUQq6JlbybmnHaqqpGlbH1yxnA5V9MMP4SbohSVZsJIwz+zdjQXSSlR1Vc34EgH1zxyTDvhg==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "tslib": "2.3.0" + } + } + } +} diff --git a/custom-series/wordCloud/package.json b/custom-series/wordCloud/package.json new file mode 100644 index 0000000..29efa8a --- /dev/null +++ b/custom-series/wordCloud/package.json @@ -0,0 +1,48 @@ +{ + "name": "@echarts-x/custom-word-cloud", + "version": "1.0.0-beta.0", + "description": "Custom wordCloud series for Apache ECharts", + "main": "dist/word-cloud.js", + "module": "dist/word-cloud.esm.mjs", + "exports": { + ".": { + "types": "./dist/word-cloud.d.ts", + "import": "./dist/word-cloud.esm.mjs", + "require": "./dist/word-cloud.js" + } + }, + "types": "dist/word-cloud.d.ts", + "keywords": [ + "echarts", + "apache-echarts", + "data-visualization", + "chart", + "dataviz" + ], + "author": "", + "license": "Apache-2.0", + "homepage": "https://github.com/apache/echarts-custom-series/tree/main/custom-series/wordCloud", + "repository": { + "type": "git", + "url": "git+https://github.com/apache/echarts-custom-series.git" + }, + "scripts": { + "test:browser": "npx http-server . -p 8088 -o examples/index.html", + "test:ssr": "node examples/ssr.js", + "test": "npm run test:ssr" + }, + "devDependencies": { + "echarts": "^6.0.0", + "typescript": "^5.5.4" + }, + "peerDependencies": { + "echarts": "^6.0.0" + }, + "files": [ + "dist", + "README.md" + ], + "publishConfig": { + "access": "public" + } +} \ No newline at end of file diff --git a/custom-series/wordCloud/src/index.ts b/custom-series/wordCloud/src/index.ts new file mode 100644 index 0000000..0046f08 --- /dev/null +++ b/custom-series/wordCloud/src/index.ts @@ -0,0 +1,56 @@ +/* + * 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 * as echarts from 'echarts'; +import type { + CustomRootElementOption, + CustomSeriesRenderItem, +} from 'echarts/types/src/chart/custom/CustomSeries.d.ts'; +import type { + EChartsExtensionInstallRegisters, + EChartsExtension, +} from 'echarts/types/src/extension.d.ts'; + +type WordCloudItemPayload = {}; + +const renderItem = ( + params: echarts.CustomSeriesRenderItemParams, + api: echarts.CustomSeriesRenderItemAPI +) => { + const itemPayload = + params.itemPayload as WordCloudItemPayload; + + const cnt = params.dataInsideLength; + if (params.dataIndex === cnt - 1) { + } + + return { + type: 'group', + children: [], + } as CustomRootElementOption; +}; + +export default { + install(registers: EChartsExtensionInstallRegisters) { + registers.registerCustomSeries( + 'wordCloud', + renderItem as unknown as CustomSeriesRenderItem + ); + }, +} as EChartsExtension; --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
