This is an automated email from the ASF dual-hosted git repository. sushuang pushed a commit to branch v6-examples-supplement in repository https://gitbox.apache.org/repos/asf/echarts-examples.git
commit b1a5b7397a779266005f120691a0c70fbf8c9987 Author: 100pah <[email protected]> AuthorDate: Thu Aug 7 01:40:12 2025 +0800 infra: Suport internal API `retrieveViewCoordSysRects` in example. --- src/editor/sandbox/setup.js | 64 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/src/editor/sandbox/setup.js b/src/editor/sandbox/setup.js index 968c7ca2..4226f42e 100644 --- a/src/editor/sandbox/setup.js +++ b/src/editor/sandbox/setup.js @@ -252,6 +252,8 @@ function setup(isShared) { appEnv = {}; appStore = store; + initInternalAPI(appEnv); + try { // run the code const compiledCode = store.runCode @@ -486,6 +488,68 @@ function setup(isShared) { }); } + /** + * This is some features that requires echarts internal API. + * Inappropriate to public to users for production usage, but useful in demo. + * Usage in examples code: + * ```js + * app.__internalAPI.xxx(myChart, otherArgs); + * ``` + */ + function initInternalAPI(appEnv) { + const internalAPI = appEnv.__internalAPI = {}; + + /** + * @param {{ + * mainType: ComponentMainType; + * subType?: ComponentSubType; + * index?: number | number[]; + * id?: OptionId | OptionId[]; + * name?: OptionName | OptionName[]; + * }} queryParam For example: + * {mainType: 'series', subType: 'map', id: 'xxx'} + * {mainType: 'geo', id: 'xxx'} + */ + internalAPI.retrieveViewCoordSysRects = function (myChart, queryParam) { + if (!queryParam + || ( + queryParam.index == null + && queryParam.id == null + && queryParam.name == null + ) + ) { + throw new Error('queryParam must have either index, id or name.'); + } + const component = myChart.getModel().queryComponents(queryParam)[0]; + if (!component) { + throw new Error('No component found for the given queryParam.'); + } + const viewCoordSys = component.coordinateSystem; + if (!viewCoordSys) { + throw new Error('The component does not have a view coordinate system.'); + } + ecInternalAPIExistingCheck(viewCoordSys, 'getViewRect'); + ecInternalAPIExistingCheck(viewCoordSys, 'getBoundingRect'); + + const viewRect = viewCoordSys.getViewRect().clone(); + const contentBoundingRect = viewCoordSys.getBoundingRect().clone(); + const trans = viewCoordSys.getComputedTransform(); + if (trans) { + contentBoundingRect.applyTransform(trans); + } + return { + viewRect, + contentBoundingRect + }; + }; + + function ecInternalAPIExistingCheck(host, apiName) { + if (!host[apiName]) { + throw new Error(`The internal API \`${apiName}\` probably have breaking changes.`); + } + } + } + echarts.registerPreprocessor(function (option) { if (appStore.enableDecal) { option.aria = option.aria || {}; --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
