You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by sh...@apache.org on 2021/11/22 02:48:29 UTC
[echarts-examples] branch gh-pages updated: use seeded random
This is an automated email from the ASF dual-hosted git repository.
shenyi pushed a commit to branch gh-pages
in repository https://gitbox.apache.org/repos/asf/echarts-examples.git
The following commit(s) were added to refs/heads/gh-pages by this push:
new 9fd301c use seeded random
9fd301c is described below
commit 9fd301c6bea57a383e1d322b6f5b73abb07546ad
Author: pissang <bm...@gmail.com>
AuthorDate: Mon Nov 22 10:47:46 2021 +0800
use seeded random
---
package-lock.json | 26 ++++++++++++++++++++++++++
package.json | 5 +++--
src/common/i18n.js | 4 ++++
src/common/route.js | 2 +-
src/common/store.js | 11 ++++++++++-
src/editor/Preview.vue | 41 +++++++++++++++++++++++++++++++++++------
src/editor/sandbox.js | 10 ++++++++--
7 files changed, 87 insertions(+), 12 deletions(-)
diff --git a/package-lock.json b/package-lock.json
index 816d08d..dac31cc 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1650,6 +1650,11 @@
"color-convert": "^1.9.0"
}
},
+ "any-base": {
+ "version": "1.1.0",
+ "resolved": "https://registry.npmjs.org/any-base/-/any-base-1.1.0.tgz",
+ "integrity": "sha512-uMgjozySS8adZZYePpaWs8cxB9/kdzmpX6SgJZ+wbz1K5eYk5QMYDVJaZKhxyIHUdnnJkfR7SVgStgH7LkGUyg=="
+ },
"any-promise": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/any-promise/-/any-promise-1.3.0.tgz",
@@ -4752,6 +4757,11 @@
"thenify-all": "^1.0.0"
}
},
+ "nanoid": {
+ "version": "3.1.30",
+ "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.1.30.tgz",
+ "integrity": "sha512-zJpuPDwOv8D2zq2WRoMe1HsfZthVewpel9CAvTfc/2mBD1uUT/agc5f7GHGWXlYkFvi1mVxe4IjvP2HNrop7nQ=="
+ },
"napi-build-utils": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/napi-build-utils/-/napi-build-utils-1.0.2.tgz",
@@ -6021,6 +6031,22 @@
}
}
},
+ "short-uuid": {
+ "version": "4.2.0",
+ "resolved": "https://registry.npmjs.org/short-uuid/-/short-uuid-4.2.0.tgz",
+ "integrity": "sha512-r3cxuPPZSuF0QkKsK9bBR7u+7cwuCRzWzgjPh07F5N2iIUNgblnMHepBY16xgj5t1lG9iOP9k/TEafY1qhRzaw==",
+ "requires": {
+ "any-base": "^1.1.0",
+ "uuid": "^8.3.2"
+ },
+ "dependencies": {
+ "uuid": {
+ "version": "8.3.2",
+ "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
+ "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg=="
+ }
+ }
+ },
"signal-exit": {
"version": "3.0.2",
"resolved": "https://registry.npm.taobao.org/signal-exit/download/signal-exit-3.0.2.tgz",
diff --git a/package.json b/package.json
index 28fb773..a195e3d 100644
--- a/package.json
+++ b/package.json
@@ -61,12 +61,13 @@
"dependencies": {
"@lang/object-visualizer": "^4.2.0",
"lodash": "^4.17.19",
+ "nanoid": "^3.1.30",
+ "prettier": "^2.3.2",
"resize-detector": "^0.2.2",
"scroll-into-view": "^1.14.2",
"sucrase": "^3.17.0",
"vanilla-lazyload": "^12.5.1",
"vue-i18n": "^8.18.2",
- "vue-scrollactive": "^0.9.3",
- "prettier": "^2.3.2"
+ "vue-scrollactive": "^0.9.3"
}
}
diff --git a/src/common/i18n.js b/src/common/i18n.js
index c760f0c..3d4c29d 100644
--- a/src/common/i18n.js
+++ b/src/common/i18n.js
@@ -14,6 +14,8 @@ export default {
renderer: 'Renderer',
useDirtyRect: 'Use Dirty Rect',
+ randomData: 'Random',
+
download: 'Download',
screenshot: 'Screenshot',
@@ -89,6 +91,8 @@ export default {
darkMode: '深色模式',
enableDecal: '无障碍花纹',
+
+ randomData: '随机数据',
// lightMode: '浅色模式',
renderCfgTitle: '渲染设置',
diff --git a/src/common/route.js b/src/common/route.js
index eeca3be..0dd04ca 100644
--- a/src/common/route.js
+++ b/src/common/route.js
@@ -23,7 +23,7 @@ export function getURL(params) {
export function gotoURL(params, pushHistory) {
if (pushHistory) {
- history.pushState({}, getURL(params));
+ history.pushState({}, '', getURL(params));
} else {
location.href = getURL(params);
}
diff --git a/src/common/store.js b/src/common/store.js
index 0a663f5..fba4b9a 100644
--- a/src/common/store.js
+++ b/src/common/store.js
@@ -2,6 +2,8 @@
import { URL_PARAMS } from '../common/config';
import CHART_LIST from '../data/chart-list-data';
import CHART_LIST_GL from '../data/chart-list-data-gl';
+import { customAlphabet } from 'nanoid';
+const nanoid = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyz', 10);
export const store = {
echartsVersion: URL_PARAMS.version || '5',
@@ -30,12 +32,19 @@ export const store = {
editorStatus: {
type: '',
message: ''
- }
+ },
+
+ randomSeed: URL_PARAMS.random || 'echarts'
};
function findExample(item) {
return URL_PARAMS.c === item.id;
}
+
+export function updateRandomSeed() {
+ store.randomSeed = nanoid();
+}
+
export function getExampleConfig() {
const example = CHART_LIST.concat(CHART_LIST_GL).find(findExample);
return example;
diff --git a/src/editor/Preview.vue b/src/editor/Preview.vue
index ff240c1..9a9a748 100644
--- a/src/editor/Preview.vue
+++ b/src/editor/Preview.vue
@@ -26,7 +26,13 @@
:inactive-text="''"
>
</el-switch>
- <el-popover placement="bottom" width="450" trigger="click" v-if="!isGL">
+ <!-- Not display when random button is displayed on mobile devices. -->
+ <el-popover
+ placement="bottom"
+ width="450"
+ trigger="click"
+ v-if="!isGL && !(shared.isMobile && hasRandomData)"
+ >
<div class="render-config-container">
<el-row :gutter="2" type="flex" align="middle">
<el-col :span="12">
@@ -56,12 +62,10 @@
{{ $t('editor.renderCfgTitle')
}}<i class="el-icon-setting el-icon--right"></i>
</el-button>
- <!-- <i class="el-icon-setting el-icon--left"></i
- >{{ $t('editor.renderCfgTitle') }} -->
</span>
</el-popover>
<el-select
- v-if="shared.echartsVersion"
+ v-if="shared.echartsVersion && !shared.isMobile"
class="version-select"
size="mini"
id="choose-echarts-version"
@@ -77,6 +81,13 @@
{{ version }}
</el-option>
</el-select>
+ <el-button
+ class="random"
+ v-if="hasRandomData"
+ size="mini"
+ @click="changeRandomSeed"
+ >{{ $t('editor.randomData') }}</el-button
+ >
</div>
<a
@@ -128,6 +139,7 @@ import {
isGLExample,
saveExampleCodeToLocal,
store,
+ updateRandomSeed,
updateRunHash
} from '../common/store';
import { SCRIPT_URLS, URL_PARAMS } from '../common/config';
@@ -141,8 +153,6 @@ import { gotoURL } from '../common/route';
const example = getExampleConfig();
const isGL = isGLExample();
-const echartsVersions = {};
-
function addDecalIfNecessary(option) {
if (store.enableDecal) {
option.aria = option.aria || {};
@@ -293,6 +303,11 @@ export default {
},
computed: {
+ hasRandomData() {
+ return (
+ this.shared.runCode && this.shared.runCode.indexOf('Math.random()') >= 0
+ );
+ },
editLink() {
const params = ['c=' + URL_PARAMS.c];
if (URL_PARAMS.theme) {
@@ -382,6 +397,17 @@ export default {
})
);
});
+ },
+ changeRandomSeed() {
+ updateRandomSeed();
+ gotoURL(
+ {
+ ...URL_PARAMS,
+ random: store.randomSeed
+ },
+ true
+ );
+ this.run();
}
// hasEditorError() {
// const annotations = this.editor.getSession().getAnnotations();
@@ -461,6 +487,9 @@ export default {
width: 80px;
margin-left: 10px;
}
+ .random {
+ margin-left: 10px;
+ }
label {
margin-bottom: 0;
diff --git a/src/editor/sandbox.js b/src/editor/sandbox.js
index de496c5..9fc9651 100644
--- a/src/editor/sandbox.js
+++ b/src/editor/sandbox.js
@@ -1,4 +1,5 @@
import showDebugDirtyRect from '../dep/showDebugDirtyRect';
+import seedrandom from 'seedrandom';
export function createSandbox(optionUpdated) {
let appEnv = {};
@@ -114,7 +115,10 @@ export function createSandbox(optionUpdated) {
// run the code
- const compiledCode = store.runCode;
+ const compiledCode = store.runCode
+ // Replace random method
+ .replace(/Math.random\(\)/g, '__ECHARTS_EXAMPLE_RANDOM__()');
+ const echartsExampleRandom = seedrandom(store.randomSeed);
const func = new Function(
'myChart',
@@ -122,6 +126,7 @@ export function createSandbox(optionUpdated) {
'setTimeout',
'setInterval',
'ROOT_PATH',
+ '__ECHARTS_EXAMPLE_RANDOM__',
'var option;\n' + compiledCode + '\nreturn option;'
);
const option = func(
@@ -129,7 +134,8 @@ export function createSandbox(optionUpdated) {
appEnv,
setTimeout,
setInterval,
- store.cdnRoot
+ store.cdnRoot,
+ echartsExampleRandom
);
let updateTime = 0;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org