Browse Source

初始化

master
pengpeng.zhai 2 years ago
parent
commit
089de6506f

+ 55
- 0
.gitignore View File

@@ -0,0 +1,55 @@
1
+# Created by .ignore support plugin (hsz.mobi)
2
+### JetBrains template
3
+# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
4
+# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
5
+
6
+# User-specific stuff:
7
+.idea/**/workspace.xml
8
+.idea/**/tasks.xml
9
+.idea/dictionaries
10
+
11
+# Sensitive or high-churn files:
12
+.idea/**/dataSources/
13
+.idea/**/dataSources.ids
14
+.idea/**/dataSources.xml
15
+.idea/**/dataSources.local.xml
16
+.idea/**/sqlDataSources.xml
17
+.idea/**/dynamic.xml
18
+.idea/**/uiDesigner.xml
19
+
20
+# Gradle:
21
+.idea/**/gradle.xml
22
+.idea/**/libraries
23
+.idea/
24
+
25
+# Mongo Explorer plugin:
26
+.idea/**/mongoSettings.xml
27
+
28
+## File-based project format:
29
+*.iws
30
+
31
+## Plugin-specific files:
32
+
33
+# IntelliJ
34
+/out/
35
+
36
+# mpeltonen/sbt-idea plugin
37
+.idea_modules/
38
+
39
+# JIRA plugin
40
+atlassian-ide-plugin.xml
41
+
42
+# Crashlytics plugin (for Android Studio and IntelliJ)
43
+com_crashlytics_export_strings.xml
44
+crashlytics.properties
45
+crashlytics-build.properties
46
+fabric.properties
47
+
48
+/node_modules/
49
+
50
+##打包的文件
51
+dll/
52
+dist/
53
+
54
+## yarn 
55
+yarn.lock

+ 285
- 0
config/config.js View File

@@ -0,0 +1,285 @@
1
+const path = require('path');
2
+const webpack = require('webpack');
3
+const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
4
+const glob = require("glob");
5
+const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
6
+const HtmlWebpackPlugin = require('html-webpack-plugin');
7
+// const CopyWebpackPlugin = require("copy-webpack-plugin");
8
+const CleanWebpackPlugin = require('clean-webpack-plugin');
9
+const packageJson = require("./../package.json");
10
+const HappyPack = require('happypack');
11
+const os = require('os');
12
+const happyThreadPool = HappyPack.ThreadPool({size: os.cpus().length});
13
+let pathVars = require("./pathVars");
14
+let config = {};
15
+
16
+/*----------------------------------- page ---------------------------------*/
17
+//测试页面
18
+let files = [].concat(
19
+    glob.sync(pathVars.testPath + `/Custom*/index.html`),
20
+);
21
+console.log("测试页面\n", files);
22
+let entryDev = {
23
+    vendor: Object.keys(packageJson.dependencies)
24
+};
25
+let pageAry = [];
26
+files.forEach(function (filePath) {
27
+    let tempAry = filePath.split('/');
28
+    //demo文件夹名
29
+    let typeName = tempAry[tempAry.length - 3];
30
+    let chunkName = tempAry[tempAry.length - 2];
31
+    let htmlName = chunkName + "/index.html";
32
+
33
+    let obj = {};
34
+    obj["filePath"] = filePath;
35
+    obj["chunkName"] = chunkName;
36
+    obj["htmlName"] = htmlName;
37
+    obj["entryJs"] = pathVars.testPath + "/" + chunkName + "/index.js";
38
+    entryDev[chunkName] = obj["entryJs"];
39
+    pageAry.push(obj);
40
+});
41
+
42
+
43
+//图表主js文件
44
+let chartFiles = glob.sync(pathVars.srcPath + "/chart/Custom*/Custom*.js");
45
+console.log("图表主js文件\n", chartFiles);
46
+let chartAry = [];
47
+let entryDist = {};
48
+chartFiles.forEach(function (filePath) {
49
+    let tempAry = filePath.split('/');
50
+    let chunkName = tempAry[tempAry.length - 2];
51
+    let obj = {};
52
+    obj["chunkName"] = chunkName;
53
+    chartAry.push(obj);
54
+    //
55
+    entryDist[chunkName] = filePath;
56
+});
57
+
58
+
59
+/*-----------------------------  entry  ------------------------------*/
60
+
61
+config["entryDev"] = entryDev;
62
+
63
+
64
+config["entryDist"] = entryDist;
65
+
66
+
67
+/*-----------------------------  devServer  ------------------------------*/
68
+let devServer = {
69
+    // open: true,
70
+    publicPath: "/",
71
+    contentBase: pathVars.devPath,
72
+    hot: true,
73
+    inline: true,
74
+    port: 3000,
75
+    host: 'localhost',
76
+    watchOptions:{
77
+        ignored:/node_modules/,
78
+        aggregateTimeout:500
79
+    }
80
+};
81
+config["devServer"] = devServer;
82
+
83
+
84
+/*-----------------------------  output  ------------------------------*/
85
+let outputDev = {
86
+    path: pathVars.distPath,
87
+    publicPath: "/",     // 表示资源的发布地址,当配置过该属性后,打包文件中所有通过相对路径引用的资源都会被配置的路径所替换(如:css中背景图的路径)
88
+    filename: "[name]/main.js"
89
+};
90
+config["outputDev"] = outputDev;
91
+
92
+let outputDist = {
93
+    path: pathVars.distPath,
94
+    publicPath: "/",
95
+    filename: "[name]_[chunkhash:5].js",
96
+    library: "[name]",
97
+    libraryTarget: "umd"
98
+//  libraryExport: "default"
99
+};
100
+config["outputDist"] = outputDist;
101
+
102
+
103
+/*-----------------------------  externals  ------------------------------*/
104
+if (process.env.NODE_ENV === "noThird") {
105
+    console.log("==================", process.env.NODE_ENV);
106
+    config["externals"] = {
107
+        'three': {
108
+            commonjs: 'THREE',
109
+            commonjs2: 'THREE',
110
+            amd: 'THREE',
111
+            root: 'THREE'
112
+        },
113
+        'zrender': {
114
+            commonjs: 'zrender',
115
+            commonjs2: 'zrender',
116
+            amd: 'zrender',
117
+            root: 'zrender'
118
+        },
119
+        'gsap': {
120
+            commonjs: 'gsap',
121
+            commonjs2: 'gsap',
122
+            amd: 'gsap',
123
+            root: 'gsap'
124
+        }
125
+    };
126
+} else {
127
+    config["externals"] = {};
128
+    config["outputDist"]["filename"]="[name].js"
129
+}
130
+
131
+let resolve = {
132
+    alias: {
133
+        utils: path.resolve(__dirname, '../src/utils/'),
134
+    }
135
+};
136
+config["resolve"] = resolve;
137
+
138
+
139
+/*-----------------------------  module  ------------------------------*/
140
+let rules = [
141
+    {
142
+        test: /\.js$/,
143
+        // exclude: pathVars.nodeModulesPath,
144
+        loader: "babel-loader",
145
+    },
146
+    {
147
+        test: /\.(glsl|vs|fs|vert|frag)$/,
148
+        // exclude: [pathVars.nodeModulesPath, pathVars.dllPath],
149
+        use: ["raw-loader", "glslify-loader"]
150
+    }
151
+]
152
+
153
+let imgRuleDev = {
154
+    test: /\.(png|jpg|gif)$/,
155
+    use: [
156
+        {
157
+            loader: 'file-loader',
158
+            options: {
159
+                publicPath: '/',
160
+                name: 'imgInChart/[name]_[hash:5].[ext]'
161
+            }
162
+        }
163
+    ]
164
+}
165
+let imgRuleDist = {
166
+    test: /\.(png|jpg|gif)$/,
167
+    use: [
168
+        {
169
+            loader: 'file-loader',
170
+            options: {
171
+                publicPath: '../../static/',
172
+                name: 'imgInChart/[name]_[hash:5].[ext]'
173
+            }
174
+        }
175
+    ]
176
+};
177
+
178
+config["moduleBaseDev"] = {rules: rules.concat(imgRuleDev)};
179
+config["moduleBaseDist"] = {rules: rules.concat(imgRuleDist)};
180
+
181
+
182
+//---------------------------------- plugin -----------------------------------//
183
+let pluginBase = [
184
+    new webpack.DllReferencePlugin({
185
+        context: pathVars.rootPath,
186
+        manifest: require(pathVars.dllPath + '/manifest.json')
187
+    }),
188
+    new HappyPack({
189
+        id: 'babel',
190
+        loaders: ["babel-loader"],
191
+        threadPool: happyThreadPool
192
+    }),
193
+    new webpack.DefinePlugin({
194
+        my_ENV: JSON.stringify(process.env.my_ENV)
195
+    })
196
+];
197
+
198
+const htmlBase = [];
199
+pageAry.forEach(function (page) {
200
+    const htmlPlugin = new HtmlWebpackPlugin({
201
+        title: '',
202
+        template: page["filePath"],
203
+        filename: page["htmlName"],
204
+        inject: 'body',
205
+        chunks: ["manifest", "vendor", "common", page["chunkName"]],
206
+        chunksSortMode: 'none'
207
+    });
208
+    htmlBase.push(htmlPlugin);
209
+});
210
+
211
+//------------------- dev
212
+let pluginsDev = [
213
+    new webpack.HotModuleReplacementPlugin()
214
+];
215
+config["pluginsDev"] = pluginBase.concat(pluginsDev, htmlBase);
216
+
217
+
218
+//------------------- dist
219
+let pluginDist = [
220
+    new CleanWebpackPlugin(pathVars.distPath,
221
+        {
222
+            root: pathVars.rootPath,
223
+            verbose: true
224
+        }
225
+    ),
226
+    new webpack.NoEmitOnErrorsPlugin(),
227
+
228
+
229
+];
230
+config["pluginDist"] = pluginBase.concat(pluginDist);
231
+
232
+//----------------------------------- optimization  ---------------------------//
233
+config["optimizationDev"] = {
234
+    minimize: false,
235
+    splitChunks: {
236
+        chunks: "all", //initial
237
+        minSize: 30 * 1024, //模块大于30k会被抽离到公共模块 也就是说每个页面的js不会大于30k
238
+        minChunks: 1, //模块出现1次就会被抽离到公共模块
239
+        maxAsyncRequests: 5, //异步模块,一次最多只能被加载5个
240
+        maxInitialRequests: 3, //入口模块最多只能加载3个
241
+        name: true,
242
+        cacheGroups: {
243
+            default: {
244
+                chunks: "all",
245
+                name: "common",
246
+                test: /[\\/]src[\\/]/,
247
+                minChunks: 3,
248
+                priority: -20,
249
+                reuseExistingChunk: true
250
+            },
251
+            vendors: {
252
+                chunks: "all",
253
+                name: "vendor",
254
+                test: /[\\/]node_modules[\\/]/,
255
+                minChunks: 1,
256
+                priority: -10
257
+            }
258
+        }
259
+    },
260
+    runtimeChunk: {
261
+        name: "manifest"
262
+    }
263
+};
264
+//
265
+config["optimizationDist"] = {
266
+    minimize: false,
267
+    minimizer: [
268
+        new UglifyJsPlugin({
269
+            cache: true,
270
+            parallel: true,
271
+            uglifyOptions: {
272
+                warnings: false,
273
+                compress: {
274
+                    // warnings: false,
275
+                    drop_debugger: true,
276
+                    drop_console: true
277
+                }
278
+            }
279
+        }),
280
+        new OptimizeCssAssetsPlugin({})
281
+    ],
282
+    splitChunks: {}
283
+
284
+};
285
+module.exports = config;

+ 28
- 0
config/pathVars.js View File

@@ -0,0 +1,28 @@
1
+const path = require('path');
2
+let pathVars = {};
3
+
4
+//项目根目录
5
+pathVars.rootPath = path.resolve(__dirname, '../');
6
+
7
+//源文件目录
8
+pathVars.srcPath = path.resolve(pathVars.rootPath, './src');
9
+
10
+//预编译文件存放目录
11
+pathVars.dllPath = path.resolve(pathVars.rootPath, './dll');
12
+
13
+//开发测试目录
14
+pathVars.devPath = path.resolve(pathVars.rootPath, './dev');
15
+
16
+//
17
+pathVars.staticPath = path.resolve(pathVars.rootPath, './dev/static');
18
+
19
+//发布目录
20
+pathVars.distPath = path.resolve(pathVars.rootPath, './dist');
21
+
22
+//node_modules目录
23
+pathVars.nodeModulesPath = path.resolve(pathVars.rootPath, './node_modules');
24
+
25
+//测试目录
26
+pathVars.testPath = path.resolve(pathVars.rootPath, './test');
27
+
28
+module.exports = pathVars;

+ 12
- 0
config/webpack.dev.config.js View File

@@ -0,0 +1,12 @@
1
+let config = require("./config");
2
+module.exports = {
3
+    mode: 'development',
4
+    devtool: 'eval-source-map',
5
+    entry: config.entryDev,
6
+    output: config.outputDev,
7
+    devServer:config.devServer,
8
+    plugins: config.pluginsDev,
9
+    module: config.moduleBaseDev,
10
+    optimization: config["optimizationDev"],
11
+    resolve: config.resolve
12
+};

+ 12
- 0
config/webpack.dist.config.js View File

@@ -0,0 +1,12 @@
1
+let config = require("./config");
2
+
3
+module.exports = {
4
+    mode:"production",
5
+    entry: config.entryDist,
6
+    output: config.outputDist,
7
+    externals: config.externals,
8
+    plugins: config.pluginDist,
9
+    module: config.moduleBaseDist,
10
+    optimization:config["optimizationDist"],
11
+    resolve: config.resolve
12
+};

+ 51
- 0
config/webpack.dll.config.js View File

@@ -0,0 +1,51 @@
1
+/*
2
+ * 用来预编译第三方库*/
3
+
4
+const webpack = require('webpack');
5
+const pathVars = require('./pathVars');
6
+const packageJson = require("./../package.json");
7
+// const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
8
+//
9
+module.exports = {
10
+    mode: 'development',
11
+    entry: {
12
+        /*第三方库*/
13
+        dll: Object.keys(packageJson.dependencies)
14
+    },
15
+    output: {
16
+        path: pathVars.dllPath,
17
+        filename: "[name].js",
18
+        library: '[name]',
19
+        libraryTarget: 'umd',
20
+        umdNamedDefine: true
21
+    },
22
+    plugins: [
23
+        //new webpack.NoEmitOnErrorsPlugin(),
24
+        new webpack.DllPlugin({
25
+            // path 定义 manifest 文件生成的位置 [name]的部分由entry的名字替换
26
+            path: pathVars.dllPath + '/manifest.json',
27
+            // name 是dll暴露的对象名,要跟 output.library 保持一致
28
+            name: '[name]',
29
+            // context 是解析包路径的上下文,这个要跟接下来配置的dll一致
30
+            context: pathVars.dllPath
31
+        })
32
+    ],
33
+    module: {
34
+        rules: [
35
+            {
36
+                test: /\.(css|less)$/,
37
+                //exclude: [pathVars.nodeModulesPath],
38
+                use: [
39
+                    "style-loader",
40
+                    "css-loader",
41
+                    "less-loader"
42
+                ],
43
+            },
44
+            {
45
+                test: /\.js$/,
46
+                //exclude: pathVars.nodeModulesPath,
47
+                loader: "babel-loader"
48
+            }
49
+        ]
50
+    }
51
+};

+ 54
- 0
package.json View File

@@ -0,0 +1,54 @@
1
+{
2
+  "name": "charts",
3
+  "version": "1.0.0",
4
+  "description": "图表二次开发",
5
+  "main": "index.js",
6
+  "scripts": {
7
+    "clear": "npm cache clean --force",
8
+    "dll": "webpack --config config/webpack.dll.config.js --progress --colors",
9
+    "dev": "webpack-dev-server --config config/webpack.dev.config.js --progress --colors",
10
+    "dist": "cross-env NODE_ENV=third ./node_modules/.bin/webpack --config config/webpack.dist.config.js --display-error-details --progress --colors"
11
+  },
12
+  "repository": {
13
+    "type": "git",
14
+    "url": "http://192.168.1.67:3000/productDpartment/chartDp.git"
15
+  },
16
+  "keywords": [
17
+    "chart"
18
+  ],
19
+  "author": "丁月明",
20
+  "license": "ISC",
21
+  "dependencies": {
22
+    "gsap": "^1.20.2",
23
+    "jquery": "^3.5.1",
24
+    "three": "^0.110.0",
25
+    "three-obj-loader": "^1.1.3",
26
+    "three-orbitcontrols": "^2.1.1",
27
+    "three-stats": "^1.0.1",
28
+    "zrender": "^4.2.0"
29
+  },
30
+  "devDependencies": {
31
+    "babel-core": "^6.26.3",
32
+    "babel-loader": "^7.1.5",
33
+    "babel-preset-env": "^1.7.0",
34
+    "babel-preset-stage-0": "^6.24.1",
35
+    "clean-webpack-plugin": "^1.0.0",
36
+    "cross-env": "^5.2.0",
37
+    "css-loader": "^2.1.0",
38
+    "file-loader": "^3.0.1",
39
+    "glob": "^7.1.3",
40
+    "happypack": "^5.0.1",
41
+    "html-webpack-plugin": "^3.2.0",
42
+    "json-loader": "^0.5.7",
43
+    "optimize-css-assets-webpack-plugin": "^5.0.1",
44
+    "style-loader": "^0.23.1",
45
+    "uglifyjs-webpack-plugin": "^2.1.1",
46
+    "url-loader": "^0.5.8",
47
+    "webpack": "^4.28.3",
48
+    "webpack-cli": "^3.2.0",
49
+    "webpack-dev-server": "^3.1.14",
50
+    "webpack-glsl-loader": "^1.0.1",
51
+    "glslify-loader": "^2.0.0",
52
+    "raw-loader": "^3.0.0"
53
+  }
54
+}

+ 108
- 0
src/chart/CustomChartBar/CustomChartBar.js View File

@@ -0,0 +1,108 @@
1
+import utils from 'utils/index.js';
2
+import echarts from './echarts.min.js';
3
+
4
+import styleConfig from './config/styleConfig';
5
+import dataConfig from './config/dataConfig';
6
+
7
+export default class CustomChartBar{
8
+    constructor(dom, opts){
9
+        opts = opts || {};
10
+        if(opts.getConfig === true){
11
+            return;
12
+        }
13
+
14
+        this.chart = null;
15
+        this._dom = dom;
16
+
17
+        this.init(opts);
18
+    }
19
+
20
+    init(opts){
21
+        this.chart = echarts.init(this._dom);
22
+        this.setOption(opts);
23
+    }
24
+
25
+    setOption(opts, data){
26
+        // this.chart.setOption(this.mergeOption(opts, data), {notMerge:true});
27
+        this.chart.setOption(opts, {notMerge:true});
28
+    }
29
+
30
+
31
+    mergeOption(style, dataConfig){
32
+        style = utils.deepCopy(style);
33
+        style.xAxis.data = dataConfig.defaultData[dataConfig.configList[0].defaultKey];
34
+        style.color = style.color.color;
35
+        style.yAxis = {
36
+            type:'value'
37
+        }
38
+
39
+        style.series = [];
40
+        let series = dataConfig.configList[1].defaultKey;
41
+        if(Array.isArray(series) === true){
42
+            series.forEach( item => {
43
+                style.series.push({
44
+                    data:dataConfig.defaultData[item],
45
+                    type:'bar'
46
+                })
47
+            })
48
+        }else{
49
+            style.series = [
50
+                {
51
+                  data: dataConfig.defaultData[series],
52
+                  type: 'bar'
53
+                }
54
+              ]
55
+        }
56
+        
57
+        return style;
58
+    }
59
+
60
+    getConfig(){
61
+        return{
62
+            styleConfig:utils.deepCopy(styleConfig),
63
+            dataConfig:utils.deepCopy(dataConfig),
64
+            fun:{
65
+                getColName: this.getColName,
66
+                themeMerge: this.themeMerge,
67
+            }
68
+        }
69
+    }
70
+    themeMerge(style, dataConfig){
71
+        style = utils.deepCopy(style);
72
+        style.xAxis.data = dataConfig.xAxis[0].data;
73
+        style.color = style.color.color;
74
+        style.yAxis = {
75
+            type:'value'
76
+        }
77
+
78
+        style.series = [];
79
+        let series = dataConfig.series;
80
+        if(Array.isArray(series) === true){
81
+            series.forEach( item => {
82
+                style.series.push({
83
+                    data:item.data,
84
+                    type:'bar'
85
+                })
86
+            })
87
+        }
88
+        
89
+        return style;
90
+    }
91
+
92
+    getColName(dataConfig){
93
+        let column = {};
94
+        dataConfig = JSON.parse(JSON.stringify(dataConfig));
95
+        let dataConfigKey = dataConfig.configList;
96
+        column.xAxis = [dataConfigKey[0].defaultKey];
97
+        column.series = dataConfigKey[1].defaultKey;
98
+        return column;
99
+    }
100
+
101
+    resize(){
102
+        this.chart.resize();
103
+    }
104
+
105
+    dispose(){
106
+        this.chart.dispose();
107
+    }
108
+}

+ 19
- 0
src/chart/CustomChartBar/config/dataConfig.js View File

@@ -0,0 +1,19 @@
1
+const dataConfig = {
2
+    configList:[{
3
+        name:'分类名称',
4
+        type:'xAxis',
5
+        comType:'single',
6
+        defaultKey:'商品'
7
+    },{
8
+        name:'数值名称',
9
+        type:'series',
10
+        comType:'multi',
11
+        defaultKey:['销量', '收入']
12
+    }],
13
+    defaultData:{
14
+        '销量': [5, 20, 36, 10, 10, 20],
15
+        '收入': [50, 100, 136, 70, 40, 80],
16
+        "商品": ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子'],
17
+    }
18
+}
19
+export default dataConfig;

+ 88
- 0
src/chart/CustomChartBar/config/styleConfig.js View File

@@ -0,0 +1,88 @@
1
+const styleConfig = {
2
+    xAxis:{
3
+        name:'X轴',
4
+        sub:{
5
+            show:{
6
+                name:'是否显示',
7
+                comType:'radio',
8
+                defaultValue:true,
9
+                comInfo:[{
10
+                        'name': '是',
11
+                        'value': true
12
+                    },
13
+                    {
14
+                        'name': '否',
15
+                        'value': false
16
+                }]
17
+            },
18
+            name:{
19
+                name:'坐标轴名称',
20
+                comType:'input',
21
+                defaultValue:''
22
+            },
23
+            nameTextStyle:{
24
+                name:'坐标轴名称样式',
25
+                sub:{
26
+                    color:{
27
+                        name:'颜色',
28
+                        comType:'colorPicker',
29
+                        defaultValue:'#fff'
30
+                    },
31
+                    fontSize:{
32
+                        name:'字体大小',
33
+                        comType:'slider',
34
+                        defaultValue:12,
35
+                        comInfo:{
36
+                            min:12,
37
+                            max:50
38
+                        }
39
+                    }
40
+                }
41
+            },
42
+            axisLine:{
43
+                name:'轴线设置',
44
+                sub:{
45
+                    show:{
46
+                        name:'是否显示',
47
+                        comType:'radio',
48
+                        defaultValue:true,
49
+                        comInfo:[{
50
+                                'name': '是',
51
+                                'value': true
52
+                            },
53
+                            {
54
+                                'name': '否',
55
+                                'value': false
56
+                        }]
57
+                    },
58
+                    lineStyle:{
59
+                        name:'样式',
60
+                        sub:{
61
+                            width:{
62
+                                name:'宽度',
63
+                                comType:'slider',
64
+                                defaultValue:1,
65
+                                comInfo:{
66
+                                    min:1,
67
+                                    max:10
68
+                                }
69
+                            }
70
+                        }
71
+                    }
72
+                }
73
+            }
74
+        }
75
+    },
76
+    color:{
77
+        name:'系列色',
78
+        sub:{
79
+            color:{
80
+                name:'系列色',
81
+                comType: 'colorPickerList',
82
+                defaultValue:['#5470c6', '#91cc75', '#fac858', '#ee6666', '#73c0de', '#3ba272', '#fc8452', '#9a60b4', '#ea7ccc']
83
+            }
84
+        }
85
+    }
86
+}
87
+
88
+export default styleConfig;

+ 16
- 0
src/chart/CustomChartBar/echarts.min.js
File diff suppressed because it is too large
View File


+ 20
- 0
src/utils/index.js View File

@@ -0,0 +1,20 @@
1
+const Utils = {
2
+    deepCopy: function(obj){
3
+        if(obj === null){
4
+            return obj;
5
+        }
6
+        var result = Array.isArray(obj) ? [] : {};
7
+        for (var key in obj) {
8
+            if (obj.hasOwnProperty(key)) {
9
+                if (typeof obj[key] === 'object' && obj[key]!==null) {
10
+                    result[key] = this.deepCopy(obj[key]);   //递归复制
11
+                } else {
12
+                    result[key] = obj[key];
13
+                }
14
+            }
15
+        }
16
+        return result;
17
+    }
18
+}
19
+
20
+export default Utils;

+ 26
- 0
test/CustomChartBar/index.html View File

@@ -0,0 +1,26 @@
1
+<!DOCTYPE html>
2
+<html lang="en">
3
+<head>
4
+    <meta charset="UTF-8">
5
+    <meta http-equiv="X-UA-Compatible" content="IE=edge">
6
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+    <title>Document</title>
8
+    <style>
9
+        *{
10
+            margin:0;
11
+            padding:0;
12
+        }
13
+        html, body{
14
+            width: 100%;
15
+            height: 100%;
16
+        }
17
+        #container{
18
+            width: 100%;
19
+            height: 100%;
20
+        }
21
+    </style>
22
+</head>
23
+<body>
24
+    <div id="container"></div>
25
+</body>
26
+</html>

+ 12
- 0
test/CustomChartBar/index.js View File

@@ -0,0 +1,12 @@
1
+import chart from '../../src/chart/CustomChartBar/CustomChartBar.js';
2
+import Utils from '../utils.js';
3
+
4
+let config = new chart(document.querySelector('#container'), {getConfig:true}).getConfig();
5
+let current_chart = new chart(document.querySelector('#container'));
6
+
7
+
8
+let styleConfig = config.styleConfig;
9
+let dataConfig = config.dataConfig;
10
+console.log(123, Utils.parseStyle(styleConfig), dataConfig)
11
+current_chart.setOption(Utils.parseStyle(styleConfig), dataConfig);
12
+

+ 17
- 0
test/utils.js View File

@@ -0,0 +1,17 @@
1
+const Utils = {
2
+    parseStyle: function(style){
3
+        let result = {};
4
+
5
+        for(var key in style){
6
+            if(style[key].sub){
7
+                result[key] = this.parseStyle(style[key].sub);
8
+            }else{
9
+                result[key] = style[key].defaultValue;
10
+            }
11
+        }
12
+
13
+        return result;
14
+    }
15
+}
16
+
17
+export default Utils;

Loading…
Cancel
Save