diff --git a/fastapp/.editorconfig b/fastapp/.editorconfig deleted file mode 100644 index 628d4aa9..00000000 --- a/fastapp/.editorconfig +++ /dev/null @@ -1,14 +0,0 @@ -# http://editorconfig.org -root = true - -[*] # 表示所有文件适用 -charset = utf-8 # 设置文件字符集为 utf-8 -indent_style = space # 缩进风格(tab | space) -indent_size = 2 # 缩进大小 -end_of_line = lf # 控制换行类型(lf | cr | crlf) -trim_trailing_whitespace = true # 去除行首的任意空白字符 -insert_final_newline = true # 始终在文件末尾插入一个新行 - -[*.md] # 表示仅 md 文件适用以下规则 -max_line_length = off # 关闭最大行长度限制 -trim_trailing_whitespace = false # 关闭末尾空格修剪 diff --git a/fastapp/.env.development b/fastapp/.env.development deleted file mode 100644 index cbd0cc9f..00000000 --- a/fastapp/.env.development +++ /dev/null @@ -1,22 +0,0 @@ -# 变量必须以 VITE_ 为前缀才能暴露给外部读取 - -# 环境 -VITE_APP_ENV=development - -# 项目名称 -VITE_APP_TITLE=fastapiadmin - -# 网络请求公用地址 -VITE_API_BASE_URL=https://service.fastapiadmin.com - -# 代理前缀 -VITE_APP_BASE_API=/api/v1 - -# 应用端口 -VITE_APP_PORT=5180 - -# 超时时间 -VITE_TIMEOUT=10000 - -# WebSocket 服务器的 URL,不配置默认关闭 WebSocket -VITE_APP_WS_ENDPOINT= ws://localhost:5180/ws \ No newline at end of file diff --git a/fastapp/.env.production b/fastapp/.env.production deleted file mode 100644 index 9a994be0..00000000 --- a/fastapp/.env.production +++ /dev/null @@ -1,22 +0,0 @@ -# 变量必须以 VITE_ 为前缀才能暴露给外部读取 - -# 环境 -VITE_APP_ENV=production - -# 项目名称 -VITE_APP_TITLE=fastapiadmin - -# 网络请求公用地址 -VITE_API_BASE_URL=http://localhost:8001 - -# 代理前缀 -VITE_APP_BASE_API=/api/v1 - -# 应用端口 -VITE_APP_PORT=5180 - -# 超时时间 -VITE_TIMEOUT=10000 - -# WebSocket 服务器的 URL,不配置默认关闭 WebSocket -VITE_APP_WS_ENDPOINT= ws://localhost:5180/ws \ No newline at end of file diff --git a/fastapp/.eslintrc-auto-import.json b/fastapp/.eslintrc-auto-import.json deleted file mode 100644 index 662da57f..00000000 --- a/fastapp/.eslintrc-auto-import.json +++ /dev/null @@ -1,98 +0,0 @@ -{ - "globals": { - "Component": true, - "ComponentPublicInstance": true, - "ComputedRef": true, - "EffectScope": true, - "ExtractDefaultPropTypes": true, - "ExtractPropTypes": true, - "ExtractPublicPropTypes": true, - "InjectionKey": true, - "PropType": true, - "Ref": true, - "VNode": true, - "WritableComputedRef": true, - "computed": true, - "createApp": true, - "customRef": true, - "defineAsyncComponent": true, - "defineComponent": true, - "effectScope": true, - "getCurrentInstance": true, - "getCurrentScope": true, - "h": true, - "inject": true, - "isProxy": true, - "isReactive": true, - "isReadonly": true, - "isRef": true, - "markRaw": true, - "nextTick": true, - "onActivated": true, - "onAddToFavorites": true, - "onBackPress": true, - "onBeforeMount": true, - "onBeforeUnmount": true, - "onBeforeUpdate": true, - "onDeactivated": true, - "onError": true, - "onErrorCaptured": true, - "onHide": true, - "onLaunch": true, - "onLoad": true, - "onMounted": true, - "onNavigationBarButtonTap": true, - "onNavigationBarSearchInputChanged": true, - "onNavigationBarSearchInputClicked": true, - "onNavigationBarSearchInputConfirmed": true, - "onNavigationBarSearchInputFocusChanged": true, - "onPageNotFound": true, - "onPageScroll": true, - "onPullDownRefresh": true, - "onReachBottom": true, - "onReady": true, - "onRenderTracked": true, - "onRenderTriggered": true, - "onResize": true, - "onScopeDispose": true, - "onServerPrefetch": true, - "onShareAppMessage": true, - "onShareTimeline": true, - "onShow": true, - "onTabItemTap": true, - "onThemeChange": true, - "onUnhandledRejection": true, - "onUnload": true, - "onUnmounted": true, - "onUpdated": true, - "onWatcherCleanup": true, - "provide": true, - "reactive": true, - "readonly": true, - "ref": true, - "resolveComponent": true, - "shallowReactive": true, - "shallowReadonly": true, - "shallowRef": true, - "toRaw": true, - "toRef": true, - "toRefs": true, - "toValue": true, - "triggerRef": true, - "unref": true, - "useAttrs": true, - "useCssModule": true, - "useCssVars": true, - "useId": true, - "useModel": true, - "useSlots": true, - "useTemplateRef": true, - "watch": true, - "watchEffect": true, - "watchPostEffect": true, - "watchSyncEffect": true, - "DirectiveBinding": true, - "MaybeRef": true, - "MaybeRefOrGetter": true - } -} diff --git a/fastapp/.gitignore b/fastapp/.gitignore deleted file mode 100644 index a7907ba0..00000000 --- a/fastapp/.gitignore +++ /dev/null @@ -1,26 +0,0 @@ -# Logs -logs -*.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* -pnpm-debug.log* -lerna-debug.log* - -node_modules -.DS_Store -dist -*.local -.history - -# Editor directories and files -.idea -*.suo -*.ntvs* -*.njsproj -*.sln -*.sw? - -launch.json -.hbuilderx -pnpm-lock.yaml diff --git a/fastapp/.npmrc b/fastapp/.npmrc deleted file mode 100644 index 1ac95762..00000000 --- a/fastapp/.npmrc +++ /dev/null @@ -1,8 +0,0 @@ -# registry = https://registry.npmjs.org -registry = https://registry.npmmirror.com - -strict-peer-dependencies=false -auto-install-peers=true -shamefully-hoist=true -ignore-workspace-root-check=true -install-workspace-root=true \ No newline at end of file diff --git a/fastapp/README.md b/fastapp/README.md deleted file mode 100644 index 413237cd..00000000 --- a/fastapp/README.md +++ /dev/null @@ -1,33 +0,0 @@ -# 项目介绍 - -基于 uni-app + wot-design-uni + Vue 3 + TypeScript 移动端跨平台开发模板,集成了 ESLint、Prettier、Stylelint、Husky 和 Commitlint 等工具,确保代码规范与质量。 - -## 项目截图 - -![截图](https://www.youlai.tech/storage/blog/2025/04/30/app.jpg) - -## 项目文档 - -[从0到1构建 UniApp + Vue3 + TypeScript 移动端跨平台开源脚手架](https://juejin.cn/post/7448963032993038376) - -## 项目启动 - -安装依赖 - -```node -pnpm install -``` - -h5启动 - -```node -pnpm run dev:h5 -``` - -构建 - -```node -pnpm run build:h5 -``` - -访问 [http://localhost:5180/app](http://localhost:5180/app) diff --git a/fastapp/eslint.config.mjs b/fastapp/eslint.config.mjs deleted file mode 100644 index 9dc1368d..00000000 --- a/fastapp/eslint.config.mjs +++ /dev/null @@ -1,120 +0,0 @@ -// https://eslint.nodejs.cn/docs/latest/use/configure/configuration-files - -import globals from "globals"; -import pluginJs from "@eslint/js"; // JavaScript 规则 -import pluginVue from "eslint-plugin-vue"; // Vue 规则 -import pluginTypeScript from "@typescript-eslint/eslint-plugin"; // TypeScript 规则 - -import parserVue from "vue-eslint-parser"; // Vue 解析器 -import parserTypeScript from "@typescript-eslint/parser"; // TypeScript 解析器 - -import configPrettier from "eslint-config-prettier"; // 禁用与 Prettier 冲突的规则 -import pluginPrettier from "eslint-plugin-prettier"; // 运行 Prettier 规则 - -// 解析自动导入配置 -import fs from "fs"; -const autoImportConfig = JSON.parse(fs.readFileSync(".eslintrc-auto-import.json", "utf-8")); - -/** @type {import('eslint').Linter.Config[]} */ -export default [ - // 忽略指定文件 - { - ignores: ["node_modules/**", "dist/**", "auto-imports.d.ts", "unpackage/**", "public/**", "static/**", "**/u-charts/**", "**/qiun-**/**", "**/auto-imports.d.ts"], - }, - // 检查文件的配置 - { - files: ["**/*.{js,mjs,cjs,ts,vue}"], - ignores: ["**/*.d.ts"], - languageOptions: { - globals: { - ...globals.browser, - ...globals.node, - ...autoImportConfig.globals, - ...{ - uni: "readonly", // uni-app 全局对象 - UniApp: "readonly", // uni-app 全局对象 - getCurrentPages: "readonly", // uni-app 全局 API - ApiResponse: "readonly", // 统一响应数据类型 - PageQuery: "readonly", // 分页查询数据类型 - PageResult: "readonly", // 分页结果数据类型 - OptionType: "readonly", // 选项类型 - creatorType: "readonly", // 创建人类型 - UploadFileResult: "readonly", // 上传文件返回类型 - plus: true, // HTML5+ 运行时环境 - }, - }, - }, - plugins: { prettier: pluginPrettier }, - rules: { - ...configPrettier.rules, // 关闭与 Prettier 冲突的规则 - ...pluginPrettier.configs.recommended.rules, // 启用 Prettier 规则 - "prettier/prettier": "off", // 完全关闭 Prettier 格式化检查 - "no-unused-vars": [ - "error", - { - argsIgnorePattern: "^_", // 忽略参数名以 _ 开头的参数未使用警告 - varsIgnorePattern: "^[A-Z0-9_]+$", // 忽略变量名为大写字母、数字或下划线组合的未使用警告(枚举定义未使用场景) - ignoreRestSiblings: true, // 忽略解构赋值中同级未使用变量的警告 - }, - ], - "no-prototype-builtins": "off", // 允许直接调用Object.prototype方法 - "no-constant-binary-expression": "warn", // 将常量二元表达式警告降为警告级别 - }, - }, - // JavaScript 配置 - pluginJs.configs.recommended, - - // TypeScript 配置 - { - files: ["**/*.ts"], - ignores: ["**/*.d.ts"], // 排除d.ts文件 - languageOptions: { - parser: parserTypeScript, - parserOptions: { - sourceType: "module", - }, - }, - plugins: { "@typescript-eslint": pluginTypeScript }, - rules: { - ...pluginTypeScript.configs.strict.rules, // TypeScript 严格规则 - "@typescript-eslint/no-explicit-any": "off", // 允许使用 any - "@typescript-eslint/no-empty-function": "off", // 允许空函数 - "@typescript-eslint/no-empty-object-type": "off", // 允许空对象类型 - }, - }, - - // Vue 配置 - { - files: ["**/*.vue"], - languageOptions: { - parser: parserVue, - parserOptions: { - parser: parserTypeScript, - sourceType: "module", - }, - }, - plugins: { vue: pluginVue, "@typescript-eslint": pluginTypeScript }, - processor: pluginVue.processors[".vue"], - rules: { - ...pluginVue.configs["vue3-recommended"].rules, // Vue 3 推荐规则 - "vue/no-v-html": "off", // 允许 v-html - "vue/multi-word-component-names": "off", // 允许单个单词组件名 - }, - }, - - // 单独针对第三方组件的处理 - { - files: ["**/qiun-data-charts.vue", "**/qiun-data-charts/**/*.vue", "**/u-charts/**"], - linterOptions: { - noInlineConfig: false, - reportUnusedDisableDirectives: false, - }, - rules: { - // 禁用所有规则 - ...Object.fromEntries(Object.keys(pluginVue.configs["vue3-recommended"].rules || {}).map((key) => [key, "off"])), - "no-unused-vars": "off", - "no-prototype-builtins": "off", - "@typescript-eslint/no-explicit-any": "off", - }, - }, -]; diff --git a/fastapp/index.html b/fastapp/index.html deleted file mode 100644 index 009e712b..00000000 --- a/fastapp/index.html +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - FastApp - - - - -
- - - diff --git a/fastapp/package.json b/fastapp/package.json deleted file mode 100644 index 2f0322c7..00000000 --- a/fastapp/package.json +++ /dev/null @@ -1,133 +0,0 @@ -{ - "name": "fastapp", - "type": "module", - "version": "3.14.0", - "unibest-version": "3.14.0", - "description": "unibest - 最好的 uniapp 开发模板", - "packageManager": "pnpm@9.15.3", - "engines": { - "node": ">=22", - "pnpm": ">=9" - }, - "scripts": { - "dev:app": "uni -p app", - "dev:app-android": "uni -p app-android", - "dev:app-ios": "uni -p app-ios", - "dev:app-harmony": "uni -p app-harmony", - "dev:custom": "uni -p", - "dev:h5": "uni", - "dev:h5:ssr": "uni --ssr", - "dev:mp-alipay": "uni -p mp-alipay", - "dev:mp-baidu": "uni -p mp-baidu", - "dev:mp-jd": "uni -p mp-jd", - "dev:mp-kuaishou": "uni -p mp-kuaishou", - "dev:mp-lark": "uni -p mp-lark", - "dev:mp-qq": "uni -p mp-qq", - "dev:mp-toutiao": "uni -p mp-toutiao", - "dev:mp-weixin": "uni -p mp-weixin", - "dev:mp-xhs": "uni -p mp-xhs", - "dev:quickapp-webview": "uni -p quickapp-webview", - "dev:quickapp-webview-huawei": "uni -p quickapp-webview-huawei", - "dev:quickapp-webview-union": "uni -p quickapp-webview-union", - "build:app": "uni build -p app", - "build:app-android": "uni build -p app-android", - "build:app-ios": "uni build -p app-ios", - "build:app-harmony": "uni build -p app-harmony", - "build:custom": "uni build -p", - "build:h5": "uni build --mode production", - "build:h5:ssr": "uni build --ssr", - "build:mp-alipay": "uni build -p mp-alipay", - "build:mp-baidu": "uni build -p mp-baidu", - "build:mp-jd": "uni build -p mp-jd", - "build:mp-kuaishou": "uni build -p mp-kuaishou", - "build:mp-lark": "uni build -p mp-lark", - "build:mp-qq": "uni build -p mp-qq", - "build:mp-toutiao": "uni build -p mp-toutiao", - "build:mp-weixin": "uni build -p mp-weixin", - "build:mp-xhs": "uni build -p mp-xhs", - "build:quickapp-webview": "uni build -p quickapp-webview", - "build:quickapp-webview-huawei": "uni build -p quickapp-webview-huawei", - "build:quickapp-webview-union": "uni build -p quickapp-webview-union", - "type-check": "vue-tsc --noEmit", - "lint:eslint": "eslint \"src/**/*.{vue,ts}\" --fix", - "lint:prettier": "prettier --write \"**/*.{js,cjs,ts,json,css,scss,vue,html,md}\"", - "lint:stylelint": "stylelint \"**/*.{css,scss,vue,html}\" --fix", - "lint:lint-staged": "lint-staged" - }, - "dependencies": { - "@dcloudio/uni-app": "3.0.0-4070620250821001", - "@dcloudio/uni-app-harmony": "3.0.0-4070620250821001", - "@dcloudio/uni-app-plus": "3.0.0-4070620250821001", - "@dcloudio/uni-components": "3.0.0-4070620250821001", - "@dcloudio/uni-h5": "3.0.0-4070620250821001", - "@dcloudio/uni-mp-alipay": "3.0.0-4070620250821001", - "@dcloudio/uni-mp-baidu": "3.0.0-4070620250821001", - "@dcloudio/uni-mp-harmony": "3.0.0-4070620250821001", - "@dcloudio/uni-mp-jd": "3.0.0-4070620250821001", - "@dcloudio/uni-mp-kuaishou": "3.0.0-4070620250821001", - "@dcloudio/uni-mp-lark": "3.0.0-4070620250821001", - "@dcloudio/uni-mp-qq": "3.0.0-4070620250821001", - "@dcloudio/uni-mp-toutiao": "3.0.0-4070620250821001", - "@dcloudio/uni-mp-weixin": "3.0.0-4070620250821001", - "@dcloudio/uni-mp-xhs": "3.0.0-4070620250821001", - "@dcloudio/uni-quickapp-webview": "3.0.0-4070620250821001", - "@stomp/stompjs": "^7.1.1", - "@uni-helper/uni-use": "^0.19.14", - "@vueuse/core": "9.13.0", - "pinia": "^3.0.3", - "vue": "^3.5.22", - "vue-i18n": "^9.14.5" - }, - "devDependencies": { - "@commitlint/cli": "^19.5.0", - "@commitlint/config-conventional": "^19.5.0", - "@dcloudio/types": "^3.4.19", - "@dcloudio/uni-automator": "3.0.0-4070620250821001", - "@dcloudio/uni-cli-shared": "3.0.0-4070620250821001", - "@dcloudio/uni-stacktracey": "3.0.0-4070620250821001", - "@dcloudio/vite-plugin-uni": "3.0.0-4070620250821001", - "@eslint/js": "^9.10.0", - "@uni-helper/uni-types": "1.0.0-alpha.6", - "@uni-helper/vite-plugin-uni-components": "^0.2.0", - "@uni-helper/vite-plugin-uni-layouts": "^0.1.10", - "@uni-helper/vite-plugin-uni-pages": "^0.2.28", - "@vue/runtime-core": "^3.5.18", - "commitizen": "^4.3.0", - "eslint": "^9.10.0", - "eslint-config-prettier": "^9.1.0", - "eslint-plugin-prettier": "^5.2.1", - "eslint-plugin-vue": "^9.28.0", - "globals": "^15.9.0", - "husky": "^9.1.6", - "lint-staged": "^15.2.10", - "postcss": "^8.4.47", - "postcss-html": "^1.7.0", - "postcss-scss": "^4.0.9", - "prettier": "^3.3.3", - "sass": "1.78.0", - "sass-loader": "^16.0.2", - "stylelint": "^16.9.0", - "stylelint-config-html": "^1.1.0", - "stylelint-config-recess-order": "^5.1.0", - "stylelint-config-recommended": "^14.0.1", - "stylelint-config-recommended-scss": "^14.1.0", - "stylelint-config-recommended-vue": "^1.5.0", - "stylelint-prettier": "^5.0.2", - "typescript": "^5.9.2", - "typescript-eslint": "^8.6.0", - "uni-mini-router": "^0.1.6", - "unocss": "^0.62.4", - "unocss-preset-weapp": "^0.62.2", - "unplugin-auto-import": "^0.18.3", - "vite": "5.2.8", - "vue-eslint-parser": "^9.4.3", - "vue-tsc": "^1.0.24", - "wot-design-uni": "^1.9.1" - }, - "resolutions": { - "bin-wrapper": "npm:bin-wrapper-china" - }, - "lint-staged": { - "*": "eslint --fix" - } -} diff --git a/fastapp/pages.config.ts b/fastapp/pages.config.ts deleted file mode 100644 index 9ddc96c9..00000000 --- a/fastapp/pages.config.ts +++ /dev/null @@ -1,42 +0,0 @@ -// pages.config.ts -import { defineUniPages } from "@uni-helper/vite-plugin-uni-pages"; - -export default defineUniPages({ - // 你也可以定义 pages 字段,它具有最高的优先级。 - pages: [], - globalStyle: { - navigationBarBackgroundColor: "@navBgColor", - navigationBarTextStyle: "@navTxtStyle", - navigationBarTitleText: "FastApp", - backgroundColor: "@bgColor", - backgroundTextStyle: "@bgTxtStyle", - backgroundColorTop: "@bgColorTop", - backgroundColorBottom: "@bgColorBottom", - enablePullDownRefresh: false, - onReachBottomDistance: 50, - animationType: "pop-in", - animationDuration: 300, - }, - - tabBar: { - custom: true, - customize: true, - overlay: true, - height: "0", - color: "@tabColor", - selectedColor: "@tabSelectedColor", - backgroundColor: "@tabBgColor", - borderStyle: "@tabBorderStyle", - list: [ - { - pagePath: "pages/index/index", - }, - { - pagePath: "pages/work/index", - }, - { - pagePath: "pages/mine/index", - }, - ], - }, -}); diff --git a/fastapp/public/favicon.png b/fastapp/public/favicon.png deleted file mode 100644 index 43eeb762..00000000 Binary files a/fastapp/public/favicon.png and /dev/null differ diff --git a/fastapp/shims-uni.d.ts b/fastapp/shims-uni.d.ts deleted file mode 100644 index 7b6be2f1..00000000 --- a/fastapp/shims-uni.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -/// -import "vue"; - -declare module "@vue/runtime-core" { - type Hooks = App.AppInstance & Page.PageInstance; - - interface ComponentCustomOptions extends Hooks {} -} diff --git a/fastapp/src/App.vue b/fastapp/src/App.vue deleted file mode 100644 index 75823435..00000000 --- a/fastapp/src/App.vue +++ /dev/null @@ -1,49 +0,0 @@ - - - diff --git a/fastapp/src/api/auth.ts b/fastapp/src/api/auth.ts deleted file mode 100644 index 756b4920..00000000 --- a/fastapp/src/api/auth.ts +++ /dev/null @@ -1,94 +0,0 @@ -import request from "@/utils/request"; -import { ApiHeader } from "@/enums/api-header.enum"; - -const AUTH_BASE_URL = "/system/auth"; - -const AuthAPI = { - /** - * 登录 - * @param body 登录表单数据 - * @returns 登录结果 - */ - login(body: LoginFormData): Promise { - return request({ - url: `${AUTH_BASE_URL}/login`, - method: "POST", - header: { [ApiHeader.KEY]: ApiHeader.FORM }, - data: body, - }); - }, - - /** - * 刷新令牌 - * @param body 刷新令牌请求体 - * @returns 新的访问令牌 - */ - refreshToken(body: RefreshToekenBody): Promise { - return request({ - url: `${AUTH_BASE_URL}/token/refresh`, - method: "POST", - data: body, - }); - }, - - /** - * 获取验证码 - * @returns 验证码信息 - */ - getCaptcha(): Promise { - return request({ - url: `${AUTH_BASE_URL}/captcha/get`, - method: "GET", - }); - }, - - /** - * 登出 - * @param body 登出请求体 - * @returns 登出结果 - */ - logout(body: LogoutBody): Promise { - return request({ - url: `${AUTH_BASE_URL}/logout`, - method: "POST", - data: body, - }); - }, -}; - -export default AuthAPI; - -/** 登录表单数据 */ -export interface LoginFormData { - username: string; - password: string; - captcha_key: string; - captcha: string; - remember: boolean; - login_type: string; -} - -// 刷新令牌 -export interface RefreshToekenBody { - refresh_token: string; -} - -/** 登录响应 */ -export interface LoginResult { - access_token: string; - refresh_token: string; - token_type: string; - expires_in: number; -} - -/** 验证码信息 */ -export interface CaptchaInfo { - enable: boolean; - key: string; - img_base: string; -} - -/** 退出登录操作 */ -export interface LogoutBody { - token: string; -} diff --git a/fastapp/src/api/file.ts b/fastapp/src/api/file.ts deleted file mode 100644 index ba42730e..00000000 --- a/fastapp/src/api/file.ts +++ /dev/null @@ -1,65 +0,0 @@ -import { getAccessToken } from "@/utils/auth"; -import { ApiCode } from "@/enums/api-code.enum"; - -// H5 使用 VITE_APP_BASE_API 作为代理路径,其他平台使用 VITE_API_BASE_URL 作为请求路径 -let baseApi = import.meta.env.VITE_API_BASE_URL; -// #ifdef H5 -baseApi = import.meta.env.VITE_APP_BASE_API; -// #endif - -const FileAPI = { - /** - * 文件上传地址 - */ - uploadUrl: baseApi + "/files/upload", - - /** - * 上传文件 - * - * @param filePath - */ - upload(filePath: string): Promise { - return new Promise((resolve, reject) => { - uni.uploadFile({ - url: this.uploadUrl, - filePath: filePath, - name: "file", - header: { - Authorization: getAccessToken() ? `Bearer ${getAccessToken()}` : "", - }, - formData: {}, - success: (response) => { - const resData = JSON.parse(response.data) as ApiResponse; - // 业务状态码 0 表示成功 - if (resData.code === ApiCode.SUCCESS) { - resolve(resData.data); - } else { - // 其他业务处理失败 - uni.showToast({ - title: resData.msg || "文件上传失败", - icon: "none", - }); - reject({ - message: resData.msg || "业务处理失败", - code: resData.code, - }); - } - }, - fail: (error) => { - console.log("fail error", error); - uni.showToast({ - title: "文件上传请求失败", - icon: "none", - duration: 2000, - }); - reject({ - message: "文件上传请求失败", - error, - }); - }, - }); - }); - }, -}; - -export default FileAPI; diff --git a/fastapp/src/api/user.ts b/fastapp/src/api/user.ts deleted file mode 100644 index 10a31269..00000000 --- a/fastapp/src/api/user.ts +++ /dev/null @@ -1,316 +0,0 @@ -import request from "@/utils/request"; -import { ApiHeader } from "@/enums/api-header.enum"; - -const USER_BASE_URL = "/system/user"; - -const UserAPI = { - /** - * 个人中心用户信息 - * - * @returns 登录用户昵称、头像信息,包括角色和权限 - */ - getCurrentUserInfo(): Promise { - return request({ - url: `${USER_BASE_URL}/current/info`, - method: "GET", - }); - }, - - /** - * 当前用户头像上传 - * - * @param body - * @returns 上传后的文件路径 - */ - uploadCurrentUserAvatar(body: any): Promise { - return request({ - url: `${USER_BASE_URL}/current/avatar/upload`, - method: "POST", - data: body, - header: { [ApiHeader.KEY]: ApiHeader.MULTIPART }, - }); - }, - - /** - * 修改个人中心用户信息 - * - * @param body - * @returns 修改后的用户信息 - */ - updateCurrentUserInfo(body: UserProfileForm): Promise { - return request({ - url: `${USER_BASE_URL}/current/info/update`, - method: "PUT", - data: body, - }); - }, - - /** - * 修改个人中心用户密码 - * - * @param body - * @returns 修改后的用户信息 - */ - changeCurrentUserPassword(body: PasswordChangeForm): Promise { - return request({ - url: `${USER_BASE_URL}/current/password/change`, - method: "PUT", - data: body, - }); - }, - - /** - * 注册用户 - * - * @param body - * @returns 忘记密码结果 - */ - registerUser(body: RegisterForm): Promise { - return request({ - url: `${USER_BASE_URL}/register`, - method: "POST", - data: body, - }); - }, - - /** - * 忘记密码 - * - * @param body - * @returns 忘记密码结果 - */ - forgetPassword(body: ForgetPasswordForm): Promise { - return request({ - url: `${USER_BASE_URL}/forget/password`, - method: "POST", - data: body, - }); - }, - - /** - * 获取用户分页列表 - *POST - * @param queryParams 查询参数 - */ - getUserPage(queryParams: UserPageQuery): Promise> { - return request>({ - url: `${USER_BASE_URL}/list`, - method: "GET", - data: queryParams, - }); - }, - - /** - * 获取用户表单详情 - * - * @param userId 用户ID - * @returns 用户表单详情 - */ - getUserDetail(userId: number): Promise { - return request({ - url: `${USER_BASE_URL}/detail/${userId}`, - method: "GET", - }); - }, - - /** - * 添加用户 - * - * @param body 用户表单数据 - */ - addUser(body: UserForm): Promise { - return request({ - url: `${USER_BASE_URL}/create`, - method: "POST", - data: body, - }); - }, - - /** - * 修改用户 - * - * @param body 用户表单数据 - */ - updateUser(body: UserForm): Promise { - return request({ - url: `${USER_BASE_URL}/update`, - method: "PUT", - data: body, - }); - }, - - /** - * 删除用户 - * - * @param ids 用户ID数组 - */ - deleteUser(ids: number[]): Promise { - return request({ - url: `${USER_BASE_URL}/delete`, - method: "DELETE", - data: ids, - }); - }, -}; - -export default UserAPI; - -/* 忘记密码表单 */ -export interface ForgetPasswordForm { - username: string; - new_password: string; - confirmPassword: string; -} - -/* 注册表单 */ -export interface RegisterForm { - username: string; - password: string; - confirmPassword: string; -} - -/* 分页查询表单 */ -export interface UserPageQuery extends PageQuery { - username?: string; - name?: string; - status?: boolean; - dept_id?: number; - start_time?: string; - end_time?: string; -} - -/* 搜索选择器数据类型 */ -export interface searchSelectDataType { - name?: string; - status?: string; -} - -/* 用户表单 */ -export interface UserForm { - id?: number; - username?: string; - name?: string; - dept_id?: number; - dept_name?: string; - role_ids?: number[]; - roleNames?: string[]; - position_ids?: number[]; - positionNames?: string[]; - password?: string; - gender?: number; - email?: string; - mobile?: string; - is_superuser?: boolean; - status?: boolean; - description?: string; -} - -/* 登录用户信息 */ -export interface UserInfo { - index?: number; - id?: number; - username?: string; - name?: string; - avatar?: string; - email?: string; - mobile?: string; - gender?: string; - password?: string; - menus?: MenuTable[]; - dept?: deptTreeType; - dept_id?: deptTreeType["id"]; - dept_name?: deptTreeType["name"]; - roles?: roleSelectorType[]; - roleNames?: roleSelectorType["name"][]; - role_ids?: roleSelectorType["id"][]; - positions?: positionSelectorType[]; - positionNames?: positionSelectorType["name"][]; - position_ids?: positionSelectorType["id"][]; - is_superuser?: boolean; - status?: boolean; - description?: string; - last_login?: string; - created_at?: string; - updated_at?: string; - creator?: creatorType; -} - -/* 菜单表 */ -export interface MenuTable { - index?: number; - id?: number; - name?: string; - type?: number; - icon?: string; - order?: number; - permission?: string; - route_name?: string; - route_path?: string; - component_path?: string; - redirect?: string; - parent_id?: number; - parent_name?: string; - keep_alive?: boolean; - hidden?: boolean; - always_show?: boolean; - title?: string; - params?: { key: string; value: string }[]; - affix?: boolean; - status?: boolean; - description?: string; - created_at?: string; - updated_at?: string; - children?: MenuTable[]; -} - -/* 部门树 */ -export interface deptTreeType { - id?: number; - name?: string; - parent_id?: number; - children?: deptTreeType[]; -} - -/* 角色选择器 */ -export interface roleSelectorType { - id?: number; - name?: string; - status?: boolean; - description?: string; -} - -/* 职位选择器 */ -export interface positionSelectorType { - id?: number; - name?: string; - status?: boolean; - description?: string; -} - -/* 个人中心用户信息表单 */ -export interface UserProfileForm { - id?: number; - name?: string; - gender?: string; - mobile?: string; - email?: string; - username?: string; - dept_name?: string; - positions?: positionSelectorType[]; - roles?: roleSelectorType[]; - avatar?: string; - created_at?: string; -} - -/* 修改密码表单 */ -export interface PasswordChangeForm { - old_password: string; - new_password: string; - confirm_password: string; -} - -/* 重置密码表单 */ -export interface ResetPasswordForm { - id: number; - password: string; -} diff --git a/fastapp/src/components/cu-date-query/index.vue b/fastapp/src/components/cu-date-query/index.vue deleted file mode 100644 index 309c6ba0..00000000 --- a/fastapp/src/components/cu-date-query/index.vue +++ /dev/null @@ -1,71 +0,0 @@ - - - - - diff --git a/fastapp/src/components/cu-picker/index.vue b/fastapp/src/components/cu-picker/index.vue deleted file mode 100644 index b263e867..00000000 --- a/fastapp/src/components/cu-picker/index.vue +++ /dev/null @@ -1,152 +0,0 @@ - - - diff --git a/fastapp/src/components/qiun-data-charts/qiun-data-charts.vue b/fastapp/src/components/qiun-data-charts/qiun-data-charts.vue deleted file mode 100644 index 5ce8fa78..00000000 --- a/fastapp/src/components/qiun-data-charts/qiun-data-charts.vue +++ /dev/null @@ -1,1589 +0,0 @@ - - - - - - - - - - diff --git a/fastapp/src/components/qiun-error/qiun-error.vue b/fastapp/src/components/qiun-error/qiun-error.vue deleted file mode 100644 index b4a5cafb..00000000 --- a/fastapp/src/components/qiun-error/qiun-error.vue +++ /dev/null @@ -1,44 +0,0 @@ - - - - - diff --git a/fastapp/src/components/qiun-loading/loading1.vue b/fastapp/src/components/qiun-loading/loading1.vue deleted file mode 100644 index ea6034be..00000000 --- a/fastapp/src/components/qiun-loading/loading1.vue +++ /dev/null @@ -1,158 +0,0 @@ - - - - - diff --git a/fastapp/src/components/qiun-loading/loading2.vue b/fastapp/src/components/qiun-loading/loading2.vue deleted file mode 100644 index a22a3da0..00000000 --- a/fastapp/src/components/qiun-loading/loading2.vue +++ /dev/null @@ -1,164 +0,0 @@ - - - - - diff --git a/fastapp/src/components/qiun-loading/loading3.vue b/fastapp/src/components/qiun-loading/loading3.vue deleted file mode 100644 index 91ce4bd4..00000000 --- a/fastapp/src/components/qiun-loading/loading3.vue +++ /dev/null @@ -1,171 +0,0 @@ - - - - - diff --git a/fastapp/src/components/qiun-loading/loading4.vue b/fastapp/src/components/qiun-loading/loading4.vue deleted file mode 100644 index 17222520..00000000 --- a/fastapp/src/components/qiun-loading/loading4.vue +++ /dev/null @@ -1,219 +0,0 @@ - - - - - diff --git a/fastapp/src/components/qiun-loading/loading5.vue b/fastapp/src/components/qiun-loading/loading5.vue deleted file mode 100644 index bade61c1..00000000 --- a/fastapp/src/components/qiun-loading/loading5.vue +++ /dev/null @@ -1,226 +0,0 @@ - - - - diff --git a/fastapp/src/components/qiun-loading/qiun-loading.vue b/fastapp/src/components/qiun-loading/qiun-loading.vue deleted file mode 100644 index dfe42c86..00000000 --- a/fastapp/src/components/qiun-loading/qiun-loading.vue +++ /dev/null @@ -1,32 +0,0 @@ - - - - - diff --git a/fastapp/src/components/u-charts/config-echarts.js b/fastapp/src/components/u-charts/config-echarts.js deleted file mode 100644 index ea4e8186..00000000 --- a/fastapp/src/components/u-charts/config-echarts.js +++ /dev/null @@ -1,422 +0,0 @@ -/* - * uCharts® - * 高性能跨平台图表库,支持H5、APP、小程序(微信/支付宝/百度/头条/QQ/360)、Vue、Taro等支持canvas的框架平台 - * Copyright (c) 2021 QIUN®秋云 https://www.ucharts.cn All rights reserved. - * Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) - * 复制使用请保留本段注释,感谢支持开源! - * - * uCharts®官方网站 - * https://www.uCharts.cn - * - * 开源地址: - * https://gitee.com/uCharts/uCharts - * - * uni-app插件市场地址: - * http://ext.dcloud.net.cn/plugin?id=271 - * - */ - -// 通用配置项 - -// 主题颜色配置:如每个图表类型需要不同主题,请在对应图表类型上更改color属性 -const color = ["#1890FF", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272", "#FC8452", "#9A60B4", "#ea7ccc"]; - -const cfe = { - //demotype为自定义图表类型 - type: ["pie", "ring", "rose", "funnel", "line", "column", "area", "radar", "gauge", "candle", "demotype"], - //增加自定义图表类型,如果需要categories,请在这里加入您的图表类型例如最后的"demotype" - categories: ["line", "column", "area", "radar", "gauge", "candle", "demotype"], - //instance为实例变量承载属性,option为eopts承载属性,不要删除 - instance: {}, - option: {}, - //下面是自定义format配置,因除H5端外的其他端无法通过props传递函数,只能通过此属性对应下标的方式来替换 - formatter: { - tooltipDemo1: function (res) { - let result = ""; - for (let i in res) { - if (i == 0) { - result += res[i].axisValueLabel + "年销售额"; - } - let value = "--"; - if (res[i].data !== null) { - value = res[i].data; - } - // #ifdef H5 - result += "\n" + res[i].seriesName + ":" + value + " 万元"; - // #endif - - // #ifdef APP-PLUS - result += "
" + res[i].marker + res[i].seriesName + ":" + value + " 万元"; - // #endif - } - return result; - }, - legendFormat: function (name) { - return "自定义图例+" + name; - }, - yAxisFormatDemo: function (value, index) { - return value + "元"; - }, - seriesFormatDemo: function (res) { - return res.name + "年" + res.value + "元"; - }, - }, - //这里演示了自定义您的图表类型的option,可以随意命名,之后在组件上 type="demotype" 后,组件会调用这个花括号里的option,如果组件上还存在eopts参数,会将demotype与eopts中option合并后渲染图表。 - demotype: { - color: color, - //在这里填写echarts的option即可 - }, - //下面是自定义配置,请添加项目所需的通用配置 - column: { - color: color, - title: { - text: "", - }, - tooltip: { - trigger: "axis", - }, - grid: { - top: 30, - bottom: 50, - right: 15, - left: 40, - }, - legend: { - bottom: "left", - }, - toolbox: { - show: false, - }, - xAxis: { - type: "category", - axisLabel: { - color: "#666666", - }, - axisLine: { - lineStyle: { - color: "#CCCCCC", - }, - }, - boundaryGap: true, - data: [], - }, - yAxis: { - type: "value", - axisTick: { - show: false, - }, - axisLabel: { - color: "#666666", - }, - axisLine: { - lineStyle: { - color: "#CCCCCC", - }, - }, - }, - seriesTemplate: { - name: "", - type: "bar", - data: [], - barwidth: 20, - label: { - show: true, - color: "#666666", - position: "top", - }, - }, - }, - line: { - color: color, - title: { - text: "", - }, - tooltip: { - trigger: "axis", - }, - grid: { - top: 30, - bottom: 50, - right: 15, - left: 40, - }, - legend: { - bottom: "left", - }, - toolbox: { - show: false, - }, - xAxis: { - type: "category", - axisLabel: { - color: "#666666", - }, - axisLine: { - lineStyle: { - color: "#CCCCCC", - }, - }, - boundaryGap: true, - data: [], - }, - yAxis: { - type: "value", - axisTick: { - show: false, - }, - axisLabel: { - color: "#666666", - }, - axisLine: { - lineStyle: { - color: "#CCCCCC", - }, - }, - }, - seriesTemplate: { - name: "", - type: "line", - data: [], - barwidth: 20, - label: { - show: true, - color: "#666666", - position: "top", - }, - }, - }, - area: { - color: color, - title: { - text: "", - }, - tooltip: { - trigger: "axis", - }, - grid: { - top: 30, - bottom: 50, - right: 15, - left: 40, - }, - legend: { - bottom: "left", - }, - toolbox: { - show: false, - }, - xAxis: { - type: "category", - axisLabel: { - color: "#666666", - }, - axisLine: { - lineStyle: { - color: "#CCCCCC", - }, - }, - boundaryGap: true, - data: [], - }, - yAxis: { - type: "value", - axisTick: { - show: false, - }, - axisLabel: { - color: "#666666", - }, - axisLine: { - lineStyle: { - color: "#CCCCCC", - }, - }, - }, - seriesTemplate: { - name: "", - type: "line", - data: [], - areaStyle: {}, - label: { - show: true, - color: "#666666", - position: "top", - }, - }, - }, - pie: { - color: color, - title: { - text: "", - }, - tooltip: { - trigger: "item", - }, - grid: { - top: 40, - bottom: 30, - right: 15, - left: 15, - }, - legend: { - bottom: "left", - }, - seriesTemplate: { - name: "", - type: "pie", - data: [], - radius: "50%", - label: { - show: true, - color: "#666666", - position: "top", - }, - }, - }, - ring: { - color: color, - title: { - text: "", - }, - tooltip: { - trigger: "item", - }, - grid: { - top: 40, - bottom: 30, - right: 15, - left: 15, - }, - legend: { - bottom: "left", - }, - seriesTemplate: { - name: "", - type: "pie", - data: [], - radius: ["40%", "70%"], - avoidLabelOverlap: false, - label: { - show: true, - color: "#666666", - position: "top", - }, - labelLine: { - show: true, - }, - }, - }, - rose: { - color: color, - title: { - text: "", - }, - tooltip: { - trigger: "item", - }, - legend: { - top: "bottom", - }, - seriesTemplate: { - name: "", - type: "pie", - data: [], - radius: "55%", - center: ["50%", "50%"], - roseType: "area", - }, - }, - funnel: { - color: color, - title: { - text: "", - }, - tooltip: { - trigger: "item", - formatter: "{b} : {c}%", - }, - legend: { - top: "bottom", - }, - seriesTemplate: { - name: "", - type: "funnel", - left: "10%", - top: 60, - bottom: 60, - width: "80%", - min: 0, - max: 100, - minSize: "0%", - maxSize: "100%", - sort: "descending", - gap: 2, - label: { - show: true, - position: "inside", - }, - labelLine: { - length: 10, - lineStyle: { - width: 1, - type: "solid", - }, - }, - itemStyle: { - bordercolor: "#fff", - borderwidth: 1, - }, - emphasis: { - label: { - fontSize: 20, - }, - }, - data: [], - }, - }, - gauge: { - color: color, - tooltip: { - formatter: "{a}
{b} : {c}%", - }, - seriesTemplate: { - name: "业务指标", - type: "gauge", - detail: { formatter: "{value}%" }, - data: [{ value: 50, name: "完成率" }], - }, - }, - candle: { - xAxis: { - data: [], - }, - yAxis: {}, - color: color, - title: { - text: "", - }, - dataZoom: [ - { - type: "inside", - xAxisIndex: [0, 1], - start: 10, - end: 100, - }, - { - show: true, - xAxisIndex: [0, 1], - type: "slider", - bottom: 10, - start: 10, - end: 100, - }, - ], - seriesTemplate: { - name: "", - type: "k", - data: [], - }, - }, -}; - -export default cfe; diff --git a/fastapp/src/components/u-charts/config-ucharts.js b/fastapp/src/components/u-charts/config-ucharts.js deleted file mode 100644 index 5354de14..00000000 --- a/fastapp/src/components/u-charts/config-ucharts.js +++ /dev/null @@ -1,611 +0,0 @@ -/* - * uCharts® - * 高性能跨平台图表库,支持H5、APP、小程序(微信/支付宝/百度/头条/QQ/360)、Vue、Taro等支持canvas的框架平台 - * Copyright (c) 2021 QIUN®秋云 https://www.ucharts.cn All rights reserved. - * Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) - * 复制使用请保留本段注释,感谢支持开源! - * - * uCharts®官方网站 - * https://www.uCharts.cn - * - * 开源地址: - * https://gitee.com/uCharts/uCharts - * - * uni-app插件市场地址: - * http://ext.dcloud.net.cn/plugin?id=271 - * - */ - -// 主题颜色配置:如每个图表类型需要不同主题,请在对应图表类型上更改color属性 -const color = ["#1890FF", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272", "#FC8452", "#9A60B4", "#ea7ccc"]; - -//事件转换函数,主要用作格式化x轴为时间轴,根据需求自行修改 -const formatDateTime = (timeStamp, returnType) => { - var date = new Date(); - date.setTime(timeStamp * 1000); - var y = date.getFullYear(); - var m = date.getMonth() + 1; - m = m < 10 ? "0" + m : m; - var d = date.getDate(); - d = d < 10 ? "0" + d : d; - var h = date.getHours(); - h = h < 10 ? "0" + h : h; - var minute = date.getMinutes(); - var second = date.getSeconds(); - minute = minute < 10 ? "0" + minute : minute; - second = second < 10 ? "0" + second : second; - if (returnType == "full") { - return y + "-" + m + "-" + d + " " + h + ":" + minute + ":" + second; - } - if (returnType == "y-m-d") { - return y + "-" + m + "-" + d; - } - if (returnType == "h:m") { - return h + ":" + minute; - } - if (returnType == "h:m:s") { - return h + ":" + minute + ":" + second; - } - return [y, m, d, h, minute, second]; -}; - -const cfu = { - //demotype为自定义图表类型,一般不需要自定义图表类型,只需要改根节点上对应的类型即可 - type: ["pie", "ring", "rose", "word", "funnel", "map", "arcbar", "line", "column", "mount", "bar", "area", "radar", "gauge", "candle", "mix", "tline", "tarea", "scatter", "bubble", "demotype"], - range: ["饼状图", "圆环图", "玫瑰图", "词云图", "漏斗图", "地图", "圆弧进度条", "折线图", "柱状图", "山峰图", "条状图", "区域图", "雷达图", "仪表盘", "K线图", "混合图", "时间轴折线", "时间轴区域", "散点图", "气泡图", "自定义类型"], - //增加自定义图表类型,如果需要categories,请在这里加入您的图表类型,例如最后的"demotype" - //自定义类型时需要注意"tline","tarea","scatter","bubble"等时间轴(矢量x轴)类图表,没有categories,不需要加入categories - categories: ["line", "column", "mount", "bar", "area", "radar", "gauge", "candle", "mix", "demotype"], - //instance为实例变量承载属性,不要删除 - instance: {}, - //option为opts及eopts承载属性,不要删除 - option: {}, - //下面是自定义format配置,因除H5端外的其他端无法通过props传递函数,只能通过此属性对应下标的方式来替换 - formatter: { - yAxisDemo1: function (val, index, opts) { - return val + "元"; - }, - yAxisDemo2: function (val, index, opts) { - return val.toFixed(2); - }, - xAxisDemo1: function (val, index, opts) { - return val + "年"; - }, - xAxisDemo2: function (val, index, opts) { - return formatDateTime(val, "h:m"); - }, - seriesDemo1: function (val, index, series, opts) { - return val + "元"; - }, - tooltipDemo1: function (item, category, index, opts) { - if (index == 0) { - return "随便用" + item.data + "年"; - } else { - return "其他我没改" + item.data + "天"; - } - }, - pieDemo: function (val, index, series, opts) { - if (index !== undefined) { - return series[index].name + ":" + series[index].data + "元"; - } - }, - }, - //这里演示了自定义您的图表类型的option,可以随意命名,之后在组件上 type="demotype" 后,组件会调用这个花括号里的option,如果组件上还存在opts参数,会将demotype与opts中option合并后渲染图表。 - demotype: { - //我这里把曲线图当做了自定义图表类型,您可以根据需要随意指定类型或配置 - type: "line", - color: color, - padding: [15, 10, 0, 15], - xAxis: { - disableGrid: true, - }, - yAxis: { - gridType: "dash", - dashLength: 2, - }, - legend: {}, - extra: { - line: { - type: "curve", - width: 2, - }, - }, - }, - //下面是自定义配置,请添加项目所需的通用配置 - pie: { - type: "pie", - color: color, - padding: [5, 5, 5, 5], - extra: { - pie: { - activeOpacity: 0.5, - activeRadius: 10, - offsetAngle: 0, - labelWidth: 15, - border: true, - borderWidth: 3, - borderColor: "#FFFFFF", - }, - }, - }, - ring: { - type: "ring", - color: color, - padding: [5, 5, 5, 5], - rotate: false, - dataLabel: true, - legend: { - show: true, - position: "right", - lineHeight: 25, - }, - title: { - name: "收益率", - fontSize: 15, - color: "#666666", - }, - subtitle: { - name: "70%", - fontSize: 25, - color: "#7cb5ec", - }, - extra: { - ring: { - ringWidth: 30, - activeOpacity: 0.5, - activeRadius: 10, - offsetAngle: 0, - labelWidth: 15, - border: true, - borderWidth: 3, - borderColor: "#FFFFFF", - }, - }, - }, - rose: { - type: "rose", - color: color, - padding: [5, 5, 5, 5], - legend: { - show: true, - position: "left", - lineHeight: 25, - }, - extra: { - rose: { - type: "area", - minRadius: 50, - activeOpacity: 0.5, - activeRadius: 10, - offsetAngle: 0, - labelWidth: 15, - border: false, - borderWidth: 2, - borderColor: "#FFFFFF", - }, - }, - }, - word: { - type: "word", - color: color, - extra: { - word: { - type: "normal", - autoColors: false, - }, - }, - }, - funnel: { - type: "funnel", - color: color, - padding: [15, 15, 0, 15], - extra: { - funnel: { - activeOpacity: 0.3, - activeWidth: 10, - border: true, - borderWidth: 2, - borderColor: "#FFFFFF", - fillOpacity: 1, - labelAlign: "right", - }, - }, - }, - map: { - type: "map", - color: color, - padding: [0, 0, 0, 0], - dataLabel: true, - extra: { - map: { - border: true, - borderWidth: 1, - borderColor: "#666666", - fillOpacity: 0.6, - activeBorderColor: "#F04864", - activeFillColor: "#FACC14", - activeFillOpacity: 1, - }, - }, - }, - arcbar: { - type: "arcbar", - color: color, - title: { - name: "百分比", - fontSize: 25, - color: "#00FF00", - }, - subtitle: { - name: "默认标题", - fontSize: 15, - color: "#666666", - }, - extra: { - arcbar: { - type: "default", - width: 12, - backgroundColor: "#E9E9E9", - startAngle: 0.75, - endAngle: 0.25, - gap: 2, - }, - }, - }, - line: { - type: "line", - color: color, - padding: [15, 10, 0, 15], - xAxis: { - disableGrid: true, - }, - yAxis: { - gridType: "dash", - dashLength: 2, - }, - legend: {}, - extra: { - line: { - type: "straight", - width: 2, - activeType: "hollow", - }, - }, - }, - tline: { - type: "line", - color: color, - padding: [15, 10, 0, 15], - xAxis: { - disableGrid: false, - boundaryGap: "justify", - }, - yAxis: { - gridType: "dash", - dashLength: 2, - data: [ - { - min: 0, - max: 80, - }, - ], - }, - legend: {}, - extra: { - line: { - type: "curve", - width: 2, - activeType: "hollow", - }, - }, - }, - tarea: { - type: "area", - color: color, - padding: [15, 10, 0, 15], - xAxis: { - disableGrid: true, - boundaryGap: "justify", - }, - yAxis: { - gridType: "dash", - dashLength: 2, - data: [ - { - min: 0, - max: 80, - }, - ], - }, - legend: {}, - extra: { - area: { - type: "curve", - opacity: 0.2, - addLine: true, - width: 2, - gradient: true, - activeType: "hollow", - }, - }, - }, - column: { - type: "column", - color: color, - padding: [15, 15, 0, 5], - xAxis: { - disableGrid: true, - }, - yAxis: { - data: [{ min: 0 }], - }, - legend: {}, - extra: { - column: { - type: "group", - width: 30, - activeBgColor: "#000000", - activeBgOpacity: 0.08, - }, - }, - }, - mount: { - type: "mount", - color: color, - padding: [15, 15, 0, 5], - xAxis: { - disableGrid: true, - }, - yAxis: { - data: [{ min: 0 }], - }, - legend: {}, - extra: { - mount: { - type: "mount", - widthRatio: 1.5, - }, - }, - }, - bar: { - type: "bar", - color: color, - padding: [15, 30, 0, 5], - xAxis: { - boundaryGap: "justify", - disableGrid: false, - min: 0, - axisLine: false, - }, - yAxis: {}, - legend: {}, - extra: { - bar: { - type: "group", - width: 30, - meterBorde: 1, - meterFillColor: "#FFFFFF", - activeBgColor: "#000000", - activeBgOpacity: 0.08, - }, - }, - }, - area: { - type: "area", - color: color, - padding: [15, 15, 0, 15], - xAxis: { - disableGrid: true, - }, - yAxis: { - gridType: "dash", - dashLength: 2, - }, - legend: {}, - extra: { - area: { - type: "straight", - opacity: 0.2, - addLine: true, - width: 2, - gradient: false, - activeType: "hollow", - }, - }, - }, - radar: { - type: "radar", - color: color, - padding: [5, 5, 5, 5], - dataLabel: false, - legend: { - show: true, - position: "right", - lineHeight: 25, - }, - extra: { - radar: { - gridType: "radar", - gridColor: "#CCCCCC", - gridCount: 3, - opacity: 0.2, - max: 200, - labelShow: true, - }, - }, - }, - gauge: { - type: "gauge", - color: color, - title: { - name: "66Km/H", - fontSize: 25, - color: "#2fc25b", - offsetY: 50, - }, - subtitle: { - name: "实时速度", - fontSize: 15, - color: "#1890ff", - offsetY: -50, - }, - extra: { - gauge: { - type: "default", - width: 30, - labelColor: "#666666", - startAngle: 0.75, - endAngle: 0.25, - startNumber: 0, - endNumber: 100, - labelFormat: "", - splitLine: { - fixRadius: 0, - splitNumber: 10, - width: 30, - color: "#FFFFFF", - childNumber: 5, - childWidth: 12, - }, - pointer: { - width: 24, - color: "auto", - }, - }, - }, - }, - candle: { - type: "candle", - color: color, - padding: [15, 15, 0, 15], - enableScroll: true, - enableMarkLine: true, - dataLabel: false, - xAxis: { - labelCount: 4, - itemCount: 40, - disableGrid: true, - gridColor: "#CCCCCC", - gridType: "solid", - dashLength: 4, - scrollShow: true, - scrollAlign: "left", - scrollColor: "#A6A6A6", - scrollBackgroundColor: "#EFEBEF", - }, - yAxis: {}, - legend: {}, - extra: { - candle: { - color: { - upLine: "#f04864", - upFill: "#f04864", - downLine: "#2fc25b", - downFill: "#2fc25b", - }, - average: { - show: true, - name: ["MA5", "MA10", "MA30"], - day: [5, 10, 20], - color: ["#1890ff", "#2fc25b", "#facc14"], - }, - }, - markLine: { - type: "dash", - dashLength: 5, - data: [ - { - value: 2150, - lineColor: "#f04864", - showLabel: true, - }, - { - value: 2350, - lineColor: "#f04864", - showLabel: true, - }, - ], - }, - }, - }, - mix: { - type: "mix", - color: color, - padding: [15, 15, 0, 15], - xAxis: { - disableGrid: true, - }, - yAxis: { - disabled: false, - disableGrid: false, - splitNumber: 5, - gridType: "dash", - dashLength: 4, - gridColor: "#CCCCCC", - padding: 10, - showTitle: true, - data: [], - }, - legend: {}, - extra: { - mix: { - column: { - width: 20, - }, - }, - }, - }, - scatter: { - type: "scatter", - color: color, - padding: [15, 15, 0, 15], - dataLabel: false, - xAxis: { - disableGrid: false, - gridType: "dash", - splitNumber: 5, - boundaryGap: "justify", - min: 0, - }, - yAxis: { - disableGrid: false, - gridType: "dash", - }, - legend: {}, - extra: { - scatter: {}, - }, - }, - bubble: { - type: "bubble", - color: color, - padding: [15, 15, 0, 15], - xAxis: { - disableGrid: false, - gridType: "dash", - splitNumber: 5, - boundaryGap: "justify", - min: 0, - max: 250, - }, - yAxis: { - disableGrid: false, - gridType: "dash", - data: [ - { - min: 0, - max: 150, - }, - ], - }, - legend: {}, - extra: { - bubble: { - border: 2, - opacity: 0.5, - }, - }, - }, -}; - -export default cfu; diff --git a/fastapp/src/components/u-charts/u-charts.js b/fastapp/src/components/u-charts/u-charts.js deleted file mode 100644 index 83fa8611..00000000 --- a/fastapp/src/components/u-charts/u-charts.js +++ /dev/null @@ -1,7905 +0,0 @@ -/* - * uCharts (R) - * 高性能跨平台图表库,支持H5、APP、小程序(微信/支付宝/百度/头条/QQ/360/快手)、Vue、Taro等支持canvas的框架平台 - * Copyright (C) 2018-2022 QIUN (R) 秋云 https://www.ucharts.cn All rights reserved. - * Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) - * 复制使用请保留本段注释,感谢支持开源! - * - * uCharts (R) 官方网站 - * https://www.uCharts.cn - * - * 开源地址: - * https://gitee.com/uCharts/uCharts - * - * uni-app插件市场地址: - * http://ext.dcloud.net.cn/plugin?id=271 - * - */ - -"use strict"; - -var config = { - version: "v2.5.0-20230101", - yAxisWidth: 15, - xAxisHeight: 22, - padding: [10, 10, 10, 10], - rotate: false, - fontSize: 13, - fontColor: "#666666", - dataPointShape: ["circle", "circle", "circle", "circle"], - color: ["#1890FF", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272", "#FC8452", "#9A60B4", "#ea7ccc"], - linearColor: ["#0EE2F8", "#2BDCA8", "#FA7D8D", "#EB88E2", "#2AE3A0", "#0EE2F8", "#EB88E2", "#6773E3", "#F78A85"], - pieChartLinePadding: 15, - pieChartTextPadding: 5, - titleFontSize: 20, - subtitleFontSize: 15, - radarLabelTextMargin: 13, -}; - -var assign = function (target, ...varArgs) { - if (target == null) { - throw new TypeError("[uCharts] Cannot convert undefined or null to object"); - } - if (!varArgs || varArgs.length <= 0) { - return target; - } - // 深度合并对象 - function deepAssign(obj1, obj2) { - for (let key in obj2) { - obj1[key] = obj1[key] && obj1[key].toString() === "[object Object]" ? deepAssign(obj1[key], obj2[key]) : (obj1[key] = obj2[key]); - } - return obj1; - } - varArgs.forEach((val) => { - target = deepAssign(target, val); - }); - return target; -}; - -var util = { - toFixed: function toFixed(num, limit) { - limit = limit || 2; - if (this.isFloat(num)) { - num = num.toFixed(limit); - } - return num; - }, - isFloat: function isFloat(num) { - return num % 1 !== 0; - }, - approximatelyEqual: function approximatelyEqual(num1, num2) { - return Math.abs(num1 - num2) < 1e-10; - }, - isSameSign: function isSameSign(num1, num2) { - return (Math.abs(num1) === num1 && Math.abs(num2) === num2) || (Math.abs(num1) !== num1 && Math.abs(num2) !== num2); - }, - isSameXCoordinateArea: function isSameXCoordinateArea(p1, p2) { - return this.isSameSign(p1.x, p2.x); - }, - isCollision: function isCollision(obj1, obj2) { - obj1.end = {}; - obj1.end.x = obj1.start.x + obj1.width; - obj1.end.y = obj1.start.y - obj1.height; - obj2.end = {}; - obj2.end.x = obj2.start.x + obj2.width; - obj2.end.y = obj2.start.y - obj2.height; - var flag = obj2.start.x > obj1.end.x || obj2.end.x < obj1.start.x || obj2.end.y > obj1.start.y || obj2.start.y < obj1.end.y; - return !flag; - }, -}; - -//兼容H5点击事件 -function getH5Offset(e) { - e.mp = { - changedTouches: [], - }; - e.mp.changedTouches.push({ - x: e.offsetX, - y: e.offsetY, - }); - return e; -} - -// hex 转 rgba -function hexToRgb(hexValue, opc) { - var rgx = /^#?([a-f\d])([a-f\d])([a-f\d])$/i; - var hex = hexValue.replace(rgx, function (m, r, g, b) { - return r + r + g + g + b + b; - }); - var rgb = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); - var r = parseInt(rgb[1], 16); - var g = parseInt(rgb[2], 16); - var b = parseInt(rgb[3], 16); - return "rgba(" + r + "," + g + "," + b + "," + opc + ")"; -} - -function findRange(num, type, limit) { - if (isNaN(num)) { - throw new Error("[uCharts] series数据需为Number格式"); - } - limit = limit || 10; - type = type ? type : "upper"; - var multiple = 1; - while (limit < 1) { - limit *= 10; - multiple *= 10; - } - if (type === "upper") { - num = Math.ceil(num * multiple); - } else { - num = Math.floor(num * multiple); - } - while (num % limit !== 0) { - if (type === "upper") { - if (num == num + 1) { - //修复数据值过大num++无效的bug by 向日葵 @xrk_jy - break; - } - num++; - } else { - num--; - } - } - return num / multiple; -} - -function calCandleMA(dayArr, nameArr, colorArr, kdata) { - let seriesTemp = []; - for (let k = 0; k < dayArr.length; k++) { - let seriesItem = { - data: [], - name: nameArr[k], - color: colorArr[k], - }; - for (let i = 0, len = kdata.length; i < len; i++) { - if (i < dayArr[k]) { - seriesItem.data.push(null); - continue; - } - let sum = 0; - for (let j = 0; j < dayArr[k]; j++) { - sum += kdata[i - j][1]; - } - seriesItem.data.push(+(sum / dayArr[k]).toFixed(3)); - } - seriesTemp.push(seriesItem); - } - return seriesTemp; -} - -function calValidDistance(self, distance, chartData, config, opts) { - var dataChartAreaWidth = opts.width - opts.area[1] - opts.area[3]; - var dataChartWidth = chartData.eachSpacing * (opts.chartData.xAxisData.xAxisPoints.length - 1); - if (opts.type == "mount" && opts.extra && opts.extra.mount && opts.extra.mount.widthRatio && opts.extra.mount.widthRatio > 1) { - if (opts.extra.mount.widthRatio > 2) opts.extra.mount.widthRatio = 2; - dataChartWidth += (opts.extra.mount.widthRatio - 1) * chartData.eachSpacing; - } - var validDistance = distance; - if (distance >= 0) { - validDistance = 0; - self.uevent.trigger("scrollLeft"); - self.scrollOption.position = "left"; - opts.xAxis.scrollPosition = "left"; - } else if (Math.abs(distance) >= dataChartWidth - dataChartAreaWidth) { - validDistance = dataChartAreaWidth - dataChartWidth; - self.uevent.trigger("scrollRight"); - self.scrollOption.position = "right"; - opts.xAxis.scrollPosition = "right"; - } else { - self.scrollOption.position = distance; - opts.xAxis.scrollPosition = distance; - } - return validDistance; -} - -function isInAngleRange(angle, startAngle, endAngle) { - function adjust(angle) { - while (angle < 0) { - angle += 2 * Math.PI; - } - while (angle > 2 * Math.PI) { - angle -= 2 * Math.PI; - } - return angle; - } - angle = adjust(angle); - startAngle = adjust(startAngle); - endAngle = adjust(endAngle); - if (startAngle > endAngle) { - endAngle += 2 * Math.PI; - if (angle < startAngle) { - angle += 2 * Math.PI; - } - } - return angle >= startAngle && angle <= endAngle; -} - -function createCurveControlPoints(points, i) { - function isNotMiddlePoint(points, i) { - if (points[i - 1] && points[i + 1]) { - return points[i].y >= Math.max(points[i - 1].y, points[i + 1].y) || points[i].y <= Math.min(points[i - 1].y, points[i + 1].y); - } else { - return false; - } - } - function isNotMiddlePointX(points, i) { - if (points[i - 1] && points[i + 1]) { - return points[i].x >= Math.max(points[i - 1].x, points[i + 1].x) || points[i].x <= Math.min(points[i - 1].x, points[i + 1].x); - } else { - return false; - } - } - var a = 0.2; - var b = 0.2; - var pAx = null; - var pAy = null; - var pBx = null; - var pBy = null; - if (i < 1) { - pAx = points[0].x + (points[1].x - points[0].x) * a; - pAy = points[0].y + (points[1].y - points[0].y) * a; - } else { - pAx = points[i].x + (points[i + 1].x - points[i - 1].x) * a; - pAy = points[i].y + (points[i + 1].y - points[i - 1].y) * a; - } - - if (i > points.length - 3) { - var last = points.length - 1; - pBx = points[last].x - (points[last].x - points[last - 1].x) * b; - pBy = points[last].y - (points[last].y - points[last - 1].y) * b; - } else { - pBx = points[i + 1].x - (points[i + 2].x - points[i].x) * b; - pBy = points[i + 1].y - (points[i + 2].y - points[i].y) * b; - } - if (isNotMiddlePoint(points, i + 1)) { - pBy = points[i + 1].y; - } - if (isNotMiddlePoint(points, i)) { - pAy = points[i].y; - } - if (isNotMiddlePointX(points, i + 1)) { - pBx = points[i + 1].x; - } - if (isNotMiddlePointX(points, i)) { - pAx = points[i].x; - } - if (pAy >= Math.max(points[i].y, points[i + 1].y) || pAy <= Math.min(points[i].y, points[i + 1].y)) { - pAy = points[i].y; - } - if (pBy >= Math.max(points[i].y, points[i + 1].y) || pBy <= Math.min(points[i].y, points[i + 1].y)) { - pBy = points[i + 1].y; - } - if (pAx >= Math.max(points[i].x, points[i + 1].x) || pAx <= Math.min(points[i].x, points[i + 1].x)) { - pAx = points[i].x; - } - if (pBx >= Math.max(points[i].x, points[i + 1].x) || pBx <= Math.min(points[i].x, points[i + 1].x)) { - pBx = points[i + 1].x; - } - return { - ctrA: { - x: pAx, - y: pAy, - }, - ctrB: { - x: pBx, - y: pBy, - }, - }; -} - -function convertCoordinateOrigin(x, y, center) { - return { - x: center.x + x, - y: center.y - y, - }; -} - -function avoidCollision(obj, target) { - if (target) { - // is collision test - while (util.isCollision(obj, target)) { - if (obj.start.x > 0) { - obj.start.y--; - } else if (obj.start.x < 0) { - obj.start.y++; - } else { - if (obj.start.y > 0) { - obj.start.y++; - } else { - obj.start.y--; - } - } - } - } - return obj; -} - -function fixPieSeries(series, opts, config) { - let pieSeriesArr = []; - if (series.length > 0 && series[0].data.constructor.toString().indexOf("Array") > -1) { - opts._pieSeries_ = series; - let oldseries = series[0].data; - for (var i = 0; i < oldseries.length; i++) { - oldseries[i].formatter = series[0].formatter; - oldseries[i].data = oldseries[i].value; - pieSeriesArr.push(oldseries[i]); - } - opts.series = pieSeriesArr; - } else { - pieSeriesArr = series; - } - return pieSeriesArr; -} - -function fillSeries(series, opts, config) { - var index = 0; - for (var i = 0; i < series.length; i++) { - let item = series[i]; - if (!item.color) { - item.color = config.color[index]; - index = (index + 1) % config.color.length; - } - if (!item.linearIndex) { - item.linearIndex = i; - } - if (!item.index) { - item.index = 0; - } - if (!item.type) { - item.type = opts.type; - } - if (typeof item.show == "undefined") { - item.show = true; - } - if (!item.type) { - item.type = opts.type; - } - if (!item.pointShape) { - item.pointShape = "circle"; - } - if (!item.legendShape) { - switch (item.type) { - case "line": - item.legendShape = "line"; - break; - case "column": - case "bar": - item.legendShape = "rect"; - break; - case "area": - case "mount": - item.legendShape = "triangle"; - break; - default: - item.legendShape = "circle"; - } - } - } - return series; -} - -function fillCustomColor(linearType, customColor, series, config) { - var newcolor = customColor || []; - if (linearType == "custom" && newcolor.length == 0) { - newcolor = config.linearColor; - } - if (linearType == "custom" && newcolor.length < series.length) { - let chazhi = series.length - newcolor.length; - for (var i = 0; i < chazhi; i++) { - newcolor.push(config.linearColor[(i + 1) % config.linearColor.length]); - } - } - return newcolor; -} - -function getDataRange(minData, maxData) { - var limit = 0; - var range = maxData - minData; - if (range >= 10000) { - limit = 1000; - } else if (range >= 1000) { - limit = 100; - } else if (range >= 100) { - limit = 10; - } else if (range >= 10) { - limit = 5; - } else if (range >= 1) { - limit = 1; - } else if (range >= 0.1) { - limit = 0.1; - } else if (range >= 0.01) { - limit = 0.01; - } else if (range >= 0.001) { - limit = 0.001; - } else if (range >= 0.0001) { - limit = 0.0001; - } else if (range >= 0.00001) { - limit = 0.00001; - } else { - limit = 0.000001; - } - return { - minRange: findRange(minData, "lower", limit), - maxRange: findRange(maxData, "upper", limit), - }; -} - -function measureText(text, fontSize, context) { - var width = 0; - text = String(text); - // #ifdef MP-ALIPAY || MP-BAIDU || APP-NVUE - context = false; - // #endif - if (context !== false && context !== undefined && context.setFontSize && context.measureText) { - context.setFontSize(fontSize); - return context.measureText(text).width; - } else { - var text = text.split(""); - for (let i = 0; i < text.length; i++) { - let item = text[i]; - if (/[a-zA-Z]/.test(item)) { - width += 7; - } else if (/[0-9]/.test(item)) { - width += 5.5; - } else if (/\./.test(item)) { - width += 2.7; - } else if (/-/.test(item)) { - width += 3.25; - } else if (/:/.test(item)) { - width += 2.5; - } else if (/[\u4e00-\u9fa5]/.test(item)) { - width += 10; - } else if (/\(|\)/.test(item)) { - width += 3.73; - } else if (/\s/.test(item)) { - width += 2.5; - } else if (/%/.test(item)) { - width += 8; - } else { - width += 10; - } - } - return (width * fontSize) / 10; - } -} - -function dataCombine(series) { - return series.reduce(function (a, b) { - return (a.data ? a.data : a).concat(b.data); - }, []); -} - -function dataCombineStack(series, len) { - var sum = new Array(len); - for (var j = 0; j < sum.length; j++) { - sum[j] = 0; - } - for (var i = 0; i < series.length; i++) { - for (var j = 0; j < sum.length; j++) { - sum[j] += series[i].data[j]; - } - } - return series.reduce(function (a, b) { - return (a.data ? a.data : a).concat(b.data).concat(sum); - }, []); -} - -function getTouches(touches, opts, e) { - let x, y; - if (touches.clientX) { - if (opts.rotate) { - y = opts.height - touches.clientX * opts.pix; - x = (touches.pageY - e.currentTarget.offsetTop - (opts.height / opts.pix / 2) * (opts.pix - 1)) * opts.pix; - } else { - x = touches.clientX * opts.pix; - y = (touches.pageY - e.currentTarget.offsetTop - (opts.height / opts.pix / 2) * (opts.pix - 1)) * opts.pix; - } - } else { - if (opts.rotate) { - y = opts.height - touches.x * opts.pix; - x = touches.y * opts.pix; - } else { - x = touches.x * opts.pix; - y = touches.y * opts.pix; - } - } - return { - x: x, - y: y, - }; -} - -function getSeriesDataItem(series, index, group) { - var data = []; - var newSeries = []; - var indexIsArr = index.constructor.toString().indexOf("Array") > -1; - if (indexIsArr) { - let tempSeries = filterSeries(series); - for (var i = 0; i < group.length; i++) { - newSeries.push(tempSeries[group[i]]); - } - } else { - newSeries = series; - } - for (let i = 0; i < newSeries.length; i++) { - let item = newSeries[i]; - let tmpindex = -1; - if (indexIsArr) { - tmpindex = index[i]; - } else { - tmpindex = index; - } - if (item.data[tmpindex] !== null && typeof item.data[tmpindex] !== "undefined" && item.show) { - let seriesItem = {}; - seriesItem.color = item.color; - seriesItem.type = item.type; - seriesItem.style = item.style; - seriesItem.pointShape = item.pointShape; - seriesItem.disableLegend = item.disableLegend; - seriesItem.legendShape = item.legendShape; - seriesItem.name = item.name; - seriesItem.show = item.show; - seriesItem.data = item.formatter ? item.formatter(item.data[tmpindex]) : item.data[tmpindex]; - data.push(seriesItem); - } - } - return data; -} - -function getMaxTextListLength(list, fontSize, context) { - var lengthList = list.map(function (item) { - return measureText(item, fontSize, context); - }); - return Math.max.apply(null, lengthList); -} - -function getRadarCoordinateSeries(length) { - var eachAngle = (2 * Math.PI) / length; - var CoordinateSeries = []; - for (var i = 0; i < length; i++) { - CoordinateSeries.push(eachAngle * i); - } - return CoordinateSeries.map(function (item) { - return -1 * item + Math.PI / 2; - }); -} - -function getToolTipData(seriesData, opts, index, group, categories) { - var option = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {}; - var calPoints = opts.chartData.calPoints ? opts.chartData.calPoints : []; - let points = {}; - if (group.length > 0) { - let filterPoints = []; - for (let i = 0; i < group.length; i++) { - filterPoints.push(calPoints[group[i]]); - } - points = filterPoints[0][index[0]]; - } else { - for (let i = 0; i < calPoints.length; i++) { - if (calPoints[i][index]) { - points = calPoints[i][index]; - break; - } - } - } - var textList = seriesData.map(function (item) { - let titleText = null; - if (opts.categories && opts.categories.length > 0) { - titleText = categories[index]; - } - return { - text: option.formatter ? option.formatter(item, titleText, index, opts) : item.name + ": " + item.data, - color: item.color, - legendShape: opts.extra.tooltip.legendShape == "auto" ? item.legendShape : opts.extra.tooltip.legendShape, - }; - }); - var offset = { - x: Math.round(points.x), - y: Math.round(points.y), - }; - return { - textList: textList, - offset: offset, - }; -} - -function getMixToolTipData(seriesData, opts, index, categories) { - var option = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {}; - var points = opts.chartData.xAxisPoints[index] + opts.chartData.eachSpacing / 2; - var textList = seriesData.map(function (item) { - return { - text: option.formatter ? option.formatter(item, categories[index], index, opts) : item.name + ": " + item.data, - color: item.color, - disableLegend: item.disableLegend ? true : false, - legendShape: opts.extra.tooltip.legendShape == "auto" ? item.legendShape : opts.extra.tooltip.legendShape, - }; - }); - textList = textList.filter(function (item) { - if (item.disableLegend !== true) { - return item; - } - }); - var offset = { - x: Math.round(points), - y: 0, - }; - return { - textList: textList, - offset: offset, - }; -} - -function getCandleToolTipData(series, seriesData, opts, index, categories, extra) { - var option = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : {}; - var calPoints = opts.chartData.calPoints; - let upColor = extra.color.upFill; - let downColor = extra.color.downFill; - //颜色顺序为开盘,收盘,最低,最高 - let color = [upColor, upColor, downColor, upColor]; - var textList = []; - seriesData.map(function (item) { - if (index == 0) { - if (item.data[1] - item.data[0] < 0) { - color[1] = downColor; - } else { - color[1] = upColor; - } - } else { - if (item.data[0] < series[index - 1][1]) { - color[0] = downColor; - } - if (item.data[1] < item.data[0]) { - color[1] = downColor; - } - if (item.data[2] > series[index - 1][1]) { - color[2] = upColor; - } - if (item.data[3] < series[index - 1][1]) { - color[3] = downColor; - } - } - let text1 = { - text: "开盘:" + item.data[0], - color: color[0], - legendShape: opts.extra.tooltip.legendShape == "auto" ? item.legendShape : opts.extra.tooltip.legendShape, - }; - let text2 = { - text: "收盘:" + item.data[1], - color: color[1], - legendShape: opts.extra.tooltip.legendShape == "auto" ? item.legendShape : opts.extra.tooltip.legendShape, - }; - let text3 = { - text: "最低:" + item.data[2], - color: color[2], - legendShape: opts.extra.tooltip.legendShape == "auto" ? item.legendShape : opts.extra.tooltip.legendShape, - }; - let text4 = { - text: "最高:" + item.data[3], - color: color[3], - legendShape: opts.extra.tooltip.legendShape == "auto" ? item.legendShape : opts.extra.tooltip.legendShape, - }; - textList.push(text1, text2, text3, text4); - }); - var validCalPoints = []; - var offset = { - x: 0, - y: 0, - }; - for (let i = 0; i < calPoints.length; i++) { - let points = calPoints[i]; - if (typeof points[index] !== "undefined" && points[index] !== null) { - validCalPoints.push(points[index]); - } - } - offset.x = Math.round(validCalPoints[0][0].x); - return { - textList: textList, - offset: offset, - }; -} - -function filterSeries(series) { - let tempSeries = []; - for (let i = 0; i < series.length; i++) { - if (series[i].show == true) { - tempSeries.push(series[i]); - } - } - return tempSeries; -} - -function findCurrentIndex(currentPoints, calPoints, opts, config) { - var offset = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0; - var current = { index: -1, group: [] }; - var spacing = opts.chartData.eachSpacing / 2; - let xAxisPoints = []; - if (calPoints && calPoints.length > 0) { - if (!opts.categories) { - spacing = 0; - } else { - for (let i = 1; i < opts.chartData.xAxisPoints.length; i++) { - xAxisPoints.push(opts.chartData.xAxisPoints[i] - spacing); - } - if ((opts.type == "line" || opts.type == "area") && opts.xAxis.boundaryGap == "justify") { - xAxisPoints = opts.chartData.xAxisPoints; - } - } - if (isInExactChartArea(currentPoints, opts, config)) { - if (!opts.categories) { - let timePoints = Array(calPoints.length); - for (let i = 0; i < calPoints.length; i++) { - timePoints[i] = Array(calPoints[i].length); - for (let j = 0; j < calPoints[i].length; j++) { - timePoints[i][j] = Math.abs(calPoints[i][j].x - currentPoints.x); - } - } - let pointValue = Array(timePoints.length); - let pointIndex = Array(timePoints.length); - for (let i = 0; i < timePoints.length; i++) { - pointValue[i] = Math.min.apply(null, timePoints[i]); - pointIndex[i] = timePoints[i].indexOf(pointValue[i]); - } - let minValue = Math.min.apply(null, pointValue); - current.index = []; - for (let i = 0; i < pointValue.length; i++) { - if (pointValue[i] == minValue) { - current.group.push(i); - current.index.push(pointIndex[i]); - } - } - } else { - xAxisPoints.forEach(function (item, index) { - if (currentPoints.x + offset + spacing > item) { - current.index = index; - } - }); - } - } - } - return current; -} - -function findBarChartCurrentIndex(currentPoints, calPoints, opts, config) { - var offset = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0; - var current = { index: -1, group: [] }; - var spacing = opts.chartData.eachSpacing / 2; - let yAxisPoints = opts.chartData.yAxisPoints; - if (calPoints && calPoints.length > 0) { - if (isInExactChartArea(currentPoints, opts, config)) { - yAxisPoints.forEach(function (item, index) { - if (currentPoints.y + offset + spacing > item) { - current.index = index; - } - }); - } - } - return current; -} - -function findLegendIndex(currentPoints, legendData, opts) { - let currentIndex = -1; - let gap = 0; - if (isInExactLegendArea(currentPoints, legendData.area)) { - let points = legendData.points; - let index = -1; - for (let i = 0, len = points.length; i < len; i++) { - let item = points[i]; - for (let j = 0; j < item.length; j++) { - index += 1; - let area = item[j]["area"]; - if (area && currentPoints.x > area[0] - gap && currentPoints.x < area[2] + gap && currentPoints.y > area[1] - gap && currentPoints.y < area[3] + gap) { - currentIndex = index; - break; - } - } - } - return currentIndex; - } - return currentIndex; -} - -function isInExactLegendArea(currentPoints, area) { - return currentPoints.x > area.start.x && currentPoints.x < area.end.x && currentPoints.y > area.start.y && currentPoints.y < area.end.y; -} - -function isInExactChartArea(currentPoints, opts, config) { - return currentPoints.x <= opts.width - opts.area[1] + 10 && currentPoints.x >= opts.area[3] - 10 && currentPoints.y >= opts.area[0] && currentPoints.y <= opts.height - opts.area[2]; -} - -function findRadarChartCurrentIndex(currentPoints, radarData, count) { - var eachAngleArea = (2 * Math.PI) / count; - var currentIndex = -1; - if (isInExactPieChartArea(currentPoints, radarData.center, radarData.radius)) { - var fixAngle = function fixAngle(angle) { - if (angle < 0) { - angle += 2 * Math.PI; - } - if (angle > 2 * Math.PI) { - angle -= 2 * Math.PI; - } - return angle; - }; - var angle = Math.atan2(radarData.center.y - currentPoints.y, currentPoints.x - radarData.center.x); - angle = -1 * angle; - if (angle < 0) { - angle += 2 * Math.PI; - } - var angleList = radarData.angleList.map(function (item) { - item = fixAngle(-1 * item); - return item; - }); - angleList.forEach(function (item, index) { - var rangeStart = fixAngle(item - eachAngleArea / 2); - var rangeEnd = fixAngle(item + eachAngleArea / 2); - if (rangeEnd < rangeStart) { - rangeEnd += 2 * Math.PI; - } - if ((angle >= rangeStart && angle <= rangeEnd) || (angle + 2 * Math.PI >= rangeStart && angle + 2 * Math.PI <= rangeEnd)) { - currentIndex = index; - } - }); - } - return currentIndex; -} - -function findFunnelChartCurrentIndex(currentPoints, funnelData) { - var currentIndex = -1; - for (var i = 0, len = funnelData.series.length; i < len; i++) { - var item = funnelData.series[i]; - if (currentPoints.x > item.funnelArea[0] && currentPoints.x < item.funnelArea[2] && currentPoints.y > item.funnelArea[1] && currentPoints.y < item.funnelArea[3]) { - currentIndex = i; - break; - } - } - return currentIndex; -} - -function findWordChartCurrentIndex(currentPoints, wordData) { - var currentIndex = -1; - for (var i = 0, len = wordData.length; i < len; i++) { - var item = wordData[i]; - if (currentPoints.x > item.area[0] && currentPoints.x < item.area[2] && currentPoints.y > item.area[1] && currentPoints.y < item.area[3]) { - currentIndex = i; - break; - } - } - return currentIndex; -} - -function findMapChartCurrentIndex(currentPoints, opts) { - var currentIndex = -1; - var cData = opts.chartData.mapData; - var data = opts.series; - var tmp = pointToCoordinate(currentPoints.y, currentPoints.x, cData.bounds, cData.scale, cData.xoffset, cData.yoffset); - var poi = [tmp.x, tmp.y]; - for (var i = 0, len = data.length; i < len; i++) { - var item = data[i].geometry.coordinates; - if (isPoiWithinPoly(poi, item, opts.chartData.mapData.mercator)) { - currentIndex = i; - break; - } - } - return currentIndex; -} - -function findRoseChartCurrentIndex(currentPoints, pieData, opts) { - var currentIndex = -1; - var series = getRoseDataPoints(opts._series_, opts.extra.rose.type, pieData.radius, pieData.radius); - if (pieData && pieData.center && isInExactPieChartArea(currentPoints, pieData.center, pieData.radius)) { - var angle = Math.atan2(pieData.center.y - currentPoints.y, currentPoints.x - pieData.center.x); - angle = -angle; - if (opts.extra.rose && opts.extra.rose.offsetAngle) { - angle = angle - (opts.extra.rose.offsetAngle * Math.PI) / 180; - } - for (var i = 0, len = series.length; i < len; i++) { - if (isInAngleRange(angle, series[i]._start_, series[i]._start_ + series[i]._rose_proportion_ * 2 * Math.PI)) { - currentIndex = i; - break; - } - } - } - return currentIndex; -} - -function findPieChartCurrentIndex(currentPoints, pieData, opts) { - var currentIndex = -1; - var series = getPieDataPoints(pieData.series); - if (pieData && pieData.center && isInExactPieChartArea(currentPoints, pieData.center, pieData.radius)) { - var angle = Math.atan2(pieData.center.y - currentPoints.y, currentPoints.x - pieData.center.x); - angle = -angle; - if (opts.extra.pie && opts.extra.pie.offsetAngle) { - angle = angle - (opts.extra.pie.offsetAngle * Math.PI) / 180; - } - if (opts.extra.ring && opts.extra.ring.offsetAngle) { - angle = angle - (opts.extra.ring.offsetAngle * Math.PI) / 180; - } - for (var i = 0, len = series.length; i < len; i++) { - if (isInAngleRange(angle, series[i]._start_, series[i]._start_ + series[i]._proportion_ * 2 * Math.PI)) { - currentIndex = i; - break; - } - } - } - return currentIndex; -} - -function isInExactPieChartArea(currentPoints, center, radius) { - return Math.pow(currentPoints.x - center.x, 2) + Math.pow(currentPoints.y - center.y, 2) <= Math.pow(radius, 2); -} - -function splitPoints(points, eachSeries) { - var newPoints = []; - var items = []; - points.forEach(function (item, index) { - if (eachSeries.connectNulls) { - if (item !== null) { - items.push(item); - } - } else { - if (item !== null) { - items.push(item); - } else { - if (items.length) { - newPoints.push(items); - } - items = []; - } - } - }); - if (items.length) { - newPoints.push(items); - } - return newPoints; -} - -function calLegendData(series, opts, config, chartData, context) { - let legendData = { - area: { - start: { - x: 0, - y: 0, - }, - end: { - x: 0, - y: 0, - }, - width: 0, - height: 0, - wholeWidth: 0, - wholeHeight: 0, - }, - points: [], - widthArr: [], - heightArr: [], - }; - if (opts.legend.show === false) { - chartData.legendData = legendData; - return legendData; - } - let padding = opts.legend.padding * opts.pix; - let margin = opts.legend.margin * opts.pix; - let fontSize = opts.legend.fontSize ? opts.legend.fontSize * opts.pix : config.fontSize; - let shapeWidth = 15 * opts.pix; - let shapeRight = 5 * opts.pix; - let lineHeight = Math.max(opts.legend.lineHeight * opts.pix, fontSize); - if (opts.legend.position == "top" || opts.legend.position == "bottom") { - let legendList = []; - let widthCount = 0; - let widthCountArr = []; - let currentRow = []; - for (let i = 0; i < series.length; i++) { - let item = series[i]; - const legendText = item.legendText ? item.legendText : item.name; - let itemWidth = shapeWidth + shapeRight + measureText(legendText || "undefined", fontSize, context) + opts.legend.itemGap * opts.pix; - if (widthCount + itemWidth > opts.width - opts.area[1] - opts.area[3]) { - legendList.push(currentRow); - widthCountArr.push(widthCount - opts.legend.itemGap * opts.pix); - widthCount = itemWidth; - currentRow = [item]; - } else { - widthCount += itemWidth; - currentRow.push(item); - } - } - if (currentRow.length) { - legendList.push(currentRow); - widthCountArr.push(widthCount - opts.legend.itemGap * opts.pix); - legendData.widthArr = widthCountArr; - let legendWidth = Math.max.apply(null, widthCountArr); - switch (opts.legend.float) { - case "left": - legendData.area.start.x = opts.area[3]; - legendData.area.end.x = opts.area[3] + legendWidth + 2 * padding; - break; - case "right": - legendData.area.start.x = opts.width - opts.area[1] - legendWidth - 2 * padding; - legendData.area.end.x = opts.width - opts.area[1]; - break; - default: - legendData.area.start.x = (opts.width - legendWidth) / 2 - padding; - legendData.area.end.x = (opts.width + legendWidth) / 2 + padding; - } - legendData.area.width = legendWidth + 2 * padding; - legendData.area.wholeWidth = legendWidth + 2 * padding; - legendData.area.height = legendList.length * lineHeight + 2 * padding; - legendData.area.wholeHeight = legendList.length * lineHeight + 2 * padding + 2 * margin; - legendData.points = legendList; - } - } else { - let len = series.length; - let maxHeight = opts.height - opts.area[0] - opts.area[2] - 2 * margin - 2 * padding; - let maxLength = Math.min(Math.floor(maxHeight / lineHeight), len); - legendData.area.height = maxLength * lineHeight + padding * 2; - legendData.area.wholeHeight = maxLength * lineHeight + padding * 2; - switch (opts.legend.float) { - case "top": - legendData.area.start.y = opts.area[0] + margin; - legendData.area.end.y = opts.area[0] + margin + legendData.area.height; - break; - case "bottom": - legendData.area.start.y = opts.height - opts.area[2] - margin - legendData.area.height; - legendData.area.end.y = opts.height - opts.area[2] - margin; - break; - default: - legendData.area.start.y = (opts.height - legendData.area.height) / 2; - legendData.area.end.y = (opts.height + legendData.area.height) / 2; - } - let lineNum = len % maxLength === 0 ? len / maxLength : Math.floor(len / maxLength + 1); - let currentRow = []; - for (let i = 0; i < lineNum; i++) { - let temp = series.slice(i * maxLength, i * maxLength + maxLength); - currentRow.push(temp); - } - legendData.points = currentRow; - if (currentRow.length) { - for (let i = 0; i < currentRow.length; i++) { - let item = currentRow[i]; - let maxWidth = 0; - for (let j = 0; j < item.length; j++) { - let itemWidth = shapeWidth + shapeRight + measureText(item[j].name || "undefined", fontSize, context) + opts.legend.itemGap * opts.pix; - if (itemWidth > maxWidth) { - maxWidth = itemWidth; - } - } - legendData.widthArr.push(maxWidth); - legendData.heightArr.push(item.length * lineHeight + padding * 2); - } - let legendWidth = 0; - for (let i = 0; i < legendData.widthArr.length; i++) { - legendWidth += legendData.widthArr[i]; - } - legendData.area.width = legendWidth - opts.legend.itemGap * opts.pix + 2 * padding; - legendData.area.wholeWidth = legendData.area.width + padding; - } - } - switch (opts.legend.position) { - case "top": - legendData.area.start.y = opts.area[0] + margin; - legendData.area.end.y = opts.area[0] + margin + legendData.area.height; - break; - case "bottom": - legendData.area.start.y = opts.height - opts.area[2] - legendData.area.height - margin; - legendData.area.end.y = opts.height - opts.area[2] - margin; - break; - case "left": - legendData.area.start.x = opts.area[3]; - legendData.area.end.x = opts.area[3] + legendData.area.width; - break; - case "right": - legendData.area.start.x = opts.width - opts.area[1] - legendData.area.width; - legendData.area.end.x = opts.width - opts.area[1]; - break; - } - chartData.legendData = legendData; - return legendData; -} - -function calCategoriesData(categories, opts, config, eachSpacing, context) { - var result = { - angle: 0, - xAxisHeight: opts.xAxis.lineHeight * opts.pix + opts.xAxis.marginTop * opts.pix, - }; - var fontSize = opts.xAxis.fontSize * opts.pix; - var categoriesTextLenth = categories.map(function (item, index) { - var xitem = opts.xAxis.formatter ? opts.xAxis.formatter(item, index, opts) : item; - return measureText(String(xitem), fontSize, context); - }); - var maxTextLength = Math.max.apply(this, categoriesTextLenth); - if (opts.xAxis.rotateLabel == true) { - result.angle = (opts.xAxis.rotateAngle * Math.PI) / 180; - let tempHeight = opts.xAxis.marginTop * opts.pix * 2 + Math.abs(maxTextLength * Math.sin(result.angle)); - tempHeight = tempHeight < fontSize + opts.xAxis.marginTop * opts.pix * 2 ? tempHeight + opts.xAxis.marginTop * opts.pix * 2 : tempHeight; - result.xAxisHeight = tempHeight; - } - if (opts.enableScroll && opts.xAxis.scrollShow) { - result.xAxisHeight += 6 * opts.pix; - } - if (opts.xAxis.disabled) { - result.xAxisHeight = 0; - } - return result; -} - -function getXAxisTextList(series, opts, config, stack) { - var index = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : -1; - var data; - if (stack == "stack") { - data = dataCombineStack(series, opts.categories.length); - } else { - data = dataCombine(series); - } - var sorted = []; - // remove null from data - data = data.filter(function (item) { - //return item !== null; - if (typeof item === "object" && item !== null) { - if (item.constructor.toString().indexOf("Array") > -1) { - return item !== null; - } else { - return item.value !== null; - } - } else { - return item !== null; - } - }); - data.map(function (item) { - if (typeof item === "object") { - if (item.constructor.toString().indexOf("Array") > -1) { - if (opts.type == "candle") { - item.map(function (subitem) { - sorted.push(subitem); - }); - } else { - sorted.push(item[0]); - } - } else { - sorted.push(item.value); - } - } else { - sorted.push(item); - } - }); - - var minData = 0; - var maxData = 0; - if (sorted.length > 0) { - minData = Math.min.apply(this, sorted); - maxData = Math.max.apply(this, sorted); - } - //为了兼容v1.9.0之前的项目 - if (index > -1) { - if (typeof opts.xAxis.data[index].min === "number") { - minData = Math.min(opts.xAxis.data[index].min, minData); - } - if (typeof opts.xAxis.data[index].max === "number") { - maxData = Math.max(opts.xAxis.data[index].max, maxData); - } - } else { - if (typeof opts.xAxis.min === "number") { - minData = Math.min(opts.xAxis.min, minData); - } - if (typeof opts.xAxis.max === "number") { - maxData = Math.max(opts.xAxis.max, maxData); - } - } - if (minData === maxData) { - var rangeSpan = maxData || 10; - maxData += rangeSpan; - } - //var dataRange = getDataRange(minData, maxData); - var minRange = minData; - var maxRange = maxData; - var range = []; - var eachRange = (maxRange - minRange) / opts.xAxis.splitNumber; - for (var i = 0; i <= opts.xAxis.splitNumber; i++) { - range.push(minRange + eachRange * i); - } - return range; -} - -function calXAxisData(series, opts, config, context) { - //堆叠图重算Y轴 - var columnstyle = assign( - {}, - { - type: "", - }, - opts.extra.bar - ); - var result = { - angle: 0, - xAxisHeight: opts.xAxis.lineHeight * opts.pix + opts.xAxis.marginTop * opts.pix, - }; - result.ranges = getXAxisTextList(series, opts, config, columnstyle.type); - result.rangesFormat = result.ranges.map(function (item) { - //item = opts.xAxis.formatter ? opts.xAxis.formatter(item) : util.toFixed(item, 2); - item = util.toFixed(item, 2); - return item; - }); - var xAxisScaleValues = result.ranges.map(function (item) { - // 如果刻度值是浮点数,则保留两位小数 - item = util.toFixed(item, 2); - // 若有自定义格式则调用自定义的格式化函数 - //item = opts.xAxis.formatter ? opts.xAxis.formatter(Number(item)) : item; - return item; - }); - result = Object.assign(result, getXAxisPoints(xAxisScaleValues, opts, config)); - // 计算X轴刻度的属性譬如每个刻度的间隔,刻度的起始点\结束点以及总长 - var eachSpacing = result.eachSpacing; - var textLength = xAxisScaleValues.map(function (item) { - return measureText(item, opts.xAxis.fontSize * opts.pix, context); - }); - if (opts.xAxis.disabled === true) { - result.xAxisHeight = 0; - } - return result; -} - -function getRadarDataPoints(angleList, center, radius, series, opts) { - var process = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 1; - var radarOption = opts.extra.radar || {}; - radarOption.max = radarOption.max || 0; - var maxData = Math.max(radarOption.max, Math.max.apply(null, dataCombine(series))); - var data = []; - for (let i = 0; i < series.length; i++) { - let each = series[i]; - let listItem = {}; - listItem.color = each.color; - listItem.legendShape = each.legendShape; - listItem.pointShape = each.pointShape; - listItem.data = []; - each.data.forEach(function (item, index) { - let tmp = {}; - tmp.angle = angleList[index]; - tmp.proportion = item / maxData; - tmp.value = item; - tmp.position = convertCoordinateOrigin(radius * tmp.proportion * process * Math.cos(tmp.angle), radius * tmp.proportion * process * Math.sin(tmp.angle), center); - listItem.data.push(tmp); - }); - data.push(listItem); - } - return data; -} - -function getPieDataPoints(series, radius) { - var process = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1; - var count = 0; - var _start_ = 0; - for (let i = 0; i < series.length; i++) { - let item = series[i]; - item.data = item.data === null ? 0 : item.data; - count += item.data; - } - for (let i = 0; i < series.length; i++) { - let item = series[i]; - item.data = item.data === null ? 0 : item.data; - if (count === 0) { - item._proportion_ = (1 / series.length) * process; - } else { - item._proportion_ = (item.data / count) * process; - } - item._radius_ = radius; - } - for (let i = 0; i < series.length; i++) { - let item = series[i]; - item._start_ = _start_; - _start_ += 2 * item._proportion_ * Math.PI; - } - return series; -} - -function getFunnelDataPoints(series, radius, option, eachSpacing) { - var process = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1; - for (let i = 0; i < series.length; i++) { - if (option.type == "funnel") { - series[i].radius = (series[i].data / series[0].data) * radius * process; - } else { - series[i].radius = ((eachSpacing * (series.length - i)) / (eachSpacing * series.length)) * radius * process; - } - series[i]._proportion_ = series[i].data / series[0].data; - } - // if(option.type !== 'pyramid'){ - // series.reverse(); - // } - return series; -} - -function getRoseDataPoints(series, type, minRadius, radius) { - var process = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1; - var count = 0; - var _start_ = 0; - var dataArr = []; - for (let i = 0; i < series.length; i++) { - let item = series[i]; - item.data = item.data === null ? 0 : item.data; - count += item.data; - dataArr.push(item.data); - } - var minData = Math.min.apply(null, dataArr); - var maxData = Math.max.apply(null, dataArr); - var radiusLength = radius - minRadius; - for (let i = 0; i < series.length; i++) { - let item = series[i]; - item.data = item.data === null ? 0 : item.data; - if (count === 0) { - item._proportion_ = (1 / series.length) * process; - item._rose_proportion_ = (1 / series.length) * process; - } else { - item._proportion_ = (item.data / count) * process; - if (type == "area") { - item._rose_proportion_ = (1 / series.length) * process; - } else { - item._rose_proportion_ = (item.data / count) * process; - } - } - item._radius_ = minRadius + radiusLength * ((item.data - minData) / (maxData - minData)) || radius; - } - for (let i = 0; i < series.length; i++) { - let item = series[i]; - item._start_ = _start_; - _start_ += 2 * item._rose_proportion_ * Math.PI; - } - return series; -} - -function getArcbarDataPoints(series, arcbarOption) { - var process = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1; - if (process == 1) { - process = 0.999999; - } - for (let i = 0; i < series.length; i++) { - let item = series[i]; - item.data = item.data === null ? 0 : item.data; - let totalAngle; - if (arcbarOption.type == "circle") { - totalAngle = 2; - } else { - if (arcbarOption.direction == "ccw") { - if (arcbarOption.startAngle < arcbarOption.endAngle) { - totalAngle = 2 + arcbarOption.startAngle - arcbarOption.endAngle; - } else { - totalAngle = arcbarOption.startAngle - arcbarOption.endAngle; - } - } else { - if (arcbarOption.endAngle < arcbarOption.startAngle) { - totalAngle = 2 + arcbarOption.endAngle - arcbarOption.startAngle; - } else { - totalAngle = arcbarOption.startAngle - arcbarOption.endAngle; - } - } - } - item._proportion_ = totalAngle * item.data * process + arcbarOption.startAngle; - if (arcbarOption.direction == "ccw") { - item._proportion_ = arcbarOption.startAngle - totalAngle * item.data * process; - } - if (item._proportion_ >= 2) { - item._proportion_ = item._proportion_ % 2; - } - } - return series; -} - -function getGaugeArcbarDataPoints(series, arcbarOption) { - var process = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1; - if (process == 1) { - process = 0.999999; - } - for (let i = 0; i < series.length; i++) { - let item = series[i]; - item.data = item.data === null ? 0 : item.data; - let totalAngle; - if (arcbarOption.type == "circle") { - totalAngle = 2; - } else { - if (arcbarOption.endAngle < arcbarOption.startAngle) { - totalAngle = 2 + arcbarOption.endAngle - arcbarOption.startAngle; - } else { - totalAngle = arcbarOption.startAngle - arcbarOption.endAngle; - } - } - item._proportion_ = totalAngle * item.data * process + arcbarOption.startAngle; - if (item._proportion_ >= 2) { - item._proportion_ = item._proportion_ % 2; - } - } - return series; -} - -function getGaugeAxisPoints(categories, startAngle, endAngle) { - let totalAngle; - if (endAngle < startAngle) { - totalAngle = 2 + endAngle - startAngle; - } else { - totalAngle = startAngle - endAngle; - } - let tempStartAngle = startAngle; - for (let i = 0; i < categories.length; i++) { - categories[i].value = categories[i].value === null ? 0 : categories[i].value; - categories[i]._startAngle_ = tempStartAngle; - categories[i]._endAngle_ = totalAngle * categories[i].value + startAngle; - if (categories[i]._endAngle_ >= 2) { - categories[i]._endAngle_ = categories[i]._endAngle_ % 2; - } - tempStartAngle = categories[i]._endAngle_; - } - return categories; -} - -function getGaugeDataPoints(series, categories, gaugeOption) { - let process = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1; - for (let i = 0; i < series.length; i++) { - let item = series[i]; - item.data = item.data === null ? 0 : item.data; - if (gaugeOption.pointer.color == "auto") { - for (let i = 0; i < categories.length; i++) { - if (item.data <= categories[i].value) { - item.color = categories[i].color; - break; - } - } - } else { - item.color = gaugeOption.pointer.color; - } - let totalAngle; - if (gaugeOption.endAngle < gaugeOption.startAngle) { - totalAngle = 2 + gaugeOption.endAngle - gaugeOption.startAngle; - } else { - totalAngle = gaugeOption.startAngle - gaugeOption.endAngle; - } - item._endAngle_ = totalAngle * item.data + gaugeOption.startAngle; - item._oldAngle_ = gaugeOption.oldAngle; - if (gaugeOption.oldAngle < gaugeOption.endAngle) { - item._oldAngle_ += 2; - } - if (item.data >= gaugeOption.oldData) { - item._proportion_ = (item._endAngle_ - item._oldAngle_) * process + gaugeOption.oldAngle; - } else { - item._proportion_ = item._oldAngle_ - (item._oldAngle_ - item._endAngle_) * process; - } - if (item._proportion_ >= 2) { - item._proportion_ = item._proportion_ % 2; - } - } - return series; -} - -function getPieTextMaxLength(series, config, context, opts) { - series = getPieDataPoints(series); - let maxLength = 0; - for (let i = 0; i < series.length; i++) { - let item = series[i]; - let text = item.formatter ? item.formatter(+item._proportion_.toFixed(2)) : util.toFixed(item._proportion_ * 100) + "%"; - maxLength = Math.max(maxLength, measureText(text, item.textSize * opts.pix || config.fontSize, context)); - } - return maxLength; -} - -function fixColumeData(points, eachSpacing, columnLen, index, config, opts) { - return points.map(function (item) { - if (item === null) { - return null; - } - var seriesGap = 0; - var categoryGap = 0; - if (opts.type == "mix") { - seriesGap = opts.extra.mix.column.seriesGap * opts.pix || 0; - categoryGap = opts.extra.mix.column.categoryGap * opts.pix || 0; - } else { - seriesGap = opts.extra.column.seriesGap * opts.pix || 0; - categoryGap = opts.extra.column.categoryGap * opts.pix || 0; - } - seriesGap = Math.min(seriesGap, eachSpacing / columnLen); - categoryGap = Math.min(categoryGap, eachSpacing / columnLen); - item.width = Math.ceil((eachSpacing - 2 * categoryGap - seriesGap * (columnLen - 1)) / columnLen); - if (opts.extra.mix && opts.extra.mix.column.width && +opts.extra.mix.column.width > 0) { - item.width = Math.min(item.width, +opts.extra.mix.column.width * opts.pix); - } - if (opts.extra.column && opts.extra.column.width && +opts.extra.column.width > 0) { - item.width = Math.min(item.width, +opts.extra.column.width * opts.pix); - } - if (item.width <= 0) { - item.width = 1; - } - item.x += (index + 0.5 - columnLen / 2) * (item.width + seriesGap); - return item; - }); -} - -function fixBarData(points, eachSpacing, columnLen, index, config, opts) { - return points.map(function (item) { - if (item === null) { - return null; - } - var seriesGap = 0; - var categoryGap = 0; - seriesGap = opts.extra.bar.seriesGap * opts.pix || 0; - categoryGap = opts.extra.bar.categoryGap * opts.pix || 0; - seriesGap = Math.min(seriesGap, eachSpacing / columnLen); - categoryGap = Math.min(categoryGap, eachSpacing / columnLen); - item.width = Math.ceil((eachSpacing - 2 * categoryGap - seriesGap * (columnLen - 1)) / columnLen); - if (opts.extra.bar && opts.extra.bar.width && +opts.extra.bar.width > 0) { - item.width = Math.min(item.width, +opts.extra.bar.width * opts.pix); - } - if (item.width <= 0) { - item.width = 1; - } - item.y += (index + 0.5 - columnLen / 2) * (item.width + seriesGap); - return item; - }); -} - -function fixColumeMeterData(points, eachSpacing, columnLen, index, config, opts, border) { - var categoryGap = opts.extra.column.categoryGap * opts.pix || 0; - return points.map(function (item) { - if (item === null) { - return null; - } - item.width = eachSpacing - 2 * categoryGap; - if (opts.extra.column && opts.extra.column.width && +opts.extra.column.width > 0) { - item.width = Math.min(item.width, +opts.extra.column.width * opts.pix); - } - if (index > 0) { - item.width -= border; - } - return item; - }); -} - -function fixColumeStackData(points, eachSpacing, columnLen, index, config, opts, series) { - var categoryGap = opts.extra.column.categoryGap * opts.pix || 0; - return points.map(function (item, indexn) { - if (item === null) { - return null; - } - item.width = Math.ceil(eachSpacing - 2 * categoryGap); - if (opts.extra.column && opts.extra.column.width && +opts.extra.column.width > 0) { - item.width = Math.min(item.width, +opts.extra.column.width * opts.pix); - } - if (item.width <= 0) { - item.width = 1; - } - return item; - }); -} - -function fixBarStackData(points, eachSpacing, columnLen, index, config, opts, series) { - var categoryGap = opts.extra.bar.categoryGap * opts.pix || 0; - return points.map(function (item, indexn) { - if (item === null) { - return null; - } - item.width = Math.ceil(eachSpacing - 2 * categoryGap); - if (opts.extra.bar && opts.extra.bar.width && +opts.extra.bar.width > 0) { - item.width = Math.min(item.width, +opts.extra.bar.width * opts.pix); - } - if (item.width <= 0) { - item.width = 1; - } - return item; - }); -} - -function getXAxisPoints(categories, opts, config) { - var spacingValid = opts.width - opts.area[1] - opts.area[3]; - var dataCount = opts.enableScroll ? Math.min(opts.xAxis.itemCount, categories.length) : categories.length; - if ((opts.type == "line" || opts.type == "area" || opts.type == "scatter" || opts.type == "bubble" || opts.type == "bar") && dataCount > 1 && opts.xAxis.boundaryGap == "justify") { - dataCount -= 1; - } - var widthRatio = 0; - if (opts.type == "mount" && opts.extra && opts.extra.mount && opts.extra.mount.widthRatio && opts.extra.mount.widthRatio > 1) { - if (opts.extra.mount.widthRatio > 2) opts.extra.mount.widthRatio = 2; - widthRatio = opts.extra.mount.widthRatio - 1; - dataCount += widthRatio; - } - var eachSpacing = spacingValid / dataCount; - var xAxisPoints = []; - var startX = opts.area[3]; - var endX = opts.width - opts.area[1]; - categories.forEach(function (item, index) { - xAxisPoints.push(startX + (widthRatio / 2) * eachSpacing + index * eachSpacing); - }); - if (opts.xAxis.boundaryGap !== "justify") { - if (opts.enableScroll === true) { - xAxisPoints.push(startX + widthRatio * eachSpacing + categories.length * eachSpacing); - } else { - xAxisPoints.push(endX); - } - } - return { - xAxisPoints: xAxisPoints, - startX: startX, - endX: endX, - eachSpacing: eachSpacing, - }; -} - -function getCandleDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config) { - var process = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : 1; - var points = []; - var validHeight = opts.height - opts.area[0] - opts.area[2]; - data.forEach(function (item, index) { - if (item === null) { - points.push(null); - } else { - var cPoints = []; - item.forEach(function (items, indexs) { - var point = {}; - point.x = xAxisPoints[index] + Math.round(eachSpacing / 2); - var value = items.value || items; - var height = (validHeight * (value - minRange)) / (maxRange - minRange); - height *= process; - point.y = opts.height - Math.round(height) - opts.area[2]; - cPoints.push(point); - }); - points.push(cPoints); - } - }); - return points; -} - -function getDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config) { - var process = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : 1; - var boundaryGap = "center"; - if (opts.type == "line" || opts.type == "area" || opts.type == "scatter" || opts.type == "bubble") { - boundaryGap = opts.xAxis.boundaryGap; - } - var points = []; - var validHeight = opts.height - opts.area[0] - opts.area[2]; - var validWidth = opts.width - opts.area[1] - opts.area[3]; - data.forEach(function (item, index) { - if (item === null) { - points.push(null); - } else { - var point = {}; - point.color = item.color; - point.x = xAxisPoints[index]; - var value = item; - if (typeof item === "object" && item !== null) { - if (item.constructor.toString().indexOf("Array") > -1) { - let xranges, xminRange, xmaxRange; - xranges = [].concat(opts.chartData.xAxisData.ranges); - xminRange = xranges.shift(); - xmaxRange = xranges.pop(); - value = item[1]; - point.x = opts.area[3] + (validWidth * (item[0] - xminRange)) / (xmaxRange - xminRange); - if (opts.type == "bubble") { - point.r = item[2]; - point.t = item[3]; - } - } else { - value = item.value; - } - } - if (boundaryGap == "center") { - point.x += eachSpacing / 2; - } - var height = (validHeight * (value - minRange)) / (maxRange - minRange); - height *= process; - point.y = opts.height - height - opts.area[2]; - points.push(point); - } - }); - return points; -} - -function getLineDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config, lineOption, process) { - var process = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : 1; - var boundaryGap = opts.xAxis.boundaryGap; - var points = []; - var validHeight = opts.height - opts.area[0] - opts.area[2]; - var validWidth = opts.width - opts.area[1] - opts.area[3]; - data.forEach(function (item, index) { - if (item === null) { - points.push(null); - } else { - var point = {}; - point.color = item.color; - if (lineOption.animation == "vertical") { - point.x = xAxisPoints[index]; - var value = item; - if (typeof item === "object" && item !== null) { - if (item.constructor.toString().indexOf("Array") > -1) { - let xranges, xminRange, xmaxRange; - xranges = [].concat(opts.chartData.xAxisData.ranges); - xminRange = xranges.shift(); - xmaxRange = xranges.pop(); - value = item[1]; - point.x = opts.area[3] + (validWidth * (item[0] - xminRange)) / (xmaxRange - xminRange); - } else { - value = item.value; - } - } - if (boundaryGap == "center") { - point.x += eachSpacing / 2; - } - var height = (validHeight * (value - minRange)) / (maxRange - minRange); - height *= process; - point.y = opts.height - height - opts.area[2]; - points.push(point); - } else { - point.x = xAxisPoints[0] + eachSpacing * index * process; - var value = item; - if (boundaryGap == "center") { - point.x += eachSpacing / 2; - } - var height = (validHeight * (value - minRange)) / (maxRange - minRange); - point.y = opts.height - height - opts.area[2]; - points.push(point); - } - } - }); - return points; -} - -function getColumnDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config, zeroPoints, process) { - var process = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : 1; - var points = []; - var validHeight = opts.height - opts.area[0] - opts.area[2]; - var validWidth = opts.width - opts.area[1] - opts.area[3]; - data.forEach(function (item, index) { - if (item === null) { - points.push(null); - } else { - var point = {}; - point.color = item.color; - point.x = xAxisPoints[index]; - var value = item; - if (typeof item === "object" && item !== null) { - if (item.constructor.toString().indexOf("Array") > -1) { - let xranges, xminRange, xmaxRange; - xranges = [].concat(opts.chartData.xAxisData.ranges); - xminRange = xranges.shift(); - xmaxRange = xranges.pop(); - value = item[1]; - point.x = opts.area[3] + (validWidth * (item[0] - xminRange)) / (xmaxRange - xminRange); - } else { - value = item.value; - } - } - point.x += eachSpacing / 2; - var height = (validHeight * (value * process - minRange)) / (maxRange - minRange); - point.y = opts.height - height - opts.area[2]; - points.push(point); - } - }); - return points; -} - -function getMountDataPoints(series, minRange, maxRange, xAxisPoints, eachSpacing, opts, mountOption, zeroPoints) { - var process = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : 1; - var points = []; - var validHeight = opts.height - opts.area[0] - opts.area[2]; - var validWidth = opts.width - opts.area[1] - opts.area[3]; - var mountWidth = eachSpacing * mountOption.widthRatio; - series.forEach(function (item, index) { - if (item === null) { - points.push(null); - } else { - var point = {}; - point.color = item.color; - point.x = xAxisPoints[index]; - point.x += eachSpacing / 2; - var value = item.data; - var height = (validHeight * (value * process - minRange)) / (maxRange - minRange); - point.y = opts.height - height - opts.area[2]; - point.value = value; - point.width = mountWidth; - points.push(point); - } - }); - return points; -} - -function getBarDataPoints(data, minRange, maxRange, yAxisPoints, eachSpacing, opts, config) { - var process = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : 1; - var points = []; - var validHeight = opts.height - opts.area[0] - opts.area[2]; - var validWidth = opts.width - opts.area[1] - opts.area[3]; - data.forEach(function (item, index) { - if (item === null) { - points.push(null); - } else { - var point = {}; - point.color = item.color; - point.y = yAxisPoints[index]; - var value = item; - if (typeof item === "object" && item !== null) { - value = item.value; - } - var height = (validWidth * (value - minRange)) / (maxRange - minRange); - height *= process; - point.height = height; - point.value = value; - point.x = height + opts.area[3]; - points.push(point); - } - }); - return points; -} - -function getStackDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config, seriesIndex, stackSeries) { - var process = arguments.length > 9 && arguments[9] !== undefined ? arguments[9] : 1; - var points = []; - var validHeight = opts.height - opts.area[0] - opts.area[2]; - data.forEach(function (item, index) { - if (item === null) { - points.push(null); - } else { - var point = {}; - point.color = item.color; - point.x = xAxisPoints[index] + Math.round(eachSpacing / 2); - - if (seriesIndex > 0) { - var value = 0; - for (let i = 0; i <= seriesIndex; i++) { - value += stackSeries[i].data[index]; - } - var value0 = value - item; - var height = (validHeight * (value - minRange)) / (maxRange - minRange); - var height0 = (validHeight * (value0 - minRange)) / (maxRange - minRange); - } else { - var value = item; - if (typeof item === "object" && item !== null) { - value = item.value; - } - var height = (validHeight * (value - minRange)) / (maxRange - minRange); - var height0 = 0; - } - var heightc = height0; - height *= process; - heightc *= process; - point.y = opts.height - Math.round(height) - opts.area[2]; - point.y0 = opts.height - Math.round(heightc) - opts.area[2]; - points.push(point); - } - }); - return points; -} - -function getBarStackDataPoints(data, minRange, maxRange, yAxisPoints, eachSpacing, opts, config, seriesIndex, stackSeries) { - var process = arguments.length > 9 && arguments[9] !== undefined ? arguments[9] : 1; - var points = []; - var validHeight = opts.width - opts.area[1] - opts.area[3]; - data.forEach(function (item, index) { - if (item === null) { - points.push(null); - } else { - var point = {}; - point.color = item.color; - point.y = yAxisPoints[index]; - if (seriesIndex > 0) { - var value = 0; - for (let i = 0; i <= seriesIndex; i++) { - value += stackSeries[i].data[index]; - } - var value0 = value - item; - var height = (validHeight * (value - minRange)) / (maxRange - minRange); - var height0 = (validHeight * (value0 - minRange)) / (maxRange - minRange); - } else { - var value = item; - if (typeof item === "object" && item !== null) { - value = item.value; - } - var height = (validHeight * (value - minRange)) / (maxRange - minRange); - var height0 = 0; - } - var heightc = height0; - height *= process; - heightc *= process; - point.height = height - heightc; - point.x = opts.area[3] + height; - point.x0 = opts.area[3] + heightc; - points.push(point); - } - }); - return points; -} - -function getYAxisTextList(series, opts, config, stack, yData) { - var index = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : -1; - var data; - if (stack == "stack") { - data = dataCombineStack(series, opts.categories.length); - } else { - data = dataCombine(series); - } - var sorted = []; - // remove null from data - data = data.filter(function (item) { - //return item !== null; - if (typeof item === "object" && item !== null) { - if (item.constructor.toString().indexOf("Array") > -1) { - return item !== null; - } else { - return item.value !== null; - } - } else { - return item !== null; - } - }); - data.map(function (item) { - if (typeof item === "object") { - if (item.constructor.toString().indexOf("Array") > -1) { - if (opts.type == "candle") { - item.map(function (subitem) { - sorted.push(subitem); - }); - } else { - sorted.push(item[1]); - } - } else { - sorted.push(item.value); - } - } else { - sorted.push(item); - } - }); - var minData = yData.min || 0; - var maxData = yData.max || 0; - if (sorted.length > 0) { - minData = Math.min.apply(this, sorted); - maxData = Math.max.apply(this, sorted); - } - if (minData === maxData) { - if (maxData == 0) { - maxData = 10; - } else { - minData = 0; - } - } - var dataRange = getDataRange(minData, maxData); - var minRange = yData.min === undefined || yData.min === null ? dataRange.minRange : yData.min; - var maxRange = yData.max === undefined || yData.max === null ? dataRange.maxRange : yData.max; - var eachRange = (maxRange - minRange) / opts.yAxis.splitNumber; - var range = []; - for (var i = 0; i <= opts.yAxis.splitNumber; i++) { - range.push(minRange + eachRange * i); - } - return range.reverse(); -} - -function calYAxisData(series, opts, config, context) { - //堆叠图重算Y轴 - var columnstyle = assign( - {}, - { - type: "", - }, - opts.extra.column - ); - //如果是多Y轴,重新计算 - var YLength = opts.yAxis.data.length; - var newSeries = new Array(YLength); - if (YLength > 0) { - for (let i = 0; i < YLength; i++) { - newSeries[i] = []; - for (let j = 0; j < series.length; j++) { - if (series[j].index == i) { - newSeries[i].push(series[j]); - } - } - } - var rangesArr = new Array(YLength); - var rangesFormatArr = new Array(YLength); - var yAxisWidthArr = new Array(YLength); - - for (let i = 0; i < YLength; i++) { - let yData = opts.yAxis.data[i]; - //如果总开关不显示,强制每个Y轴为不显示 - if (opts.yAxis.disabled == true) { - yData.disabled = true; - } - if (yData.type === "categories") { - if (!yData.formatter) { - yData.formatter = (val, index, opts) => { - return val + (yData.unit || ""); - }; - } - yData.categories = yData.categories || opts.categories; - rangesArr[i] = yData.categories; - } else { - if (!yData.formatter) { - yData.formatter = (val, index, opts) => { - return util.toFixed(val, yData.tofix || 0) + (yData.unit || ""); - }; - } - rangesArr[i] = getYAxisTextList(newSeries[i], opts, config, columnstyle.type, yData, i); - } - let yAxisFontSizes = yData.fontSize * opts.pix || config.fontSize; - yAxisWidthArr[i] = { - position: yData.position ? yData.position : "left", - width: 0, - }; - rangesFormatArr[i] = rangesArr[i].map(function (items, index) { - items = yData.formatter(items, index, opts); - yAxisWidthArr[i].width = Math.max(yAxisWidthArr[i].width, measureText(items, yAxisFontSizes, context) + 5); - return items; - }); - let calibration = yData.calibration ? 4 * opts.pix : 0; - yAxisWidthArr[i].width += calibration + 3 * opts.pix; - if (yData.disabled === true) { - yAxisWidthArr[i].width = 0; - } - } - } else { - var rangesArr = new Array(1); - var rangesFormatArr = new Array(1); - var yAxisWidthArr = new Array(1); - if (opts.type === "bar") { - rangesArr[0] = opts.categories; - if (!opts.yAxis.formatter) { - opts.yAxis.formatter = (val, index, opts) => { - return val + (opts.yAxis.unit || ""); - }; - } - } else { - if (!opts.yAxis.formatter) { - opts.yAxis.formatter = (val, index, opts) => { - return val.toFixed(opts.yAxis.tofix) + (opts.yAxis.unit || ""); - }; - } - rangesArr[0] = getYAxisTextList(series, opts, config, columnstyle.type, {}); - } - yAxisWidthArr[0] = { - position: "left", - width: 0, - }; - var yAxisFontSize = opts.yAxis.fontSize * opts.pix || config.fontSize; - rangesFormatArr[0] = rangesArr[0].map(function (item, index) { - item = opts.yAxis.formatter(item, index, opts); - yAxisWidthArr[0].width = Math.max(yAxisWidthArr[0].width, measureText(item, yAxisFontSize, context) + 5); - return item; - }); - yAxisWidthArr[0].width += 3 * opts.pix; - if (opts.yAxis.disabled === true) { - yAxisWidthArr[0] = { - position: "left", - width: 0, - }; - opts.yAxis.data[0] = { - disabled: true, - }; - } else { - opts.yAxis.data[0] = { - disabled: false, - position: "left", - max: opts.yAxis.max, - min: opts.yAxis.min, - formatter: opts.yAxis.formatter, - }; - if (opts.type === "bar") { - opts.yAxis.data[0].categories = opts.categories; - opts.yAxis.data[0].type = "categories"; - } - } - } - return { - rangesFormat: rangesFormatArr, - ranges: rangesArr, - yAxisWidth: yAxisWidthArr, - }; -} - -function calTooltipYAxisData(point, series, opts, config, eachSpacing) { - let ranges = [].concat(opts.chartData.yAxisData.ranges); - let spacingValid = opts.height - opts.area[0] - opts.area[2]; - let minAxis = opts.area[0]; - let items = []; - for (let i = 0; i < ranges.length; i++) { - let maxVal = Math.max.apply(this, ranges[i]); - let minVal = Math.min.apply(this, ranges[i]); - let item = maxVal - ((maxVal - minVal) * (point - minAxis)) / spacingValid; - item = opts.yAxis.data && opts.yAxis.data[i].formatter ? opts.yAxis.data[i].formatter(item, i, opts) : item.toFixed(0); - items.push(String(item)); - } - return items; -} - -function calMarkLineData(points, opts) { - let minRange, maxRange; - let spacingValid = opts.height - opts.area[0] - opts.area[2]; - for (let i = 0; i < points.length; i++) { - points[i].yAxisIndex = points[i].yAxisIndex ? points[i].yAxisIndex : 0; - let range = [].concat(opts.chartData.yAxisData.ranges[points[i].yAxisIndex]); - minRange = range.pop(); - maxRange = range.shift(); - let height = (spacingValid * (points[i].value - minRange)) / (maxRange - minRange); - points[i].y = opts.height - Math.round(height) - opts.area[2]; - } - return points; -} - -function contextRotate(context, opts) { - if (opts.rotateLock !== true) { - context.translate(opts.height, 0); - context.rotate((90 * Math.PI) / 180); - } else if (opts._rotate_ !== true) { - context.translate(opts.height, 0); - context.rotate((90 * Math.PI) / 180); - opts._rotate_ = true; - } -} - -function drawPointShape(points, color, shape, context, opts) { - context.beginPath(); - if (opts.dataPointShapeType == "hollow") { - context.setStrokeStyle(color); - context.setFillStyle(opts.background); - context.setLineWidth(2 * opts.pix); - } else { - context.setStrokeStyle("#ffffff"); - context.setFillStyle(color); - context.setLineWidth(1 * opts.pix); - } - if (shape === "diamond") { - points.forEach(function (item, index) { - if (item !== null) { - context.moveTo(item.x, item.y - 4.5); - context.lineTo(item.x - 4.5, item.y); - context.lineTo(item.x, item.y + 4.5); - context.lineTo(item.x + 4.5, item.y); - context.lineTo(item.x, item.y - 4.5); - } - }); - } else if (shape === "circle") { - points.forEach(function (item, index) { - if (item !== null) { - context.moveTo(item.x + 2.5 * opts.pix, item.y); - context.arc(item.x, item.y, 3 * opts.pix, 0, 2 * Math.PI, false); - } - }); - } else if (shape === "square") { - points.forEach(function (item, index) { - if (item !== null) { - context.moveTo(item.x - 3.5, item.y - 3.5); - context.rect(item.x - 3.5, item.y - 3.5, 7, 7); - } - }); - } else if (shape === "triangle") { - points.forEach(function (item, index) { - if (item !== null) { - context.moveTo(item.x, item.y - 4.5); - context.lineTo(item.x - 4.5, item.y + 4.5); - context.lineTo(item.x + 4.5, item.y + 4.5); - context.lineTo(item.x, item.y - 4.5); - } - }); - } else if (shape === "none") { - return; - } - context.closePath(); - context.fill(); - context.stroke(); -} - -function drawActivePoint(points, color, shape, context, opts, option, seriesIndex) { - if (!opts.tooltip) { - return; - } - if (opts.tooltip.group.length > 0 && opts.tooltip.group.includes(seriesIndex) == false) { - return; - } - var pointIndex = typeof opts.tooltip.index === "number" ? opts.tooltip.index : opts.tooltip.index[opts.tooltip.group.indexOf(seriesIndex)]; - context.beginPath(); - if (option.activeType == "hollow") { - context.setStrokeStyle(color); - context.setFillStyle(opts.background); - context.setLineWidth(2 * opts.pix); - } else { - context.setStrokeStyle("#ffffff"); - context.setFillStyle(color); - context.setLineWidth(1 * opts.pix); - } - if (shape === "diamond") { - points.forEach(function (item, index) { - if (item !== null && pointIndex == index) { - context.moveTo(item.x, item.y - 4.5); - context.lineTo(item.x - 4.5, item.y); - context.lineTo(item.x, item.y + 4.5); - context.lineTo(item.x + 4.5, item.y); - context.lineTo(item.x, item.y - 4.5); - } - }); - } else if (shape === "circle") { - points.forEach(function (item, index) { - if (item !== null && pointIndex == index) { - context.moveTo(item.x + 2.5 * opts.pix, item.y); - context.arc(item.x, item.y, 3 * opts.pix, 0, 2 * Math.PI, false); - } - }); - } else if (shape === "square") { - points.forEach(function (item, index) { - if (item !== null && pointIndex == index) { - context.moveTo(item.x - 3.5, item.y - 3.5); - context.rect(item.x - 3.5, item.y - 3.5, 7, 7); - } - }); - } else if (shape === "triangle") { - points.forEach(function (item, index) { - if (item !== null && pointIndex == index) { - context.moveTo(item.x, item.y - 4.5); - context.lineTo(item.x - 4.5, item.y + 4.5); - context.lineTo(item.x + 4.5, item.y + 4.5); - context.lineTo(item.x, item.y - 4.5); - } - }); - } else if (shape === "none") { - return; - } - context.closePath(); - context.fill(); - context.stroke(); -} - -function drawRingTitle(opts, config, context, center) { - var titlefontSize = opts.title.fontSize || config.titleFontSize; - var subtitlefontSize = opts.subtitle.fontSize || config.subtitleFontSize; - var title = opts.title.name || ""; - var subtitle = opts.subtitle.name || ""; - var titleFontColor = opts.title.color || opts.fontColor; - var subtitleFontColor = opts.subtitle.color || opts.fontColor; - var titleHeight = title ? titlefontSize : 0; - var subtitleHeight = subtitle ? subtitlefontSize : 0; - var margin = 5; - if (subtitle) { - var textWidth = measureText(subtitle, subtitlefontSize * opts.pix, context); - var startX = center.x - textWidth / 2 + (opts.subtitle.offsetX || 0) * opts.pix; - var startY = center.y + (subtitlefontSize * opts.pix) / 2 + (opts.subtitle.offsetY || 0) * opts.pix; - if (title) { - startY += (titleHeight * opts.pix + margin) / 2; - } - context.beginPath(); - context.setFontSize(subtitlefontSize * opts.pix); - context.setFillStyle(subtitleFontColor); - context.fillText(subtitle, startX, startY); - context.closePath(); - context.stroke(); - } - if (title) { - var _textWidth = measureText(title, titlefontSize * opts.pix, context); - var _startX = center.x - _textWidth / 2 + (opts.title.offsetX || 0); - var _startY = center.y + (titlefontSize * opts.pix) / 2 + (opts.title.offsetY || 0) * opts.pix; - if (subtitle) { - _startY -= (subtitleHeight * opts.pix + margin) / 2; - } - context.beginPath(); - context.setFontSize(titlefontSize * opts.pix); - context.setFillStyle(titleFontColor); - context.fillText(title, _startX, _startY); - context.closePath(); - context.stroke(); - } -} - -function drawPointText(points, series, config, context, opts) { - // 绘制数据文案 - var data = series.data; - var textOffset = series.textOffset ? series.textOffset : 0; - points.forEach(function (item, index) { - if (item !== null) { - context.beginPath(); - var fontSize = series.textSize ? series.textSize * opts.pix : config.fontSize; - context.setFontSize(fontSize); - context.setFillStyle(series.textColor || opts.fontColor); - var value = data[index]; - if (typeof data[index] === "object" && data[index] !== null) { - if (data[index].constructor.toString().indexOf("Array") > -1) { - value = data[index][1]; - } else { - value = data[index].value; - } - } - var formatVal = series.formatter ? series.formatter(value, index, series, opts) : value; - context.setTextAlign("center"); - context.fillText(String(formatVal), item.x, item.y - 4 + textOffset * opts.pix); - context.closePath(); - context.stroke(); - context.setTextAlign("left"); - } - }); -} - -function drawColumePointText(points, series, config, context, opts) { - // 绘制数据文案 - var data = series.data; - var textOffset = series.textOffset ? series.textOffset : 0; - var Position = opts.extra.column.labelPosition; - points.forEach(function (item, index) { - if (item !== null) { - context.beginPath(); - var fontSize = series.textSize ? series.textSize * opts.pix : config.fontSize; - context.setFontSize(fontSize); - context.setFillStyle(series.textColor || opts.fontColor); - var value = data[index]; - if (typeof data[index] === "object" && data[index] !== null) { - if (data[index].constructor.toString().indexOf("Array") > -1) { - value = data[index][1]; - } else { - value = data[index].value; - } - } - var formatVal = series.formatter ? series.formatter(value, index, series, opts) : value; - context.setTextAlign("center"); - var startY = item.y - 4 * opts.pix + textOffset * opts.pix; - if (item.y > series.zeroPoints) { - startY = item.y + textOffset * opts.pix + fontSize; - } - if (Position == "insideTop") { - startY = item.y + fontSize + textOffset * opts.pix; - if (item.y > series.zeroPoints) { - startY = item.y - textOffset * opts.pix - 4 * opts.pix; - } - } - if (Position == "center") { - startY = item.y + textOffset * opts.pix + (opts.height - opts.area[2] - item.y + fontSize) / 2; - if (series.zeroPoints < opts.height - opts.area[2]) { - startY = item.y + textOffset * opts.pix + (series.zeroPoints - item.y + fontSize) / 2; - } - if (item.y > series.zeroPoints) { - startY = item.y - textOffset * opts.pix - (item.y - series.zeroPoints - fontSize) / 2; - } - if (opts.extra.column.type == "stack") { - startY = item.y + textOffset * opts.pix + (item.y0 - item.y + fontSize) / 2; - } - } - if (Position == "bottom") { - startY = opts.height - opts.area[2] + textOffset * opts.pix - 4 * opts.pix; - if (series.zeroPoints < opts.height - opts.area[2]) { - startY = series.zeroPoints + textOffset * opts.pix - 4 * opts.pix; - } - if (item.y > series.zeroPoints) { - startY = series.zeroPoints - textOffset * opts.pix + fontSize + 2 * opts.pix; - } - if (opts.extra.column.type == "stack") { - startY = item.y0 + textOffset * opts.pix - 4 * opts.pix; - } - } - context.fillText(String(formatVal), item.x, startY); - context.closePath(); - context.stroke(); - context.setTextAlign("left"); - } - }); -} - -function drawMountPointText(points, series, config, context, opts, zeroPoints) { - // 绘制数据文案 - var data = series.data; - var textOffset = series.textOffset ? series.textOffset : 0; - var Position = opts.extra.mount.labelPosition; - points.forEach(function (item, index) { - if (item !== null) { - context.beginPath(); - var fontSize = series[index].textSize ? series[index].textSize * opts.pix : config.fontSize; - context.setFontSize(fontSize); - context.setFillStyle(series[index].textColor || opts.fontColor); - var value = item.value; - var formatVal = series[index].formatter ? series[index].formatter(value, index, series, opts) : value; - context.setTextAlign("center"); - var startY = item.y - 4 * opts.pix + textOffset * opts.pix; - if (item.y > zeroPoints) { - startY = item.y + textOffset * opts.pix + fontSize; - } - context.fillText(String(formatVal), item.x, startY); - context.closePath(); - context.stroke(); - context.setTextAlign("left"); - } - }); -} - -function drawBarPointText(points, series, config, context, opts) { - // 绘制数据文案 - var data = series.data; - var textOffset = series.textOffset ? series.textOffset : 0; - points.forEach(function (item, index) { - if (item !== null) { - context.beginPath(); - var fontSize = series.textSize ? series.textSize * opts.pix : config.fontSize; - context.setFontSize(fontSize); - context.setFillStyle(series.textColor || opts.fontColor); - var value = data[index]; - if (typeof data[index] === "object" && data[index] !== null) { - value = data[index].value; - } - var formatVal = series.formatter ? series.formatter(value, index, series, opts) : value; - context.setTextAlign("left"); - context.fillText(String(formatVal), item.x + 4 * opts.pix, item.y + fontSize / 2 - 3); - context.closePath(); - context.stroke(); - } - }); -} - -function drawGaugeLabel(gaugeOption, radius, centerPosition, opts, config, context) { - radius -= gaugeOption.width / 2 + gaugeOption.labelOffset * opts.pix; - radius = radius < 10 ? 10 : radius; - let totalAngle; - if (gaugeOption.endAngle < gaugeOption.startAngle) { - totalAngle = 2 + gaugeOption.endAngle - gaugeOption.startAngle; - } else { - totalAngle = gaugeOption.startAngle - gaugeOption.endAngle; - } - let splitAngle = totalAngle / gaugeOption.splitLine.splitNumber; - let totalNumber = gaugeOption.endNumber - gaugeOption.startNumber; - let splitNumber = totalNumber / gaugeOption.splitLine.splitNumber; - let nowAngle = gaugeOption.startAngle; - let nowNumber = gaugeOption.startNumber; - for (let i = 0; i < gaugeOption.splitLine.splitNumber + 1; i++) { - var pos = { - x: radius * Math.cos(nowAngle * Math.PI), - y: radius * Math.sin(nowAngle * Math.PI), - }; - var labelText = gaugeOption.formatter ? gaugeOption.formatter(nowNumber, i, opts) : nowNumber; - pos.x += centerPosition.x - measureText(labelText, config.fontSize, context) / 2; - pos.y += centerPosition.y; - var startX = pos.x; - var startY = pos.y; - context.beginPath(); - context.setFontSize(config.fontSize); - context.setFillStyle(gaugeOption.labelColor || opts.fontColor); - context.fillText(labelText, startX, startY + config.fontSize / 2); - context.closePath(); - context.stroke(); - nowAngle += splitAngle; - if (nowAngle >= 2) { - nowAngle = nowAngle % 2; - } - nowNumber += splitNumber; - } -} - -function drawRadarLabel(angleList, radius, centerPosition, opts, config, context) { - var radarOption = opts.extra.radar || {}; - angleList.forEach(function (angle, index) { - if (radarOption.labelPointShow === true && opts.categories[index] !== "") { - var posPoint = { - x: radius * Math.cos(angle), - y: radius * Math.sin(angle), - }; - var posPointAxis = convertCoordinateOrigin(posPoint.x, posPoint.y, centerPosition); - context.setFillStyle(radarOption.labelPointColor); - context.beginPath(); - context.arc(posPointAxis.x, posPointAxis.y, radarOption.labelPointRadius * opts.pix, 0, 2 * Math.PI, false); - context.closePath(); - context.fill(); - } - if (radarOption.labelShow === true) { - var pos = { - x: (radius + config.radarLabelTextMargin * opts.pix) * Math.cos(angle), - y: (radius + config.radarLabelTextMargin * opts.pix) * Math.sin(angle), - }; - var posRelativeCanvas = convertCoordinateOrigin(pos.x, pos.y, centerPosition); - var startX = posRelativeCanvas.x; - var startY = posRelativeCanvas.y; - if (util.approximatelyEqual(pos.x, 0)) { - startX -= measureText(opts.categories[index] || "", config.fontSize, context) / 2; - } else if (pos.x < 0) { - startX -= measureText(opts.categories[index] || "", config.fontSize, context); - } - context.beginPath(); - context.setFontSize(config.fontSize); - context.setFillStyle(radarOption.labelColor || opts.fontColor); - context.fillText(opts.categories[index] || "", startX, startY + config.fontSize / 2); - context.closePath(); - context.stroke(); - } - }); -} - -function drawPieText(series, opts, config, context, radius, center) { - var lineRadius = config.pieChartLinePadding; - var textObjectCollection = []; - var lastTextObject = null; - var seriesConvert = series.map(function (item, index) { - var text = item.formatter ? item.formatter(item, index, series, opts) : util.toFixed(item._proportion_.toFixed(4) * 100) + "%"; - text = item.labelText ? item.labelText : text; - var arc = 2 * Math.PI - (item._start_ + (2 * Math.PI * item._proportion_) / 2); - if (item._rose_proportion_) { - arc = 2 * Math.PI - (item._start_ + (2 * Math.PI * item._rose_proportion_) / 2); - } - var color = item.color; - var radius = item._radius_; - return { - arc: arc, - text: text, - color: color, - radius: radius, - textColor: item.textColor, - textSize: item.textSize, - labelShow: item.labelShow, - }; - }); - for (let i = 0; i < seriesConvert.length; i++) { - let item = seriesConvert[i]; - // line end - let orginX1 = Math.cos(item.arc) * (item.radius + lineRadius); - let orginY1 = Math.sin(item.arc) * (item.radius + lineRadius); - // line start - let orginX2 = Math.cos(item.arc) * item.radius; - let orginY2 = Math.sin(item.arc) * item.radius; - // text start - let orginX3 = orginX1 >= 0 ? orginX1 + config.pieChartTextPadding : orginX1 - config.pieChartTextPadding; - let orginY3 = orginY1; - let textWidth = measureText(item.text, item.textSize * opts.pix || config.fontSize, context); - let startY = orginY3; - if ( - lastTextObject && - util.isSameXCoordinateArea(lastTextObject.start, { - x: orginX3, - }) - ) { - if (orginX3 > 0) { - startY = Math.min(orginY3, lastTextObject.start.y); - } else if (orginX1 < 0) { - startY = Math.max(orginY3, lastTextObject.start.y); - } else { - if (orginY3 > 0) { - startY = Math.max(orginY3, lastTextObject.start.y); - } else { - startY = Math.min(orginY3, lastTextObject.start.y); - } - } - } - if (orginX3 < 0) { - orginX3 -= textWidth; - } - let textObject = { - lineStart: { - x: orginX2, - y: orginY2, - }, - lineEnd: { - x: orginX1, - y: orginY1, - }, - start: { - x: orginX3, - y: startY, - }, - width: textWidth, - height: config.fontSize, - text: item.text, - color: item.color, - textColor: item.textColor, - textSize: item.textSize, - }; - lastTextObject = avoidCollision(textObject, lastTextObject); - textObjectCollection.push(lastTextObject); - } - for (let i = 0; i < textObjectCollection.length; i++) { - if (seriesConvert[i].labelShow === false) { - continue; - } - let item = textObjectCollection[i]; - let lineStartPoistion = convertCoordinateOrigin(item.lineStart.x, item.lineStart.y, center); - let lineEndPoistion = convertCoordinateOrigin(item.lineEnd.x, item.lineEnd.y, center); - let textPosition = convertCoordinateOrigin(item.start.x, item.start.y, center); - context.setLineWidth(1 * opts.pix); - context.setFontSize(item.textSize * opts.pix || config.fontSize); - context.beginPath(); - context.setStrokeStyle(item.color); - context.setFillStyle(item.color); - context.moveTo(lineStartPoistion.x, lineStartPoistion.y); - let curveStartX = item.start.x < 0 ? textPosition.x + item.width : textPosition.x; - let textStartX = item.start.x < 0 ? textPosition.x - 5 : textPosition.x + 5; - context.quadraticCurveTo(lineEndPoistion.x, lineEndPoistion.y, curveStartX, textPosition.y); - context.moveTo(lineStartPoistion.x, lineStartPoistion.y); - context.stroke(); - context.closePath(); - context.beginPath(); - context.moveTo(textPosition.x + item.width, textPosition.y); - context.arc(curveStartX, textPosition.y, 2 * opts.pix, 0, 2 * Math.PI); - context.closePath(); - context.fill(); - context.beginPath(); - context.setFontSize(item.textSize * opts.pix || config.fontSize); - context.setFillStyle(item.textColor || opts.fontColor); - context.fillText(item.text, textStartX, textPosition.y + 3); - context.closePath(); - context.stroke(); - context.closePath(); - } -} - -function drawToolTipSplitLine(offsetX, opts, config, context) { - var toolTipOption = opts.extra.tooltip || {}; - toolTipOption.gridType = toolTipOption.gridType == undefined ? "solid" : toolTipOption.gridType; - toolTipOption.dashLength = toolTipOption.dashLength == undefined ? 4 : toolTipOption.dashLength; - var startY = opts.area[0]; - var endY = opts.height - opts.area[2]; - if (toolTipOption.gridType == "dash") { - context.setLineDash([toolTipOption.dashLength, toolTipOption.dashLength]); - } - context.setStrokeStyle(toolTipOption.gridColor || "#cccccc"); - context.setLineWidth(1 * opts.pix); - context.beginPath(); - context.moveTo(offsetX, startY); - context.lineTo(offsetX, endY); - context.stroke(); - context.setLineDash([]); - if (toolTipOption.xAxisLabel) { - let labelText = opts.categories[opts.tooltip.index]; - context.setFontSize(config.fontSize); - let textWidth = measureText(labelText, config.fontSize, context); - let textX = offsetX - 0.5 * textWidth; - let textY = endY + 2 * opts.pix; - context.beginPath(); - context.setFillStyle(hexToRgb(toolTipOption.labelBgColor || config.toolTipBackground, toolTipOption.labelBgOpacity || config.toolTipOpacity)); - context.setStrokeStyle(toolTipOption.labelBgColor || config.toolTipBackground); - context.setLineWidth(1 * opts.pix); - context.rect(textX - toolTipOption.boxPadding * opts.pix, textY, textWidth + 2 * toolTipOption.boxPadding * opts.pix, config.fontSize + 2 * toolTipOption.boxPadding * opts.pix); - context.closePath(); - context.stroke(); - context.fill(); - context.beginPath(); - context.setFontSize(config.fontSize); - context.setFillStyle(toolTipOption.labelFontColor || opts.fontColor); - context.fillText(String(labelText), textX, textY + toolTipOption.boxPadding * opts.pix + config.fontSize); - context.closePath(); - context.stroke(); - } -} - -function drawMarkLine(opts, config, context) { - let markLineOption = assign( - {}, - { - type: "solid", - dashLength: 4, - data: [], - }, - opts.extra.markLine - ); - let startX = opts.area[3]; - let endX = opts.width - opts.area[1]; - let points = calMarkLineData(markLineOption.data, opts); - for (let i = 0; i < points.length; i++) { - let item = assign( - {}, - { - lineColor: "#DE4A42", - showLabel: false, - labelFontSize: 13, - labelPadding: 6, - labelFontColor: "#666666", - labelBgColor: "#DFE8FF", - labelBgOpacity: 0.8, - labelAlign: "left", - labelOffsetX: 0, - labelOffsetY: 0, - }, - points[i] - ); - if (markLineOption.type == "dash") { - context.setLineDash([markLineOption.dashLength, markLineOption.dashLength]); - } - context.setStrokeStyle(item.lineColor); - context.setLineWidth(1 * opts.pix); - context.beginPath(); - context.moveTo(startX, item.y); - context.lineTo(endX, item.y); - context.stroke(); - context.setLineDash([]); - if (item.showLabel) { - let fontSize = item.labelFontSize * opts.pix; - let labelText = item.labelText ? item.labelText : item.value; - context.setFontSize(fontSize); - let textWidth = measureText(labelText, fontSize, context); - let bgWidth = textWidth + item.labelPadding * opts.pix * 2; - let bgStartX = item.labelAlign == "left" ? opts.area[3] - bgWidth : opts.width - opts.area[1]; - bgStartX += item.labelOffsetX; - let bgStartY = item.y - 0.5 * fontSize - item.labelPadding * opts.pix; - bgStartY += item.labelOffsetY; - let textX = bgStartX + item.labelPadding * opts.pix; - let textY = item.y; - context.setFillStyle(hexToRgb(item.labelBgColor, item.labelBgOpacity)); - context.setStrokeStyle(item.labelBgColor); - context.setLineWidth(1 * opts.pix); - context.beginPath(); - context.rect(bgStartX, bgStartY, bgWidth, fontSize + 2 * item.labelPadding * opts.pix); - context.closePath(); - context.stroke(); - context.fill(); - context.setFontSize(fontSize); - context.setTextAlign("left"); - context.setFillStyle(item.labelFontColor); - context.fillText(String(labelText), textX, bgStartY + fontSize + (item.labelPadding * opts.pix) / 2); - context.stroke(); - context.setTextAlign("left"); - } - } -} - -function drawToolTipHorizentalLine(opts, config, context, eachSpacing, xAxisPoints) { - var toolTipOption = assign( - {}, - { - gridType: "solid", - dashLength: 4, - }, - opts.extra.tooltip - ); - var startX = opts.area[3]; - var endX = opts.width - opts.area[1]; - if (toolTipOption.gridType == "dash") { - context.setLineDash([toolTipOption.dashLength, toolTipOption.dashLength]); - } - context.setStrokeStyle(toolTipOption.gridColor || "#cccccc"); - context.setLineWidth(1 * opts.pix); - context.beginPath(); - context.moveTo(startX, opts.tooltip.offset.y); - context.lineTo(endX, opts.tooltip.offset.y); - context.stroke(); - context.setLineDash([]); - if (toolTipOption.yAxisLabel) { - let boxPadding = toolTipOption.boxPadding * opts.pix; - let labelText = calTooltipYAxisData(opts.tooltip.offset.y, opts.series, opts, config, eachSpacing); - let widthArr = opts.chartData.yAxisData.yAxisWidth; - let tStartLeft = opts.area[3]; - let tStartRight = opts.width - opts.area[1]; - for (let i = 0; i < labelText.length; i++) { - context.setFontSize(toolTipOption.fontSize * opts.pix); - let textWidth = measureText(labelText[i], toolTipOption.fontSize * opts.pix, context); - let bgStartX, bgEndX, bgWidth; - if (widthArr[i].position == "left") { - bgStartX = tStartLeft - (textWidth + boxPadding * 2) - 2 * opts.pix; - bgEndX = Math.max(bgStartX, bgStartX + textWidth + boxPadding * 2); - } else { - bgStartX = tStartRight + 2 * opts.pix; - bgEndX = Math.max(bgStartX + widthArr[i].width, bgStartX + textWidth + boxPadding * 2); - } - bgWidth = bgEndX - bgStartX; - let textX = bgStartX + (bgWidth - textWidth) / 2; - let textY = opts.tooltip.offset.y; - context.beginPath(); - context.setFillStyle(hexToRgb(toolTipOption.labelBgColor || config.toolTipBackground, toolTipOption.labelBgOpacity || config.toolTipOpacity)); - context.setStrokeStyle(toolTipOption.labelBgColor || config.toolTipBackground); - context.setLineWidth(1 * opts.pix); - context.rect(bgStartX, textY - 0.5 * config.fontSize - boxPadding, bgWidth, config.fontSize + 2 * boxPadding); - context.closePath(); - context.stroke(); - context.fill(); - context.beginPath(); - context.setFontSize(config.fontSize); - context.setFillStyle(toolTipOption.labelFontColor || opts.fontColor); - context.fillText(labelText[i], textX, textY + 0.5 * config.fontSize); - context.closePath(); - context.stroke(); - if (widthArr[i].position == "left") { - tStartLeft -= widthArr[i].width + opts.yAxis.padding * opts.pix; - } else { - tStartRight += widthArr[i].width + opts.yAxis.padding * opts.pix; - } - } - } -} - -function drawToolTipSplitArea(offsetX, opts, config, context, eachSpacing) { - var toolTipOption = assign( - {}, - { - activeBgColor: "#000000", - activeBgOpacity: 0.08, - activeWidth: eachSpacing, - }, - opts.extra.column - ); - toolTipOption.activeWidth = toolTipOption.activeWidth > eachSpacing ? eachSpacing : toolTipOption.activeWidth; - var startY = opts.area[0]; - var endY = opts.height - opts.area[2]; - context.beginPath(); - context.setFillStyle(hexToRgb(toolTipOption.activeBgColor, toolTipOption.activeBgOpacity)); - context.rect(offsetX - toolTipOption.activeWidth / 2, startY, toolTipOption.activeWidth, endY - startY); - context.closePath(); - context.fill(); - context.setFillStyle("#FFFFFF"); -} - -function drawBarToolTipSplitArea(offsetX, opts, config, context, eachSpacing) { - var toolTipOption = assign( - {}, - { - activeBgColor: "#000000", - activeBgOpacity: 0.08, - }, - opts.extra.bar - ); - var startX = opts.area[3]; - var endX = opts.width - opts.area[1]; - context.beginPath(); - context.setFillStyle(hexToRgb(toolTipOption.activeBgColor, toolTipOption.activeBgOpacity)); - context.rect(startX, offsetX - eachSpacing / 2, endX - startX, eachSpacing); - context.closePath(); - context.fill(); - context.setFillStyle("#FFFFFF"); -} - -function drawToolTip(textList, offset, opts, config, context, eachSpacing, xAxisPoints) { - var toolTipOption = assign( - {}, - { - showBox: true, - showArrow: true, - showCategory: false, - bgColor: "#000000", - bgOpacity: 0.7, - borderColor: "#000000", - borderWidth: 0, - borderRadius: 0, - borderOpacity: 0.7, - boxPadding: 3, - fontColor: "#FFFFFF", - fontSize: 13, - lineHeight: 20, - legendShow: true, - legendShape: "auto", - splitLine: true, - }, - opts.extra.tooltip - ); - if (toolTipOption.showCategory == true && opts.categories) { - textList.unshift({ text: opts.categories[opts.tooltip.index], color: null }); - } - var fontSize = toolTipOption.fontSize * opts.pix; - var lineHeight = toolTipOption.lineHeight * opts.pix; - var boxPadding = toolTipOption.boxPadding * opts.pix; - var legendWidth = fontSize; - var legendMarginRight = 5 * opts.pix; - if (toolTipOption.legendShow == false) { - legendWidth = 0; - legendMarginRight = 0; - } - var arrowWidth = toolTipOption.showArrow ? 8 * opts.pix : 0; - var isOverRightBorder = false; - if (opts.type == "line" || opts.type == "mount" || opts.type == "area" || opts.type == "candle" || opts.type == "mix") { - if (toolTipOption.splitLine == true) { - drawToolTipSplitLine(opts.tooltip.offset.x, opts, config, context); - } - } - offset = assign( - { - x: 0, - y: 0, - }, - offset - ); - offset.y -= 8 * opts.pix; - var textWidth = textList.map(function (item) { - return measureText(item.text, fontSize, context); - }); - var toolTipWidth = legendWidth + legendMarginRight + 4 * boxPadding + Math.max.apply(null, textWidth); - var toolTipHeight = 2 * boxPadding + textList.length * lineHeight; - if (toolTipOption.showBox == false) { - return; - } - // if beyond the right border - if (offset.x - Math.abs(opts._scrollDistance_ || 0) + arrowWidth + toolTipWidth > opts.width) { - isOverRightBorder = true; - } - if (toolTipHeight + offset.y > opts.height) { - offset.y = opts.height - toolTipHeight; - } - // draw background rect - context.beginPath(); - context.setFillStyle(hexToRgb(toolTipOption.bgColor, toolTipOption.bgOpacity)); - context.setLineWidth(toolTipOption.borderWidth * opts.pix); - context.setStrokeStyle(hexToRgb(toolTipOption.borderColor, toolTipOption.borderOpacity)); - var radius = toolTipOption.borderRadius; - if (isOverRightBorder) { - // 增加左侧仍然超出的判断 - if (toolTipWidth + arrowWidth > opts.width) { - offset.x = opts.width + Math.abs(opts._scrollDistance_ || 0) + arrowWidth + (toolTipWidth - opts.width); - } - if (toolTipWidth > offset.x) { - offset.x = opts.width + Math.abs(opts._scrollDistance_ || 0) + arrowWidth + (toolTipWidth - opts.width); - } - if (toolTipOption.showArrow) { - context.moveTo(offset.x, offset.y + 10 * opts.pix); - context.lineTo(offset.x - arrowWidth, offset.y + 10 * opts.pix + 5 * opts.pix); - } - context.arc(offset.x - arrowWidth - radius, offset.y + toolTipHeight - radius, radius, 0, Math.PI / 2, false); - context.arc(offset.x - arrowWidth - Math.round(toolTipWidth) + radius, offset.y + toolTipHeight - radius, radius, Math.PI / 2, Math.PI, false); - context.arc(offset.x - arrowWidth - Math.round(toolTipWidth) + radius, offset.y + radius, radius, -Math.PI, -Math.PI / 2, false); - context.arc(offset.x - arrowWidth - radius, offset.y + radius, radius, -Math.PI / 2, 0, false); - if (toolTipOption.showArrow) { - context.lineTo(offset.x - arrowWidth, offset.y + 10 * opts.pix - 5 * opts.pix); - context.lineTo(offset.x, offset.y + 10 * opts.pix); - } - } else { - if (toolTipOption.showArrow) { - context.moveTo(offset.x, offset.y + 10 * opts.pix); - context.lineTo(offset.x + arrowWidth, offset.y + 10 * opts.pix - 5 * opts.pix); - } - context.arc(offset.x + arrowWidth + radius, offset.y + radius, radius, -Math.PI, -Math.PI / 2, false); - context.arc(offset.x + arrowWidth + Math.round(toolTipWidth) - radius, offset.y + radius, radius, -Math.PI / 2, 0, false); - context.arc(offset.x + arrowWidth + Math.round(toolTipWidth) - radius, offset.y + toolTipHeight - radius, radius, 0, Math.PI / 2, false); - context.arc(offset.x + arrowWidth + radius, offset.y + toolTipHeight - radius, radius, Math.PI / 2, Math.PI, false); - if (toolTipOption.showArrow) { - context.lineTo(offset.x + arrowWidth, offset.y + 10 * opts.pix + 5 * opts.pix); - context.lineTo(offset.x, offset.y + 10 * opts.pix); - } - } - context.closePath(); - context.fill(); - if (toolTipOption.borderWidth > 0) { - context.stroke(); - } - // draw legend - if (toolTipOption.legendShow) { - textList.forEach(function (item, index) { - if (item.color !== null) { - context.beginPath(); - context.setFillStyle(item.color); - var startX = offset.x + arrowWidth + 2 * boxPadding; - var startY = offset.y + (lineHeight - fontSize) / 2 + lineHeight * index + boxPadding + 1; - if (isOverRightBorder) { - startX = offset.x - toolTipWidth - arrowWidth + 2 * boxPadding; - } - switch (item.legendShape) { - case "line": - context.moveTo(startX, startY + 0.5 * legendWidth - 2 * opts.pix); - context.fillRect(startX, startY + 0.5 * legendWidth - 2 * opts.pix, legendWidth, 4 * opts.pix); - break; - case "triangle": - context.moveTo(startX + 7.5 * opts.pix, startY + 0.5 * legendWidth - 5 * opts.pix); - context.lineTo(startX + 2.5 * opts.pix, startY + 0.5 * legendWidth + 5 * opts.pix); - context.lineTo(startX + 12.5 * opts.pix, startY + 0.5 * legendWidth + 5 * opts.pix); - context.lineTo(startX + 7.5 * opts.pix, startY + 0.5 * legendWidth - 5 * opts.pix); - break; - case "diamond": - context.moveTo(startX + 7.5 * opts.pix, startY + 0.5 * legendWidth - 5 * opts.pix); - context.lineTo(startX + 2.5 * opts.pix, startY + 0.5 * legendWidth); - context.lineTo(startX + 7.5 * opts.pix, startY + 0.5 * legendWidth + 5 * opts.pix); - context.lineTo(startX + 12.5 * opts.pix, startY + 0.5 * legendWidth); - context.lineTo(startX + 7.5 * opts.pix, startY + 0.5 * legendWidth - 5 * opts.pix); - break; - case "circle": - context.moveTo(startX + 7.5 * opts.pix, startY + 0.5 * legendWidth); - context.arc(startX + 7.5 * opts.pix, startY + 0.5 * legendWidth, 5 * opts.pix, 0, 2 * Math.PI); - break; - case "rect": - context.moveTo(startX, startY + 0.5 * legendWidth - 5 * opts.pix); - context.fillRect(startX, startY + 0.5 * legendWidth - 5 * opts.pix, 15 * opts.pix, 10 * opts.pix); - break; - case "square": - context.moveTo(startX + 2 * opts.pix, startY + 0.5 * legendWidth - 5 * opts.pix); - context.fillRect(startX + 2 * opts.pix, startY + 0.5 * legendWidth - 5 * opts.pix, 10 * opts.pix, 10 * opts.pix); - break; - default: - context.moveTo(startX, startY + 0.5 * legendWidth - 5 * opts.pix); - context.fillRect(startX, startY + 0.5 * legendWidth - 5 * opts.pix, 15 * opts.pix, 10 * opts.pix); - } - context.closePath(); - context.fill(); - } - }); - } - - // draw text list - textList.forEach(function (item, index) { - var startX = offset.x + arrowWidth + 2 * boxPadding + legendWidth + legendMarginRight; - if (isOverRightBorder) { - startX = offset.x - toolTipWidth - arrowWidth + 2 * boxPadding + legendWidth + legendMarginRight; - } - var startY = offset.y + lineHeight * index + (lineHeight - fontSize) / 2 - 1 + boxPadding + fontSize; - context.beginPath(); - context.setFontSize(fontSize); - context.setTextBaseline("normal"); - context.setFillStyle(toolTipOption.fontColor); - context.fillText(item.text, startX, startY); - context.closePath(); - context.stroke(); - }); -} - -function drawColumnDataPoints(series, opts, config, context) { - let process = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1; - let xAxisData = opts.chartData.xAxisData, - xAxisPoints = xAxisData.xAxisPoints, - eachSpacing = xAxisData.eachSpacing; - let columnOption = assign( - {}, - { - type: "group", - width: eachSpacing / 2, - meterBorder: 4, - meterFillColor: "#FFFFFF", - barBorderCircle: false, - barBorderRadius: [], - seriesGap: 2, - linearType: "none", - linearOpacity: 1, - customColor: [], - colorStop: 0, - labelPosition: "outside", - }, - opts.extra.column - ); - let calPoints = []; - context.save(); - let leftNum = -2; - let rightNum = xAxisPoints.length + 2; - if (opts._scrollDistance_ && opts._scrollDistance_ !== 0 && opts.enableScroll === true) { - context.translate(opts._scrollDistance_, 0); - leftNum = Math.floor(-opts._scrollDistance_ / eachSpacing) - 2; - rightNum = leftNum + opts.xAxis.itemCount + 4; - } - if (opts.tooltip && opts.tooltip.textList && opts.tooltip.textList.length && process === 1) { - drawToolTipSplitArea(opts.tooltip.offset.x, opts, config, context, eachSpacing); - } - columnOption.customColor = fillCustomColor(columnOption.linearType, columnOption.customColor, series, config); - series.forEach(function (eachSeries, seriesIndex) { - let ranges, minRange, maxRange; - ranges = [].concat(opts.chartData.yAxisData.ranges[eachSeries.index]); - minRange = ranges.pop(); - maxRange = ranges.shift(); - - // 计算0轴坐标 - let spacingValid = opts.height - opts.area[0] - opts.area[2]; - let zeroHeight = (spacingValid * (0 - minRange)) / (maxRange - minRange); - let zeroPoints = opts.height - Math.round(zeroHeight) - opts.area[2]; - eachSeries.zeroPoints = zeroPoints; - var data = eachSeries.data; - switch (columnOption.type) { - case "group": - var points = getColumnDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config, zeroPoints, process); - var tooltipPoints = getStackDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config, seriesIndex, series, process); - calPoints.push(tooltipPoints); - points = fixColumeData(points, eachSpacing, series.length, seriesIndex, config, opts); - for (let i = 0; i < points.length; i++) { - let item = points[i]; - //fix issues/I27B1N yyoinge & Joeshu - if (item !== null && i > leftNum && i < rightNum) { - var startX = item.x - item.width / 2; - var height = opts.height - item.y - opts.area[2]; - context.beginPath(); - var fillColor = item.color || eachSeries.color; - var strokeColor = item.color || eachSeries.color; - if (columnOption.linearType !== "none") { - var grd = context.createLinearGradient(startX, item.y, startX, zeroPoints); - //透明渐变 - if (columnOption.linearType == "opacity") { - grd.addColorStop(0, hexToRgb(fillColor, columnOption.linearOpacity)); - grd.addColorStop(1, hexToRgb(fillColor, 1)); - } else { - grd.addColorStop(0, hexToRgb(columnOption.customColor[eachSeries.linearIndex], columnOption.linearOpacity)); - grd.addColorStop(columnOption.colorStop, hexToRgb(columnOption.customColor[eachSeries.linearIndex], columnOption.linearOpacity)); - grd.addColorStop(1, hexToRgb(fillColor, 1)); - } - fillColor = grd; - } - // 圆角边框 - if ((columnOption.barBorderRadius && columnOption.barBorderRadius.length === 4) || columnOption.barBorderCircle === true) { - const left = startX; - const top = item.y > zeroPoints ? zeroPoints : item.y; - const width = item.width; - const height = Math.abs(zeroPoints - item.y); - if (columnOption.barBorderCircle) { - columnOption.barBorderRadius = [width / 2, width / 2, 0, 0]; - } - if (item.y > zeroPoints) { - columnOption.barBorderRadius = [0, 0, width / 2, width / 2]; - } - let [r0, r1, r2, r3] = columnOption.barBorderRadius; - let minRadius = Math.min(width / 2, height / 2); - r0 = r0 > minRadius ? minRadius : r0; - r1 = r1 > minRadius ? minRadius : r1; - r2 = r2 > minRadius ? minRadius : r2; - r3 = r3 > minRadius ? minRadius : r3; - r0 = r0 < 0 ? 0 : r0; - r1 = r1 < 0 ? 0 : r1; - r2 = r2 < 0 ? 0 : r2; - r3 = r3 < 0 ? 0 : r3; - context.arc(left + r0, top + r0, r0, -Math.PI, -Math.PI / 2); - context.arc(left + width - r1, top + r1, r1, -Math.PI / 2, 0); - context.arc(left + width - r2, top + height - r2, r2, 0, Math.PI / 2); - context.arc(left + r3, top + height - r3, r3, Math.PI / 2, Math.PI); - } else { - context.moveTo(startX, item.y); - context.lineTo(startX + item.width, item.y); - context.lineTo(startX + item.width, zeroPoints); - context.lineTo(startX, zeroPoints); - context.lineTo(startX, item.y); - context.setLineWidth(1); - context.setStrokeStyle(strokeColor); - } - context.setFillStyle(fillColor); - context.closePath(); - //context.stroke(); - context.fill(); - } - } - break; - case "stack": - // 绘制堆叠数据图 - var points = getStackDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config, seriesIndex, series, process); - calPoints.push(points); - points = fixColumeStackData(points, eachSpacing, series.length, seriesIndex, config, opts, series); - for (let i = 0; i < points.length; i++) { - let item = points[i]; - if (item !== null && i > leftNum && i < rightNum) { - context.beginPath(); - var fillColor = item.color || eachSeries.color; - var startX = item.x - item.width / 2 + 1; - var height = opts.height - item.y - opts.area[2]; - var height0 = opts.height - item.y0 - opts.area[2]; - if (seriesIndex > 0) { - height -= height0; - } - context.setFillStyle(fillColor); - context.moveTo(startX, item.y); - context.fillRect(startX, item.y, item.width, height); - context.closePath(); - context.fill(); - } - } - break; - case "meter": - // 绘制温度计数据图 - var points = getDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config, process); - calPoints.push(points); - points = fixColumeMeterData(points, eachSpacing, series.length, seriesIndex, config, opts, columnOption.meterBorder); - for (let i = 0; i < points.length; i++) { - let item = points[i]; - if (item !== null && i > leftNum && i < rightNum) { - //画背景颜色 - context.beginPath(); - if (seriesIndex == 0 && columnOption.meterBorder > 0) { - context.setStrokeStyle(eachSeries.color); - context.setLineWidth(columnOption.meterBorder * opts.pix); - } - if (seriesIndex == 0) { - context.setFillStyle(columnOption.meterFillColor); - } else { - context.setFillStyle(item.color || eachSeries.color); - } - var startX = item.x - item.width / 2; - var height = opts.height - item.y - opts.area[2]; - if ((columnOption.barBorderRadius && columnOption.barBorderRadius.length === 4) || columnOption.barBorderCircle === true) { - const left = startX; - const top = item.y; - const width = item.width; - const height = zeroPoints - item.y; - if (columnOption.barBorderCircle) { - columnOption.barBorderRadius = [width / 2, width / 2, 0, 0]; - } - let [r0, r1, r2, r3] = columnOption.barBorderRadius; - let minRadius = Math.min(width / 2, height / 2); - r0 = r0 > minRadius ? minRadius : r0; - r1 = r1 > minRadius ? minRadius : r1; - r2 = r2 > minRadius ? minRadius : r2; - r3 = r3 > minRadius ? minRadius : r3; - r0 = r0 < 0 ? 0 : r0; - r1 = r1 < 0 ? 0 : r1; - r2 = r2 < 0 ? 0 : r2; - r3 = r3 < 0 ? 0 : r3; - context.arc(left + r0, top + r0, r0, -Math.PI, -Math.PI / 2); - context.arc(left + width - r1, top + r1, r1, -Math.PI / 2, 0); - context.arc(left + width - r2, top + height - r2, r2, 0, Math.PI / 2); - context.arc(left + r3, top + height - r3, r3, Math.PI / 2, Math.PI); - context.fill(); - } else { - context.moveTo(startX, item.y); - context.lineTo(startX + item.width, item.y); - context.lineTo(startX + item.width, zeroPoints); - context.lineTo(startX, zeroPoints); - context.lineTo(startX, item.y); - context.fill(); - } - if (seriesIndex == 0 && columnOption.meterBorder > 0) { - context.closePath(); - context.stroke(); - } - } - } - break; - } - }); - - if (opts.dataLabel !== false && process === 1) { - series.forEach(function (eachSeries, seriesIndex) { - let ranges, minRange, maxRange; - ranges = [].concat(opts.chartData.yAxisData.ranges[eachSeries.index]); - minRange = ranges.pop(); - maxRange = ranges.shift(); - var data = eachSeries.data; - switch (columnOption.type) { - case "group": - var points = getColumnDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config, process); - points = fixColumeData(points, eachSpacing, series.length, seriesIndex, config, opts); - drawColumePointText(points, eachSeries, config, context, opts); - break; - case "stack": - var points = getStackDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config, seriesIndex, series, process); - drawColumePointText(points, eachSeries, config, context, opts); - break; - case "meter": - var points = getDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config, process); - drawColumePointText(points, eachSeries, config, context, opts); - break; - } - }); - } - context.restore(); - return { - xAxisPoints: xAxisPoints, - calPoints: calPoints, - eachSpacing: eachSpacing, - }; -} - -function drawMountDataPoints(series, opts, config, context) { - let process = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1; - let xAxisData = opts.chartData.xAxisData, - xAxisPoints = xAxisData.xAxisPoints, - eachSpacing = xAxisData.eachSpacing; - let mountOption = assign( - {}, - { - type: "mount", - widthRatio: 1, - borderWidth: 1, - barBorderCircle: false, - barBorderRadius: [], - linearType: "none", - linearOpacity: 1, - customColor: [], - colorStop: 0, - }, - opts.extra.mount - ); - mountOption.widthRatio = mountOption.widthRatio <= 0 ? 0 : mountOption.widthRatio; - mountOption.widthRatio = mountOption.widthRatio >= 2 ? 2 : mountOption.widthRatio; - let calPoints = []; - context.save(); - let leftNum = -2; - let rightNum = xAxisPoints.length + 2; - if (opts._scrollDistance_ && opts._scrollDistance_ !== 0 && opts.enableScroll === true) { - context.translate(opts._scrollDistance_, 0); - leftNum = Math.floor(-opts._scrollDistance_ / eachSpacing) - 2; - rightNum = leftNum + opts.xAxis.itemCount + 4; - } - mountOption.customColor = fillCustomColor(mountOption.linearType, mountOption.customColor, series, config); - let ranges, minRange, maxRange; - ranges = [].concat(opts.chartData.yAxisData.ranges[0]); - minRange = ranges.pop(); - maxRange = ranges.shift(); - - // 计算0轴坐标 - let spacingValid = opts.height - opts.area[0] - opts.area[2]; - let zeroHeight = (spacingValid * (0 - minRange)) / (maxRange - minRange); - let zeroPoints = opts.height - Math.round(zeroHeight) - opts.area[2]; - - var points = getMountDataPoints(series, minRange, maxRange, xAxisPoints, eachSpacing, opts, mountOption, zeroPoints, process); - switch (mountOption.type) { - case "bar": - for (let i = 0; i < points.length; i++) { - let item = points[i]; - if (item !== null && i > leftNum && i < rightNum) { - var startX = item.x - (eachSpacing * mountOption.widthRatio) / 2; - var height = opts.height - item.y - opts.area[2]; - context.beginPath(); - var fillColor = item.color || series[i].color; - var strokeColor = item.color || series[i].color; - if (mountOption.linearType !== "none") { - var grd = context.createLinearGradient(startX, item.y, startX, zeroPoints); - //透明渐变 - if (mountOption.linearType == "opacity") { - grd.addColorStop(0, hexToRgb(fillColor, mountOption.linearOpacity)); - grd.addColorStop(1, hexToRgb(fillColor, 1)); - } else { - grd.addColorStop(0, hexToRgb(mountOption.customColor[series[i].linearIndex], mountOption.linearOpacity)); - grd.addColorStop(mountOption.colorStop, hexToRgb(mountOption.customColor[series[i].linearIndex], mountOption.linearOpacity)); - grd.addColorStop(1, hexToRgb(fillColor, 1)); - } - fillColor = grd; - } - // 圆角边框 - if ((mountOption.barBorderRadius && mountOption.barBorderRadius.length === 4) || mountOption.barBorderCircle === true) { - const left = startX; - const top = item.y > zeroPoints ? zeroPoints : item.y; - const width = item.width; - const height = Math.abs(zeroPoints - item.y); - if (mountOption.barBorderCircle) { - mountOption.barBorderRadius = [width / 2, width / 2, 0, 0]; - } - if (item.y > zeroPoints) { - mountOption.barBorderRadius = [0, 0, width / 2, width / 2]; - } - let [r0, r1, r2, r3] = mountOption.barBorderRadius; - let minRadius = Math.min(width / 2, height / 2); - r0 = r0 > minRadius ? minRadius : r0; - r1 = r1 > minRadius ? minRadius : r1; - r2 = r2 > minRadius ? minRadius : r2; - r3 = r3 > minRadius ? minRadius : r3; - r0 = r0 < 0 ? 0 : r0; - r1 = r1 < 0 ? 0 : r1; - r2 = r2 < 0 ? 0 : r2; - r3 = r3 < 0 ? 0 : r3; - context.arc(left + r0, top + r0, r0, -Math.PI, -Math.PI / 2); - context.arc(left + width - r1, top + r1, r1, -Math.PI / 2, 0); - context.arc(left + width - r2, top + height - r2, r2, 0, Math.PI / 2); - context.arc(left + r3, top + height - r3, r3, Math.PI / 2, Math.PI); - } else { - context.moveTo(startX, item.y); - context.lineTo(startX + item.width, item.y); - context.lineTo(startX + item.width, zeroPoints); - context.lineTo(startX, zeroPoints); - context.lineTo(startX, item.y); - } - context.setStrokeStyle(strokeColor); - context.setFillStyle(fillColor); - if (mountOption.borderWidth > 0) { - context.setLineWidth(mountOption.borderWidth * opts.pix); - context.closePath(); - context.stroke(); - } - context.fill(); - } - } - break; - case "triangle": - for (let i = 0; i < points.length; i++) { - let item = points[i]; - if (item !== null && i > leftNum && i < rightNum) { - var startX = item.x - (eachSpacing * mountOption.widthRatio) / 2; - var height = opts.height - item.y - opts.area[2]; - context.beginPath(); - var fillColor = item.color || series[i].color; - var strokeColor = item.color || series[i].color; - if (mountOption.linearType !== "none") { - var grd = context.createLinearGradient(startX, item.y, startX, zeroPoints); - //透明渐变 - if (mountOption.linearType == "opacity") { - grd.addColorStop(0, hexToRgb(fillColor, mountOption.linearOpacity)); - grd.addColorStop(1, hexToRgb(fillColor, 1)); - } else { - grd.addColorStop(0, hexToRgb(mountOption.customColor[series[i].linearIndex], mountOption.linearOpacity)); - grd.addColorStop(mountOption.colorStop, hexToRgb(mountOption.customColor[series[i].linearIndex], mountOption.linearOpacity)); - grd.addColorStop(1, hexToRgb(fillColor, 1)); - } - fillColor = grd; - } - context.moveTo(startX, zeroPoints); - context.lineTo(item.x, item.y); - context.lineTo(startX + item.width, zeroPoints); - context.setStrokeStyle(strokeColor); - context.setFillStyle(fillColor); - if (mountOption.borderWidth > 0) { - context.setLineWidth(mountOption.borderWidth * opts.pix); - context.stroke(); - } - context.fill(); - } - } - break; - case "mount": - for (let i = 0; i < points.length; i++) { - let item = points[i]; - if (item !== null && i > leftNum && i < rightNum) { - var startX = item.x - (eachSpacing * mountOption.widthRatio) / 2; - var height = opts.height - item.y - opts.area[2]; - context.beginPath(); - var fillColor = item.color || series[i].color; - var strokeColor = item.color || series[i].color; - if (mountOption.linearType !== "none") { - var grd = context.createLinearGradient(startX, item.y, startX, zeroPoints); - //透明渐变 - if (mountOption.linearType == "opacity") { - grd.addColorStop(0, hexToRgb(fillColor, mountOption.linearOpacity)); - grd.addColorStop(1, hexToRgb(fillColor, 1)); - } else { - grd.addColorStop(0, hexToRgb(mountOption.customColor[series[i].linearIndex], mountOption.linearOpacity)); - grd.addColorStop(mountOption.colorStop, hexToRgb(mountOption.customColor[series[i].linearIndex], mountOption.linearOpacity)); - grd.addColorStop(1, hexToRgb(fillColor, 1)); - } - fillColor = grd; - } - context.moveTo(startX, zeroPoints); - context.bezierCurveTo(item.x - item.width / 4, zeroPoints, item.x - item.width / 4, item.y, item.x, item.y); - context.bezierCurveTo(item.x + item.width / 4, item.y, item.x + item.width / 4, zeroPoints, startX + item.width, zeroPoints); - context.setStrokeStyle(strokeColor); - context.setFillStyle(fillColor); - if (mountOption.borderWidth > 0) { - context.setLineWidth(mountOption.borderWidth * opts.pix); - context.stroke(); - } - context.fill(); - } - } - break; - case "sharp": - for (let i = 0; i < points.length; i++) { - let item = points[i]; - if (item !== null && i > leftNum && i < rightNum) { - var startX = item.x - (eachSpacing * mountOption.widthRatio) / 2; - var height = opts.height - item.y - opts.area[2]; - context.beginPath(); - var fillColor = item.color || series[i].color; - var strokeColor = item.color || series[i].color; - if (mountOption.linearType !== "none") { - var grd = context.createLinearGradient(startX, item.y, startX, zeroPoints); - //透明渐变 - if (mountOption.linearType == "opacity") { - grd.addColorStop(0, hexToRgb(fillColor, mountOption.linearOpacity)); - grd.addColorStop(1, hexToRgb(fillColor, 1)); - } else { - grd.addColorStop(0, hexToRgb(mountOption.customColor[series[i].linearIndex], mountOption.linearOpacity)); - grd.addColorStop(mountOption.colorStop, hexToRgb(mountOption.customColor[series[i].linearIndex], mountOption.linearOpacity)); - grd.addColorStop(1, hexToRgb(fillColor, 1)); - } - fillColor = grd; - } - context.moveTo(startX, zeroPoints); - context.quadraticCurveTo(item.x - 0, zeroPoints - height / 4, item.x, item.y); - context.quadraticCurveTo(item.x + 0, zeroPoints - height / 4, startX + item.width, zeroPoints); - context.setStrokeStyle(strokeColor); - context.setFillStyle(fillColor); - if (mountOption.borderWidth > 0) { - context.setLineWidth(mountOption.borderWidth * opts.pix); - context.stroke(); - } - context.fill(); - } - } - break; - } - - if (opts.dataLabel !== false && process === 1) { - let ranges, minRange, maxRange; - ranges = [].concat(opts.chartData.yAxisData.ranges[0]); - minRange = ranges.pop(); - maxRange = ranges.shift(); - var points = getMountDataPoints(series, minRange, maxRange, xAxisPoints, eachSpacing, opts, mountOption, zeroPoints, process); - drawMountPointText(points, series, config, context, opts, zeroPoints); - } - context.restore(); - return { - xAxisPoints: xAxisPoints, - calPoints: points, - eachSpacing: eachSpacing, - }; -} - -function drawBarDataPoints(series, opts, config, context) { - let process = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1; - let yAxisPoints = []; - let eachSpacing = (opts.height - opts.area[0] - opts.area[2]) / opts.categories.length; - for (let i = 0; i < opts.categories.length; i++) { - yAxisPoints.push(opts.area[0] + eachSpacing / 2 + eachSpacing * i); - } - let columnOption = assign( - {}, - { - type: "group", - width: eachSpacing / 2, - meterBorder: 4, - meterFillColor: "#FFFFFF", - barBorderCircle: false, - barBorderRadius: [], - seriesGap: 2, - linearType: "none", - linearOpacity: 1, - customColor: [], - colorStop: 0, - }, - opts.extra.bar - ); - let calPoints = []; - context.save(); - let leftNum = -2; - let rightNum = yAxisPoints.length + 2; - if (opts.tooltip && opts.tooltip.textList && opts.tooltip.textList.length && process === 1) { - drawBarToolTipSplitArea(opts.tooltip.offset.y, opts, config, context, eachSpacing); - } - columnOption.customColor = fillCustomColor(columnOption.linearType, columnOption.customColor, series, config); - series.forEach(function (eachSeries, seriesIndex) { - let ranges, minRange, maxRange; - ranges = [].concat(opts.chartData.xAxisData.ranges); - maxRange = ranges.pop(); - minRange = ranges.shift(); - var data = eachSeries.data; - switch (columnOption.type) { - case "group": - var points = getBarDataPoints(data, minRange, maxRange, yAxisPoints, eachSpacing, opts, config, process); - var tooltipPoints = getBarStackDataPoints(data, minRange, maxRange, yAxisPoints, eachSpacing, opts, config, seriesIndex, series, process); - calPoints.push(tooltipPoints); - points = fixBarData(points, eachSpacing, series.length, seriesIndex, config, opts); - for (let i = 0; i < points.length; i++) { - let item = points[i]; - //fix issues/I27B1N yyoinge & Joeshu - if (item !== null && i > leftNum && i < rightNum) { - //var startX = item.x - item.width / 2; - var startX = opts.area[3]; - var startY = item.y - item.width / 2; - var height = item.height; - context.beginPath(); - var fillColor = item.color || eachSeries.color; - var strokeColor = item.color || eachSeries.color; - if (columnOption.linearType !== "none") { - var grd = context.createLinearGradient(startX, item.y, item.x, item.y); - //透明渐变 - if (columnOption.linearType == "opacity") { - grd.addColorStop(0, hexToRgb(fillColor, columnOption.linearOpacity)); - grd.addColorStop(1, hexToRgb(fillColor, 1)); - } else { - grd.addColorStop(0, hexToRgb(columnOption.customColor[eachSeries.linearIndex], columnOption.linearOpacity)); - grd.addColorStop(columnOption.colorStop, hexToRgb(columnOption.customColor[eachSeries.linearIndex], columnOption.linearOpacity)); - grd.addColorStop(1, hexToRgb(fillColor, 1)); - } - fillColor = grd; - } - // 圆角边框 - if ((columnOption.barBorderRadius && columnOption.barBorderRadius.length === 4) || columnOption.barBorderCircle === true) { - const left = startX; - const width = item.width; - const top = item.y - item.width / 2; - const height = item.height; - if (columnOption.barBorderCircle) { - columnOption.barBorderRadius = [width / 2, width / 2, 0, 0]; - } - let [r0, r1, r2, r3] = columnOption.barBorderRadius; - let minRadius = Math.min(width / 2, height / 2); - r0 = r0 > minRadius ? minRadius : r0; - r1 = r1 > minRadius ? minRadius : r1; - r2 = r2 > minRadius ? minRadius : r2; - r3 = r3 > minRadius ? minRadius : r3; - r0 = r0 < 0 ? 0 : r0; - r1 = r1 < 0 ? 0 : r1; - r2 = r2 < 0 ? 0 : r2; - r3 = r3 < 0 ? 0 : r3; - - context.arc(left + r3, top + r3, r3, -Math.PI, -Math.PI / 2); - context.arc(item.x - r0, top + r0, r0, -Math.PI / 2, 0); - context.arc(item.x - r1, top + width - r1, r1, 0, Math.PI / 2); - context.arc(left + r2, top + width - r2, r2, Math.PI / 2, Math.PI); - } else { - context.moveTo(startX, startY); - context.lineTo(item.x, startY); - context.lineTo(item.x, startY + item.width); - context.lineTo(startX, startY + item.width); - context.lineTo(startX, startY); - context.setLineWidth(1); - context.setStrokeStyle(strokeColor); - } - context.setFillStyle(fillColor); - context.closePath(); - //context.stroke(); - context.fill(); - } - } - break; - case "stack": - // 绘制堆叠数据图 - var points = getBarStackDataPoints(data, minRange, maxRange, yAxisPoints, eachSpacing, opts, config, seriesIndex, series, process); - calPoints.push(points); - points = fixBarStackData(points, eachSpacing, series.length, seriesIndex, config, opts, series); - for (let i = 0; i < points.length; i++) { - let item = points[i]; - if (item !== null && i > leftNum && i < rightNum) { - context.beginPath(); - var fillColor = item.color || eachSeries.color; - var startX = item.x0; - context.setFillStyle(fillColor); - context.moveTo(startX, item.y - item.width / 2); - context.fillRect(startX, item.y - item.width / 2, item.height, item.width); - context.closePath(); - context.fill(); - } - } - break; - } - }); - - if (opts.dataLabel !== false && process === 1) { - series.forEach(function (eachSeries, seriesIndex) { - let ranges, minRange, maxRange; - ranges = [].concat(opts.chartData.xAxisData.ranges); - maxRange = ranges.pop(); - minRange = ranges.shift(); - var data = eachSeries.data; - switch (columnOption.type) { - case "group": - var points = getBarDataPoints(data, minRange, maxRange, yAxisPoints, eachSpacing, opts, config, process); - points = fixBarData(points, eachSpacing, series.length, seriesIndex, config, opts); - drawBarPointText(points, eachSeries, config, context, opts); - break; - case "stack": - var points = getBarStackDataPoints(data, minRange, maxRange, yAxisPoints, eachSpacing, opts, config, seriesIndex, series, process); - drawBarPointText(points, eachSeries, config, context, opts); - break; - } - }); - } - return { - yAxisPoints: yAxisPoints, - calPoints: calPoints, - eachSpacing: eachSpacing, - }; -} - -function drawCandleDataPoints(series, seriesMA, opts, config, context) { - var process = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 1; - var candleOption = assign( - {}, - { - color: {}, - average: {}, - }, - opts.extra.candle - ); - candleOption.color = assign( - {}, - { - upLine: "#f04864", - upFill: "#f04864", - downLine: "#2fc25b", - downFill: "#2fc25b", - }, - candleOption.color - ); - candleOption.average = assign( - {}, - { - show: false, - name: [], - day: [], - color: config.color, - }, - candleOption.average - ); - opts.extra.candle = candleOption; - let xAxisData = opts.chartData.xAxisData, - xAxisPoints = xAxisData.xAxisPoints, - eachSpacing = xAxisData.eachSpacing; - let calPoints = []; - context.save(); - let leftNum = -2; - let rightNum = xAxisPoints.length + 2; - let leftSpace = 0; - let rightSpace = opts.width + eachSpacing; - if (opts._scrollDistance_ && opts._scrollDistance_ !== 0 && opts.enableScroll === true) { - context.translate(opts._scrollDistance_, 0); - leftNum = Math.floor(-opts._scrollDistance_ / eachSpacing) - 2; - rightNum = leftNum + opts.xAxis.itemCount + 4; - leftSpace = -opts._scrollDistance_ - eachSpacing * 2 + opts.area[3]; - rightSpace = leftSpace + (opts.xAxis.itemCount + 4) * eachSpacing; - } - //画均线 - if (candleOption.average.show || seriesMA) { - //Merge pull request !12 from 邱贵翔 - seriesMA.forEach(function (eachSeries, seriesIndex) { - let ranges, minRange, maxRange; - ranges = [].concat(opts.chartData.yAxisData.ranges[eachSeries.index]); - minRange = ranges.pop(); - maxRange = ranges.shift(); - var data = eachSeries.data; - var points = getDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config, process); - var splitPointList = splitPoints(points, eachSeries); - for (let i = 0; i < splitPointList.length; i++) { - let points = splitPointList[i]; - context.beginPath(); - context.setStrokeStyle(eachSeries.color); - context.setLineWidth(1); - if (points.length === 1) { - context.moveTo(points[0].x, points[0].y); - context.arc(points[0].x, points[0].y, 1, 0, 2 * Math.PI); - } else { - context.moveTo(points[0].x, points[0].y); - let startPoint = 0; - for (let j = 0; j < points.length; j++) { - let item = points[j]; - if (startPoint == 0 && item.x > leftSpace) { - context.moveTo(item.x, item.y); - startPoint = 1; - } - if (j > 0 && item.x > leftSpace && item.x < rightSpace) { - var ctrlPoint = createCurveControlPoints(points, j - 1); - context.bezierCurveTo(ctrlPoint.ctrA.x, ctrlPoint.ctrA.y, ctrlPoint.ctrB.x, ctrlPoint.ctrB.y, item.x, item.y); - } - } - context.moveTo(points[0].x, points[0].y); - } - context.closePath(); - context.stroke(); - } - }); - } - //画K线 - series.forEach(function (eachSeries, seriesIndex) { - let ranges, minRange, maxRange; - ranges = [].concat(opts.chartData.yAxisData.ranges[eachSeries.index]); - minRange = ranges.pop(); - maxRange = ranges.shift(); - var data = eachSeries.data; - var points = getCandleDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config, process); - calPoints.push(points); - var splitPointList = splitPoints(points, eachSeries); - for (let i = 0; i < splitPointList[0].length; i++) { - if (i > leftNum && i < rightNum) { - let item = splitPointList[0][i]; - context.beginPath(); - //如果上涨 - if (data[i][1] - data[i][0] > 0) { - context.setStrokeStyle(candleOption.color.upLine); - context.setFillStyle(candleOption.color.upFill); - context.setLineWidth(1 * opts.pix); - context.moveTo(item[3].x, item[3].y); //顶点 - context.lineTo(item[1].x, item[1].y); //收盘中间点 - context.lineTo(item[1].x - eachSpacing / 4, item[1].y); //收盘左侧点 - context.lineTo(item[0].x - eachSpacing / 4, item[0].y); //开盘左侧点 - context.lineTo(item[0].x, item[0].y); //开盘中间点 - context.lineTo(item[2].x, item[2].y); //底点 - context.lineTo(item[0].x, item[0].y); //开盘中间点 - context.lineTo(item[0].x + eachSpacing / 4, item[0].y); //开盘右侧点 - context.lineTo(item[1].x + eachSpacing / 4, item[1].y); //收盘右侧点 - context.lineTo(item[1].x, item[1].y); //收盘中间点 - context.moveTo(item[3].x, item[3].y); //顶点 - } else { - context.setStrokeStyle(candleOption.color.downLine); - context.setFillStyle(candleOption.color.downFill); - context.setLineWidth(1 * opts.pix); - context.moveTo(item[3].x, item[3].y); //顶点 - context.lineTo(item[0].x, item[0].y); //开盘中间点 - context.lineTo(item[0].x - eachSpacing / 4, item[0].y); //开盘左侧点 - context.lineTo(item[1].x - eachSpacing / 4, item[1].y); //收盘左侧点 - context.lineTo(item[1].x, item[1].y); //收盘中间点 - context.lineTo(item[2].x, item[2].y); //底点 - context.lineTo(item[1].x, item[1].y); //收盘中间点 - context.lineTo(item[1].x + eachSpacing / 4, item[1].y); //收盘右侧点 - context.lineTo(item[0].x + eachSpacing / 4, item[0].y); //开盘右侧点 - context.lineTo(item[0].x, item[0].y); //开盘中间点 - context.moveTo(item[3].x, item[3].y); //顶点 - } - context.closePath(); - context.fill(); - context.stroke(); - } - } - }); - context.restore(); - return { - xAxisPoints: xAxisPoints, - calPoints: calPoints, - eachSpacing: eachSpacing, - }; -} - -function drawAreaDataPoints(series, opts, config, context) { - var process = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1; - var areaOption = assign( - {}, - { - type: "straight", - opacity: 0.2, - addLine: false, - width: 2, - gradient: false, - activeType: "none", - }, - opts.extra.area - ); - let xAxisData = opts.chartData.xAxisData, - xAxisPoints = xAxisData.xAxisPoints, - eachSpacing = xAxisData.eachSpacing; - let endY = opts.height - opts.area[2]; - let calPoints = []; - context.save(); - let leftSpace = 0; - let rightSpace = opts.width + eachSpacing; - if (opts._scrollDistance_ && opts._scrollDistance_ !== 0 && opts.enableScroll === true) { - context.translate(opts._scrollDistance_, 0); - leftSpace = -opts._scrollDistance_ - eachSpacing * 2 + opts.area[3]; - rightSpace = leftSpace + (opts.xAxis.itemCount + 4) * eachSpacing; - } - series.forEach(function (eachSeries, seriesIndex) { - let ranges, minRange, maxRange; - ranges = [].concat(opts.chartData.yAxisData.ranges[eachSeries.index]); - minRange = ranges.pop(); - maxRange = ranges.shift(); - let data = eachSeries.data; - let points = getDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config, process); - calPoints.push(points); - let splitPointList = splitPoints(points, eachSeries); - for (let i = 0; i < splitPointList.length; i++) { - let points = splitPointList[i]; - // 绘制区域数 - context.beginPath(); - context.setStrokeStyle(hexToRgb(eachSeries.color, areaOption.opacity)); - if (areaOption.gradient) { - let gradient = context.createLinearGradient(0, opts.area[0], 0, opts.height - opts.area[2]); - gradient.addColorStop("0", hexToRgb(eachSeries.color, areaOption.opacity)); - gradient.addColorStop("1.0", hexToRgb("#FFFFFF", 0.1)); - context.setFillStyle(gradient); - } else { - context.setFillStyle(hexToRgb(eachSeries.color, areaOption.opacity)); - } - context.setLineWidth(areaOption.width * opts.pix); - if (points.length > 1) { - let firstPoint = points[0]; - let lastPoint = points[points.length - 1]; - context.moveTo(firstPoint.x, firstPoint.y); - let startPoint = 0; - if (areaOption.type === "curve") { - for (let j = 0; j < points.length; j++) { - let item = points[j]; - if (startPoint == 0 && item.x > leftSpace) { - context.moveTo(item.x, item.y); - startPoint = 1; - } - if (j > 0 && item.x > leftSpace && item.x < rightSpace) { - let ctrlPoint = createCurveControlPoints(points, j - 1); - context.bezierCurveTo(ctrlPoint.ctrA.x, ctrlPoint.ctrA.y, ctrlPoint.ctrB.x, ctrlPoint.ctrB.y, item.x, item.y); - } - } - } - if (areaOption.type === "straight") { - for (let j = 0; j < points.length; j++) { - let item = points[j]; - if (startPoint == 0 && item.x > leftSpace) { - context.moveTo(item.x, item.y); - startPoint = 1; - } - if (j > 0 && item.x > leftSpace && item.x < rightSpace) { - context.lineTo(item.x, item.y); - } - } - } - if (areaOption.type === "step") { - for (let j = 0; j < points.length; j++) { - let item = points[j]; - if (startPoint == 0 && item.x > leftSpace) { - context.moveTo(item.x, item.y); - startPoint = 1; - } - if (j > 0 && item.x > leftSpace && item.x < rightSpace) { - context.lineTo(item.x, points[j - 1].y); - context.lineTo(item.x, item.y); - } - } - } - context.lineTo(lastPoint.x, endY); - context.lineTo(firstPoint.x, endY); - context.lineTo(firstPoint.x, firstPoint.y); - } else { - let item = points[0]; - context.moveTo(item.x - eachSpacing / 2, item.y); - // context.lineTo(item.x + eachSpacing / 2, item.y); - // context.lineTo(item.x + eachSpacing / 2, endY); - // context.lineTo(item.x - eachSpacing / 2, endY); - // context.moveTo(item.x - eachSpacing / 2, item.y); - } - context.closePath(); - context.fill(); - //画连线 - if (areaOption.addLine) { - if (eachSeries.lineType == "dash") { - let dashLength = eachSeries.dashLength ? eachSeries.dashLength : 8; - dashLength *= opts.pix; - context.setLineDash([dashLength, dashLength]); - } - context.beginPath(); - context.setStrokeStyle(eachSeries.color); - context.setLineWidth(areaOption.width * opts.pix); - if (points.length === 1) { - context.moveTo(points[0].x, points[0].y); - // context.arc(points[0].x, points[0].y, 1, 0, 2 * Math.PI); - } else { - context.moveTo(points[0].x, points[0].y); - let startPoint = 0; - if (areaOption.type === "curve") { - for (let j = 0; j < points.length; j++) { - let item = points[j]; - if (startPoint == 0 && item.x > leftSpace) { - context.moveTo(item.x, item.y); - startPoint = 1; - } - if (j > 0 && item.x > leftSpace && item.x < rightSpace) { - let ctrlPoint = createCurveControlPoints(points, j - 1); - context.bezierCurveTo(ctrlPoint.ctrA.x, ctrlPoint.ctrA.y, ctrlPoint.ctrB.x, ctrlPoint.ctrB.y, item.x, item.y); - } - } - } - if (areaOption.type === "straight") { - for (let j = 0; j < points.length; j++) { - let item = points[j]; - if (startPoint == 0 && item.x > leftSpace) { - context.moveTo(item.x, item.y); - startPoint = 1; - } - if (j > 0 && item.x > leftSpace && item.x < rightSpace) { - context.lineTo(item.x, item.y); - } - } - } - if (areaOption.type === "step") { - for (let j = 0; j < points.length; j++) { - let item = points[j]; - if (startPoint == 0 && item.x > leftSpace) { - context.moveTo(item.x, item.y); - startPoint = 1; - } - if (j > 0 && item.x > leftSpace && item.x < rightSpace) { - context.lineTo(item.x, points[j - 1].y); - context.lineTo(item.x, item.y); - } - } - } - context.moveTo(points[0].x, points[0].y); - } - context.stroke(); - context.setLineDash([]); - } - } - //画点 - if (opts.dataPointShape !== false) { - drawPointShape(points, eachSeries.color, eachSeries.pointShape, context, opts); - } - drawActivePoint(points, eachSeries.color, eachSeries.pointShape, context, opts, areaOption, seriesIndex); - }); - - if (opts.dataLabel !== false && process === 1) { - series.forEach(function (eachSeries, seriesIndex) { - let ranges, minRange, maxRange; - ranges = [].concat(opts.chartData.yAxisData.ranges[eachSeries.index]); - minRange = ranges.pop(); - maxRange = ranges.shift(); - var data = eachSeries.data; - var points = getDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config, process); - drawPointText(points, eachSeries, config, context, opts); - }); - } - context.restore(); - return { - xAxisPoints: xAxisPoints, - calPoints: calPoints, - eachSpacing: eachSpacing, - }; -} - -function drawScatterDataPoints(series, opts, config, context) { - var process = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1; - var scatterOption = assign( - {}, - { - type: "circle", - }, - opts.extra.scatter - ); - let xAxisData = opts.chartData.xAxisData, - xAxisPoints = xAxisData.xAxisPoints, - eachSpacing = xAxisData.eachSpacing; - var calPoints = []; - context.save(); - let leftSpace = 0; - let rightSpace = opts.width + eachSpacing; - if (opts._scrollDistance_ && opts._scrollDistance_ !== 0 && opts.enableScroll === true) { - context.translate(opts._scrollDistance_, 0); - leftSpace = -opts._scrollDistance_ - eachSpacing * 2 + opts.area[3]; - rightSpace = leftSpace + (opts.xAxis.itemCount + 4) * eachSpacing; - } - series.forEach(function (eachSeries, seriesIndex) { - let ranges, minRange, maxRange; - ranges = [].concat(opts.chartData.yAxisData.ranges[eachSeries.index]); - minRange = ranges.pop(); - maxRange = ranges.shift(); - var data = eachSeries.data; - var points = getDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config, process); - context.beginPath(); - context.setStrokeStyle(eachSeries.color); - context.setFillStyle(eachSeries.color); - context.setLineWidth(1 * opts.pix); - var shape = eachSeries.pointShape; - if (shape === "diamond") { - points.forEach(function (item, index) { - if (item !== null) { - context.moveTo(item.x, item.y - 4.5); - context.lineTo(item.x - 4.5, item.y); - context.lineTo(item.x, item.y + 4.5); - context.lineTo(item.x + 4.5, item.y); - context.lineTo(item.x, item.y - 4.5); - } - }); - } else if (shape === "circle") { - points.forEach(function (item, index) { - if (item !== null) { - context.moveTo(item.x + 2.5 * opts.pix, item.y); - context.arc(item.x, item.y, 3 * opts.pix, 0, 2 * Math.PI, false); - } - }); - } else if (shape === "square") { - points.forEach(function (item, index) { - if (item !== null) { - context.moveTo(item.x - 3.5, item.y - 3.5); - context.rect(item.x - 3.5, item.y - 3.5, 7, 7); - } - }); - } else if (shape === "triangle") { - points.forEach(function (item, index) { - if (item !== null) { - context.moveTo(item.x, item.y - 4.5); - context.lineTo(item.x - 4.5, item.y + 4.5); - context.lineTo(item.x + 4.5, item.y + 4.5); - context.lineTo(item.x, item.y - 4.5); - } - }); - } else if (shape === "triangle") { - return; - } - context.closePath(); - context.fill(); - context.stroke(); - }); - if (opts.dataLabel !== false && process === 1) { - series.forEach(function (eachSeries, seriesIndex) { - let ranges, minRange, maxRange; - ranges = [].concat(opts.chartData.yAxisData.ranges[eachSeries.index]); - minRange = ranges.pop(); - maxRange = ranges.shift(); - var data = eachSeries.data; - var points = getDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config, process); - drawPointText(points, eachSeries, config, context, opts); - }); - } - context.restore(); - return { - xAxisPoints: xAxisPoints, - calPoints: calPoints, - eachSpacing: eachSpacing, - }; -} - -function drawBubbleDataPoints(series, opts, config, context) { - var process = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1; - var bubbleOption = assign( - {}, - { - opacity: 1, - border: 2, - }, - opts.extra.bubble - ); - let xAxisData = opts.chartData.xAxisData, - xAxisPoints = xAxisData.xAxisPoints, - eachSpacing = xAxisData.eachSpacing; - var calPoints = []; - context.save(); - let leftSpace = 0; - let rightSpace = opts.width + eachSpacing; - if (opts._scrollDistance_ && opts._scrollDistance_ !== 0 && opts.enableScroll === true) { - context.translate(opts._scrollDistance_, 0); - leftSpace = -opts._scrollDistance_ - eachSpacing * 2 + opts.area[3]; - rightSpace = leftSpace + (opts.xAxis.itemCount + 4) * eachSpacing; - } - series.forEach(function (eachSeries, seriesIndex) { - let ranges, minRange, maxRange; - ranges = [].concat(opts.chartData.yAxisData.ranges[eachSeries.index]); - minRange = ranges.pop(); - maxRange = ranges.shift(); - var data = eachSeries.data; - var points = getDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config, process); - context.beginPath(); - context.setStrokeStyle(eachSeries.color); - context.setLineWidth(bubbleOption.border * opts.pix); - context.setFillStyle(hexToRgb(eachSeries.color, bubbleOption.opacity)); - points.forEach(function (item, index) { - context.moveTo(item.x + item.r, item.y); - context.arc(item.x, item.y, item.r * opts.pix, 0, 2 * Math.PI, false); - }); - context.closePath(); - context.fill(); - context.stroke(); - - if (opts.dataLabel !== false && process === 1) { - points.forEach(function (item, index) { - context.beginPath(); - var fontSize = eachSeries.textSize * opts.pix || config.fontSize; - context.setFontSize(fontSize); - context.setFillStyle(eachSeries.textColor || "#FFFFFF"); - context.setTextAlign("center"); - context.fillText(String(item.t), item.x, item.y + fontSize / 2); - context.closePath(); - context.stroke(); - context.setTextAlign("left"); - }); - } - }); - context.restore(); - return { - xAxisPoints: xAxisPoints, - calPoints: calPoints, - eachSpacing: eachSpacing, - }; -} - -function drawLineDataPoints(series, opts, config, context) { - var process = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1; - var lineOption = assign( - {}, - { - type: "straight", - width: 2, - activeType: "none", - linearType: "none", - onShadow: false, - animation: "vertical", - }, - opts.extra.line - ); - lineOption.width *= opts.pix; - let xAxisData = opts.chartData.xAxisData, - xAxisPoints = xAxisData.xAxisPoints, - eachSpacing = xAxisData.eachSpacing; - var calPoints = []; - context.save(); - let leftSpace = 0; - let rightSpace = opts.width + eachSpacing; - if (opts._scrollDistance_ && opts._scrollDistance_ !== 0 && opts.enableScroll === true) { - context.translate(opts._scrollDistance_, 0); - leftSpace = -opts._scrollDistance_ - eachSpacing * 2 + opts.area[3]; - rightSpace = leftSpace + (opts.xAxis.itemCount + 4) * eachSpacing; - } - series.forEach(function (eachSeries, seriesIndex) { - // 这段很神奇的代码用于解决ios16的setStrokeStyle失效的bug - context.beginPath(); - context.setStrokeStyle(eachSeries.color); - context.moveTo(-10000, -10000); - context.lineTo(-10001, -10001); - context.stroke(); - let ranges, minRange, maxRange; - ranges = [].concat(opts.chartData.yAxisData.ranges[eachSeries.index]); - minRange = ranges.pop(); - maxRange = ranges.shift(); - var data = eachSeries.data; - var points = getLineDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config, lineOption, process); - calPoints.push(points); - var splitPointList = splitPoints(points, eachSeries); - if (eachSeries.lineType == "dash") { - let dashLength = eachSeries.dashLength ? eachSeries.dashLength : 8; - dashLength *= opts.pix; - context.setLineDash([dashLength, dashLength]); - } - context.beginPath(); - var strokeColor = eachSeries.color; - if (lineOption.linearType !== "none" && eachSeries.linearColor && eachSeries.linearColor.length > 0) { - var grd = context.createLinearGradient(opts.chartData.xAxisData.startX, opts.height / 2, opts.chartData.xAxisData.endX, opts.height / 2); - for (var i = 0; i < eachSeries.linearColor.length; i++) { - grd.addColorStop(eachSeries.linearColor[i][0], hexToRgb(eachSeries.linearColor[i][1], 1)); - } - strokeColor = grd; - } - context.setStrokeStyle(strokeColor); - if (lineOption.onShadow == true && eachSeries.setShadow && eachSeries.setShadow.length > 0) { - context.setShadow(eachSeries.setShadow[0], eachSeries.setShadow[1], eachSeries.setShadow[2], eachSeries.setShadow[3]); - } else { - context.setShadow(0, 0, 0, "rgba(0,0,0,0)"); - } - context.setLineWidth(lineOption.width); - splitPointList.forEach(function (points, index) { - if (points.length === 1) { - context.moveTo(points[0].x, points[0].y); - // context.arc(points[0].x, points[0].y, 1, 0, 2 * Math.PI); - } else { - context.moveTo(points[0].x, points[0].y); - let startPoint = 0; - if (lineOption.type === "curve") { - for (let j = 0; j < points.length; j++) { - let item = points[j]; - if (startPoint == 0 && item.x > leftSpace) { - context.moveTo(item.x, item.y); - startPoint = 1; - } - if (j > 0 && item.x > leftSpace && item.x < rightSpace) { - var ctrlPoint = createCurveControlPoints(points, j - 1); - context.bezierCurveTo(ctrlPoint.ctrA.x, ctrlPoint.ctrA.y, ctrlPoint.ctrB.x, ctrlPoint.ctrB.y, item.x, item.y); - } - } - } - if (lineOption.type === "straight") { - for (let j = 0; j < points.length; j++) { - let item = points[j]; - if (startPoint == 0 && item.x > leftSpace) { - context.moveTo(item.x, item.y); - startPoint = 1; - } - if (j > 0 && item.x > leftSpace && item.x < rightSpace) { - context.lineTo(item.x, item.y); - } - } - } - if (lineOption.type === "step") { - for (let j = 0; j < points.length; j++) { - let item = points[j]; - if (startPoint == 0 && item.x > leftSpace) { - context.moveTo(item.x, item.y); - startPoint = 1; - } - if (j > 0 && item.x > leftSpace && item.x < rightSpace) { - context.lineTo(item.x, points[j - 1].y); - context.lineTo(item.x, item.y); - } - } - } - context.moveTo(points[0].x, points[0].y); - } - }); - context.stroke(); - context.setLineDash([]); - if (opts.dataPointShape !== false) { - drawPointShape(points, eachSeries.color, eachSeries.pointShape, context, opts); - } - drawActivePoint(points, eachSeries.color, eachSeries.pointShape, context, opts, lineOption); - }); - if (opts.dataLabel !== false && process === 1) { - series.forEach(function (eachSeries, seriesIndex) { - let ranges, minRange, maxRange; - ranges = [].concat(opts.chartData.yAxisData.ranges[eachSeries.index]); - minRange = ranges.pop(); - maxRange = ranges.shift(); - var data = eachSeries.data; - var points = getDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config, process); - drawPointText(points, eachSeries, config, context, opts); - }); - } - context.restore(); - return { - xAxisPoints: xAxisPoints, - calPoints: calPoints, - eachSpacing: eachSpacing, - }; -} - -function drawMixDataPoints(series, opts, config, context) { - let process = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1; - let xAxisData = opts.chartData.xAxisData, - xAxisPoints = xAxisData.xAxisPoints, - eachSpacing = xAxisData.eachSpacing; - let columnOption = assign( - {}, - { - width: eachSpacing / 2, - barBorderCircle: false, - barBorderRadius: [], - seriesGap: 2, - linearType: "none", - linearOpacity: 1, - customColor: [], - colorStop: 0, - }, - opts.extra.mix.column - ); - let areaOption = assign( - {}, - { - opacity: 0.2, - gradient: false, - }, - opts.extra.mix.area - ); - let lineOption = assign( - {}, - { - width: 2, - }, - opts.extra.mix.line - ); - let endY = opts.height - opts.area[2]; - let calPoints = []; - var columnIndex = 0; - var columnLength = 0; - series.forEach(function (eachSeries, seriesIndex) { - if (eachSeries.type == "column") { - columnLength += 1; - } - }); - context.save(); - let leftNum = -2; - let rightNum = xAxisPoints.length + 2; - let leftSpace = 0; - let rightSpace = opts.width + eachSpacing; - if (opts._scrollDistance_ && opts._scrollDistance_ !== 0 && opts.enableScroll === true) { - context.translate(opts._scrollDistance_, 0); - leftNum = Math.floor(-opts._scrollDistance_ / eachSpacing) - 2; - rightNum = leftNum + opts.xAxis.itemCount + 4; - leftSpace = -opts._scrollDistance_ - eachSpacing * 2 + opts.area[3]; - rightSpace = leftSpace + (opts.xAxis.itemCount + 4) * eachSpacing; - } - columnOption.customColor = fillCustomColor(columnOption.linearType, columnOption.customColor, series, config); - series.forEach(function (eachSeries, seriesIndex) { - let ranges, minRange, maxRange; - ranges = [].concat(opts.chartData.yAxisData.ranges[eachSeries.index]); - minRange = ranges.pop(); - maxRange = ranges.shift(); - var data = eachSeries.data; - var points = getDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config, process); - calPoints.push(points); - // 绘制柱状数据图 - if (eachSeries.type == "column") { - points = fixColumeData(points, eachSpacing, columnLength, columnIndex, config, opts); - for (let i = 0; i < points.length; i++) { - let item = points[i]; - if (item !== null && i > leftNum && i < rightNum) { - var startX = item.x - item.width / 2; - var height = opts.height - item.y - opts.area[2]; - context.beginPath(); - var fillColor = item.color || eachSeries.color; - var strokeColor = item.color || eachSeries.color; - if (columnOption.linearType !== "none") { - var grd = context.createLinearGradient(startX, item.y, startX, opts.height - opts.area[2]); - //透明渐变 - if (columnOption.linearType == "opacity") { - grd.addColorStop(0, hexToRgb(fillColor, columnOption.linearOpacity)); - grd.addColorStop(1, hexToRgb(fillColor, 1)); - } else { - grd.addColorStop(0, hexToRgb(columnOption.customColor[eachSeries.linearIndex], columnOption.linearOpacity)); - grd.addColorStop(columnOption.colorStop, hexToRgb(columnOption.customColor[eachSeries.linearIndex], columnOption.linearOpacity)); - grd.addColorStop(1, hexToRgb(fillColor, 1)); - } - fillColor = grd; - } - // 圆角边框 - if ((columnOption.barBorderRadius && columnOption.barBorderRadius.length === 4) || columnOption.barBorderCircle) { - const left = startX; - const top = item.y; - const width = item.width; - const height = opts.height - opts.area[2] - item.y; - if (columnOption.barBorderCircle) { - columnOption.barBorderRadius = [width / 2, width / 2, 0, 0]; - } - let [r0, r1, r2, r3] = columnOption.barBorderRadius; - let minRadius = Math.min(width / 2, height / 2); - r0 = r0 > minRadius ? minRadius : r0; - r1 = r1 > minRadius ? minRadius : r1; - r2 = r2 > minRadius ? minRadius : r2; - r3 = r3 > minRadius ? minRadius : r3; - r0 = r0 < 0 ? 0 : r0; - r1 = r1 < 0 ? 0 : r1; - r2 = r2 < 0 ? 0 : r2; - r3 = r3 < 0 ? 0 : r3; - context.arc(left + r0, top + r0, r0, -Math.PI, -Math.PI / 2); - context.arc(left + width - r1, top + r1, r1, -Math.PI / 2, 0); - context.arc(left + width - r2, top + height - r2, r2, 0, Math.PI / 2); - context.arc(left + r3, top + height - r3, r3, Math.PI / 2, Math.PI); - } else { - context.moveTo(startX, item.y); - context.lineTo(startX + item.width, item.y); - context.lineTo(startX + item.width, opts.height - opts.area[2]); - context.lineTo(startX, opts.height - opts.area[2]); - context.lineTo(startX, item.y); - context.setLineWidth(1); - context.setStrokeStyle(strokeColor); - } - context.setFillStyle(fillColor); - context.closePath(); - context.fill(); - } - } - columnIndex += 1; - } - //绘制区域图数据 - if (eachSeries.type == "area") { - let splitPointList = splitPoints(points, eachSeries); - for (let i = 0; i < splitPointList.length; i++) { - let points = splitPointList[i]; - // 绘制区域数据 - context.beginPath(); - context.setStrokeStyle(eachSeries.color); - context.setStrokeStyle(hexToRgb(eachSeries.color, areaOption.opacity)); - if (areaOption.gradient) { - let gradient = context.createLinearGradient(0, opts.area[0], 0, opts.height - opts.area[2]); - gradient.addColorStop("0", hexToRgb(eachSeries.color, areaOption.opacity)); - gradient.addColorStop("1.0", hexToRgb("#FFFFFF", 0.1)); - context.setFillStyle(gradient); - } else { - context.setFillStyle(hexToRgb(eachSeries.color, areaOption.opacity)); - } - context.setLineWidth(2 * opts.pix); - if (points.length > 1) { - var firstPoint = points[0]; - let lastPoint = points[points.length - 1]; - context.moveTo(firstPoint.x, firstPoint.y); - let startPoint = 0; - if (eachSeries.style === "curve") { - for (let j = 0; j < points.length; j++) { - let item = points[j]; - if (startPoint == 0 && item.x > leftSpace) { - context.moveTo(item.x, item.y); - startPoint = 1; - } - if (j > 0 && item.x > leftSpace && item.x < rightSpace) { - var ctrlPoint = createCurveControlPoints(points, j - 1); - context.bezierCurveTo(ctrlPoint.ctrA.x, ctrlPoint.ctrA.y, ctrlPoint.ctrB.x, ctrlPoint.ctrB.y, item.x, item.y); - } - } - } else { - for (let j = 0; j < points.length; j++) { - let item = points[j]; - if (startPoint == 0 && item.x > leftSpace) { - context.moveTo(item.x, item.y); - startPoint = 1; - } - if (j > 0 && item.x > leftSpace && item.x < rightSpace) { - context.lineTo(item.x, item.y); - } - } - } - context.lineTo(lastPoint.x, endY); - context.lineTo(firstPoint.x, endY); - context.lineTo(firstPoint.x, firstPoint.y); - } else { - let item = points[0]; - context.moveTo(item.x - eachSpacing / 2, item.y); - // context.lineTo(item.x + eachSpacing / 2, item.y); - // context.lineTo(item.x + eachSpacing / 2, endY); - // context.lineTo(item.x - eachSpacing / 2, endY); - // context.moveTo(item.x - eachSpacing / 2, item.y); - } - context.closePath(); - context.fill(); - } - } - // 绘制折线数据图 - if (eachSeries.type == "line") { - var splitPointList = splitPoints(points, eachSeries); - splitPointList.forEach(function (points, index) { - if (eachSeries.lineType == "dash") { - let dashLength = eachSeries.dashLength ? eachSeries.dashLength : 8; - dashLength *= opts.pix; - context.setLineDash([dashLength, dashLength]); - } - context.beginPath(); - context.setStrokeStyle(eachSeries.color); - context.setLineWidth(lineOption.width * opts.pix); - if (points.length === 1) { - context.moveTo(points[0].x, points[0].y); - // context.arc(points[0].x, points[0].y, 1, 0, 2 * Math.PI); - } else { - context.moveTo(points[0].x, points[0].y); - let startPoint = 0; - if (eachSeries.style == "curve") { - for (let j = 0; j < points.length; j++) { - let item = points[j]; - if (startPoint == 0 && item.x > leftSpace) { - context.moveTo(item.x, item.y); - startPoint = 1; - } - if (j > 0 && item.x > leftSpace && item.x < rightSpace) { - var ctrlPoint = createCurveControlPoints(points, j - 1); - context.bezierCurveTo(ctrlPoint.ctrA.x, ctrlPoint.ctrA.y, ctrlPoint.ctrB.x, ctrlPoint.ctrB.y, item.x, item.y); - } - } - } else { - for (let j = 0; j < points.length; j++) { - let item = points[j]; - if (startPoint == 0 && item.x > leftSpace) { - context.moveTo(item.x, item.y); - startPoint = 1; - } - if (j > 0 && item.x > leftSpace && item.x < rightSpace) { - context.lineTo(item.x, item.y); - } - } - } - context.moveTo(points[0].x, points[0].y); - } - context.stroke(); - context.setLineDash([]); - }); - } - // 绘制点数据图 - if (eachSeries.type == "point") { - eachSeries.addPoint = true; - } - if (eachSeries.addPoint == true && eachSeries.type !== "column") { - drawPointShape(points, eachSeries.color, eachSeries.pointShape, context, opts); - } - }); - if (opts.dataLabel !== false && process === 1) { - var columnIndex = 0; - series.forEach(function (eachSeries, seriesIndex) { - let ranges, minRange, maxRange; - ranges = [].concat(opts.chartData.yAxisData.ranges[eachSeries.index]); - minRange = ranges.pop(); - maxRange = ranges.shift(); - var data = eachSeries.data; - var points = getDataPoints(data, minRange, maxRange, xAxisPoints, eachSpacing, opts, config, process); - if (eachSeries.type !== "column") { - drawPointText(points, eachSeries, config, context, opts); - } else { - points = fixColumeData(points, eachSpacing, columnLength, columnIndex, config, opts); - drawPointText(points, eachSeries, config, context, opts); - columnIndex += 1; - } - }); - } - context.restore(); - return { - xAxisPoints: xAxisPoints, - calPoints: calPoints, - eachSpacing: eachSpacing, - }; -} - -function drawToolTipBridge(opts, config, context, process, eachSpacing, xAxisPoints) { - var toolTipOption = opts.extra.tooltip || {}; - if (toolTipOption.horizentalLine && opts.tooltip && process === 1 && (opts.type == "line" || opts.type == "area" || opts.type == "column" || opts.type == "mount" || opts.type == "candle" || opts.type == "mix")) { - drawToolTipHorizentalLine(opts, config, context, eachSpacing, xAxisPoints); - } - context.save(); - if (opts._scrollDistance_ && opts._scrollDistance_ !== 0 && opts.enableScroll === true) { - context.translate(opts._scrollDistance_, 0); - } - if (opts.tooltip && opts.tooltip.textList && opts.tooltip.textList.length && process === 1) { - drawToolTip(opts.tooltip.textList, opts.tooltip.offset, opts, config, context, eachSpacing, xAxisPoints); - } - context.restore(); -} - -function drawXAxis(categories, opts, config, context) { - let xAxisData = opts.chartData.xAxisData, - xAxisPoints = xAxisData.xAxisPoints, - startX = xAxisData.startX, - endX = xAxisData.endX, - eachSpacing = xAxisData.eachSpacing; - var boundaryGap = "center"; - if (opts.type == "bar" || opts.type == "line" || opts.type == "area" || opts.type == "scatter" || opts.type == "bubble") { - boundaryGap = opts.xAxis.boundaryGap; - } - var startY = opts.height - opts.area[2]; - var endY = opts.area[0]; - - //绘制滚动条 - if (opts.enableScroll && opts.xAxis.scrollShow) { - var scrollY = opts.height - opts.area[2] + config.xAxisHeight; - var scrollScreenWidth = endX - startX; - var scrollTotalWidth = eachSpacing * (xAxisPoints.length - 1); - if (opts.type == "mount" && opts.extra && opts.extra.mount && opts.extra.mount.widthRatio && opts.extra.mount.widthRatio > 1) { - if (opts.extra.mount.widthRatio > 2) opts.extra.mount.widthRatio = 2; - scrollTotalWidth += (opts.extra.mount.widthRatio - 1) * eachSpacing; - } - var scrollWidth = (scrollScreenWidth * scrollScreenWidth) / scrollTotalWidth; - var scrollLeft = 0; - if (opts._scrollDistance_) { - scrollLeft = (-opts._scrollDistance_ * scrollScreenWidth) / scrollTotalWidth; - } - context.beginPath(); - context.setLineCap("round"); - context.setLineWidth(6 * opts.pix); - context.setStrokeStyle(opts.xAxis.scrollBackgroundColor || "#EFEBEF"); - context.moveTo(startX, scrollY); - context.lineTo(endX, scrollY); - context.stroke(); - context.closePath(); - context.beginPath(); - context.setLineCap("round"); - context.setLineWidth(6 * opts.pix); - context.setStrokeStyle(opts.xAxis.scrollColor || "#A6A6A6"); - context.moveTo(startX + scrollLeft, scrollY); - context.lineTo(startX + scrollLeft + scrollWidth, scrollY); - context.stroke(); - context.closePath(); - context.setLineCap("butt"); - } - context.save(); - if (opts._scrollDistance_ && opts._scrollDistance_ !== 0) { - context.translate(opts._scrollDistance_, 0); - } - //绘制X轴刻度线 - if (opts.xAxis.calibration === true) { - context.setStrokeStyle(opts.xAxis.gridColor || "#cccccc"); - context.setLineCap("butt"); - context.setLineWidth(1 * opts.pix); - xAxisPoints.forEach(function (item, index) { - if (index > 0) { - context.beginPath(); - context.moveTo(item - eachSpacing / 2, startY); - context.lineTo(item - eachSpacing / 2, startY + 3 * opts.pix); - context.closePath(); - context.stroke(); - } - }); - } - //绘制X轴网格 - if (opts.xAxis.disableGrid !== true) { - context.setStrokeStyle(opts.xAxis.gridColor || "#cccccc"); - context.setLineCap("butt"); - context.setLineWidth(1 * opts.pix); - if (opts.xAxis.gridType == "dash") { - context.setLineDash([opts.xAxis.dashLength * opts.pix, opts.xAxis.dashLength * opts.pix]); - } - opts.xAxis.gridEval = opts.xAxis.gridEval || 1; - xAxisPoints.forEach(function (item, index) { - if (index % opts.xAxis.gridEval == 0) { - context.beginPath(); - context.moveTo(item, startY); - context.lineTo(item, endY); - context.stroke(); - } - }); - context.setLineDash([]); - } - //绘制X轴文案 - if (opts.xAxis.disabled !== true) { - // 对X轴列表做抽稀处理 - //默认全部显示X轴标签 - let maxXAxisListLength = categories.length; - //如果设置了X轴单屏数量 - if (opts.xAxis.labelCount) { - //如果设置X轴密度 - if (opts.xAxis.itemCount) { - maxXAxisListLength = Math.ceil((categories.length / opts.xAxis.itemCount) * opts.xAxis.labelCount); - } else { - maxXAxisListLength = opts.xAxis.labelCount; - } - maxXAxisListLength -= 1; - } - - let ratio = Math.ceil(categories.length / maxXAxisListLength); - - let newCategories = []; - let cgLength = categories.length; - for (let i = 0; i < cgLength; i++) { - if (i % ratio !== 0) { - newCategories.push(""); - } else { - newCategories.push(categories[i]); - } - } - newCategories[cgLength - 1] = categories[cgLength - 1]; - var xAxisFontSize = opts.xAxis.fontSize * opts.pix || config.fontSize; - if (config._xAxisTextAngle_ === 0) { - newCategories.forEach(function (item, index) { - var xitem = opts.xAxis.formatter ? opts.xAxis.formatter(item, index, opts) : item; - var offset = -measureText(String(xitem), xAxisFontSize, context) / 2; - if (boundaryGap == "center") { - offset += eachSpacing / 2; - } - var scrollHeight = 0; - if (opts.xAxis.scrollShow) { - scrollHeight = 6 * opts.pix; - } - // 如果在主视图区域内 - var _scrollDistance_ = opts._scrollDistance_ || 0; - var truePoints = boundaryGap == "center" ? xAxisPoints[index] + eachSpacing / 2 : xAxisPoints[index]; - if (truePoints - Math.abs(_scrollDistance_) >= opts.area[3] - 1 && truePoints - Math.abs(_scrollDistance_) <= opts.width - opts.area[1] + 1) { - context.beginPath(); - context.setFontSize(xAxisFontSize); - context.setFillStyle(opts.xAxis.fontColor || opts.fontColor); - context.fillText(String(xitem), xAxisPoints[index] + offset, startY + opts.xAxis.marginTop * opts.pix + ((opts.xAxis.lineHeight - opts.xAxis.fontSize) * opts.pix) / 2 + opts.xAxis.fontSize * opts.pix); - context.closePath(); - context.stroke(); - } - }); - } else { - newCategories.forEach(function (item, index) { - var xitem = opts.xAxis.formatter ? opts.xAxis.formatter(item) : item; - // 如果在主视图区域内 - var _scrollDistance_ = opts._scrollDistance_ || 0; - var truePoints = boundaryGap == "center" ? xAxisPoints[index] + eachSpacing / 2 : xAxisPoints[index]; - if (truePoints - Math.abs(_scrollDistance_) >= opts.area[3] - 1 && truePoints - Math.abs(_scrollDistance_) <= opts.width - opts.area[1] + 1) { - context.save(); - context.beginPath(); - context.setFontSize(xAxisFontSize); - context.setFillStyle(opts.xAxis.fontColor || opts.fontColor); - var textWidth = measureText(String(xitem), xAxisFontSize, context); - var offsetX = xAxisPoints[index]; - if (boundaryGap == "center") { - offsetX = xAxisPoints[index] + eachSpacing / 2; - } - var scrollHeight = 0; - if (opts.xAxis.scrollShow) { - scrollHeight = 6 * opts.pix; - } - var offsetY = startY + opts.xAxis.marginTop * opts.pix + xAxisFontSize - xAxisFontSize * Math.abs(Math.sin(config._xAxisTextAngle_)); - if (opts.xAxis.rotateAngle < 0) { - offsetX -= xAxisFontSize / 2; - textWidth = 0; - } else { - offsetX += xAxisFontSize / 2; - textWidth = -textWidth; - } - context.translate(offsetX, offsetY); - context.rotate(-1 * config._xAxisTextAngle_); - context.fillText(String(xitem), textWidth, 0); - context.closePath(); - context.stroke(); - context.restore(); - } - }); - } - } - context.restore(); - - //画X轴标题 - if (opts.xAxis.title) { - context.beginPath(); - context.setFontSize(opts.xAxis.titleFontSize * opts.pix); - context.setFillStyle(opts.xAxis.titleFontColor); - context.fillText( - String(opts.xAxis.title), - opts.width - opts.area[1] + opts.xAxis.titleOffsetX * opts.pix, - opts.height - opts.area[2] + opts.xAxis.marginTop * opts.pix + ((opts.xAxis.lineHeight - opts.xAxis.titleFontSize) * opts.pix) / 2 + (opts.xAxis.titleFontSize + opts.xAxis.titleOffsetY) * opts.pix - ); - context.closePath(); - context.stroke(); - } - - //绘制X轴轴线 - if (opts.xAxis.axisLine) { - context.beginPath(); - context.setStrokeStyle(opts.xAxis.axisLineColor); - context.setLineWidth(1 * opts.pix); - context.moveTo(startX, opts.height - opts.area[2]); - context.lineTo(endX, opts.height - opts.area[2]); - context.stroke(); - } -} - -function drawYAxisGrid(categories, opts, config, context) { - if (opts.yAxis.disableGrid === true) { - return; - } - let spacingValid = opts.height - opts.area[0] - opts.area[2]; - let eachSpacing = spacingValid / opts.yAxis.splitNumber; - let startX = opts.area[3]; - let xAxisPoints = opts.chartData.xAxisData.xAxisPoints, - xAxiseachSpacing = opts.chartData.xAxisData.eachSpacing; - let TotalWidth = xAxiseachSpacing * (xAxisPoints.length - 1); - if (opts.type == "mount" && opts.extra && opts.extra.mount && opts.extra.mount.widthRatio && opts.extra.mount.widthRatio > 1) { - if (opts.extra.mount.widthRatio > 2) opts.extra.mount.widthRatio = 2; - TotalWidth += (opts.extra.mount.widthRatio - 1) * xAxiseachSpacing; - } - let endX = startX + TotalWidth; - let points = []; - let startY = 1; - if (opts.xAxis.axisLine === false) { - startY = 0; - } - for (let i = startY; i < opts.yAxis.splitNumber + 1; i++) { - points.push(opts.height - opts.area[2] - eachSpacing * i); - } - context.save(); - if (opts._scrollDistance_ && opts._scrollDistance_ !== 0) { - context.translate(opts._scrollDistance_, 0); - } - if (opts.yAxis.gridType == "dash") { - context.setLineDash([opts.yAxis.dashLength * opts.pix, opts.yAxis.dashLength * opts.pix]); - } - context.setStrokeStyle(opts.yAxis.gridColor); - context.setLineWidth(1 * opts.pix); - points.forEach(function (item, index) { - context.beginPath(); - context.moveTo(startX, item); - context.lineTo(endX, item); - context.stroke(); - }); - context.setLineDash([]); - context.restore(); -} - -function drawYAxis(series, opts, config, context) { - if (opts.yAxis.disabled === true) { - return; - } - var spacingValid = opts.height - opts.area[0] - opts.area[2]; - var eachSpacing = spacingValid / opts.yAxis.splitNumber; - var startX = opts.area[3]; - var endX = opts.width - opts.area[1]; - var endY = opts.height - opts.area[2]; - // set YAxis background - context.beginPath(); - context.setFillStyle(opts.background); - if (opts.enableScroll == true && opts.xAxis.scrollPosition && opts.xAxis.scrollPosition !== "left") { - context.fillRect(0, 0, startX, endY + 2 * opts.pix); - } - if (opts.enableScroll == true && opts.xAxis.scrollPosition && opts.xAxis.scrollPosition !== "right") { - context.fillRect(endX, 0, opts.width, endY + 2 * opts.pix); - } - context.closePath(); - context.stroke(); - - let tStartLeft = opts.area[3]; - let tStartRight = opts.width - opts.area[1]; - let tStartCenter = opts.area[3] + (opts.width - opts.area[1] - opts.area[3]) / 2; - if (opts.yAxis.data) { - for (let i = 0; i < opts.yAxis.data.length; i++) { - let yData = opts.yAxis.data[i]; - var points = []; - if (yData.type === "categories") { - for (let i = 0; i <= yData.categories.length; i++) { - points.push(opts.area[0] + spacingValid / yData.categories.length / 2 + (spacingValid / yData.categories.length) * i); - } - } else { - for (let i = 0; i <= opts.yAxis.splitNumber; i++) { - points.push(opts.area[0] + eachSpacing * i); - } - } - if (yData.disabled !== true) { - let rangesFormat = opts.chartData.yAxisData.rangesFormat[i]; - let yAxisFontSize = yData.fontSize ? yData.fontSize * opts.pix : config.fontSize; - let yAxisWidth = opts.chartData.yAxisData.yAxisWidth[i]; - let textAlign = yData.textAlign || "right"; - //画Y轴刻度及文案 - rangesFormat.forEach(function (item, index) { - var pos = points[index]; - context.beginPath(); - context.setFontSize(yAxisFontSize); - context.setLineWidth(1 * opts.pix); - context.setStrokeStyle(yData.axisLineColor || "#cccccc"); - context.setFillStyle(yData.fontColor || opts.fontColor); - let tmpstrat = 0; - let gapwidth = 4 * opts.pix; - if (yAxisWidth.position == "left") { - //画刻度线 - if (yData.calibration == true) { - context.moveTo(tStartLeft, pos); - context.lineTo(tStartLeft - 3 * opts.pix, pos); - gapwidth += 3 * opts.pix; - } - //画文字 - switch (textAlign) { - case "left": - context.setTextAlign("left"); - tmpstrat = tStartLeft - yAxisWidth.width; - break; - case "right": - context.setTextAlign("right"); - tmpstrat = tStartLeft - gapwidth; - break; - default: - context.setTextAlign("center"); - tmpstrat = tStartLeft - yAxisWidth.width / 2; - } - context.fillText(String(item), tmpstrat, pos + yAxisFontSize / 2 - 3 * opts.pix); - } else if (yAxisWidth.position == "right") { - //画刻度线 - if (yData.calibration == true) { - context.moveTo(tStartRight, pos); - context.lineTo(tStartRight + 3 * opts.pix, pos); - gapwidth += 3 * opts.pix; - } - switch (textAlign) { - case "left": - context.setTextAlign("left"); - tmpstrat = tStartRight + gapwidth; - break; - case "right": - context.setTextAlign("right"); - tmpstrat = tStartRight + yAxisWidth.width; - break; - default: - context.setTextAlign("center"); - tmpstrat = tStartRight + yAxisWidth.width / 2; - } - context.fillText(String(item), tmpstrat, pos + yAxisFontSize / 2 - 3 * opts.pix); - } else if (yAxisWidth.position == "center") { - //画刻度线 - if (yData.calibration == true) { - context.moveTo(tStartCenter, pos); - context.lineTo(tStartCenter - 3 * opts.pix, pos); - gapwidth += 3 * opts.pix; - } - //画文字 - switch (textAlign) { - case "left": - context.setTextAlign("left"); - tmpstrat = tStartCenter - yAxisWidth.width; - break; - case "right": - context.setTextAlign("right"); - tmpstrat = tStartCenter - gapwidth; - break; - default: - context.setTextAlign("center"); - tmpstrat = tStartCenter - yAxisWidth.width / 2; - } - context.fillText(String(item), tmpstrat, pos + yAxisFontSize / 2 - 3 * opts.pix); - } - context.closePath(); - context.stroke(); - context.setTextAlign("left"); - }); - //画Y轴轴线 - if (yData.axisLine !== false) { - context.beginPath(); - context.setStrokeStyle(yData.axisLineColor || "#cccccc"); - context.setLineWidth(1 * opts.pix); - if (yAxisWidth.position == "left") { - context.moveTo(tStartLeft, opts.height - opts.area[2]); - context.lineTo(tStartLeft, opts.area[0]); - } else if (yAxisWidth.position == "right") { - context.moveTo(tStartRight, opts.height - opts.area[2]); - context.lineTo(tStartRight, opts.area[0]); - } else if (yAxisWidth.position == "center") { - context.moveTo(tStartCenter, opts.height - opts.area[2]); - context.lineTo(tStartCenter, opts.area[0]); - } - context.stroke(); - } - //画Y轴标题 - if (opts.yAxis.showTitle) { - let titleFontSize = yData.titleFontSize * opts.pix || config.fontSize; - let title = yData.title; - context.beginPath(); - context.setFontSize(titleFontSize); - context.setFillStyle(yData.titleFontColor || opts.fontColor); - if (yAxisWidth.position == "left") { - context.fillText(title, tStartLeft - measureText(title, titleFontSize, context) / 2 + (yData.titleOffsetX || 0), opts.area[0] - (10 - (yData.titleOffsetY || 0)) * opts.pix); - } else if (yAxisWidth.position == "right") { - context.fillText(title, tStartRight - measureText(title, titleFontSize, context) / 2 + (yData.titleOffsetX || 0), opts.area[0] - (10 - (yData.titleOffsetY || 0)) * opts.pix); - } else if (yAxisWidth.position == "center") { - context.fillText(title, tStartCenter - measureText(title, titleFontSize, context) / 2 + (yData.titleOffsetX || 0), opts.area[0] - (10 - (yData.titleOffsetY || 0)) * opts.pix); - } - context.closePath(); - context.stroke(); - } - if (yAxisWidth.position == "left") { - tStartLeft -= yAxisWidth.width + opts.yAxis.padding * opts.pix; - } else { - tStartRight += yAxisWidth.width + opts.yAxis.padding * opts.pix; - } - } - } - } -} - -function drawLegend(series, opts, config, context, chartData) { - if (opts.legend.show === false) { - return; - } - let legendData = chartData.legendData; - let legendList = legendData.points; - let legendArea = legendData.area; - let padding = opts.legend.padding * opts.pix; - let fontSize = opts.legend.fontSize * opts.pix; - let shapeWidth = 15 * opts.pix; - let shapeRight = 5 * opts.pix; - let itemGap = opts.legend.itemGap * opts.pix; - let lineHeight = Math.max(opts.legend.lineHeight * opts.pix, fontSize); - //画背景及边框 - context.beginPath(); - context.setLineWidth(opts.legend.borderWidth * opts.pix); - context.setStrokeStyle(opts.legend.borderColor); - context.setFillStyle(opts.legend.backgroundColor); - context.moveTo(legendArea.start.x, legendArea.start.y); - context.rect(legendArea.start.x, legendArea.start.y, legendArea.width, legendArea.height); - context.closePath(); - context.fill(); - context.stroke(); - legendList.forEach(function (itemList, listIndex) { - let width = 0; - let height = 0; - width = legendData.widthArr[listIndex]; - height = legendData.heightArr[listIndex]; - let startX = 0; - let startY = 0; - if (opts.legend.position == "top" || opts.legend.position == "bottom") { - switch (opts.legend.float) { - case "left": - startX = legendArea.start.x + padding; - break; - case "right": - startX = legendArea.start.x + legendArea.width - width; - break; - default: - startX = legendArea.start.x + (legendArea.width - width) / 2; - } - startY = legendArea.start.y + padding + listIndex * lineHeight; - } else { - if (listIndex == 0) { - width = 0; - } else { - width = legendData.widthArr[listIndex - 1]; - } - startX = legendArea.start.x + padding + width; - startY = legendArea.start.y + padding + (legendArea.height - height) / 2; - } - context.setFontSize(config.fontSize); - for (let i = 0; i < itemList.length; i++) { - let item = itemList[i]; - item.area = [0, 0, 0, 0]; - item.area[0] = startX; - item.area[1] = startY; - item.area[3] = startY + lineHeight; - context.beginPath(); - context.setLineWidth(1 * opts.pix); - context.setStrokeStyle(item.show ? item.color : opts.legend.hiddenColor); - context.setFillStyle(item.show ? item.color : opts.legend.hiddenColor); - switch (item.legendShape) { - case "line": - context.moveTo(startX, startY + 0.5 * lineHeight - 2 * opts.pix); - context.fillRect(startX, startY + 0.5 * lineHeight - 2 * opts.pix, 15 * opts.pix, 4 * opts.pix); - break; - case "triangle": - context.moveTo(startX + 7.5 * opts.pix, startY + 0.5 * lineHeight - 5 * opts.pix); - context.lineTo(startX + 2.5 * opts.pix, startY + 0.5 * lineHeight + 5 * opts.pix); - context.lineTo(startX + 12.5 * opts.pix, startY + 0.5 * lineHeight + 5 * opts.pix); - context.lineTo(startX + 7.5 * opts.pix, startY + 0.5 * lineHeight - 5 * opts.pix); - break; - case "diamond": - context.moveTo(startX + 7.5 * opts.pix, startY + 0.5 * lineHeight - 5 * opts.pix); - context.lineTo(startX + 2.5 * opts.pix, startY + 0.5 * lineHeight); - context.lineTo(startX + 7.5 * opts.pix, startY + 0.5 * lineHeight + 5 * opts.pix); - context.lineTo(startX + 12.5 * opts.pix, startY + 0.5 * lineHeight); - context.lineTo(startX + 7.5 * opts.pix, startY + 0.5 * lineHeight - 5 * opts.pix); - break; - case "circle": - context.moveTo(startX + 7.5 * opts.pix, startY + 0.5 * lineHeight); - context.arc(startX + 7.5 * opts.pix, startY + 0.5 * lineHeight, 5 * opts.pix, 0, 2 * Math.PI); - break; - case "rect": - context.moveTo(startX, startY + 0.5 * lineHeight - 5 * opts.pix); - context.fillRect(startX, startY + 0.5 * lineHeight - 5 * opts.pix, 15 * opts.pix, 10 * opts.pix); - break; - case "square": - context.moveTo(startX + 5 * opts.pix, startY + 0.5 * lineHeight - 5 * opts.pix); - context.fillRect(startX + 5 * opts.pix, startY + 0.5 * lineHeight - 5 * opts.pix, 10 * opts.pix, 10 * opts.pix); - break; - case "none": - break; - default: - context.moveTo(startX, startY + 0.5 * lineHeight - 5 * opts.pix); - context.fillRect(startX, startY + 0.5 * lineHeight - 5 * opts.pix, 15 * opts.pix, 10 * opts.pix); - } - context.closePath(); - context.fill(); - context.stroke(); - startX += shapeWidth + shapeRight; - let fontTrans = 0.5 * lineHeight + 0.5 * fontSize - 2; - const legendText = item.legendText ? item.legendText : item.name; - context.beginPath(); - context.setFontSize(fontSize); - context.setFillStyle(item.show ? opts.legend.fontColor : opts.legend.hiddenColor); - context.fillText(legendText, startX, startY + fontTrans); - context.closePath(); - context.stroke(); - if (opts.legend.position == "top" || opts.legend.position == "bottom") { - startX += measureText(legendText, fontSize, context) + itemGap; - item.area[2] = startX; - } else { - item.area[2] = startX + measureText(legendText, fontSize, context) + itemGap; - startX -= shapeWidth + shapeRight; - startY += lineHeight; - } - } - }); -} - -function drawPieDataPoints(series, opts, config, context) { - var process = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1; - var pieOption = assign( - {}, - { - activeOpacity: 0.5, - activeRadius: 10, - offsetAngle: 0, - labelWidth: 15, - ringWidth: 30, - customRadius: 0, - border: false, - borderWidth: 2, - borderColor: "#FFFFFF", - centerColor: "#FFFFFF", - linearType: "none", - customColor: [], - }, - opts.type == "pie" ? opts.extra.pie : opts.extra.ring - ); - var centerPosition = { - x: opts.area[3] + (opts.width - opts.area[1] - opts.area[3]) / 2, - y: opts.area[0] + (opts.height - opts.area[0] - opts.area[2]) / 2, - }; - if (config.pieChartLinePadding == 0) { - config.pieChartLinePadding = pieOption.activeRadius * opts.pix; - } - - var radius = Math.min((opts.width - opts.area[1] - opts.area[3]) / 2 - config.pieChartLinePadding - config.pieChartTextPadding - config._pieTextMaxLength_, (opts.height - opts.area[0] - opts.area[2]) / 2 - config.pieChartLinePadding - config.pieChartTextPadding); - radius = radius < 10 ? 10 : radius; - if (pieOption.customRadius > 0) { - radius = pieOption.customRadius * opts.pix; - } - series = getPieDataPoints(series, radius, process); - var activeRadius = pieOption.activeRadius * opts.pix; - pieOption.customColor = fillCustomColor(pieOption.linearType, pieOption.customColor, series, config); - series = series.map(function (eachSeries) { - eachSeries._start_ += (pieOption.offsetAngle * Math.PI) / 180; - return eachSeries; - }); - series.forEach(function (eachSeries, seriesIndex) { - if (opts.tooltip) { - if (opts.tooltip.index == seriesIndex) { - context.beginPath(); - context.setFillStyle(hexToRgb(eachSeries.color, pieOption.activeOpacity || 0.5)); - context.moveTo(centerPosition.x, centerPosition.y); - context.arc(centerPosition.x, centerPosition.y, eachSeries._radius_ + activeRadius, eachSeries._start_, eachSeries._start_ + 2 * eachSeries._proportion_ * Math.PI); - context.closePath(); - context.fill(); - } - } - context.beginPath(); - context.setLineWidth(pieOption.borderWidth * opts.pix); - context.lineJoin = "round"; - context.setStrokeStyle(pieOption.borderColor); - var fillcolor = eachSeries.color; - if (pieOption.linearType == "custom") { - var grd; - if (context.createCircularGradient) { - grd = context.createCircularGradient(centerPosition.x, centerPosition.y, eachSeries._radius_); - } else { - grd = context.createRadialGradient(centerPosition.x, centerPosition.y, 0, centerPosition.x, centerPosition.y, eachSeries._radius_); - } - grd.addColorStop(0, hexToRgb(pieOption.customColor[eachSeries.linearIndex], 1)); - grd.addColorStop(1, hexToRgb(eachSeries.color, 1)); - fillcolor = grd; - } - context.setFillStyle(fillcolor); - context.moveTo(centerPosition.x, centerPosition.y); - context.arc(centerPosition.x, centerPosition.y, eachSeries._radius_, eachSeries._start_, eachSeries._start_ + 2 * eachSeries._proportion_ * Math.PI); - context.closePath(); - context.fill(); - if (pieOption.border == true) { - context.stroke(); - } - }); - if (opts.type === "ring") { - var innerPieWidth = radius * 0.6; - if (typeof pieOption.ringWidth === "number" && pieOption.ringWidth > 0) { - innerPieWidth = Math.max(0, radius - pieOption.ringWidth * opts.pix); - } - context.beginPath(); - context.setFillStyle(pieOption.centerColor); - context.moveTo(centerPosition.x, centerPosition.y); - context.arc(centerPosition.x, centerPosition.y, innerPieWidth, 0, 2 * Math.PI); - context.closePath(); - context.fill(); - } - if (opts.dataLabel !== false && process === 1) { - drawPieText(series, opts, config, context, radius, centerPosition); - } - if (process === 1 && opts.type === "ring") { - drawRingTitle(opts, config, context, centerPosition); - } - return { - center: centerPosition, - radius: radius, - series: series, - }; -} - -function drawRoseDataPoints(series, opts, config, context) { - var process = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1; - var roseOption = assign( - {}, - { - type: "area", - activeOpacity: 0.5, - activeRadius: 10, - offsetAngle: 0, - labelWidth: 15, - border: false, - borderWidth: 2, - borderColor: "#FFFFFF", - linearType: "none", - customColor: [], - }, - opts.extra.rose - ); - if (config.pieChartLinePadding == 0) { - config.pieChartLinePadding = roseOption.activeRadius * opts.pix; - } - var centerPosition = { - x: opts.area[3] + (opts.width - opts.area[1] - opts.area[3]) / 2, - y: opts.area[0] + (opts.height - opts.area[0] - opts.area[2]) / 2, - }; - var radius = Math.min((opts.width - opts.area[1] - opts.area[3]) / 2 - config.pieChartLinePadding - config.pieChartTextPadding - config._pieTextMaxLength_, (opts.height - opts.area[0] - opts.area[2]) / 2 - config.pieChartLinePadding - config.pieChartTextPadding); - radius = radius < 10 ? 10 : radius; - var minRadius = roseOption.minRadius || radius * 0.5; - if (radius < minRadius) { - radius = minRadius + 10; - } - series = getRoseDataPoints(series, roseOption.type, minRadius, radius, process); - var activeRadius = roseOption.activeRadius * opts.pix; - roseOption.customColor = fillCustomColor(roseOption.linearType, roseOption.customColor, series, config); - series = series.map(function (eachSeries) { - eachSeries._start_ += ((roseOption.offsetAngle || 0) * Math.PI) / 180; - return eachSeries; - }); - series.forEach(function (eachSeries, seriesIndex) { - if (opts.tooltip) { - if (opts.tooltip.index == seriesIndex) { - context.beginPath(); - context.setFillStyle(hexToRgb(eachSeries.color, roseOption.activeOpacity || 0.5)); - context.moveTo(centerPosition.x, centerPosition.y); - context.arc(centerPosition.x, centerPosition.y, activeRadius + eachSeries._radius_, eachSeries._start_, eachSeries._start_ + 2 * eachSeries._rose_proportion_ * Math.PI); - context.closePath(); - context.fill(); - } - } - context.beginPath(); - context.setLineWidth(roseOption.borderWidth * opts.pix); - context.lineJoin = "round"; - context.setStrokeStyle(roseOption.borderColor); - var fillcolor = eachSeries.color; - if (roseOption.linearType == "custom") { - var grd; - if (context.createCircularGradient) { - grd = context.createCircularGradient(centerPosition.x, centerPosition.y, eachSeries._radius_); - } else { - grd = context.createRadialGradient(centerPosition.x, centerPosition.y, 0, centerPosition.x, centerPosition.y, eachSeries._radius_); - } - grd.addColorStop(0, hexToRgb(roseOption.customColor[eachSeries.linearIndex], 1)); - grd.addColorStop(1, hexToRgb(eachSeries.color, 1)); - fillcolor = grd; - } - context.setFillStyle(fillcolor); - context.moveTo(centerPosition.x, centerPosition.y); - context.arc(centerPosition.x, centerPosition.y, eachSeries._radius_, eachSeries._start_, eachSeries._start_ + 2 * eachSeries._rose_proportion_ * Math.PI); - context.closePath(); - context.fill(); - if (roseOption.border == true) { - context.stroke(); - } - }); - - if (opts.dataLabel !== false && process === 1) { - drawPieText(series, opts, config, context, radius, centerPosition); - } - return { - center: centerPosition, - radius: radius, - series: series, - }; -} - -function drawArcbarDataPoints(series, opts, config, context) { - var process = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1; - var arcbarOption = assign( - {}, - { - startAngle: 0.75, - endAngle: 0.25, - type: "default", - direction: "cw", - lineCap: "round", - width: 12, - gap: 2, - linearType: "none", - customColor: [], - }, - opts.extra.arcbar - ); - series = getArcbarDataPoints(series, arcbarOption, process); - var centerPosition; - if (arcbarOption.centerX || arcbarOption.centerY) { - centerPosition = { - x: arcbarOption.centerX ? arcbarOption.centerX : opts.width / 2, - y: arcbarOption.centerY ? arcbarOption.centerY : opts.height / 2, - }; - } else { - centerPosition = { - x: opts.width / 2, - y: opts.height / 2, - }; - } - var radius; - if (arcbarOption.radius) { - radius = arcbarOption.radius; - } else { - radius = Math.min(centerPosition.x, centerPosition.y); - radius -= 5 * opts.pix; - radius -= arcbarOption.width / 2; - } - radius = radius < 10 ? 10 : radius; - arcbarOption.customColor = fillCustomColor(arcbarOption.linearType, arcbarOption.customColor, series, config); - - for (let i = 0; i < series.length; i++) { - let eachSeries = series[i]; - //背景颜色 - context.setLineWidth(arcbarOption.width * opts.pix); - context.setStrokeStyle(arcbarOption.backgroundColor || "#E9E9E9"); - context.setLineCap(arcbarOption.lineCap); - context.beginPath(); - if (arcbarOption.type == "default") { - context.arc(centerPosition.x, centerPosition.y, radius - (arcbarOption.width * opts.pix + arcbarOption.gap * opts.pix) * i, arcbarOption.startAngle * Math.PI, arcbarOption.endAngle * Math.PI, arcbarOption.direction == "ccw"); - } else { - context.arc(centerPosition.x, centerPosition.y, radius - (arcbarOption.width * opts.pix + arcbarOption.gap * opts.pix) * i, 0, 2 * Math.PI, arcbarOption.direction == "ccw"); - } - context.stroke(); - //进度条 - var fillColor = eachSeries.color; - if (arcbarOption.linearType == "custom") { - var grd = context.createLinearGradient(centerPosition.x - radius, centerPosition.y, centerPosition.x + radius, centerPosition.y); - grd.addColorStop(1, hexToRgb(arcbarOption.customColor[eachSeries.linearIndex], 1)); - grd.addColorStop(0, hexToRgb(eachSeries.color, 1)); - fillColor = grd; - } - context.setLineWidth(arcbarOption.width * opts.pix); - context.setStrokeStyle(fillColor); - context.setLineCap(arcbarOption.lineCap); - context.beginPath(); - context.arc(centerPosition.x, centerPosition.y, radius - (arcbarOption.width * opts.pix + arcbarOption.gap * opts.pix) * i, arcbarOption.startAngle * Math.PI, eachSeries._proportion_ * Math.PI, arcbarOption.direction == "ccw"); - context.stroke(); - } - drawRingTitle(opts, config, context, centerPosition); - return { - center: centerPosition, - radius: radius, - series: series, - }; -} - -function drawGaugeDataPoints(categories, series, opts, config, context) { - var process = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 1; - var gaugeOption = assign( - {}, - { - type: "default", - startAngle: 0.75, - endAngle: 0.25, - width: 15, - labelOffset: 13, - splitLine: { - fixRadius: 0, - splitNumber: 10, - width: 15, - color: "#FFFFFF", - childNumber: 5, - childWidth: 5, - }, - pointer: { - width: 15, - color: "auto", - }, - }, - opts.extra.gauge - ); - if (gaugeOption.oldAngle == undefined) { - gaugeOption.oldAngle = gaugeOption.startAngle; - } - if (gaugeOption.oldData == undefined) { - gaugeOption.oldData = 0; - } - categories = getGaugeAxisPoints(categories, gaugeOption.startAngle, gaugeOption.endAngle); - var centerPosition = { - x: opts.width / 2, - y: opts.height / 2, - }; - var radius = Math.min(centerPosition.x, centerPosition.y); - radius -= 5 * opts.pix; - radius -= gaugeOption.width / 2; - radius = radius < 10 ? 10 : radius; - var innerRadius = radius - gaugeOption.width; - var totalAngle = 0; - //判断仪表盘的样式:default百度样式,progress新样式 - if (gaugeOption.type == "progress") { - //## 第一步画中心圆形背景和进度条背景 - //中心圆形背景 - var pieRadius = radius - gaugeOption.width * 3; - context.beginPath(); - let gradient = context.createLinearGradient(centerPosition.x, centerPosition.y - pieRadius, centerPosition.x, centerPosition.y + pieRadius); - //配置渐变填充(起点:中心点向上减半径;结束点中心点向下加半径) - gradient.addColorStop("0", hexToRgb(series[0].color, 0.3)); - gradient.addColorStop("1.0", hexToRgb("#FFFFFF", 0.1)); - context.setFillStyle(gradient); - context.arc(centerPosition.x, centerPosition.y, pieRadius, 0, 2 * Math.PI, false); - context.fill(); - //画进度条背景 - context.setLineWidth(gaugeOption.width); - context.setStrokeStyle(hexToRgb(series[0].color, 0.3)); - context.setLineCap("round"); - context.beginPath(); - context.arc(centerPosition.x, centerPosition.y, innerRadius, gaugeOption.startAngle * Math.PI, gaugeOption.endAngle * Math.PI, false); - context.stroke(); - //## 第二步画刻度线 - if (gaugeOption.endAngle < gaugeOption.startAngle) { - totalAngle = 2 + gaugeOption.endAngle - gaugeOption.startAngle; - } else { - totalAngle = gaugeOption.startAngle - gaugeOption.endAngle; - } - let splitAngle = totalAngle / gaugeOption.splitLine.splitNumber; - let childAngle = totalAngle / gaugeOption.splitLine.splitNumber / gaugeOption.splitLine.childNumber; - let startX = -radius - gaugeOption.width * 0.5 - gaugeOption.splitLine.fixRadius; - let endX = -radius - gaugeOption.width - gaugeOption.splitLine.fixRadius + gaugeOption.splitLine.width; - context.save(); - context.translate(centerPosition.x, centerPosition.y); - context.rotate((gaugeOption.startAngle - 1) * Math.PI); - let len = gaugeOption.splitLine.splitNumber * gaugeOption.splitLine.childNumber + 1; - let proc = series[0].data * process; - for (let i = 0; i < len; i++) { - context.beginPath(); - //刻度线随进度变色 - if (proc > i / len) { - context.setStrokeStyle(hexToRgb(series[0].color, 1)); - } else { - context.setStrokeStyle(hexToRgb(series[0].color, 0.3)); - } - context.setLineWidth(3 * opts.pix); - context.moveTo(startX, 0); - context.lineTo(endX, 0); - context.stroke(); - context.rotate(childAngle * Math.PI); - } - context.restore(); - //## 第三步画进度条 - series = getGaugeArcbarDataPoints(series, gaugeOption, process); - context.setLineWidth(gaugeOption.width); - context.setStrokeStyle(series[0].color); - context.setLineCap("round"); - context.beginPath(); - context.arc(centerPosition.x, centerPosition.y, innerRadius, gaugeOption.startAngle * Math.PI, series[0]._proportion_ * Math.PI, false); - context.stroke(); - //## 第四步画指针 - let pointerRadius = radius - gaugeOption.width * 2.5; - context.save(); - context.translate(centerPosition.x, centerPosition.y); - context.rotate((series[0]._proportion_ - 1) * Math.PI); - context.beginPath(); - context.setLineWidth(gaugeOption.width / 3); - let gradient3 = context.createLinearGradient(0, -pointerRadius * 0.6, 0, pointerRadius * 0.6); - gradient3.addColorStop("0", hexToRgb("#FFFFFF", 0)); - gradient3.addColorStop("0.5", hexToRgb(series[0].color, 1)); - gradient3.addColorStop("1.0", hexToRgb("#FFFFFF", 0)); - context.setStrokeStyle(gradient3); - context.arc(0, 0, pointerRadius, 0.85 * Math.PI, 1.15 * Math.PI, false); - context.stroke(); - context.beginPath(); - context.setLineWidth(1); - context.setStrokeStyle(series[0].color); - context.setFillStyle(series[0].color); - context.moveTo(-pointerRadius - gaugeOption.width / 3 / 2, -4); - context.lineTo(-pointerRadius - gaugeOption.width / 3 / 2 - 4, 0); - context.lineTo(-pointerRadius - gaugeOption.width / 3 / 2, 4); - context.lineTo(-pointerRadius - gaugeOption.width / 3 / 2, -4); - context.stroke(); - context.fill(); - context.restore(); - //default百度样式 - } else { - //画背景 - context.setLineWidth(gaugeOption.width); - context.setLineCap("butt"); - for (let i = 0; i < categories.length; i++) { - let eachCategories = categories[i]; - context.beginPath(); - context.setStrokeStyle(eachCategories.color); - context.arc(centerPosition.x, centerPosition.y, radius, eachCategories._startAngle_ * Math.PI, eachCategories._endAngle_ * Math.PI, false); - context.stroke(); - } - context.save(); - //画刻度线 - if (gaugeOption.endAngle < gaugeOption.startAngle) { - totalAngle = 2 + gaugeOption.endAngle - gaugeOption.startAngle; - } else { - totalAngle = gaugeOption.startAngle - gaugeOption.endAngle; - } - let splitAngle = totalAngle / gaugeOption.splitLine.splitNumber; - let childAngle = totalAngle / gaugeOption.splitLine.splitNumber / gaugeOption.splitLine.childNumber; - let startX = -radius - gaugeOption.width * 0.5 - gaugeOption.splitLine.fixRadius; - let endX = -radius - gaugeOption.width * 0.5 - gaugeOption.splitLine.fixRadius + gaugeOption.splitLine.width; - let childendX = -radius - gaugeOption.width * 0.5 - gaugeOption.splitLine.fixRadius + gaugeOption.splitLine.childWidth; - context.translate(centerPosition.x, centerPosition.y); - context.rotate((gaugeOption.startAngle - 1) * Math.PI); - for (let i = 0; i < gaugeOption.splitLine.splitNumber + 1; i++) { - context.beginPath(); - context.setStrokeStyle(gaugeOption.splitLine.color); - context.setLineWidth(2 * opts.pix); - context.moveTo(startX, 0); - context.lineTo(endX, 0); - context.stroke(); - context.rotate(splitAngle * Math.PI); - } - context.restore(); - context.save(); - context.translate(centerPosition.x, centerPosition.y); - context.rotate((gaugeOption.startAngle - 1) * Math.PI); - for (let i = 0; i < gaugeOption.splitLine.splitNumber * gaugeOption.splitLine.childNumber + 1; i++) { - context.beginPath(); - context.setStrokeStyle(gaugeOption.splitLine.color); - context.setLineWidth(1 * opts.pix); - context.moveTo(startX, 0); - context.lineTo(childendX, 0); - context.stroke(); - context.rotate(childAngle * Math.PI); - } - context.restore(); - //画指针 - series = getGaugeDataPoints(series, categories, gaugeOption, process); - for (let i = 0; i < series.length; i++) { - let eachSeries = series[i]; - context.save(); - context.translate(centerPosition.x, centerPosition.y); - context.rotate((eachSeries._proportion_ - 1) * Math.PI); - context.beginPath(); - context.setFillStyle(eachSeries.color); - context.moveTo(gaugeOption.pointer.width, 0); - context.lineTo(0, -gaugeOption.pointer.width / 2); - context.lineTo(-innerRadius, 0); - context.lineTo(0, gaugeOption.pointer.width / 2); - context.lineTo(gaugeOption.pointer.width, 0); - context.closePath(); - context.fill(); - context.beginPath(); - context.setFillStyle("#FFFFFF"); - context.arc(0, 0, gaugeOption.pointer.width / 6, 0, 2 * Math.PI, false); - context.fill(); - context.restore(); - } - if (opts.dataLabel !== false) { - drawGaugeLabel(gaugeOption, radius, centerPosition, opts, config, context); - } - } - //画仪表盘标题,副标题 - drawRingTitle(opts, config, context, centerPosition); - if (process === 1 && opts.type === "gauge") { - opts.extra.gauge.oldAngle = series[0]._proportion_; - opts.extra.gauge.oldData = series[0].data; - } - return { - center: centerPosition, - radius: radius, - innerRadius: innerRadius, - categories: categories, - totalAngle: totalAngle, - }; -} - -function drawRadarDataPoints(series, opts, config, context) { - var process = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1; - var radarOption = assign( - {}, - { - gridColor: "#cccccc", - gridType: "radar", - gridEval: 1, - axisLabel: false, - axisLabelTofix: 0, - labelShow: true, - labelColor: "#666666", - labelPointShow: false, - labelPointRadius: 3, - labelPointColor: "#cccccc", - opacity: 0.2, - gridCount: 3, - border: false, - borderWidth: 2, - linearType: "none", - customColor: [], - }, - opts.extra.radar - ); - var coordinateAngle = getRadarCoordinateSeries(opts.categories.length); - var centerPosition = { - x: opts.area[3] + (opts.width - opts.area[1] - opts.area[3]) / 2, - y: opts.area[0] + (opts.height - opts.area[0] - opts.area[2]) / 2, - }; - var xr = (opts.width - opts.area[1] - opts.area[3]) / 2; - var yr = (opts.height - opts.area[0] - opts.area[2]) / 2; - var radius = Math.min(xr - (getMaxTextListLength(opts.categories, config.fontSize, context) + config.radarLabelTextMargin), yr - config.radarLabelTextMargin); - radius -= config.radarLabelTextMargin * opts.pix; - radius = radius < 10 ? 10 : radius; - radius = radarOption.radius ? radarOption.radius : radius; - // 画分割线 - context.beginPath(); - context.setLineWidth(1 * opts.pix); - context.setStrokeStyle(radarOption.gridColor); - coordinateAngle.forEach(function (angle, index) { - var pos = convertCoordinateOrigin(radius * Math.cos(angle), radius * Math.sin(angle), centerPosition); - context.moveTo(centerPosition.x, centerPosition.y); - if (index % radarOption.gridEval == 0) { - context.lineTo(pos.x, pos.y); - } - }); - context.stroke(); - context.closePath(); - - // 画背景网格 - var _loop = function _loop(i) { - var startPos = {}; - context.beginPath(); - context.setLineWidth(1 * opts.pix); - context.setStrokeStyle(radarOption.gridColor); - if (radarOption.gridType == "radar") { - coordinateAngle.forEach(function (angle, index) { - var pos = convertCoordinateOrigin((radius / radarOption.gridCount) * i * Math.cos(angle), (radius / radarOption.gridCount) * i * Math.sin(angle), centerPosition); - if (index === 0) { - startPos = pos; - context.moveTo(pos.x, pos.y); - } else { - context.lineTo(pos.x, pos.y); - } - }); - context.lineTo(startPos.x, startPos.y); - } else { - var pos = convertCoordinateOrigin((radius / radarOption.gridCount) * i * Math.cos(1.5), (radius / radarOption.gridCount) * i * Math.sin(1.5), centerPosition); - context.arc(centerPosition.x, centerPosition.y, centerPosition.y - pos.y, 0, 2 * Math.PI, false); - } - context.stroke(); - context.closePath(); - }; - for (var i = 1; i <= radarOption.gridCount; i++) { - _loop(i); - } - radarOption.customColor = fillCustomColor(radarOption.linearType, radarOption.customColor, series, config); - var radarDataPoints = getRadarDataPoints(coordinateAngle, centerPosition, radius, series, opts, process); - radarDataPoints.forEach(function (eachSeries, seriesIndex) { - // 绘制区域数据 - context.beginPath(); - context.setLineWidth(radarOption.borderWidth * opts.pix); - context.setStrokeStyle(eachSeries.color); - - var fillcolor = hexToRgb(eachSeries.color, radarOption.opacity); - if (radarOption.linearType == "custom") { - var grd; - if (context.createCircularGradient) { - grd = context.createCircularGradient(centerPosition.x, centerPosition.y, radius); - } else { - grd = context.createRadialGradient(centerPosition.x, centerPosition.y, 0, centerPosition.x, centerPosition.y, radius); - } - grd.addColorStop(0, hexToRgb(radarOption.customColor[series[seriesIndex].linearIndex], radarOption.opacity)); - grd.addColorStop(1, hexToRgb(eachSeries.color, radarOption.opacity)); - fillcolor = grd; - } - - context.setFillStyle(fillcolor); - eachSeries.data.forEach(function (item, index) { - if (index === 0) { - context.moveTo(item.position.x, item.position.y); - } else { - context.lineTo(item.position.x, item.position.y); - } - }); - context.closePath(); - context.fill(); - if (radarOption.border === true) { - context.stroke(); - } - context.closePath(); - if (opts.dataPointShape !== false) { - var points = eachSeries.data.map(function (item) { - return item.position; - }); - drawPointShape(points, eachSeries.color, eachSeries.pointShape, context, opts); - } - }); - // 画刻度值 - if (radarOption.axisLabel === true) { - const maxData = Math.max(radarOption.max, Math.max.apply(null, dataCombine(series))); - const stepLength = radius / radarOption.gridCount; - const fontSize = opts.fontSize * opts.pix; - context.setFontSize(fontSize); - context.setFillStyle(opts.fontColor); - context.setTextAlign("left"); - for (var i = 0; i < radarOption.gridCount + 1; i++) { - let label = (i * maxData) / radarOption.gridCount; - label = label.toFixed(radarOption.axisLabelTofix); - context.fillText(String(label), centerPosition.x + 3 * opts.pix, centerPosition.y - i * stepLength + fontSize / 2); - } - } - - // draw label text - drawRadarLabel(coordinateAngle, radius, centerPosition, opts, config, context); - - // draw dataLabel - if (opts.dataLabel !== false && process === 1) { - radarDataPoints.forEach(function (eachSeries, seriesIndex) { - context.beginPath(); - var fontSize = eachSeries.textSize * opts.pix || config.fontSize; - context.setFontSize(fontSize); - context.setFillStyle(eachSeries.textColor || opts.fontColor); - eachSeries.data.forEach(function (item, index) { - //如果是中心点垂直的上下点位 - if (Math.abs(item.position.x - centerPosition.x) < 2) { - //如果在上面 - if (item.position.y < centerPosition.y) { - context.setTextAlign("center"); - context.fillText(item.value, item.position.x, item.position.y - 4); - } else { - context.setTextAlign("center"); - context.fillText(item.value, item.position.x, item.position.y + fontSize + 2); - } - } else { - //如果在左侧 - if (item.position.x < centerPosition.x) { - context.setTextAlign("right"); - context.fillText(item.value, item.position.x - 4, item.position.y + fontSize / 2 - 2); - } else { - context.setTextAlign("left"); - context.fillText(item.value, item.position.x + 4, item.position.y + fontSize / 2 - 2); - } - } - }); - context.closePath(); - context.stroke(); - }); - context.setTextAlign("left"); - } - - return { - center: centerPosition, - radius: radius, - angleList: coordinateAngle, - }; -} - -// 经纬度转墨卡托 -function lonlat2mercator(longitude, latitude) { - var mercator = Array(2); - var x = (longitude * 20037508.34) / 180; - var y = Math.log(Math.tan(((90 + latitude) * Math.PI) / 360)) / (Math.PI / 180); - y = (y * 20037508.34) / 180; - mercator[0] = x; - mercator[1] = y; - return mercator; -} - -// 墨卡托转经纬度 -function mercator2lonlat(longitude, latitude) { - var lonlat = Array(2); - var x = (longitude / 20037508.34) * 180; - var y = (latitude / 20037508.34) * 180; - y = (180 / Math.PI) * (2 * Math.atan(Math.exp((y * Math.PI) / 180)) - Math.PI / 2); - lonlat[0] = x; - lonlat[1] = y; - return lonlat; -} - -function getBoundingBox(data) { - var bounds = {}, - coords; - bounds.xMin = 180; - bounds.xMax = 0; - bounds.yMin = 90; - bounds.yMax = 0; - for (var i = 0; i < data.length; i++) { - var coorda = data[i].geometry.coordinates; - for (var k = 0; k < coorda.length; k++) { - coords = coorda[k]; - if (coords.length == 1) { - coords = coords[0]; - } - for (var j = 0; j < coords.length; j++) { - var longitude = coords[j][0]; - var latitude = coords[j][1]; - var point = { - x: longitude, - y: latitude, - }; - bounds.xMin = bounds.xMin < point.x ? bounds.xMin : point.x; - bounds.xMax = bounds.xMax > point.x ? bounds.xMax : point.x; - bounds.yMin = bounds.yMin < point.y ? bounds.yMin : point.y; - bounds.yMax = bounds.yMax > point.y ? bounds.yMax : point.y; - } - } - } - return bounds; -} - -function coordinateToPoint(latitude, longitude, bounds, scale, xoffset, yoffset) { - return { - x: (longitude - bounds.xMin) * scale + xoffset, - y: (bounds.yMax - latitude) * scale + yoffset, - }; -} - -function pointToCoordinate(pointY, pointX, bounds, scale, xoffset, yoffset) { - return { - x: (pointX - xoffset) / scale + bounds.xMin, - y: bounds.yMax - (pointY - yoffset) / scale, - }; -} - -function isRayIntersectsSegment(poi, s_poi, e_poi) { - if (s_poi[1] == e_poi[1]) { - return false; - } - if (s_poi[1] > poi[1] && e_poi[1] > poi[1]) { - return false; - } - if (s_poi[1] < poi[1] && e_poi[1] < poi[1]) { - return false; - } - if (s_poi[1] == poi[1] && e_poi[1] > poi[1]) { - return false; - } - if (e_poi[1] == poi[1] && s_poi[1] > poi[1]) { - return false; - } - if (s_poi[0] < poi[0] && e_poi[1] < poi[1]) { - return false; - } - let xseg = e_poi[0] - ((e_poi[0] - s_poi[0]) * (e_poi[1] - poi[1])) / (e_poi[1] - s_poi[1]); - if (xseg < poi[0]) { - return false; - } else { - return true; - } -} - -function isPoiWithinPoly(poi, poly, mercator) { - let sinsc = 0; - for (let i = 0; i < poly.length; i++) { - let epoly = poly[i][0]; - if (poly.length == 1) { - epoly = poly[i][0]; - } - for (let j = 0; j < epoly.length - 1; j++) { - let s_poi = epoly[j]; - let e_poi = epoly[j + 1]; - if (mercator) { - s_poi = lonlat2mercator(epoly[j][0], epoly[j][1]); - e_poi = lonlat2mercator(epoly[j + 1][0], epoly[j + 1][1]); - } - if (isRayIntersectsSegment(poi, s_poi, e_poi)) { - sinsc += 1; - } - } - } - if (sinsc % 2 == 1) { - return true; - } else { - return false; - } -} - -function drawMapDataPoints(series, opts, config, context) { - var mapOption = assign( - {}, - { - border: true, - mercator: false, - borderWidth: 1, - active: true, - borderColor: "#666666", - fillOpacity: 0.6, - activeBorderColor: "#f04864", - activeFillColor: "#facc14", - activeFillOpacity: 1, - }, - opts.extra.map - ); - var coords, point; - var data = series; - var bounds = getBoundingBox(data); - if (mapOption.mercator) { - var max = lonlat2mercator(bounds.xMax, bounds.yMax); - var min = lonlat2mercator(bounds.xMin, bounds.yMin); - bounds.xMax = max[0]; - bounds.yMax = max[1]; - bounds.xMin = min[0]; - bounds.yMin = min[1]; - } - var xScale = opts.width / Math.abs(bounds.xMax - bounds.xMin); - var yScale = opts.height / Math.abs(bounds.yMax - bounds.yMin); - var scale = xScale < yScale ? xScale : yScale; - var xoffset = opts.width / 2 - (Math.abs(bounds.xMax - bounds.xMin) / 2) * scale; - var yoffset = opts.height / 2 - (Math.abs(bounds.yMax - bounds.yMin) / 2) * scale; - for (var i = 0; i < data.length; i++) { - context.beginPath(); - context.setLineWidth(mapOption.borderWidth * opts.pix); - context.setStrokeStyle(mapOption.borderColor); - context.setFillStyle(hexToRgb(series[i].color, series[i].fillOpacity || mapOption.fillOpacity)); - if (mapOption.active == true && opts.tooltip) { - if (opts.tooltip.index == i) { - context.setStrokeStyle(mapOption.activeBorderColor); - context.setFillStyle(hexToRgb(mapOption.activeFillColor, mapOption.activeFillOpacity)); - } - } - var coorda = data[i].geometry.coordinates; - for (var k = 0; k < coorda.length; k++) { - coords = coorda[k]; - if (coords.length == 1) { - coords = coords[0]; - } - for (var j = 0; j < coords.length; j++) { - var gaosi = Array(2); - if (mapOption.mercator) { - gaosi = lonlat2mercator(coords[j][0], coords[j][1]); - } else { - gaosi = coords[j]; - } - point = coordinateToPoint(gaosi[1], gaosi[0], bounds, scale, xoffset, yoffset); - if (j === 0) { - context.beginPath(); - context.moveTo(point.x, point.y); - } else { - context.lineTo(point.x, point.y); - } - } - context.fill(); - if (mapOption.border == true) { - context.stroke(); - } - } - } - if (opts.dataLabel == true) { - for (var i = 0; i < data.length; i++) { - var centerPoint = data[i].properties.centroid; - if (centerPoint) { - if (mapOption.mercator) { - centerPoint = lonlat2mercator(data[i].properties.centroid[0], data[i].properties.centroid[1]); - } - point = coordinateToPoint(centerPoint[1], centerPoint[0], bounds, scale, xoffset, yoffset); - let fontSize = data[i].textSize * opts.pix || config.fontSize; - let fontColor = data[i].textColor || opts.fontColor; - if (mapOption.active && mapOption.activeTextColor && opts.tooltip && opts.tooltip.index == i) { - fontColor = mapOption.activeTextColor; - } - let text = data[i].properties.name; - context.beginPath(); - context.setFontSize(fontSize); - context.setFillStyle(fontColor); - context.fillText(text, point.x - measureText(text, fontSize, context) / 2, point.y + fontSize / 2); - context.closePath(); - context.stroke(); - } - } - } - opts.chartData.mapData = { - bounds: bounds, - scale: scale, - xoffset: xoffset, - yoffset: yoffset, - mercator: mapOption.mercator, - }; - drawToolTipBridge(opts, config, context, 1); - context.draw(); -} - -function normalInt(min, max, iter) { - iter = iter == 0 ? 1 : iter; - var arr = []; - for (var i = 0; i < iter; i++) { - arr[i] = Math.random(); - } - return ( - Math.floor( - (arr.reduce(function (i, j) { - return i + j; - }) / - iter) * - (max - min) - ) + min - ); -} - -function collisionNew(area, points, width, height) { - var isIn = false; - for (let i = 0; i < points.length; i++) { - if (points[i].area) { - if (area[3] < points[i].area[1] || area[0] > points[i].area[2] || area[1] > points[i].area[3] || area[2] < points[i].area[0]) { - if (area[0] < 0 || area[1] < 0 || area[2] > width || area[3] > height) { - isIn = true; - break; - } else { - isIn = false; - } - } else { - isIn = true; - break; - } - } - } - return isIn; -} - -function getWordCloudPoint(opts, type, context) { - let points = opts.series; - switch (type) { - case "normal": - for (let i = 0; i < points.length; i++) { - let text = points[i].name; - let tHeight = points[i].textSize * opts.pix; - let tWidth = measureText(text, tHeight, context); - let x, y; - let area; - let breaknum = 0; - while (true) { - breaknum++; - x = normalInt(-opts.width / 2, opts.width / 2, 5) - tWidth / 2; - y = normalInt(-opts.height / 2, opts.height / 2, 5) + tHeight / 2; - area = [x - 5 + opts.width / 2, y - 5 - tHeight + opts.height / 2, x + tWidth + 5 + opts.width / 2, y + 5 + opts.height / 2]; - let isCollision = collisionNew(area, points, opts.width, opts.height); - if (!isCollision) break; - if (breaknum == 1000) { - area = [-100, -100, -100, -100]; - break; - } - } - points[i].area = area; - } - break; - case "vertical": - function Spin() { - //获取均匀随机值,是否旋转,旋转的概率为(1-0.5) - if (Math.random() > 0.7) { - return true; - } else { - return false; - } - } - for (let i = 0; i < points.length; i++) { - let text = points[i].name; - let tHeight = points[i].textSize * opts.pix; - let tWidth = measureText(text, tHeight, context); - let isSpin = Spin(); - let x, y, area, areav; - let breaknum = 0; - while (true) { - breaknum++; - let isCollision; - if (isSpin) { - x = normalInt(-opts.width / 2, opts.width / 2, 5) - tWidth / 2; - y = normalInt(-opts.height / 2, opts.height / 2, 5) + tHeight / 2; - area = [y - 5 - tWidth + opts.width / 2, -x - 5 + opts.height / 2, y + 5 + opts.width / 2, -x + tHeight + 5 + opts.height / 2]; - areav = [ - opts.width - (opts.width / 2 - opts.height / 2) - (-x + tHeight + 5 + opts.height / 2) - 5, - opts.height / 2 - opts.width / 2 + (y - 5 - tWidth + opts.width / 2) - 5, - opts.width - (opts.width / 2 - opts.height / 2) - (-x + tHeight + 5 + opts.height / 2) + tHeight, - opts.height / 2 - opts.width / 2 + (y - 5 - tWidth + opts.width / 2) + tWidth + 5, - ]; - isCollision = collisionNew(areav, points, opts.height, opts.width); - } else { - x = normalInt(-opts.width / 2, opts.width / 2, 5) - tWidth / 2; - y = normalInt(-opts.height / 2, opts.height / 2, 5) + tHeight / 2; - area = [x - 5 + opts.width / 2, y - 5 - tHeight + opts.height / 2, x + tWidth + 5 + opts.width / 2, y + 5 + opts.height / 2]; - isCollision = collisionNew(area, points, opts.width, opts.height); - } - if (!isCollision) break; - if (breaknum == 1000) { - area = [-1000, -1000, -1000, -1000]; - break; - } - } - if (isSpin) { - points[i].area = areav; - points[i].areav = area; - } else { - points[i].area = area; - } - points[i].rotate = isSpin; - } - break; - } - return points; -} - -function drawWordCloudDataPoints(series, opts, config, context) { - let process = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1; - let wordOption = assign( - {}, - { - type: "normal", - autoColors: true, - }, - opts.extra.word - ); - if (!opts.chartData.wordCloudData) { - opts.chartData.wordCloudData = getWordCloudPoint(opts, wordOption.type, context); - } - context.beginPath(); - context.setFillStyle(opts.background); - context.rect(0, 0, opts.width, opts.height); - context.fill(); - context.save(); - let points = opts.chartData.wordCloudData; - context.translate(opts.width / 2, opts.height / 2); - for (let i = 0; i < points.length; i++) { - context.save(); - if (points[i].rotate) { - context.rotate((90 * Math.PI) / 180); - } - let text = points[i].name; - let tHeight = points[i].textSize * opts.pix; - let tWidth = measureText(text, tHeight, context); - context.beginPath(); - context.setStrokeStyle(points[i].color); - context.setFillStyle(points[i].color); - context.setFontSize(tHeight); - if (points[i].rotate) { - if (points[i].areav[0] > 0) { - if (opts.tooltip) { - if (opts.tooltip.index == i) { - context.strokeText(text, (points[i].areav[0] + 5 - opts.width / 2) * process - (tWidth * (1 - process)) / 2, (points[i].areav[1] + 5 + tHeight - opts.height / 2) * process); - } else { - context.fillText(text, (points[i].areav[0] + 5 - opts.width / 2) * process - (tWidth * (1 - process)) / 2, (points[i].areav[1] + 5 + tHeight - opts.height / 2) * process); - } - } else { - context.fillText(text, (points[i].areav[0] + 5 - opts.width / 2) * process - (tWidth * (1 - process)) / 2, (points[i].areav[1] + 5 + tHeight - opts.height / 2) * process); - } - } - } else { - if (points[i].area[0] > 0) { - if (opts.tooltip) { - if (opts.tooltip.index == i) { - context.strokeText(text, (points[i].area[0] + 5 - opts.width / 2) * process - (tWidth * (1 - process)) / 2, (points[i].area[1] + 5 + tHeight - opts.height / 2) * process); - } else { - context.fillText(text, (points[i].area[0] + 5 - opts.width / 2) * process - (tWidth * (1 - process)) / 2, (points[i].area[1] + 5 + tHeight - opts.height / 2) * process); - } - } else { - context.fillText(text, (points[i].area[0] + 5 - opts.width / 2) * process - (tWidth * (1 - process)) / 2, (points[i].area[1] + 5 + tHeight - opts.height / 2) * process); - } - } - } - context.stroke(); - context.restore(); - } - context.restore(); -} - -function drawFunnelDataPoints(series, opts, config, context) { - let process = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1; - let funnelOption = assign( - {}, - { - type: "funnel", - activeWidth: 10, - activeOpacity: 0.3, - border: false, - borderWidth: 2, - borderColor: "#FFFFFF", - fillOpacity: 1, - minSize: 0, - labelAlign: "right", - linearType: "none", - customColor: [], - }, - opts.extra.funnel - ); - let eachSpacing = (opts.height - opts.area[0] - opts.area[2]) / series.length; - let centerPosition = { - x: opts.area[3] + (opts.width - opts.area[1] - opts.area[3]) / 2, - y: opts.height - opts.area[2], - }; - let activeWidth = funnelOption.activeWidth * opts.pix; - let radius = Math.min((opts.width - opts.area[1] - opts.area[3]) / 2 - activeWidth, (opts.height - opts.area[0] - opts.area[2]) / 2 - activeWidth); - let seriesNew = getFunnelDataPoints(series, radius, funnelOption, eachSpacing, process); - context.save(); - context.translate(centerPosition.x, centerPosition.y); - funnelOption.customColor = fillCustomColor(funnelOption.linearType, funnelOption.customColor, series, config); - if (funnelOption.type == "pyramid") { - for (let i = 0; i < seriesNew.length; i++) { - if (i == seriesNew.length - 1) { - if (opts.tooltip) { - if (opts.tooltip.index == i) { - context.beginPath(); - context.setFillStyle(hexToRgb(seriesNew[i].color, funnelOption.activeOpacity)); - context.moveTo(-activeWidth, -eachSpacing); - context.lineTo(-seriesNew[i].radius - activeWidth, 0); - context.lineTo(seriesNew[i].radius + activeWidth, 0); - context.lineTo(activeWidth, -eachSpacing); - context.lineTo(-activeWidth, -eachSpacing); - context.closePath(); - context.fill(); - } - } - seriesNew[i].funnelArea = [centerPosition.x - seriesNew[i].radius, centerPosition.y - eachSpacing * (i + 1), centerPosition.x + seriesNew[i].radius, centerPosition.y - eachSpacing * i]; - context.beginPath(); - context.setLineWidth(funnelOption.borderWidth * opts.pix); - context.setStrokeStyle(funnelOption.borderColor); - var fillColor = hexToRgb(seriesNew[i].color, funnelOption.fillOpacity); - if (funnelOption.linearType == "custom") { - var grd = context.createLinearGradient(seriesNew[i].radius, -eachSpacing, -seriesNew[i].radius, -eachSpacing); - grd.addColorStop(0, hexToRgb(seriesNew[i].color, funnelOption.fillOpacity)); - grd.addColorStop(0.5, hexToRgb(funnelOption.customColor[seriesNew[i].linearIndex], funnelOption.fillOpacity)); - grd.addColorStop(1, hexToRgb(seriesNew[i].color, funnelOption.fillOpacity)); - fillColor = grd; - } - context.setFillStyle(fillColor); - context.moveTo(0, -eachSpacing); - context.lineTo(-seriesNew[i].radius, 0); - context.lineTo(seriesNew[i].radius, 0); - context.lineTo(0, -eachSpacing); - context.closePath(); - context.fill(); - if (funnelOption.border == true) { - context.stroke(); - } - } else { - if (opts.tooltip) { - if (opts.tooltip.index == i) { - context.beginPath(); - context.setFillStyle(hexToRgb(seriesNew[i].color, funnelOption.activeOpacity)); - context.moveTo(0, 0); - context.lineTo(-seriesNew[i].radius - activeWidth, 0); - context.lineTo(-seriesNew[i + 1].radius - activeWidth, -eachSpacing); - context.lineTo(seriesNew[i + 1].radius + activeWidth, -eachSpacing); - context.lineTo(seriesNew[i].radius + activeWidth, 0); - context.lineTo(0, 0); - context.closePath(); - context.fill(); - } - } - seriesNew[i].funnelArea = [centerPosition.x - seriesNew[i].radius, centerPosition.y - eachSpacing * (i + 1), centerPosition.x + seriesNew[i].radius, centerPosition.y - eachSpacing * i]; - context.beginPath(); - context.setLineWidth(funnelOption.borderWidth * opts.pix); - context.setStrokeStyle(funnelOption.borderColor); - var fillColor = hexToRgb(seriesNew[i].color, funnelOption.fillOpacity); - if (funnelOption.linearType == "custom") { - var grd = context.createLinearGradient(seriesNew[i].radius, -eachSpacing, -seriesNew[i].radius, -eachSpacing); - grd.addColorStop(0, hexToRgb(seriesNew[i].color, funnelOption.fillOpacity)); - grd.addColorStop(0.5, hexToRgb(funnelOption.customColor[seriesNew[i].linearIndex], funnelOption.fillOpacity)); - grd.addColorStop(1, hexToRgb(seriesNew[i].color, funnelOption.fillOpacity)); - fillColor = grd; - } - context.setFillStyle(fillColor); - context.moveTo(0, 0); - context.lineTo(-seriesNew[i].radius, 0); - context.lineTo(-seriesNew[i + 1].radius, -eachSpacing); - context.lineTo(seriesNew[i + 1].radius, -eachSpacing); - context.lineTo(seriesNew[i].radius, 0); - context.lineTo(0, 0); - context.closePath(); - context.fill(); - if (funnelOption.border == true) { - context.stroke(); - } - } - context.translate(0, -eachSpacing); - } - } else { - context.translate(0, -(seriesNew.length - 1) * eachSpacing); - for (let i = 0; i < seriesNew.length; i++) { - if (i == seriesNew.length - 1) { - if (opts.tooltip) { - if (opts.tooltip.index == i) { - context.beginPath(); - context.setFillStyle(hexToRgb(seriesNew[i].color, funnelOption.activeOpacity)); - context.moveTo(-activeWidth - funnelOption.minSize / 2, 0); - context.lineTo(-seriesNew[i].radius - activeWidth, -eachSpacing); - context.lineTo(seriesNew[i].radius + activeWidth, -eachSpacing); - context.lineTo(activeWidth + funnelOption.minSize / 2, 0); - context.lineTo(-activeWidth - funnelOption.minSize / 2, 0); - context.closePath(); - context.fill(); - } - } - seriesNew[i].funnelArea = [centerPosition.x - seriesNew[i].radius, centerPosition.y - eachSpacing, centerPosition.x + seriesNew[i].radius, centerPosition.y]; - context.beginPath(); - context.setLineWidth(funnelOption.borderWidth * opts.pix); - context.setStrokeStyle(funnelOption.borderColor); - var fillColor = hexToRgb(seriesNew[i].color, funnelOption.fillOpacity); - if (funnelOption.linearType == "custom") { - var grd = context.createLinearGradient(seriesNew[i].radius, -eachSpacing, -seriesNew[i].radius, -eachSpacing); - grd.addColorStop(0, hexToRgb(seriesNew[i].color, funnelOption.fillOpacity)); - grd.addColorStop(0.5, hexToRgb(funnelOption.customColor[seriesNew[i].linearIndex], funnelOption.fillOpacity)); - grd.addColorStop(1, hexToRgb(seriesNew[i].color, funnelOption.fillOpacity)); - fillColor = grd; - } - context.setFillStyle(fillColor); - context.moveTo(0, 0); - context.lineTo(-funnelOption.minSize / 2, 0); - context.lineTo(-seriesNew[i].radius, -eachSpacing); - context.lineTo(seriesNew[i].radius, -eachSpacing); - context.lineTo(funnelOption.minSize / 2, 0); - context.lineTo(0, 0); - context.closePath(); - context.fill(); - if (funnelOption.border == true) { - context.stroke(); - } - } else { - if (opts.tooltip) { - if (opts.tooltip.index == i) { - context.beginPath(); - context.setFillStyle(hexToRgb(seriesNew[i].color, funnelOption.activeOpacity)); - context.moveTo(0, 0); - context.lineTo(-seriesNew[i + 1].radius - activeWidth, 0); - context.lineTo(-seriesNew[i].radius - activeWidth, -eachSpacing); - context.lineTo(seriesNew[i].radius + activeWidth, -eachSpacing); - context.lineTo(seriesNew[i + 1].radius + activeWidth, 0); - context.lineTo(0, 0); - context.closePath(); - context.fill(); - } - } - seriesNew[i].funnelArea = [centerPosition.x - seriesNew[i].radius, centerPosition.y - eachSpacing * (seriesNew.length - i), centerPosition.x + seriesNew[i].radius, centerPosition.y - eachSpacing * (seriesNew.length - i - 1)]; - context.beginPath(); - context.setLineWidth(funnelOption.borderWidth * opts.pix); - context.setStrokeStyle(funnelOption.borderColor); - var fillColor = hexToRgb(seriesNew[i].color, funnelOption.fillOpacity); - if (funnelOption.linearType == "custom") { - var grd = context.createLinearGradient(seriesNew[i].radius, -eachSpacing, -seriesNew[i].radius, -eachSpacing); - grd.addColorStop(0, hexToRgb(seriesNew[i].color, funnelOption.fillOpacity)); - grd.addColorStop(0.5, hexToRgb(funnelOption.customColor[seriesNew[i].linearIndex], funnelOption.fillOpacity)); - grd.addColorStop(1, hexToRgb(seriesNew[i].color, funnelOption.fillOpacity)); - fillColor = grd; - } - context.setFillStyle(fillColor); - context.moveTo(0, 0); - context.lineTo(-seriesNew[i + 1].radius, 0); - context.lineTo(-seriesNew[i].radius, -eachSpacing); - context.lineTo(seriesNew[i].radius, -eachSpacing); - context.lineTo(seriesNew[i + 1].radius, 0); - context.lineTo(0, 0); - context.closePath(); - context.fill(); - if (funnelOption.border == true) { - context.stroke(); - } - } - context.translate(0, eachSpacing); - } - } - - context.restore(); - if (opts.dataLabel !== false && process === 1) { - drawFunnelText(seriesNew, opts, context, eachSpacing, funnelOption.labelAlign, activeWidth, centerPosition); - } - if (process === 1) { - drawFunnelCenterText(seriesNew, opts, context, eachSpacing, funnelOption.labelAlign, activeWidth, centerPosition); - } - return { - center: centerPosition, - radius: radius, - series: seriesNew, - }; -} - -function drawFunnelText(series, opts, context, eachSpacing, labelAlign, activeWidth, centerPosition) { - for (let i = 0; i < series.length; i++) { - let item = series[i]; - if (item.labelShow === false) { - continue; - } - let startX, endX, startY, fontSize; - let text = item.formatter ? item.formatter(item, i, series, opts) : util.toFixed(item._proportion_ * 100) + "%"; - text = item.labelText ? item.labelText : text; - if (labelAlign == "right") { - if (i == series.length - 1) { - startX = (item.funnelArea[2] + centerPosition.x) / 2; - } else { - startX = (item.funnelArea[2] + series[i + 1].funnelArea[2]) / 2; - } - endX = startX + activeWidth * 2; - startY = item.funnelArea[1] + eachSpacing / 2; - fontSize = item.textSize * opts.pix || opts.fontSize * opts.pix; - context.setLineWidth(1 * opts.pix); - context.setStrokeStyle(item.color); - context.setFillStyle(item.color); - context.beginPath(); - context.moveTo(startX, startY); - context.lineTo(endX, startY); - context.stroke(); - context.closePath(); - context.beginPath(); - context.moveTo(endX, startY); - context.arc(endX, startY, 2 * opts.pix, 0, 2 * Math.PI); - context.closePath(); - context.fill(); - context.beginPath(); - context.setFontSize(fontSize); - context.setFillStyle(item.textColor || opts.fontColor); - context.fillText(text, endX + 5, startY + fontSize / 2 - 2); - context.closePath(); - context.stroke(); - context.closePath(); - } - if (labelAlign == "left") { - if (i == series.length - 1) { - startX = (item.funnelArea[0] + centerPosition.x) / 2; - } else { - startX = (item.funnelArea[0] + series[i + 1].funnelArea[0]) / 2; - } - endX = startX - activeWidth * 2; - startY = item.funnelArea[1] + eachSpacing / 2; - fontSize = item.textSize * opts.pix || opts.fontSize * opts.pix; - context.setLineWidth(1 * opts.pix); - context.setStrokeStyle(item.color); - context.setFillStyle(item.color); - context.beginPath(); - context.moveTo(startX, startY); - context.lineTo(endX, startY); - context.stroke(); - context.closePath(); - context.beginPath(); - context.moveTo(endX, startY); - context.arc(endX, startY, 2, 0, 2 * Math.PI); - context.closePath(); - context.fill(); - context.beginPath(); - context.setFontSize(fontSize); - context.setFillStyle(item.textColor || opts.fontColor); - context.fillText(text, endX - 5 - measureText(text, fontSize, context), startY + fontSize / 2 - 2); - context.closePath(); - context.stroke(); - context.closePath(); - } - } -} - -function drawFunnelCenterText(series, opts, context, eachSpacing, labelAlign, activeWidth, centerPosition) { - for (let i = 0; i < series.length; i++) { - let item = series[i]; - let startY, fontSize; - if (item.centerText) { - startY = item.funnelArea[1] + eachSpacing / 2; - fontSize = item.centerTextSize * opts.pix || opts.fontSize * opts.pix; - context.beginPath(); - context.setFontSize(fontSize); - context.setFillStyle(item.centerTextColor || "#FFFFFF"); - context.fillText(item.centerText, centerPosition.x - measureText(item.centerText, fontSize, context) / 2, startY + fontSize / 2 - 2); - context.closePath(); - context.stroke(); - context.closePath(); - } - } -} - -function drawCanvas(opts, context) { - context.save(); - context.translate(0, 0.5); - context.restore(); - context.draw(); -} - -var Timing = { - easeIn: function easeIn(pos) { - return Math.pow(pos, 3); - }, - easeOut: function easeOut(pos) { - return Math.pow(pos - 1, 3) + 1; - }, - easeInOut: function easeInOut(pos) { - if ((pos /= 0.5) < 1) { - return 0.5 * Math.pow(pos, 3); - } else { - return 0.5 * (Math.pow(pos - 2, 3) + 2); - } - }, - linear: function linear(pos) { - return pos; - }, -}; - -function Animation(opts) { - this.isStop = false; - opts.duration = typeof opts.duration === "undefined" ? 1000 : opts.duration; - opts.timing = opts.timing || "easeInOut"; - var delay = 17; - function createAnimationFrame() { - if (typeof setTimeout !== "undefined") { - return function (step, delay) { - setTimeout(function () { - var timeStamp = +new Date(); - step(timeStamp); - }, delay); - }; - } else if (typeof requestAnimationFrame !== "undefined") { - return requestAnimationFrame; - } else { - return function (step) { - step(null); - }; - } - } - var animationFrame = createAnimationFrame(); - var startTimeStamp = null; - var _step = function step(timestamp) { - if (timestamp === null || this.isStop === true) { - opts.onProcess && opts.onProcess(1); - opts.onAnimationFinish && opts.onAnimationFinish(); - return; - } - if (startTimeStamp === null) { - startTimeStamp = timestamp; - } - if (timestamp - startTimeStamp < opts.duration) { - var process = (timestamp - startTimeStamp) / opts.duration; - var timingFunction = Timing[opts.timing]; - process = timingFunction(process); - opts.onProcess && opts.onProcess(process); - animationFrame(_step, delay); - } else { - opts.onProcess && opts.onProcess(1); - opts.onAnimationFinish && opts.onAnimationFinish(); - } - }; - _step = _step.bind(this); - animationFrame(_step, delay); -} - -Animation.prototype.stop = function () { - this.isStop = true; -}; - -function drawCharts(type, opts, config, context) { - var _this = this; - var series = opts.series; - //兼容ECharts饼图类数据格式 - if (type === "pie" || type === "ring" || type === "mount" || type === "rose" || type === "funnel") { - series = fixPieSeries(series, opts, config); - } - var categories = opts.categories; - if (type === "mount") { - categories = []; - for (let j = 0; j < series.length; j++) { - if (series[j].show !== false) categories.push(series[j].name); - } - opts.categories = categories; - } - series = fillSeries(series, opts, config); - var duration = opts.animation ? opts.duration : 0; - _this.animationInstance && _this.animationInstance.stop(); - var seriesMA = null; - if (type == "candle") { - let average = assign({}, opts.extra.candle.average); - if (average.show) { - seriesMA = calCandleMA(average.day, average.name, average.color, series[0].data); - seriesMA = fillSeries(seriesMA, opts, config); - opts.seriesMA = seriesMA; - } else if (opts.seriesMA) { - seriesMA = opts.seriesMA = fillSeries(opts.seriesMA, opts, config); - } else { - seriesMA = series; - } - } else { - seriesMA = series; - } - /* 过滤掉show=false的series */ - opts._series_ = series = filterSeries(series); - //重新计算图表区域 - opts.area = new Array(4); - //复位绘图区域 - for (let j = 0; j < 4; j++) { - opts.area[j] = opts.padding[j] * opts.pix; - } - //通过计算三大区域:图例、X轴、Y轴的大小,确定绘图区域 - var _calLegendData = calLegendData(seriesMA, opts, config, opts.chartData, context), - legendHeight = _calLegendData.area.wholeHeight, - legendWidth = _calLegendData.area.wholeWidth; - - switch (opts.legend.position) { - case "top": - opts.area[0] += legendHeight; - break; - case "bottom": - opts.area[2] += legendHeight; - break; - case "left": - opts.area[3] += legendWidth; - break; - case "right": - opts.area[1] += legendWidth; - break; - } - - let _calYAxisData = {}, - yAxisWidth = 0; - if (opts.type === "line" || opts.type === "column" || opts.type === "mount" || opts.type === "area" || opts.type === "mix" || opts.type === "candle" || opts.type === "scatter" || opts.type === "bubble" || opts.type === "bar") { - _calYAxisData = calYAxisData(series, opts, config, context); - yAxisWidth = _calYAxisData.yAxisWidth; - //如果显示Y轴标题 - if (opts.yAxis.showTitle) { - let maxTitleHeight = 0; - for (let i = 0; i < opts.yAxis.data.length; i++) { - maxTitleHeight = Math.max(maxTitleHeight, opts.yAxis.data[i].titleFontSize ? opts.yAxis.data[i].titleFontSize * opts.pix : config.fontSize); - } - opts.area[0] += maxTitleHeight; - } - let rightIndex = 0, - leftIndex = 0; - //计算主绘图区域左右位置 - for (let i = 0; i < yAxisWidth.length; i++) { - if (yAxisWidth[i].position == "left") { - if (leftIndex > 0) { - opts.area[3] += yAxisWidth[i].width + opts.yAxis.padding * opts.pix; - } else { - opts.area[3] += yAxisWidth[i].width; - } - leftIndex += 1; - } else if (yAxisWidth[i].position == "right") { - if (rightIndex > 0) { - opts.area[1] += yAxisWidth[i].width + opts.yAxis.padding * opts.pix; - } else { - opts.area[1] += yAxisWidth[i].width; - } - rightIndex += 1; - } - } - } else { - config.yAxisWidth = yAxisWidth; - } - opts.chartData.yAxisData = _calYAxisData; - - if (opts.categories && opts.categories.length && opts.type !== "radar" && opts.type !== "gauge" && opts.type !== "bar") { - opts.chartData.xAxisData = getXAxisPoints(opts.categories, opts, config); - let _calCategoriesData = calCategoriesData(opts.categories, opts, config, opts.chartData.xAxisData.eachSpacing, context), - xAxisHeight = _calCategoriesData.xAxisHeight, - angle = _calCategoriesData.angle; - config.xAxisHeight = xAxisHeight; - config._xAxisTextAngle_ = angle; - opts.area[2] += xAxisHeight; - opts.chartData.categoriesData = _calCategoriesData; - } else { - if (opts.type === "line" || opts.type === "area" || opts.type === "scatter" || opts.type === "bubble" || opts.type === "bar") { - opts.chartData.xAxisData = calXAxisData(series, opts, config, context); - categories = opts.chartData.xAxisData.rangesFormat; - let _calCategoriesData = calCategoriesData(categories, opts, config, opts.chartData.xAxisData.eachSpacing, context), - xAxisHeight = _calCategoriesData.xAxisHeight, - angle = _calCategoriesData.angle; - config.xAxisHeight = xAxisHeight; - config._xAxisTextAngle_ = angle; - opts.area[2] += xAxisHeight; - opts.chartData.categoriesData = _calCategoriesData; - } else { - opts.chartData.xAxisData = { - xAxisPoints: [], - }; - } - } - - //计算右对齐偏移距离 - if (opts.enableScroll && opts.xAxis.scrollAlign == "right" && opts._scrollDistance_ === undefined) { - let offsetLeft = 0, - xAxisPoints = opts.chartData.xAxisData.xAxisPoints, - startX = opts.chartData.xAxisData.startX, - endX = opts.chartData.xAxisData.endX, - eachSpacing = opts.chartData.xAxisData.eachSpacing; - let totalWidth = eachSpacing * (xAxisPoints.length - 1); - let screenWidth = endX - startX; - offsetLeft = screenWidth - totalWidth; - _this.scrollOption.currentOffset = offsetLeft; - _this.scrollOption.startTouchX = offsetLeft; - _this.scrollOption.distance = 0; - _this.scrollOption.lastMoveTime = 0; - opts._scrollDistance_ = offsetLeft; - } - - if (type === "pie" || type === "ring" || type === "rose") { - config._pieTextMaxLength_ = opts.dataLabel === false ? 0 : getPieTextMaxLength(seriesMA, config, context, opts); - } - - switch (type) { - case "word": - this.animationInstance = new Animation({ - timing: opts.timing, - duration: duration, - onProcess: function (process) { - context.clearRect(0, 0, opts.width, opts.height); - if (opts.rotate) { - contextRotate(context, opts); - } - drawWordCloudDataPoints(series, opts, config, context, process); - drawCanvas(opts, context); - }, - onAnimationFinish: function onAnimationFinish() { - _this.uevent.trigger("renderComplete"); - }, - }); - break; - case "map": - context.clearRect(0, 0, opts.width, opts.height); - drawMapDataPoints(series, opts, config, context); - setTimeout(() => { - this.uevent.trigger("renderComplete"); - }, 50); - break; - case "funnel": - this.animationInstance = new Animation({ - timing: opts.timing, - duration: duration, - onProcess: function (process) { - context.clearRect(0, 0, opts.width, opts.height); - if (opts.rotate) { - contextRotate(context, opts); - } - opts.chartData.funnelData = drawFunnelDataPoints(series, opts, config, context, process); - drawLegend(opts.series, opts, config, context, opts.chartData); - drawToolTipBridge(opts, config, context, process); - drawCanvas(opts, context); - }, - onAnimationFinish: function onAnimationFinish() { - _this.uevent.trigger("renderComplete"); - }, - }); - break; - case "line": - this.animationInstance = new Animation({ - timing: opts.timing, - duration: duration, - onProcess: function onProcess(process) { - context.clearRect(0, 0, opts.width, opts.height); - if (opts.rotate) { - contextRotate(context, opts); - } - drawYAxisGrid(categories, opts, config, context); - drawXAxis(categories, opts, config, context); - var _drawLineDataPoints = drawLineDataPoints(series, opts, config, context, process), - xAxisPoints = _drawLineDataPoints.xAxisPoints, - calPoints = _drawLineDataPoints.calPoints, - eachSpacing = _drawLineDataPoints.eachSpacing; - opts.chartData.xAxisPoints = xAxisPoints; - opts.chartData.calPoints = calPoints; - opts.chartData.eachSpacing = eachSpacing; - drawYAxis(series, opts, config, context); - if (opts.enableMarkLine !== false && process === 1) { - drawMarkLine(opts, config, context); - } - drawLegend(opts.series, opts, config, context, opts.chartData); - drawToolTipBridge(opts, config, context, process, eachSpacing, xAxisPoints); - drawCanvas(opts, context); - }, - onAnimationFinish: function onAnimationFinish() { - _this.uevent.trigger("renderComplete"); - }, - }); - break; - case "scatter": - this.animationInstance = new Animation({ - timing: opts.timing, - duration: duration, - onProcess: function onProcess(process) { - context.clearRect(0, 0, opts.width, opts.height); - if (opts.rotate) { - contextRotate(context, opts); - } - drawYAxisGrid(categories, opts, config, context); - drawXAxis(categories, opts, config, context); - var _drawScatterDataPoints = drawScatterDataPoints(series, opts, config, context, process), - xAxisPoints = _drawScatterDataPoints.xAxisPoints, - calPoints = _drawScatterDataPoints.calPoints, - eachSpacing = _drawScatterDataPoints.eachSpacing; - opts.chartData.xAxisPoints = xAxisPoints; - opts.chartData.calPoints = calPoints; - opts.chartData.eachSpacing = eachSpacing; - drawYAxis(series, opts, config, context); - if (opts.enableMarkLine !== false && process === 1) { - drawMarkLine(opts, config, context); - } - drawLegend(opts.series, opts, config, context, opts.chartData); - drawToolTipBridge(opts, config, context, process, eachSpacing, xAxisPoints); - drawCanvas(opts, context); - }, - onAnimationFinish: function onAnimationFinish() { - _this.uevent.trigger("renderComplete"); - }, - }); - break; - case "bubble": - this.animationInstance = new Animation({ - timing: opts.timing, - duration: duration, - onProcess: function onProcess(process) { - context.clearRect(0, 0, opts.width, opts.height); - if (opts.rotate) { - contextRotate(context, opts); - } - drawYAxisGrid(categories, opts, config, context); - drawXAxis(categories, opts, config, context); - var _drawBubbleDataPoints = drawBubbleDataPoints(series, opts, config, context, process), - xAxisPoints = _drawBubbleDataPoints.xAxisPoints, - calPoints = _drawBubbleDataPoints.calPoints, - eachSpacing = _drawBubbleDataPoints.eachSpacing; - opts.chartData.xAxisPoints = xAxisPoints; - opts.chartData.calPoints = calPoints; - opts.chartData.eachSpacing = eachSpacing; - drawYAxis(series, opts, config, context); - if (opts.enableMarkLine !== false && process === 1) { - drawMarkLine(opts, config, context); - } - drawLegend(opts.series, opts, config, context, opts.chartData); - drawToolTipBridge(opts, config, context, process, eachSpacing, xAxisPoints); - drawCanvas(opts, context); - }, - onAnimationFinish: function onAnimationFinish() { - _this.uevent.trigger("renderComplete"); - }, - }); - break; - case "mix": - this.animationInstance = new Animation({ - timing: opts.timing, - duration: duration, - onProcess: function onProcess(process) { - context.clearRect(0, 0, opts.width, opts.height); - if (opts.rotate) { - contextRotate(context, opts); - } - drawYAxisGrid(categories, opts, config, context); - drawXAxis(categories, opts, config, context); - var _drawMixDataPoints = drawMixDataPoints(series, opts, config, context, process), - xAxisPoints = _drawMixDataPoints.xAxisPoints, - calPoints = _drawMixDataPoints.calPoints, - eachSpacing = _drawMixDataPoints.eachSpacing; - opts.chartData.xAxisPoints = xAxisPoints; - opts.chartData.calPoints = calPoints; - opts.chartData.eachSpacing = eachSpacing; - drawYAxis(series, opts, config, context); - if (opts.enableMarkLine !== false && process === 1) { - drawMarkLine(opts, config, context); - } - drawLegend(opts.series, opts, config, context, opts.chartData); - drawToolTipBridge(opts, config, context, process, eachSpacing, xAxisPoints); - drawCanvas(opts, context); - }, - onAnimationFinish: function onAnimationFinish() { - _this.uevent.trigger("renderComplete"); - }, - }); - break; - case "column": - this.animationInstance = new Animation({ - timing: opts.timing, - duration: duration, - onProcess: function onProcess(process) { - context.clearRect(0, 0, opts.width, opts.height); - if (opts.rotate) { - contextRotate(context, opts); - } - drawYAxisGrid(categories, opts, config, context); - drawXAxis(categories, opts, config, context); - var _drawColumnDataPoints = drawColumnDataPoints(series, opts, config, context, process), - xAxisPoints = _drawColumnDataPoints.xAxisPoints, - calPoints = _drawColumnDataPoints.calPoints, - eachSpacing = _drawColumnDataPoints.eachSpacing; - opts.chartData.xAxisPoints = xAxisPoints; - opts.chartData.calPoints = calPoints; - opts.chartData.eachSpacing = eachSpacing; - drawYAxis(series, opts, config, context); - if (opts.enableMarkLine !== false && process === 1) { - drawMarkLine(opts, config, context); - } - drawLegend(opts.series, opts, config, context, opts.chartData); - drawToolTipBridge(opts, config, context, process, eachSpacing, xAxisPoints); - drawCanvas(opts, context); - }, - onAnimationFinish: function onAnimationFinish() { - _this.uevent.trigger("renderComplete"); - }, - }); - break; - case "mount": - this.animationInstance = new Animation({ - timing: opts.timing, - duration: duration, - onProcess: function onProcess(process) { - context.clearRect(0, 0, opts.width, opts.height); - if (opts.rotate) { - contextRotate(context, opts); - } - drawYAxisGrid(categories, opts, config, context); - drawXAxis(categories, opts, config, context); - var _drawMountDataPoints = drawMountDataPoints(series, opts, config, context, process), - xAxisPoints = _drawMountDataPoints.xAxisPoints, - calPoints = _drawMountDataPoints.calPoints, - eachSpacing = _drawMountDataPoints.eachSpacing; - opts.chartData.xAxisPoints = xAxisPoints; - opts.chartData.calPoints = calPoints; - opts.chartData.eachSpacing = eachSpacing; - drawYAxis(series, opts, config, context); - if (opts.enableMarkLine !== false && process === 1) { - drawMarkLine(opts, config, context); - } - drawLegend(opts.series, opts, config, context, opts.chartData); - drawToolTipBridge(opts, config, context, process, eachSpacing, xAxisPoints); - drawCanvas(opts, context); - }, - onAnimationFinish: function onAnimationFinish() { - _this.uevent.trigger("renderComplete"); - }, - }); - break; - case "bar": - this.animationInstance = new Animation({ - timing: opts.timing, - duration: duration, - onProcess: function onProcess(process) { - context.clearRect(0, 0, opts.width, opts.height); - if (opts.rotate) { - contextRotate(context, opts); - } - drawXAxis(categories, opts, config, context); - var _drawBarDataPoints = drawBarDataPoints(series, opts, config, context, process), - yAxisPoints = _drawBarDataPoints.yAxisPoints, - calPoints = _drawBarDataPoints.calPoints, - eachSpacing = _drawBarDataPoints.eachSpacing; - opts.chartData.yAxisPoints = yAxisPoints; - opts.chartData.xAxisPoints = opts.chartData.xAxisData.xAxisPoints; - opts.chartData.calPoints = calPoints; - opts.chartData.eachSpacing = eachSpacing; - drawYAxis(series, opts, config, context); - if (opts.enableMarkLine !== false && process === 1) { - drawMarkLine(opts, config, context); - } - drawLegend(opts.series, opts, config, context, opts.chartData); - drawToolTipBridge(opts, config, context, process, eachSpacing, yAxisPoints); - drawCanvas(opts, context); - }, - onAnimationFinish: function onAnimationFinish() { - _this.uevent.trigger("renderComplete"); - }, - }); - break; - case "area": - this.animationInstance = new Animation({ - timing: opts.timing, - duration: duration, - onProcess: function onProcess(process) { - context.clearRect(0, 0, opts.width, opts.height); - if (opts.rotate) { - contextRotate(context, opts); - } - drawYAxisGrid(categories, opts, config, context); - drawXAxis(categories, opts, config, context); - var _drawAreaDataPoints = drawAreaDataPoints(series, opts, config, context, process), - xAxisPoints = _drawAreaDataPoints.xAxisPoints, - calPoints = _drawAreaDataPoints.calPoints, - eachSpacing = _drawAreaDataPoints.eachSpacing; - opts.chartData.xAxisPoints = xAxisPoints; - opts.chartData.calPoints = calPoints; - opts.chartData.eachSpacing = eachSpacing; - drawYAxis(series, opts, config, context); - if (opts.enableMarkLine !== false && process === 1) { - drawMarkLine(opts, config, context); - } - drawLegend(opts.series, opts, config, context, opts.chartData); - drawToolTipBridge(opts, config, context, process, eachSpacing, xAxisPoints); - drawCanvas(opts, context); - }, - onAnimationFinish: function onAnimationFinish() { - _this.uevent.trigger("renderComplete"); - }, - }); - break; - case "ring": - this.animationInstance = new Animation({ - timing: opts.timing, - duration: duration, - onProcess: function onProcess(process) { - context.clearRect(0, 0, opts.width, opts.height); - if (opts.rotate) { - contextRotate(context, opts); - } - opts.chartData.pieData = drawPieDataPoints(series, opts, config, context, process); - drawLegend(opts.series, opts, config, context, opts.chartData); - drawToolTipBridge(opts, config, context, process); - drawCanvas(opts, context); - }, - onAnimationFinish: function onAnimationFinish() { - _this.uevent.trigger("renderComplete"); - }, - }); - break; - case "pie": - this.animationInstance = new Animation({ - timing: opts.timing, - duration: duration, - onProcess: function onProcess(process) { - context.clearRect(0, 0, opts.width, opts.height); - if (opts.rotate) { - contextRotate(context, opts); - } - opts.chartData.pieData = drawPieDataPoints(series, opts, config, context, process); - drawLegend(opts.series, opts, config, context, opts.chartData); - drawToolTipBridge(opts, config, context, process); - drawCanvas(opts, context); - }, - onAnimationFinish: function onAnimationFinish() { - _this.uevent.trigger("renderComplete"); - }, - }); - break; - case "rose": - this.animationInstance = new Animation({ - timing: opts.timing, - duration: duration, - onProcess: function onProcess(process) { - context.clearRect(0, 0, opts.width, opts.height); - if (opts.rotate) { - contextRotate(context, opts); - } - opts.chartData.pieData = drawRoseDataPoints(series, opts, config, context, process); - drawLegend(opts.series, opts, config, context, opts.chartData); - drawToolTipBridge(opts, config, context, process); - drawCanvas(opts, context); - }, - onAnimationFinish: function onAnimationFinish() { - _this.uevent.trigger("renderComplete"); - }, - }); - break; - case "radar": - this.animationInstance = new Animation({ - timing: opts.timing, - duration: duration, - onProcess: function onProcess(process) { - context.clearRect(0, 0, opts.width, opts.height); - if (opts.rotate) { - contextRotate(context, opts); - } - opts.chartData.radarData = drawRadarDataPoints(series, opts, config, context, process); - drawLegend(opts.series, opts, config, context, opts.chartData); - drawToolTipBridge(opts, config, context, process); - drawCanvas(opts, context); - }, - onAnimationFinish: function onAnimationFinish() { - _this.uevent.trigger("renderComplete"); - }, - }); - break; - case "arcbar": - this.animationInstance = new Animation({ - timing: opts.timing, - duration: duration, - onProcess: function onProcess(process) { - context.clearRect(0, 0, opts.width, opts.height); - if (opts.rotate) { - contextRotate(context, opts); - } - opts.chartData.arcbarData = drawArcbarDataPoints(series, opts, config, context, process); - drawCanvas(opts, context); - }, - onAnimationFinish: function onAnimationFinish() { - _this.uevent.trigger("renderComplete"); - }, - }); - break; - case "gauge": - this.animationInstance = new Animation({ - timing: opts.timing, - duration: duration, - onProcess: function onProcess(process) { - context.clearRect(0, 0, opts.width, opts.height); - if (opts.rotate) { - contextRotate(context, opts); - } - opts.chartData.gaugeData = drawGaugeDataPoints(categories, series, opts, config, context, process); - drawCanvas(opts, context); - }, - onAnimationFinish: function onAnimationFinish() { - _this.uevent.trigger("renderComplete"); - }, - }); - break; - case "candle": - this.animationInstance = new Animation({ - timing: opts.timing, - duration: duration, - onProcess: function onProcess(process) { - context.clearRect(0, 0, opts.width, opts.height); - if (opts.rotate) { - contextRotate(context, opts); - } - drawYAxisGrid(categories, opts, config, context); - drawXAxis(categories, opts, config, context); - var _drawCandleDataPoints = drawCandleDataPoints(series, seriesMA, opts, config, context, process), - xAxisPoints = _drawCandleDataPoints.xAxisPoints, - calPoints = _drawCandleDataPoints.calPoints, - eachSpacing = _drawCandleDataPoints.eachSpacing; - opts.chartData.xAxisPoints = xAxisPoints; - opts.chartData.calPoints = calPoints; - opts.chartData.eachSpacing = eachSpacing; - drawYAxis(series, opts, config, context); - if (opts.enableMarkLine !== false && process === 1) { - drawMarkLine(opts, config, context); - } - if (seriesMA) { - drawLegend(seriesMA, opts, config, context, opts.chartData); - } else { - drawLegend(opts.series, opts, config, context, opts.chartData); - } - drawToolTipBridge(opts, config, context, process, eachSpacing, xAxisPoints); - drawCanvas(opts, context); - }, - onAnimationFinish: function onAnimationFinish() { - _this.uevent.trigger("renderComplete"); - }, - }); - break; - } -} - -function uChartsEvent() { - this.events = {}; -} - -uChartsEvent.prototype.addEventListener = function (type, listener) { - this.events[type] = this.events[type] || []; - this.events[type].push(listener); -}; - -uChartsEvent.prototype.delEventListener = function (type) { - this.events[type] = []; -}; - -uChartsEvent.prototype.trigger = function () { - for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { - args[_key] = arguments[_key]; - } - var type = args[0]; - var params = args.slice(1); - if (!!this.events[type]) { - this.events[type].forEach(function (listener) { - try { - listener.apply(null, params); - } catch (e) { - //console.log('[uCharts] '+e); - } - }); - } -}; - -var uCharts = function uCharts(opts) { - opts.pix = opts.pixelRatio ? opts.pixelRatio : 1; - opts.fontSize = opts.fontSize ? opts.fontSize : 13; - opts.fontColor = opts.fontColor ? opts.fontColor : config.fontColor; - if (opts.background == "" || opts.background == "none") { - opts.background = "#FFFFFF"; - } - opts.title = assign({}, opts.title); - opts.subtitle = assign({}, opts.subtitle); - opts.duration = opts.duration ? opts.duration : 1000; - opts.yAxis = assign( - {}, - { - data: [], - showTitle: false, - disabled: false, - disableGrid: false, - gridSet: "number", - splitNumber: 5, - gridType: "solid", - dashLength: 4 * opts.pix, - gridColor: "#cccccc", - padding: 10, - fontColor: "#666666", - }, - opts.yAxis - ); - opts.xAxis = assign( - {}, - { - rotateLabel: false, - rotateAngle: 45, - disabled: false, - disableGrid: false, - splitNumber: 5, - calibration: false, - fontColor: "#666666", - fontSize: 13, - lineHeight: 20, - marginTop: 0, - gridType: "solid", - dashLength: 4, - scrollAlign: "left", - boundaryGap: "center", - axisLine: true, - axisLineColor: "#cccccc", - titleFontSize: 13, - titleOffsetY: 0, - titleOffsetX: 0, - titleFontColor: "#666666", - }, - opts.xAxis - ); - opts.xAxis.scrollPosition = opts.xAxis.scrollAlign; - opts.legend = assign( - {}, - { - show: true, - position: "bottom", - float: "center", - backgroundColor: "rgba(0,0,0,0)", - borderColor: "rgba(0,0,0,0)", - borderWidth: 0, - padding: 5, - margin: 5, - itemGap: 10, - fontSize: opts.fontSize, - lineHeight: opts.fontSize, - fontColor: opts.fontColor, - formatter: {}, - hiddenColor: "#CECECE", - }, - opts.legend - ); - opts.extra = assign( - { - tooltip: { - legendShape: "auto", - }, - }, - opts.extra - ); - opts.rotate = opts.rotate ? true : false; - opts.animation = opts.animation ? true : false; - opts.rotate = opts.rotate ? true : false; - opts.canvas2d = opts.canvas2d ? true : false; - - let config$$1 = assign({}, config); - config$$1.color = opts.color ? opts.color : config$$1.color; - if (opts.type == "pie") { - config$$1.pieChartLinePadding = opts.dataLabel === false ? 0 : opts.extra.pie.labelWidth * opts.pix || config$$1.pieChartLinePadding * opts.pix; - } - if (opts.type == "ring") { - config$$1.pieChartLinePadding = opts.dataLabel === false ? 0 : opts.extra.ring.labelWidth * opts.pix || config$$1.pieChartLinePadding * opts.pix; - } - if (opts.type == "rose") { - config$$1.pieChartLinePadding = opts.dataLabel === false ? 0 : opts.extra.rose.labelWidth * opts.pix || config$$1.pieChartLinePadding * opts.pix; - } - config$$1.pieChartTextPadding = opts.dataLabel === false ? 0 : config$$1.pieChartTextPadding * opts.pix; - - //屏幕旋转 - config$$1.rotate = opts.rotate; - if (opts.rotate) { - let tempWidth = opts.width; - let tempHeight = opts.height; - opts.width = tempHeight; - opts.height = tempWidth; - } - - //适配高分屏 - opts.padding = opts.padding ? opts.padding : config$$1.padding; - config$$1.yAxisWidth = config.yAxisWidth * opts.pix; - config$$1.fontSize = opts.fontSize * opts.pix; - config$$1.titleFontSize = config.titleFontSize * opts.pix; - config$$1.subtitleFontSize = config.subtitleFontSize * opts.pix; - if (!opts.context) { - throw new Error("[uCharts] 未获取到context!注意:v2.0版本后,需要自行获取canvas的绘图上下文并传入opts.context!"); - } - this.context = opts.context; - if (!this.context.setTextAlign) { - this.context.setStrokeStyle = function (e) { - return (this.strokeStyle = e); - }; - this.context.setLineWidth = function (e) { - return (this.lineWidth = e); - }; - this.context.setLineCap = function (e) { - return (this.lineCap = e); - }; - this.context.setFontSize = function (e) { - return (this.font = e + "px sans-serif"); - }; - this.context.setFillStyle = function (e) { - return (this.fillStyle = e); - }; - this.context.setTextAlign = function (e) { - return (this.textAlign = e); - }; - this.context.setTextBaseline = function (e) { - return (this.textBaseline = e); - }; - this.context.setShadow = function (offsetX, offsetY, blur, color) { - this.shadowColor = color; - this.shadowOffsetX = offsetX; - this.shadowOffsetY = offsetY; - this.shadowBlur = blur; - }; - this.context.draw = function () {}; - } - //兼容NVUEsetLineDash - if (!this.context.setLineDash) { - this.context.setLineDash = function (e) {}; - } - opts.chartData = {}; - this.uevent = new uChartsEvent(); - this.scrollOption = { - currentOffset: 0, - startTouchX: 0, - distance: 0, - lastMoveTime: 0, - }; - this.opts = opts; - this.config = config$$1; - drawCharts.call(this, opts.type, opts, config$$1, this.context); -}; - -uCharts.prototype.updateData = function () { - let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - this.opts = assign({}, this.opts, data); - this.opts.updateData = true; - let scrollPosition = data.scrollPosition || "current"; - switch (scrollPosition) { - case "current": - this.opts._scrollDistance_ = this.scrollOption.currentOffset; - break; - case "left": - this.opts._scrollDistance_ = 0; - this.scrollOption = { - currentOffset: 0, - startTouchX: 0, - distance: 0, - lastMoveTime: 0, - }; - break; - case "right": - let _calYAxisData = calYAxisData(this.opts.series, this.opts, this.config, this.context), - yAxisWidth = _calYAxisData.yAxisWidth; - this.config.yAxisWidth = yAxisWidth; - let offsetLeft = 0; - let _getXAxisPoints0 = getXAxisPoints(this.opts.categories, this.opts, this.config), - xAxisPoints = _getXAxisPoints0.xAxisPoints, - startX = _getXAxisPoints0.startX, - endX = _getXAxisPoints0.endX, - eachSpacing = _getXAxisPoints0.eachSpacing; - let totalWidth = eachSpacing * (xAxisPoints.length - 1); - let screenWidth = endX - startX; - offsetLeft = screenWidth - totalWidth; - this.scrollOption = { - currentOffset: offsetLeft, - startTouchX: offsetLeft, - distance: 0, - lastMoveTime: 0, - }; - this.opts._scrollDistance_ = offsetLeft; - break; - } - drawCharts.call(this, this.opts.type, this.opts, this.config, this.context); -}; - -uCharts.prototype.zoom = function () { - var val = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.opts.xAxis.itemCount; - if (this.opts.enableScroll !== true) { - console.log("[uCharts] 请启用滚动条后使用"); - return; - } - //当前屏幕中间点 - let centerPoint = Math.round(Math.abs(this.scrollOption.currentOffset) / this.opts.chartData.eachSpacing) + Math.round(this.opts.xAxis.itemCount / 2); - this.opts.animation = false; - this.opts.xAxis.itemCount = val.itemCount; - //重新计算x轴偏移距离 - let _calYAxisData = calYAxisData(this.opts.series, this.opts, this.config, this.context), - yAxisWidth = _calYAxisData.yAxisWidth; - this.config.yAxisWidth = yAxisWidth; - let offsetLeft = 0; - let _getXAxisPoints0 = getXAxisPoints(this.opts.categories, this.opts, this.config), - xAxisPoints = _getXAxisPoints0.xAxisPoints, - startX = _getXAxisPoints0.startX, - endX = _getXAxisPoints0.endX, - eachSpacing = _getXAxisPoints0.eachSpacing; - let centerLeft = eachSpacing * centerPoint; - let screenWidth = endX - startX; - let MaxLeft = screenWidth - eachSpacing * (xAxisPoints.length - 1); - offsetLeft = screenWidth / 2 - centerLeft; - if (offsetLeft > 0) { - offsetLeft = 0; - } - if (offsetLeft < MaxLeft) { - offsetLeft = MaxLeft; - } - this.scrollOption = { - currentOffset: offsetLeft, - startTouchX: 0, - distance: 0, - lastMoveTime: 0, - }; - calValidDistance(this, offsetLeft, this.opts.chartData, this.config, this.opts); - this.opts._scrollDistance_ = offsetLeft; - drawCharts.call(this, this.opts.type, this.opts, this.config, this.context); -}; - -uCharts.prototype.dobuleZoom = function (e) { - if (this.opts.enableScroll !== true) { - console.log("[uCharts] 请启用滚动条后使用"); - return; - } - const tcs = e.changedTouches; - if (tcs.length < 2) { - return; - } - for (var i = 0; i < tcs.length; i++) { - tcs[i].x = tcs[i].x ? tcs[i].x : tcs[i].clientX; - tcs[i].y = tcs[i].y ? tcs[i].y : tcs[i].clientY; - } - const ntcs = [getTouches(tcs[0], this.opts, e), getTouches(tcs[1], this.opts, e)]; - const xlength = Math.abs(ntcs[0].x - ntcs[1].x); - // 记录初始的两指之间的数据 - if (!this.scrollOption.moveCount) { - let cts0 = { changedTouches: [{ x: tcs[0].x, y: this.opts.area[0] / this.opts.pix + 2 }] }; - let cts1 = { changedTouches: [{ x: tcs[1].x, y: this.opts.area[0] / this.opts.pix + 2 }] }; - if (this.opts.rotate) { - cts0 = { - changedTouches: [ - { - x: this.opts.height / this.opts.pix - this.opts.area[0] / this.opts.pix - 2, - y: tcs[0].y, - }, - ], - }; - cts1 = { - changedTouches: [ - { - x: this.opts.height / this.opts.pix - this.opts.area[0] / this.opts.pix - 2, - y: tcs[1].y, - }, - ], - }; - } - const moveCurrent1 = this.getCurrentDataIndex(cts0).index; - const moveCurrent2 = this.getCurrentDataIndex(cts1).index; - const moveCount = Math.abs(moveCurrent1 - moveCurrent2); - this.scrollOption.moveCount = moveCount; - this.scrollOption.moveCurrent1 = Math.min(moveCurrent1, moveCurrent2); - this.scrollOption.moveCurrent2 = Math.max(moveCurrent1, moveCurrent2); - return; - } - - let currentEachSpacing = xlength / this.scrollOption.moveCount; - let itemCount = (this.opts.width - this.opts.area[1] - this.opts.area[3]) / currentEachSpacing; - itemCount = itemCount <= 2 ? 2 : itemCount; - itemCount = itemCount >= this.opts.categories.length ? this.opts.categories.length : itemCount; - this.opts.animation = false; - this.opts.xAxis.itemCount = itemCount; - // 重新计算滚动条偏移距离 - let offsetLeft = 0; - let _getXAxisPoints0 = getXAxisPoints(this.opts.categories, this.opts, this.config), - xAxisPoints = _getXAxisPoints0.xAxisPoints, - startX = _getXAxisPoints0.startX, - endX = _getXAxisPoints0.endX, - eachSpacing = _getXAxisPoints0.eachSpacing; - let currentLeft = eachSpacing * this.scrollOption.moveCurrent1; - let screenWidth = endX - startX; - let MaxLeft = screenWidth - eachSpacing * (xAxisPoints.length - 1); - offsetLeft = -currentLeft + Math.min(ntcs[0].x, ntcs[1].x) - this.opts.area[3] - eachSpacing; - if (offsetLeft > 0) { - offsetLeft = 0; - } - if (offsetLeft < MaxLeft) { - offsetLeft = MaxLeft; - } - this.scrollOption.currentOffset = offsetLeft; - this.scrollOption.startTouchX = 0; - this.scrollOption.distance = 0; - calValidDistance(this, offsetLeft, this.opts.chartData, this.config, this.opts); - this.opts._scrollDistance_ = offsetLeft; - drawCharts.call(this, this.opts.type, this.opts, this.config, this.context); -}; - -uCharts.prototype.stopAnimation = function () { - this.animationInstance && this.animationInstance.stop(); -}; - -uCharts.prototype.addEventListener = function (type, listener) { - this.uevent.addEventListener(type, listener); -}; - -uCharts.prototype.delEventListener = function (type) { - this.uevent.delEventListener(type); -}; - -uCharts.prototype.getCurrentDataIndex = function (e) { - var touches = null; - if (e.changedTouches) { - touches = e.changedTouches[0]; - } else { - touches = e.mp.changedTouches[0]; - } - if (touches) { - let _touches$ = getTouches(touches, this.opts, e); - if (this.opts.type === "pie" || this.opts.type === "ring") { - return findPieChartCurrentIndex( - { - x: _touches$.x, - y: _touches$.y, - }, - this.opts.chartData.pieData, - this.opts - ); - } else if (this.opts.type === "rose") { - return findRoseChartCurrentIndex( - { - x: _touches$.x, - y: _touches$.y, - }, - this.opts.chartData.pieData, - this.opts - ); - } else if (this.opts.type === "radar") { - return findRadarChartCurrentIndex( - { - x: _touches$.x, - y: _touches$.y, - }, - this.opts.chartData.radarData, - this.opts.categories.length - ); - } else if (this.opts.type === "funnel") { - return findFunnelChartCurrentIndex( - { - x: _touches$.x, - y: _touches$.y, - }, - this.opts.chartData.funnelData - ); - } else if (this.opts.type === "map") { - return findMapChartCurrentIndex( - { - x: _touches$.x, - y: _touches$.y, - }, - this.opts - ); - } else if (this.opts.type === "word") { - return findWordChartCurrentIndex( - { - x: _touches$.x, - y: _touches$.y, - }, - this.opts.chartData.wordCloudData - ); - } else if (this.opts.type === "bar") { - return findBarChartCurrentIndex( - { - x: _touches$.x, - y: _touches$.y, - }, - this.opts.chartData.calPoints, - this.opts, - this.config, - Math.abs(this.scrollOption.currentOffset) - ); - } else { - return findCurrentIndex( - { - x: _touches$.x, - y: _touches$.y, - }, - this.opts.chartData.calPoints, - this.opts, - this.config, - Math.abs(this.scrollOption.currentOffset) - ); - } - } - return -1; -}; - -uCharts.prototype.getLegendDataIndex = function (e) { - var touches = null; - if (e.changedTouches) { - touches = e.changedTouches[0]; - } else { - touches = e.mp.changedTouches[0]; - } - if (touches) { - let _touches$ = getTouches(touches, this.opts, e); - return findLegendIndex( - { - x: _touches$.x, - y: _touches$.y, - }, - this.opts.chartData.legendData - ); - } - return -1; -}; - -uCharts.prototype.touchLegend = function (e) { - var option = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - var touches = null; - if (e.changedTouches) { - touches = e.changedTouches[0]; - } else { - touches = e.mp.changedTouches[0]; - } - if (touches) { - var _touches$ = getTouches(touches, this.opts, e); - var index = this.getLegendDataIndex(e); - if (index >= 0) { - if (this.opts.type == "candle") { - this.opts.seriesMA[index].show = !this.opts.seriesMA[index].show; - } else { - this.opts.series[index].show = !this.opts.series[index].show; - } - this.opts.animation = option.animation ? true : false; - this.opts._scrollDistance_ = this.scrollOption.currentOffset; - drawCharts.call(this, this.opts.type, this.opts, this.config, this.context); - } - } -}; - -uCharts.prototype.showToolTip = function (e) { - var option = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - var touches = null; - if (e.changedTouches) { - touches = e.changedTouches[0]; - } else { - touches = e.mp.changedTouches[0]; - } - if (!touches) { - console.log("[uCharts] 未获取到event坐标信息"); - } - var _touches$ = getTouches(touches, this.opts, e); - var currentOffset = this.scrollOption.currentOffset; - var opts = assign({}, this.opts, { - _scrollDistance_: currentOffset, - animation: false, - }); - if (this.opts.type === "line" || this.opts.type === "area" || this.opts.type === "column" || this.opts.type === "scatter" || this.opts.type === "bubble") { - var current = this.getCurrentDataIndex(e); - var index = option.index == undefined ? current.index : option.index; - if (index > -1 || index.length > 0) { - var seriesData = getSeriesDataItem(this.opts.series, index, current.group); - if (seriesData.length !== 0) { - var _getToolTipData = getToolTipData(seriesData, this.opts, index, current.group, this.opts.categories, option), - textList = _getToolTipData.textList, - offset = _getToolTipData.offset; - offset.y = _touches$.y; - opts.tooltip = { - textList: option.textList !== undefined ? option.textList : textList, - offset: option.offset !== undefined ? option.offset : offset, - option: option, - index: index, - group: current.group, - }; - } - } - drawCharts.call(this, opts.type, opts, this.config, this.context); - } - if (this.opts.type === "mount") { - var index = option.index == undefined ? this.getCurrentDataIndex(e).index : option.index; - if (index > -1) { - var opts = assign({}, this.opts, { animation: false }); - var seriesData = assign({}, opts._series_[index]); - var textList = [ - { - text: option.formatter ? option.formatter(seriesData, undefined, index, opts) : seriesData.name + ": " + seriesData.data, - color: seriesData.color, - legendShape: this.opts.extra.tooltip.legendShape == "auto" ? seriesData.legendShape : this.opts.extra.tooltip.legendShape, - }, - ]; - var offset = { - x: opts.chartData.calPoints[index].x, - y: _touches$.y, - }; - opts.tooltip = { - textList: option.textList ? option.textList : textList, - offset: option.offset !== undefined ? option.offset : offset, - option: option, - index: index, - }; - } - - drawCharts.call(this, opts.type, opts, this.config, this.context); - } - if (this.opts.type === "bar") { - var current = this.getCurrentDataIndex(e); - var index = option.index == undefined ? current.index : option.index; - if (index > -1 || index.length > 0) { - var seriesData = getSeriesDataItem(this.opts.series, index, current.group); - if (seriesData.length !== 0) { - var _getToolTipData = getToolTipData(seriesData, this.opts, index, current.group, this.opts.categories, option), - textList = _getToolTipData.textList, - offset = _getToolTipData.offset; - offset.x = _touches$.x; - opts.tooltip = { - textList: option.textList !== undefined ? option.textList : textList, - offset: option.offset !== undefined ? option.offset : offset, - option: option, - index: index, - }; - } - } - drawCharts.call(this, opts.type, opts, this.config, this.context); - } - if (this.opts.type === "mix") { - var current = this.getCurrentDataIndex(e); - var index = option.index == undefined ? current.index : option.index; - if (index > -1) { - var currentOffset = this.scrollOption.currentOffset; - var opts = assign({}, this.opts, { - _scrollDistance_: currentOffset, - animation: false, - }); - var seriesData = getSeriesDataItem(this.opts.series, index); - if (seriesData.length !== 0) { - var _getMixToolTipData = getMixToolTipData(seriesData, this.opts, index, this.opts.categories, option), - textList = _getMixToolTipData.textList, - offset = _getMixToolTipData.offset; - offset.y = _touches$.y; - opts.tooltip = { - textList: option.textList ? option.textList : textList, - offset: option.offset !== undefined ? option.offset : offset, - option: option, - index: index, - }; - } - } - drawCharts.call(this, opts.type, opts, this.config, this.context); - } - if (this.opts.type === "candle") { - var current = this.getCurrentDataIndex(e); - var index = option.index == undefined ? current.index : option.index; - if (index > -1) { - var currentOffset = this.scrollOption.currentOffset; - var opts = assign({}, this.opts, { - _scrollDistance_: currentOffset, - animation: false, - }); - var seriesData = getSeriesDataItem(this.opts.series, index); - if (seriesData.length !== 0) { - var _getToolTipData = getCandleToolTipData(this.opts.series[0].data, seriesData, this.opts, index, this.opts.categories, this.opts.extra.candle, option), - textList = _getToolTipData.textList, - offset = _getToolTipData.offset; - offset.y = _touches$.y; - opts.tooltip = { - textList: option.textList ? option.textList : textList, - offset: option.offset !== undefined ? option.offset : offset, - option: option, - index: index, - }; - } - } - drawCharts.call(this, opts.type, opts, this.config, this.context); - } - if (this.opts.type === "pie" || this.opts.type === "ring" || this.opts.type === "rose" || this.opts.type === "funnel") { - var index = option.index == undefined ? this.getCurrentDataIndex(e) : option.index; - if (index > -1) { - var opts = assign({}, this.opts, { animation: false }); - var seriesData = assign({}, opts._series_[index]); - var textList = [ - { - text: option.formatter ? option.formatter(seriesData, undefined, index, opts) : seriesData.name + ": " + seriesData.data, - color: seriesData.color, - legendShape: this.opts.extra.tooltip.legendShape == "auto" ? seriesData.legendShape : this.opts.extra.tooltip.legendShape, - }, - ]; - var offset = { - x: _touches$.x, - y: _touches$.y, - }; - opts.tooltip = { - textList: option.textList ? option.textList : textList, - offset: option.offset !== undefined ? option.offset : offset, - option: option, - index: index, - }; - } - drawCharts.call(this, opts.type, opts, this.config, this.context); - } - if (this.opts.type === "map") { - var index = option.index == undefined ? this.getCurrentDataIndex(e) : option.index; - if (index > -1) { - var opts = assign({}, this.opts, { animation: false }); - var seriesData = assign({}, this.opts.series[index]); - seriesData.name = seriesData.properties.name; - var textList = [ - { - text: option.formatter ? option.formatter(seriesData, undefined, index, this.opts) : seriesData.name, - color: seriesData.color, - legendShape: this.opts.extra.tooltip.legendShape == "auto" ? seriesData.legendShape : this.opts.extra.tooltip.legendShape, - }, - ]; - var offset = { - x: _touches$.x, - y: _touches$.y, - }; - opts.tooltip = { - textList: option.textList ? option.textList : textList, - offset: option.offset !== undefined ? option.offset : offset, - option: option, - index: index, - }; - } - opts.updateData = false; - drawCharts.call(this, opts.type, opts, this.config, this.context); - } - if (this.opts.type === "word") { - var index = option.index == undefined ? this.getCurrentDataIndex(e) : option.index; - if (index > -1) { - var opts = assign({}, this.opts, { animation: false }); - var seriesData = assign({}, this.opts.series[index]); - var textList = [ - { - text: option.formatter ? option.formatter(seriesData, undefined, index, this.opts) : seriesData.name, - color: seriesData.color, - legendShape: this.opts.extra.tooltip.legendShape == "auto" ? seriesData.legendShape : this.opts.extra.tooltip.legendShape, - }, - ]; - var offset = { - x: _touches$.x, - y: _touches$.y, - }; - opts.tooltip = { - textList: option.textList ? option.textList : textList, - offset: option.offset !== undefined ? option.offset : offset, - option: option, - index: index, - }; - } - opts.updateData = false; - drawCharts.call(this, opts.type, opts, this.config, this.context); - } - if (this.opts.type === "radar") { - var index = option.index == undefined ? this.getCurrentDataIndex(e) : option.index; - if (index > -1) { - var opts = assign({}, this.opts, { animation: false }); - var seriesData = getSeriesDataItem(this.opts.series, index); - if (seriesData.length !== 0) { - var textList = seriesData.map((item) => { - return { - text: option.formatter ? option.formatter(item, this.opts.categories[index], index, this.opts) : item.name + ": " + item.data, - color: item.color, - legendShape: this.opts.extra.tooltip.legendShape == "auto" ? item.legendShape : this.opts.extra.tooltip.legendShape, - }; - }); - var offset = { - x: _touches$.x, - y: _touches$.y, - }; - opts.tooltip = { - textList: option.textList ? option.textList : textList, - offset: option.offset !== undefined ? option.offset : offset, - option: option, - index: index, - }; - } - } - drawCharts.call(this, opts.type, opts, this.config, this.context); - } -}; - -uCharts.prototype.translate = function (distance) { - this.scrollOption = { - currentOffset: distance, - startTouchX: distance, - distance: 0, - lastMoveTime: 0, - }; - let opts = assign({}, this.opts, { - _scrollDistance_: distance, - animation: false, - }); - drawCharts.call(this, this.opts.type, opts, this.config, this.context); -}; - -uCharts.prototype.scrollStart = function (e) { - var touches = null; - if (e.changedTouches) { - touches = e.changedTouches[0]; - } else { - touches = e.mp.changedTouches[0]; - } - var _touches$ = getTouches(touches, this.opts, e); - if (touches && this.opts.enableScroll === true) { - this.scrollOption.startTouchX = _touches$.x; - } -}; - -uCharts.prototype.scroll = function (e) { - if (this.scrollOption.lastMoveTime === 0) { - this.scrollOption.lastMoveTime = Date.now(); - } - let Limit = this.opts.touchMoveLimit || 60; - let currMoveTime = Date.now(); - let duration = currMoveTime - this.scrollOption.lastMoveTime; - if (duration < Math.floor(1000 / Limit)) return; - if (this.scrollOption.startTouchX == 0) return; - this.scrollOption.lastMoveTime = currMoveTime; - var touches = null; - if (e.changedTouches) { - touches = e.changedTouches[0]; - } else { - touches = e.mp.changedTouches[0]; - } - if (touches && this.opts.enableScroll === true) { - var _touches$ = getTouches(touches, this.opts, e); - var _distance; - _distance = _touches$.x - this.scrollOption.startTouchX; - var currentOffset = this.scrollOption.currentOffset; - var validDistance = calValidDistance(this, currentOffset + _distance, this.opts.chartData, this.config, this.opts); - this.scrollOption.distance = _distance = validDistance - currentOffset; - var opts = assign({}, this.opts, { - _scrollDistance_: currentOffset + _distance, - animation: false, - }); - this.opts = opts; - drawCharts.call(this, opts.type, opts, this.config, this.context); - return currentOffset + _distance; - } -}; - -uCharts.prototype.scrollEnd = function (e) { - if (this.opts.enableScroll === true) { - var _scrollOption = this.scrollOption, - currentOffset = _scrollOption.currentOffset, - distance = _scrollOption.distance; - this.scrollOption.currentOffset = currentOffset + distance; - this.scrollOption.distance = 0; - this.scrollOption.moveCount = 0; - } -}; - -export default uCharts; diff --git a/fastapp/src/components/u-charts/u-charts.min.js b/fastapp/src/components/u-charts/u-charts.min.js deleted file mode 100644 index 0902ecd3..00000000 --- a/fastapp/src/components/u-charts/u-charts.min.js +++ /dev/null @@ -1,18 +0,0 @@ -/* - * uCharts (R) - * 高性能跨平台图表库,支持H5、APP、小程序(微信/支付宝/百度/头条/QQ/360/快手)、Vue、Taro等支持canvas的框架平台 - * Copyright (C) 2021 QIUN (R) 秋云 https://www.ucharts.cn All rights reserved. - * Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) - * 复制使用请保留本段注释,感谢支持开源! - * - * uCharts (R) 官方网站 - * https://www.uCharts.cn - * - * 开源地址: - * https://gitee.com/uCharts/uCharts - * - * uni-app插件市场地址: - * http://ext.dcloud.net.cn/plugin?id=271 - * - */ -"use strict";var config={version:"v2.5.0-20230101",yAxisWidth:15,xAxisHeight:22,padding:[10,10,10,10],rotate:false,fontSize:13,fontColor:"#666666",dataPointShape:["circle","circle","circle","circle"],color:["#1890FF","#91CB74","#FAC858","#EE6666","#73C0DE","#3CA272","#FC8452","#9A60B4","#ea7ccc"],linearColor:["#0EE2F8","#2BDCA8","#FA7D8D","#EB88E2","#2AE3A0","#0EE2F8","#EB88E2","#6773E3","#F78A85"],pieChartLinePadding:15,pieChartTextPadding:5,titleFontSize:20,subtitleFontSize:15,radarLabelTextMargin:13};var assign=function(e,...t){if(e==null){throw new TypeError("[uCharts] Cannot convert undefined or null to object")}if(!t||t.length<=0){return e}function i(e,a){for(let t in a){e[t]=e[t]&&e[t].toString()==="[object Object]"?i(e[t],a[t]):e[t]=a[t]}return e}t.forEach(t=>{e=i(e,t)});return e};var util={toFixed:function t(e,a){a=a||2;if(this.isFloat(e)){e=e.toFixed(a)}return e},isFloat:function t(e){return e%1!==0},approximatelyEqual:function t(e,a){return Math.abs(e-a)<1e-10},isSameSign:function t(e,a){return Math.abs(e)===e&&Math.abs(a)===a||Math.abs(e)!==e&&Math.abs(a)!==a},isSameXCoordinateArea:function t(e,a){return this.isSameSign(e.x,a.x)},isCollision:function t(e,a){e.end={};e.end.x=e.start.x+e.width;e.end.y=e.start.y-e.height;a.end={};a.end.x=a.start.x+a.width;a.end.y=a.start.y-a.height;var i=a.start.x>e.end.x||a.end.xe.start.y||a.start.y1){if(r.extra.mount.widthRatio>2)r.extra.mount.widthRatio=2;n+=(r.extra.mount.widthRatio-1)*a.eachSpacing}var l=e;if(e>=0){l=0;t.uevent.trigger("scrollLeft");t.scrollOption.position="left";r.xAxis.scrollPosition="left"}else if(Math.abs(e)>=n-o){l=o-n;t.uevent.trigger("scrollRight");t.scrollOption.position="right";r.xAxis.scrollPosition="right"}else{t.scrollOption.position=e;r.xAxis.scrollPosition=e}return l}function isInAngleRange(t,e,a){function i(t){while(t<0){t+=2*Math.PI}while(t>2*Math.PI){t-=2*Math.PI}return t}t=i(t);e=i(e);a=i(a);if(e>a){a+=2*Math.PI;if(t=e&&t<=a}function createCurveControlPoints(t,e){function a(t,e){if(t[e-1]&&t[e+1]){return t[e].y>=Math.max(t[e-1].y,t[e+1].y)||t[e].y<=Math.min(t[e-1].y,t[e+1].y)}else{return false}}function c(t,e){if(t[e-1]&&t[e+1]){return t[e].x>=Math.max(t[e-1].x,t[e+1].x)||t[e].x<=Math.min(t[e-1].x,t[e+1].x)}else{return false}}var i=.2;var r=.2;var o=null;var n=null;var l=null;var s=null;if(e<1){o=t[0].x+(t[1].x-t[0].x)*i;n=t[0].y+(t[1].y-t[0].y)*i}else{o=t[e].x+(t[e+1].x-t[e-1].x)*i;n=t[e].y+(t[e+1].y-t[e-1].y)*i}if(e>t.length-3){var h=t.length-1;l=t[h].x-(t[h].x-t[h-1].x)*r;s=t[h].y-(t[h].y-t[h-1].y)*r}else{l=t[e+1].x-(t[e+2].x-t[e].x)*r;s=t[e+1].y-(t[e+2].y-t[e].y)*r}if(a(t,e+1)){s=t[e+1].y}if(a(t,e)){n=t[e].y}if(c(t,e+1)){l=t[e+1].x}if(c(t,e)){o=t[e].x}if(n>=Math.max(t[e].y,t[e+1].y)||n<=Math.min(t[e].y,t[e+1].y)){n=t[e].y}if(s>=Math.max(t[e].y,t[e+1].y)||s<=Math.min(t[e].y,t[e+1].y)){s=t[e+1].y}if(o>=Math.max(t[e].x,t[e+1].x)||o<=Math.min(t[e].x,t[e+1].x)){o=t[e].x}if(l>=Math.max(t[e].x,t[e+1].x)||l<=Math.min(t[e].x,t[e+1].x)){l=t[e+1].x}return{ctrA:{x:o,y:n},ctrB:{x:l,y:s}}}function convertCoordinateOrigin(t,e,a){return{x:a.x+t,y:a.y-e}}function avoidCollision(t,e){if(e){while(util.isCollision(t,e)){if(t.start.x>0){t.start.y--}else if(t.start.x<0){t.start.y++}else{if(t.start.y>0){t.start.y++}else{t.start.y--}}}}return t}function fixPieSeries(e,a,t){let i=[];if(e.length>0&&e[0].data.constructor.toString().indexOf("Array")>-1){a._pieSeries_=e;let t=e[0].data;for(var r=0;r=1e4){a=1e3}else if(i>=1e3){a=100}else if(i>=100){a=10}else if(i>=10){a=5}else if(i>=1){a=1}else if(i>=.1){a=.1}else if(i>=.01){a=.01}else if(i>=.001){a=.001}else if(i>=1e-4){a=1e-4}else if(i>=1e-5){a=1e-5}else{a=1e-6}return{minRange:findRange(t,"lower",a),maxRange:findRange(e,"upper",a)}}function measureText(a,t,e){var i=0;a=String(a);e=false;if(e!==false&&e!==undefined&&e.setFontSize&&e.measureText){e.setFontSize(t);return e.measureText(a).width}else{var a=a.split("");for(let e=0;e-1;if(n){let t=filterSeries(e);for(var l=0;l5&&arguments[5]!==undefined?arguments[5]:{};var l=a.chartData.calPoints?a.chartData.calPoints:[];let s={};if(r.length>0){let e=[];for(let t=0;t0){e=o[i]}return{text:n.formatter?n.formatter(t,e,i,a):t.name+": "+t.data,color:t.color,legendShape:a.extra.tooltip.legendShape=="auto"?t.legendShape:a.extra.tooltip.legendShape}});var h={x:Math.round(s.x),y:Math.round(s.y)};return{textList:e,offset:h}}function getMixToolTipData(t,e,a,i){var r=arguments.length>4&&arguments[4]!==undefined?arguments[4]:{};var o=e.chartData.xAxisPoints[a]+e.chartData.eachSpacing/2;var n=t.map(function(t){return{text:r.formatter?r.formatter(t,i[a],a,e):t.name+": "+t.data,color:t.color,disableLegend:t.disableLegend?true:false,legendShape:e.extra.tooltip.legendShape=="auto"?t.legendShape:e.extra.tooltip.legendShape}});n=n.filter(function(t){if(t.disableLegend!==true){return t}});var l={x:Math.round(o),y:0};return{textList:n,offset:l}}function getCandleToolTipData(o,e,n,l,i,t){var r=arguments.length>6&&arguments[6]!==undefined?arguments[6]:{};var a=n.chartData.calPoints;let s=t.color.upFill;let h=t.color.downFill;let c=[s,s,h,s];var d=[];e.map(function(t){if(l==0){if(t.data[1]-t.data[0]<0){c[1]=h}else{c[1]=s}}else{if(t.data[0]o[l-1][1]){c[2]=s}if(t.data[3]4&&arguments[4]!==undefined?arguments[4]:0;var l={index:-1,group:[]};var i=e.chartData.eachSpacing/2;let r=[];if(n&&n.length>0){if(!e.categories){i=0}else{for(let t=1;tt){l.index=e}})}}}return l}function findBarChartCurrentIndex(a,t,e,i){var r=arguments.length>4&&arguments[4]!==undefined?arguments[4]:0;var o={index:-1,group:[]};var n=e.chartData.eachSpacing/2;let l=e.chartData.yAxisPoints;if(t&&t.length>0){if(isInExactChartArea(a,e,i)){l.forEach(function(t,e){if(a.y+r+n>t){o.index=e}})}}return o}function findLegendIndex(o,t,e){let n=-1;let l=0;if(isInExactLegendArea(o,t.area)){let i=t.points;let r=-1;for(let t=0,e=i.length;tt[0]-l&&o.xt[1]-l&&o.ye.start.x&&t.xe.start.y&&t.y=e.area[3]-10&&t.y>=e.area[0]&&t.y<=e.height-e.area[2]}function findRadarChartCurrentIndex(t,e,a){var r=2*Math.PI/a;var o=-1;if(isInExactPieChartArea(t,e.center,e.radius)){var n=function t(e){if(e<0){e+=2*Math.PI}if(e>2*Math.PI){e-=2*Math.PI}return e};var l=Math.atan2(e.center.y-t.y,t.x-e.center.x);l=-1*l;if(l<0){l+=2*Math.PI}var i=e.angleList.map(function(t){t=n(-1*t);return t});i.forEach(function(t,e){var a=n(t-r/2);var i=n(t+r/2);if(i=a&&l<=i||l+2*Math.PI>=a&&l+2*Math.PI<=i){o=e}})}return o}function findFunnelChartCurrentIndex(t,e){var a=-1;for(var i=0,r=e.series.length;io.funnelArea[0]&&t.xo.funnelArea[1]&&t.yo.area[0]&&t.xo.area[1]&&t.ys.width-s.area[1]-s.area[3]){i.push(n);o.push(r-s.legend.itemGap*s.pix);r=e;n=[t]}else{r+=e;n.push(t)}}if(n.length){i.push(n);o.push(r-s.legend.itemGap*s.pix);c.widthArr=o;let t=Math.max.apply(null,o);switch(s.legend.float){case"left":c.area.start.x=s.area[3];c.area.end.x=s.area[3]+t+2*d;break;case"right":c.area.start.x=s.width-s.area[1]-t-2*d;c.area.end.x=s.width-s.area[1];break;default:c.area.start.x=(s.width-t)/2-d;c.area.end.x=(s.width+t)/2+d}c.area.width=t+2*d;c.area.wholeWidth=t+2*d;c.area.height=i.length*u+2*d;c.area.wholeHeight=i.length*u+2*d+2*x;c.points=i}}else{let t=l.length;let e=s.height-s.area[0]-s.area[2]-2*x-2*d;let a=Math.min(Math.floor(e/u),t);c.area.height=a*u+d*2;c.area.wholeHeight=a*u+d*2;switch(s.legend.float){case"top":c.area.start.y=s.area[0]+x;c.area.end.y=s.area[0]+x+c.area.height;break;case"bottom":c.area.start.y=s.height-s.area[2]-x-c.area.height;c.area.end.y=s.height-s.area[2]-x;break;default:c.area.start.y=(s.height-c.area.height)/2;c.area.end.y=(s.height+c.area.height)/2}let i=t%a===0?t/a:Math.floor(t/a+1);let r=[];for(let e=0;ei){i=t}}c.widthArr.push(i);c.heightArr.push(a.length*u+d*2)}let e=0;for(let t=0;t4&&arguments[4]!==undefined?arguments[4]:-1;var i;if(c=="stack"){i=dataCombineStack(t,e.categories.length)}else{i=dataCombine(t)}var r=[];i=i.filter(function(t){if(typeof t==="object"&&t!==null){if(t.constructor.toString().indexOf("Array")>-1){return t!==null}else{return t.value!==null}}else{return t!==null}});i.map(function(t){if(typeof t==="object"){if(t.constructor.toString().indexOf("Array")>-1){if(e.type=="candle"){t.map(function(t){r.push(t)})}else{r.push(t[0])}}else{r.push(t.value)}}else{r.push(t)}});var o=0;var n=0;if(r.length>0){o=Math.min.apply(this,r);n=Math.max.apply(this,r)}if(a>-1){if(typeof e.xAxis.data[a].min==="number"){o=Math.min(e.xAxis.data[a].min,o)}if(typeof e.xAxis.data[a].max==="number"){n=Math.max(e.xAxis.data[a].max,n)}}else{if(typeof e.xAxis.min==="number"){o=Math.min(e.xAxis.min,o)}if(typeof e.xAxis.max==="number"){n=Math.max(e.xAxis.max,n)}}if(o===n){var d=n||10;n+=d}var l=o;var x=n;var f=[];var p=(x-l)/e.xAxis.splitNumber;for(var s=0;s<=e.xAxis.splitNumber;s++){f.push(l+p*s)}return f}function calXAxisData(t,e,a,i){var r=assign({},{type:""},e.extra.bar);var o={angle:0,xAxisHeight:e.xAxis.lineHeight*e.pix+e.xAxis.marginTop*e.pix};o.ranges=getXAxisTextList(t,e,a,r.type);o.rangesFormat=o.ranges.map(function(t){t=util.toFixed(t,2);return t});var n=o.ranges.map(function(t){t=util.toFixed(t,2);return t});o=Object.assign(o,getXAxisPoints(n,e,a));var l=o.eachSpacing;var s=n.map(function(t){return measureText(t,e.xAxis.fontSize*e.pix,i)});if(e.xAxis.disabled===true){o.xAxisHeight=0}return o}function getRadarDataPoints(r,o,n,a,t){var l=arguments.length>5&&arguments[5]!==undefined?arguments[5]:1;var e=t.extra.radar||{};e.max=e.max||0;var s=Math.max(e.max,Math.max.apply(null,dataCombine(a)));var h=[];for(let e=0;e2&&arguments[2]!==undefined?arguments[2]:1;var o=0;var n=0;for(let e=0;e4&&arguments[4]!==undefined?arguments[4]:1;for(let t=0;t4&&arguments[4]!==undefined?arguments[4]:1;var l=0;var s=0;var h=[];for(let e=0;e2&&arguments[2]!==undefined?arguments[2]:1;if(o==1){o=.999999}for(let a=0;a=2){t._proportion_=t._proportion_%2}}return i}function getGaugeArcbarDataPoints(i,r){var o=arguments.length>2&&arguments[2]!==undefined?arguments[2]:1;if(o==1){o=.999999}for(let a=0;a=2){t._proportion_=t._proportion_%2}}return i}function getGaugeAxisPoints(e,a,t){let i;if(t=2){e[t]._endAngle_=e[t]._endAngle_%2}r=e[t]._endAngle_}return e}function getGaugeDataPoints(i,r,o){let n=arguments.length>3&&arguments[3]!==undefined?arguments[3]:1;for(let a=0;a=o.oldData){e._proportion_=(e._endAngle_-e._oldAngle_)*n+o.oldAngle}else{e._proportion_=e._oldAngle_-(e._oldAngle_-e._endAngle_)*n}if(e._proportion_>=2){e._proportion_=e._proportion_%2}}return i}function getPieTextMaxLength(i,r,o,n){i=getPieDataPoints(i);let l=0;for(let a=0;a0){t.width=Math.min(t.width,+n.extra.mix.column.width*n.pix)}if(n.extra.column&&n.extra.column.width&&+n.extra.column.width>0){t.width=Math.min(t.width,+n.extra.column.width*n.pix)}if(t.width<=0){t.width=1}t.x+=(o+.5-r/2)*(t.width+e);return t})}function fixBarData(t,i,r,o,e,n){return t.map(function(t){if(t===null){return null}var e=0;var a=0;e=n.extra.bar.seriesGap*n.pix||0;a=n.extra.bar.categoryGap*n.pix||0;e=Math.min(e,i/r);a=Math.min(a,i/r);t.width=Math.ceil((i-2*a-e*(r-1))/r);if(n.extra.bar&&n.extra.bar.width&&+n.extra.bar.width>0){t.width=Math.min(t.width,+n.extra.bar.width*n.pix)}if(t.width<=0){t.width=1}t.y+=(o+.5-r/2)*(t.width+e);return t})}function fixColumeMeterData(t,e,a,i,r,o,n){var l=o.extra.column.categoryGap*o.pix||0;return t.map(function(t){if(t===null){return null}t.width=e-2*l;if(o.extra.column&&o.extra.column.width&&+o.extra.column.width>0){t.width=Math.min(t.width,+o.extra.column.width*o.pix)}if(i>0){t.width-=n}return t})}function fixColumeStackData(t,a,e,i,r,o,n){var l=o.extra.column.categoryGap*o.pix||0;return t.map(function(t,e){if(t===null){return null}t.width=Math.ceil(a-2*l);if(o.extra.column&&o.extra.column.width&&+o.extra.column.width>0){t.width=Math.min(t.width,+o.extra.column.width*o.pix)}if(t.width<=0){t.width=1}return t})}function fixBarStackData(t,a,e,i,r,o,n){var l=o.extra.bar.categoryGap*o.pix||0;return t.map(function(t,e){if(t===null){return null}t.width=Math.ceil(a-2*l);if(o.extra.bar&&o.extra.bar.width&&+o.extra.bar.width>0){t.width=Math.min(t.width,+o.extra.bar.width*o.pix)}if(t.width<=0){t.width=1}return t})}function getXAxisPoints(t,e,h){var a=e.width-e.area[1]-e.area[3];var i=e.enableScroll?Math.min(e.xAxis.itemCount,t.length):t.length;if((e.type=="line"||e.type=="area"||e.type=="scatter"||e.type=="bubble"||e.type=="bar")&&i>1&&e.xAxis.boundaryGap=="justify"){i-=1}var r=0;if(e.type=="mount"&&e.extra&&e.extra.mount&&e.extra.mount.widthRatio&&e.extra.mount.widthRatio>1){if(e.extra.mount.widthRatio>2)e.extra.mount.widthRatio=2;r=e.extra.mount.widthRatio-1;i+=r}var o=a/i;var n=[];var l=e.area[3];var s=e.width-e.area[1];t.forEach(function(t,e){n.push(l+r/2*o+e*o)});if(e.xAxis.boundaryGap!=="justify"){if(e.enableScroll===true){n.push(l+r*o+t.length*o)}else{n.push(s)}}return{xAxisPoints:n,startX:l,endX:s,eachSpacing:o}}function getCandleDataPoints(t,l,s,h,c,d,a){var x=arguments.length>7&&arguments[7]!==undefined?arguments[7]:1;var e=[];var f=d.height-d.area[0]-d.area[2];t.forEach(function(t,o){if(t===null){e.push(null)}else{var n=[];t.forEach(function(t,e){var a={};a.x=h[o]+Math.round(c/2);var i=t.value||t;var r=f*(i-l)/(s-l);r*=x;a.y=d.height-Math.round(r)-d.area[2];n.push(a)});e.push(n)}});return e}function getDataPoints(t,a,n,l,s,h,e){var c=arguments.length>7&&arguments[7]!==undefined?arguments[7]:1;var d="center";if(h.type=="line"||h.type=="area"||h.type=="scatter"||h.type=="bubble"){d=h.xAxis.boundaryGap}var x=[];var f=h.height-h.area[0]-h.area[2];var p=h.width-h.area[1]-h.area[3];t.forEach(function(i,t){if(i===null){x.push(null)}else{var r={};r.color=i.color;r.x=l[t];var o=i;if(typeof i==="object"&&i!==null){if(i.constructor.toString().indexOf("Array")>-1){let t,e,a;t=[].concat(h.chartData.xAxisData.ranges);e=t.shift();a=t.pop();o=i[1];r.x=h.area[3]+p*(i[0]-e)/(a-e);if(h.type=="bubble"){r.r=i[2];r.t=i[3]}}else{o=i.value}}if(d=="center"){r.x+=s/2}var e=f*(o-a)/(n-a);e*=c;r.y=h.height-e-h.area[2];x.push(r)}});return x}function getLineDataPoints(t,a,n,l,s,h,e,p,c){var c=arguments.length>8&&arguments[8]!==undefined?arguments[8]:1;var d=h.xAxis.boundaryGap;var x=[];var f=h.height-h.area[0]-h.area[2];var u=h.width-h.area[1]-h.area[3];t.forEach(function(i,t){if(i===null){x.push(null)}else{var r={};r.color=i.color;if(p.animation=="vertical"){r.x=l[t];var o=i;if(typeof i==="object"&&i!==null){if(i.constructor.toString().indexOf("Array")>-1){let t,e,a;t=[].concat(h.chartData.xAxisData.ranges);e=t.shift();a=t.pop();o=i[1];r.x=h.area[3]+u*(i[0]-e)/(a-e)}else{o=i.value}}if(d=="center"){r.x+=s/2}var e=f*(o-a)/(n-a);e*=c;r.y=h.height-e-h.area[2];x.push(r)}else{r.x=l[0]+s*t*c;var o=i;if(d=="center"){r.x+=s/2}var e=f*(o-a)/(n-a);r.y=h.height-e-h.area[2];x.push(r)}}});return x}function getColumnDataPoints(t,a,n,l,s,h,e,i,c){var c=arguments.length>8&&arguments[8]!==undefined?arguments[8]:1;var d=[];var x=h.height-h.area[0]-h.area[2];var f=h.width-h.area[1]-h.area[3];t.forEach(function(i,t){if(i===null){d.push(null)}else{var r={};r.color=i.color;r.x=l[t];var o=i;if(typeof i==="object"&&i!==null){if(i.constructor.toString().indexOf("Array")>-1){let t,e,a;t=[].concat(h.chartData.xAxisData.ranges);e=t.shift();a=t.pop();o=i[1];r.x=h.area[3]+f*(i[0]-e)/(a-e)}else{o=i.value}}r.x+=s/2;var e=x*(o*c-a)/(n-a);r.y=h.height-e-h.area[2];d.push(r)}});return d}function getMountDataPoints(t,o,n,l,s,h,e,a){var c=arguments.length>8&&arguments[8]!==undefined?arguments[8]:1;var d=[];var x=h.height-h.area[0]-h.area[2];var i=h.width-h.area[1]-h.area[3];var f=s*e.widthRatio;t.forEach(function(t,e){if(t===null){d.push(null)}else{var a={};a.color=t.color;a.x=l[e];a.x+=s/2;var i=t.data;var r=x*(i*c-o)/(n-o);a.y=h.height-r-h.area[2];a.value=i;a.width=f;d.push(a)}});return d}function getBarDataPoints(t,o,n,l,e,s,a){var h=arguments.length>7&&arguments[7]!==undefined?arguments[7]:1;var c=[];var i=s.height-s.area[0]-s.area[2];var d=s.width-s.area[1]-s.area[3];t.forEach(function(t,e){if(t===null){c.push(null)}else{var a={};a.color=t.color;a.y=l[e];var i=t;if(typeof t==="object"&&t!==null){i=t.value}var r=d*(i-o)/(n-o);r*=h;a.height=r;a.value=i;a.x=r+s.area[3];c.push(a)}});return c}function getStackDataPoints(t,s,h,c,g,d,e,x,y){var f=arguments.length>9&&arguments[9]!==undefined?arguments[9]:1;var p=[];var u=d.height-d.area[0]-d.area[2];t.forEach(function(t,e){if(t===null){p.push(null)}else{var a={};a.color=t.color;a.x=c[e]+Math.round(g/2);if(x>0){var i=0;for(let t=0;t<=x;t++){i+=y[t].data[e]}var r=i-t;var o=u*(i-s)/(h-s);var n=u*(r-s)/(h-s)}else{var i=t;if(typeof t==="object"&&t!==null){i=t.value}var o=u*(i-s)/(h-s);var n=0}var l=n;o*=f;l*=f;a.y=d.height-Math.round(o)-d.area[2];a.y0=d.height-Math.round(l)-d.area[2];p.push(a)}});return p}function getBarStackDataPoints(t,s,h,c,e,d,a,x,g){var f=arguments.length>9&&arguments[9]!==undefined?arguments[9]:1;var p=[];var u=d.width-d.area[1]-d.area[3];t.forEach(function(t,e){if(t===null){p.push(null)}else{var a={};a.color=t.color;a.y=c[e];if(x>0){var i=0;for(let t=0;t<=x;t++){i+=g[t].data[e]}var r=i-t;var o=u*(i-s)/(h-s);var n=u*(r-s)/(h-s)}else{var i=t;if(typeof t==="object"&&t!==null){i=t.value}var o=u*(i-s)/(h-s);var n=0}var l=n;o*=f;l*=f;a.height=o-l;a.x=d.area[3]+o;a.x0=d.area[3]+l;p.push(a)}});return p}function getYAxisTextList(t,e,h,c,a){var d=arguments.length>5&&arguments[5]!==undefined?arguments[5]:-1;var i;if(c=="stack"){i=dataCombineStack(t,e.categories.length)}else{i=dataCombine(t)}var r=[];i=i.filter(function(t){if(typeof t==="object"&&t!==null){if(t.constructor.toString().indexOf("Array")>-1){return t!==null}else{return t.value!==null}}else{return t!==null}});i.map(function(t){if(typeof t==="object"){if(t.constructor.toString().indexOf("Array")>-1){if(e.type=="candle"){t.map(function(t){r.push(t)})}else{r.push(t[1])}}else{r.push(t.value)}}else{r.push(t)}});var o=a.min||0;var n=a.max||0;if(r.length>0){o=Math.min.apply(this,r);n=Math.max.apply(this,r)}if(o===n){if(n==0){n=10}else{o=0}}var l=getDataRange(o,n);var x=a.min===undefined||a.min===null?l.minRange:a.min;var f=a.max===undefined||a.max===null?l.maxRange:a.max;var p=(f-x)/e.yAxis.splitNumber;var u=[];for(var s=0;s<=e.yAxis.splitNumber;s++){u.push(x+p*s)}return u.reverse()}function calYAxisData(a,o,e,n){var l=assign({},{type:""},o.extra.column);var t=o.yAxis.data.length;var s=new Array(t);if(t>0){for(let e=0;e{return t+(i.unit||"")}}i.categories=i.categories||o.categories;h[r]=i.categories}else{if(!i.formatter){i.formatter=(t,e,a)=>{return util.toFixed(t,i.tofix||0)+(i.unit||"")}}h[r]=getYAxisTextList(s[r],o,e,l.type,i,r)}let a=i.fontSize*o.pix||e.fontSize;d[r]={position:i.position?i.position:"left",width:0};c[r]=h[r].map(function(t,e){t=i.formatter(t,e,o);d[r].width=Math.max(d[r].width,measureText(t,a,n)+5);return t});let t=i.calibration?4*o.pix:0;d[r].width+=t+3*o.pix;if(i.disabled===true){d[r].width=0}}}else{var h=new Array(1);var c=new Array(1);var d=new Array(1);if(o.type==="bar"){h[0]=o.categories;if(!o.yAxis.formatter){o.yAxis.formatter=(t,e,a)=>{return t+(a.yAxis.unit||"")}}}else{if(!o.yAxis.formatter){o.yAxis.formatter=(t,e,a)=>{return t.toFixed(a.yAxis.tofix)+(a.yAxis.unit||"")}}h[0]=getYAxisTextList(a,o,e,l.type,{})}d[0]={position:"left",width:0};var i=o.yAxis.fontSize*o.pix||e.fontSize;c[0]=h[0].map(function(t,e){t=o.yAxis.formatter(t,e,o);d[0].width=Math.max(d[0].width,measureText(t,i,n)+5);return t});d[0].width+=3*o.pix;if(o.yAxis.disabled===true){d[0]={position:"left",width:0};o.yAxis.data[0]={disabled:true}}else{o.yAxis.data[0]={disabled:false,position:"left",max:o.yAxis.max,min:o.yAxis.min,formatter:o.yAxis.formatter};if(o.type==="bar"){o.yAxis.data[0].categories=o.categories;o.yAxis.data[0].type="categories"}}}return{rangesFormat:c,ranges:h,yAxisWidth:d}}function calTooltipYAxisData(r,t,o,e,a){let n=[].concat(o.chartData.yAxisData.ranges);let l=o.height-o.area[0]-o.area[2];let s=o.area[0];let h=[];for(let i=0;i0&&r.tooltip.group.includes(n)==false){return}var l=typeof r.tooltip.index==="number"?r.tooltip.index:r.tooltip.index[r.tooltip.group.indexOf(n)];i.beginPath();if(o.activeType=="hollow"){i.setStrokeStyle(e);i.setFillStyle(r.background);i.setLineWidth(2*r.pix)}else{i.setStrokeStyle("#ffffff");i.setFillStyle(e);i.setLineWidth(1*r.pix)}if(a==="diamond"){t.forEach(function(t,e){if(t!==null&&l==e){i.moveTo(t.x,t.y-4.5);i.lineTo(t.x-4.5,t.y);i.lineTo(t.x,t.y+4.5);i.lineTo(t.x+4.5,t.y);i.lineTo(t.x,t.y-4.5)}})}else if(a==="circle"){t.forEach(function(t,e){if(t!==null&&l==e){i.moveTo(t.x+2.5*r.pix,t.y);i.arc(t.x,t.y,3*r.pix,0,2*Math.PI,false)}})}else if(a==="square"){t.forEach(function(t,e){if(t!==null&&l==e){i.moveTo(t.x-3.5,t.y-3.5);i.rect(t.x-3.5,t.y-3.5,7,7)}})}else if(a==="triangle"){t.forEach(function(t,e){if(t!==null&&l==e){i.moveTo(t.x,t.y-4.5);i.lineTo(t.x-4.5,t.y+4.5);i.lineTo(t.x+4.5,t.y+4.5);i.lineTo(t.x,t.y-4.5)}})}else if(a==="none"){return}i.closePath();i.fill();i.stroke()}function drawRingTitle(t,e,a,i){var r=t.title.fontSize||e.titleFontSize;var o=t.subtitle.fontSize||e.subtitleFontSize;var n=t.title.name||"";var l=t.subtitle.name||"";var c=t.title.color||t.fontColor;var d=t.subtitle.color||t.fontColor;var x=n?r:0;var f=l?o:0;var s=5;if(l){var p=measureText(l,o*t.pix,a);var u=i.x-p/2+(t.subtitle.offsetX||0)*t.pix;var h=i.y+o*t.pix/2+(t.subtitle.offsetY||0)*t.pix;if(n){h+=(x*t.pix+s)/2}a.beginPath();a.setFontSize(o*t.pix);a.setFillStyle(d);a.fillText(l,u,h);a.closePath();a.stroke()}if(n){var g=measureText(n,r*t.pix,a);var y=i.x-g/2+(t.title.offsetX||0);var v=i.y+r*t.pix/2+(t.title.offsetY||0)*t.pix;if(l){v-=(f*t.pix+s)/2}a.beginPath();a.setFontSize(r*t.pix);a.setFillStyle(c);a.fillText(n,y,v);a.closePath();a.stroke()}}function drawPointText(t,o,n,l,s){var h=o.data;var c=o.textOffset?o.textOffset:0;t.forEach(function(t,e){if(t!==null){l.beginPath();var a=o.textSize?o.textSize*s.pix:n.fontSize;l.setFontSize(a);l.setFillStyle(o.textColor||s.fontColor);var i=h[e];if(typeof h[e]==="object"&&h[e]!==null){if(h[e].constructor.toString().indexOf("Array")>-1){i=h[e][1]}else{i=h[e].value}}var r=o.formatter?o.formatter(i,e,o,s):i;l.setTextAlign("center");l.fillText(String(r),t.x,t.y-4+c*s.pix);l.closePath();l.stroke();l.setTextAlign("left")}})}function drawColumePointText(t,n,l,s,h){var c=n.data;var d=n.textOffset?n.textOffset:0;var x=h.extra.column.labelPosition;t.forEach(function(t,e){if(t!==null){s.beginPath();var a=n.textSize?n.textSize*h.pix:l.fontSize;s.setFontSize(a);s.setFillStyle(n.textColor||h.fontColor);var i=c[e];if(typeof c[e]==="object"&&c[e]!==null){if(c[e].constructor.toString().indexOf("Array")>-1){i=c[e][1]}else{i=c[e].value}}var r=n.formatter?n.formatter(i,e,n,h):i;s.setTextAlign("center");var o=t.y-4*h.pix+d*h.pix;if(t.y>n.zeroPoints){o=t.y+d*h.pix+a}if(x=="insideTop"){o=t.y+a+d*h.pix;if(t.y>n.zeroPoints){o=t.y-d*h.pix-4*h.pix}}if(x=="center"){o=t.y+d*h.pix+(h.height-h.area[2]-t.y+a)/2;if(n.zeroPointsn.zeroPoints){o=t.y-d*h.pix-(t.y-n.zeroPoints-a)/2}if(h.extra.column.type=="stack"){o=t.y+d*h.pix+(t.y0-t.y+a)/2}}if(x=="bottom"){o=h.height-h.area[2]+d*h.pix-4*h.pix;if(n.zeroPointsn.zeroPoints){o=n.zeroPoints-d*h.pix+a+2*h.pix}if(h.extra.column.type=="stack"){o=t.y0+d*h.pix-4*h.pix}}s.fillText(String(r),t.x,o);s.closePath();s.stroke();s.setTextAlign("left")}})}function drawMountPointText(t,n,l,s,h,c){var e=n.data;var d=n.textOffset?n.textOffset:0;var a=h.extra.mount.labelPosition;t.forEach(function(t,e){if(t!==null){s.beginPath();var a=n[e].textSize?n[e].textSize*h.pix:l.fontSize;s.setFontSize(a);s.setFillStyle(n[e].textColor||h.fontColor);var i=t.value;var r=n[e].formatter?n[e].formatter(i,e,n,h):i;s.setTextAlign("center");var o=t.y-4*h.pix+d*h.pix;if(t.y>c){o=t.y+d*h.pix+a}s.fillText(String(r),t.x,o);s.closePath();s.stroke();s.setTextAlign("left")}})}function drawBarPointText(t,o,n,l,s){var h=o.data;var e=o.textOffset?o.textOffset:0;t.forEach(function(t,e){if(t!==null){l.beginPath();var a=o.textSize?o.textSize*s.pix:n.fontSize;l.setFontSize(a);l.setFillStyle(o.textColor||s.fontColor);var i=h[e];if(typeof h[e]==="object"&&h[e]!==null){i=h[e].value}var r=o.formatter?o.formatter(i,e,o,s):i;l.setTextAlign("left");l.fillText(String(r),t.x+4*s.pix,t.y+a/2-3);l.closePath();l.stroke()}})}function drawGaugeLabel(e,a,i,r,o,n){a-=e.width/2+e.labelOffset*r.pix;a=a<10?10:a;let t;if(e.endAngle=2){l=l%2}s+=x}}function drawRadarLabel(t,s,h,c,d,x){var f=c.extra.radar||{};t.forEach(function(t,e){if(f.labelPointShow===true&&c.categories[e]!==""){var a={x:s*Math.cos(t),y:s*Math.sin(t)};var i=convertCoordinateOrigin(a.x,a.y,h);x.setFillStyle(f.labelPointColor);x.beginPath();x.arc(i.x,i.y,f.labelPointRadius*c.pix,0,2*Math.PI,false);x.closePath();x.fill()}if(f.labelShow===true){var r={x:(s+d.radarLabelTextMargin*c.pix)*Math.cos(t),y:(s+d.radarLabelTextMargin*c.pix)*Math.sin(t)};var o=convertCoordinateOrigin(r.x,r.y,h);var n=o.x;var l=o.y;if(util.approximatelyEqual(r.x,0)){n-=measureText(c.categories[e]||"",d.fontSize,x)/2}else if(r.x<0){n-=measureText(c.categories[e]||"",d.fontSize,x)}x.beginPath();x.setFontSize(d.fontSize);x.setFillStyle(f.labelColor||c.fontColor);x.fillText(c.categories[e]||"",n,l+d.fontSize/2);x.closePath();x.stroke()}})}function drawPieText(n,d,x,f,t,l){var p=x.pieChartLinePadding;var u=[];var g=null;var y=n.map(function(t,e){var a=t.formatter?t.formatter(t,e,n,d):util.toFixed(t._proportion_.toFixed(4)*100)+"%";a=t.labelText?t.labelText:a;var i=2*Math.PI-(t._start_+2*Math.PI*t._proportion_/2);if(t._rose_proportion_){i=2*Math.PI-(t._start_+2*Math.PI*t._rose_proportion_/2)}var r=t.color;var o=t._radius_;return{arc:i,text:a,color:r,radius:o,textColor:t.textColor,textSize:t.textSize,labelShow:t.labelShow}});for(let c=0;c=0?e+x.pieChartTextPadding:e-x.pieChartTextPadding;let n=a;let l=measureText(t.text,t.textSize*d.pix||x.fontSize,f);let s=n;if(g&&util.isSameXCoordinateArea(g.start,{x:o})){if(o>0){s=Math.min(n,g.start.y)}else if(e<0){s=Math.max(n,g.start.y)}else{if(n>0){s=Math.max(n,g.start.y)}else{s=Math.min(n,g.start.y)}}}if(o<0){o-=l}let h={lineStart:{x:i,y:r},lineEnd:{x:e,y:a},start:{x:o,y:s},width:l,height:x.fontSize,text:t.text,color:t.color,textColor:t.textColor,textSize:t.textSize};g=avoidCollision(h,g);u.push(g)}for(let n=0;nr?r:o.activeWidth;var n=e.area[0];var l=e.height-e.area[2];i.beginPath();i.setFillStyle(hexToRgb(o.activeBgColor,o.activeBgOpacity));i.rect(t-o.activeWidth/2,n,o.activeWidth,l-n);i.closePath();i.fill();i.setFillStyle("#FFFFFF")}function drawBarToolTipSplitArea(t,e,a,i,r){var o=assign({},{activeBgColor:"#000000",activeBgOpacity:.08},e.extra.bar);var n=e.area[3];var l=e.width-e.area[1];i.beginPath();i.setFillStyle(hexToRgb(o.activeBgColor,o.activeBgOpacity));i.rect(n,t-r/2,l-n,r);i.closePath();i.fill();i.setFillStyle("#FFFFFF")}function drawToolTip(e,r,o,a,n,i,f){var l=assign({},{showBox:true,showArrow:true,showCategory:false,bgColor:"#000000",bgOpacity:.7,borderColor:"#000000",borderWidth:0,borderRadius:0,borderOpacity:.7,boxPadding:3,fontColor:"#FFFFFF",fontSize:13,lineHeight:20,legendShow:true,legendShape:"auto",splitLine:true},o.extra.tooltip);if(l.showCategory==true&&o.categories){e.unshift({text:o.categories[o.tooltip.index],color:null})}var s=l.fontSize*o.pix;var p=l.lineHeight*o.pix;var h=l.boxPadding*o.pix;var c=s;var u=5*o.pix;if(l.legendShow==false){c=0;u=0}var d=l.showArrow?8*o.pix:0;var g=false;if(o.type=="line"||o.type=="mount"||o.type=="area"||o.type=="candle"||o.type=="mix"){if(l.splitLine==true){drawToolTipSplitLine(o.tooltip.offset.x,o,a,n)}}r=assign({x:0,y:0},r);r.y-=8*o.pix;var y=e.map(function(t){return measureText(t.text,s,n)});var x=c+u+4*h+Math.max.apply(null,y);var v=2*h+e.length*p;if(l.showBox==false){return}if(r.x-Math.abs(o._scrollDistance_||0)+d+x>o.width){g=true}if(v+r.y>o.height){r.y=o.height-v}n.beginPath();n.setFillStyle(hexToRgb(l.bgColor,l.bgOpacity));n.setLineWidth(l.borderWidth*o.pix);n.setStrokeStyle(hexToRgb(l.borderColor,l.borderOpacity));var t=l.borderRadius;if(g){if(x+d>o.width){r.x=o.width+Math.abs(o._scrollDistance_||0)+d+(x-o.width)}if(x>r.x){r.x=o.width+Math.abs(o._scrollDistance_||0)+d+(x-o.width)}if(l.showArrow){n.moveTo(r.x,r.y+10*o.pix);n.lineTo(r.x-d,r.y+10*o.pix+5*o.pix)}n.arc(r.x-d-t,r.y+v-t,t,0,Math.PI/2,false);n.arc(r.x-d-Math.round(x)+t,r.y+v-t,t,Math.PI/2,Math.PI,false);n.arc(r.x-d-Math.round(x)+t,r.y+t,t,-Math.PI,-Math.PI/2,false);n.arc(r.x-d-t,r.y+t,t,-Math.PI/2,0,false);if(l.showArrow){n.lineTo(r.x-d,r.y+10*o.pix-5*o.pix);n.lineTo(r.x,r.y+10*o.pix)}}else{if(l.showArrow){n.moveTo(r.x,r.y+10*o.pix);n.lineTo(r.x+d,r.y+10*o.pix-5*o.pix)}n.arc(r.x+d+t,r.y+t,t,-Math.PI,-Math.PI/2,false);n.arc(r.x+d+Math.round(x)-t,r.y+t,t,-Math.PI/2,0,false);n.arc(r.x+d+Math.round(x)-t,r.y+v-t,t,0,Math.PI/2,false);n.arc(r.x+d+t,r.y+v-t,t,Math.PI/2,Math.PI,false);if(l.showArrow){n.lineTo(r.x+d,r.y+10*o.pix+5*o.pix);n.lineTo(r.x,r.y+10*o.pix)}}n.closePath();n.fill();if(l.borderWidth>0){n.stroke()}if(l.legendShow){e.forEach(function(t,e){if(t.color!==null){n.beginPath();n.setFillStyle(t.color);var a=r.x+d+2*h;var i=r.y+(p-s)/2+p*e+h+1;if(g){a=r.x-x-d+2*h}switch(t.legendShape){case"line":n.moveTo(a,i+.5*c-2*o.pix);n.fillRect(a,i+.5*c-2*o.pix,c,4*o.pix);break;case"triangle":n.moveTo(a+7.5*o.pix,i+.5*c-5*o.pix);n.lineTo(a+2.5*o.pix,i+.5*c+5*o.pix);n.lineTo(a+12.5*o.pix,i+.5*c+5*o.pix);n.lineTo(a+7.5*o.pix,i+.5*c-5*o.pix);break;case"diamond":n.moveTo(a+7.5*o.pix,i+.5*c-5*o.pix);n.lineTo(a+2.5*o.pix,i+.5*c);n.lineTo(a+7.5*o.pix,i+.5*c+5*o.pix);n.lineTo(a+12.5*o.pix,i+.5*c);n.lineTo(a+7.5*o.pix,i+.5*c-5*o.pix);break;case"circle":n.moveTo(a+7.5*o.pix,i+.5*c);n.arc(a+7.5*o.pix,i+.5*c,5*o.pix,0,2*Math.PI);break;case"rect":n.moveTo(a,i+.5*c-5*o.pix);n.fillRect(a,i+.5*c-5*o.pix,15*o.pix,10*o.pix);break;case"square":n.moveTo(a+2*o.pix,i+.5*c-5*o.pix);n.fillRect(a+2*o.pix,i+.5*c-5*o.pix,10*o.pix,10*o.pix);break;default:n.moveTo(a,i+.5*c-5*o.pix);n.fillRect(a,i+.5*c-5*o.pix,15*o.pix,10*o.pix)}n.closePath();n.fill()}})}e.forEach(function(t,e){var a=r.x+d+2*h+c+u;if(g){a=r.x-x-d+2*h+c+u}var i=r.y+p*e+(p-s)/2-1+h+s;n.beginPath();n.setFontSize(s);n.setTextBaseline("normal");n.setFillStyle(l.fontColor);n.fillText(t.text,a,i);n.closePath();n.stroke()})}function drawColumnDataPoints(T,b,S,w){let A=arguments.length>4&&arguments[4]!==undefined?arguments[4]:1;let t=b.chartData.xAxisData,P=t.xAxisPoints,C=t.eachSpacing;let D=assign({},{type:"group",width:C/2,meterBorder:4,meterFillColor:"#FFFFFF",barBorderCircle:false,barBorderRadius:[],seriesGap:2,linearType:"none",linearOpacity:1,customColor:[],colorStop:0,labelPosition:"outside"},b.extra.column);let M=[];w.save();let L=-2;let F=P.length+2;if(b._scrollDistance_&&b._scrollDistance_!==0&&b.enableScroll===true){w.translate(b._scrollDistance_,0);L=Math.floor(-b._scrollDistance_/C)-2;F=L+b.xAxis.itemCount+4}if(b.tooltip&&b.tooltip.textList&&b.tooltip.textList.length&&A===1){drawToolTipSplitArea(b.tooltip.offset.x,b,S,w,C)}D.customColor=fillCustomColor(D.linearType,D.customColor,T,S);T.forEach(function(a,i){let e,t,o;e=[].concat(b.chartData.yAxisData.ranges[a.index]);t=e.pop();o=e.shift();let x=b.height-b.area[0]-b.area[2];let f=x*(0-t)/(o-t);let n=b.height-Math.round(f)-b.area[2];a.zeroPoints=n;var p=a.data;switch(D.type){case"group":var r=getColumnDataPoints(p,t,o,P,C,b,S,n,A);var u=getStackDataPoints(p,t,o,P,C,b,S,i,T,A);M.push(u);r=fixColumeData(r,C,T.length,i,S,b);for(let t=0;tL&&tn?n:o.y;const d=o.width;const s=Math.abs(n-o.y);if(D.barBorderCircle){D.barBorderRadius=[d/2,d/2,0,0]}if(o.y>n){D.barBorderRadius=[0,0,d/2,d/2]}let[t,e,a,i]=D.barBorderRadius;let r=Math.min(d/2,s/2);t=t>r?r:t;e=e>r?r:e;a=a>r?r:a;i=i>r?r:i;t=t<0?0:t;e=e<0?0:e;a=a<0?0:a;i=i<0?0:i;w.arc(h+t,c+t,t,-Math.PI,-Math.PI/2);w.arc(h+d-e,c+e,e,-Math.PI/2,0);w.arc(h+d-a,c+s-a,a,0,Math.PI/2);w.arc(h+i,c+s-i,i,Math.PI/2,Math.PI)}else{w.moveTo(l,o.y);w.lineTo(l+o.width,o.y);w.lineTo(l+o.width,n);w.lineTo(l,n);w.lineTo(l,o.y);w.setLineWidth(1);w.setStrokeStyle(y)}w.setFillStyle(g);w.closePath();w.fill()}};break;case"stack":var r=getStackDataPoints(p,t,o,P,C,b,S,i,T,A);M.push(r);r=fixColumeStackData(r,C,T.length,i,S,b,T);for(let e=0;eL&&e0){s-=m}w.setFillStyle(g);w.moveTo(l,t.y);w.fillRect(l,t.y,t.width,s);w.closePath();w.fill()}};break;case"meter":var r=getDataPoints(p,t,o,P,C,b,S,A);M.push(r);r=fixColumeMeterData(r,C,T.length,i,S,b,D.meterBorder);for(let t=0;tL&&t0){w.setStrokeStyle(a.color);w.setLineWidth(D.meterBorder*b.pix)}if(i==0){w.setFillStyle(D.meterFillColor)}else{w.setFillStyle(o.color||a.color)}var l=o.x-o.width/2;var s=b.height-o.y-b.area[2];if(D.barBorderRadius&&D.barBorderRadius.length===4||D.barBorderCircle===true){const h=l;const c=o.y;const d=o.width;const s=n-o.y;if(D.barBorderCircle){D.barBorderRadius=[d/2,d/2,0,0]}let[t,e,a,i]=D.barBorderRadius;let r=Math.min(d/2,s/2);t=t>r?r:t;e=e>r?r:e;a=a>r?r:a;i=i>r?r:i;t=t<0?0:t;e=e<0?0:e;a=a<0?0:a;i=i<0?0:i;w.arc(h+t,c+t,t,-Math.PI,-Math.PI/2);w.arc(h+d-e,c+e,e,-Math.PI/2,0);w.arc(h+d-a,c+s-a,a,0,Math.PI/2);w.arc(h+i,c+s-i,i,Math.PI/2,Math.PI);w.fill()}else{w.moveTo(l,o.y);w.lineTo(l+o.width,o.y);w.lineTo(l+o.width,n);w.lineTo(l,n);w.lineTo(l,o.y);w.fill()}if(i==0&&D.meterBorder>0){w.closePath();w.stroke()}}}break}});if(b.dataLabel!==false&&A===1){T.forEach(function(t,e){let a,i,r;a=[].concat(b.chartData.yAxisData.ranges[t.index]);i=a.pop();r=a.shift();var o=t.data;switch(D.type){case"group":var n=getColumnDataPoints(o,i,r,P,C,b,S,A);n=fixColumeData(n,C,T.length,e,S,b);drawColumePointText(n,t,S,w,b);break;case"stack":var n=getStackDataPoints(o,i,r,P,C,b,S,e,T,A);drawColumePointText(n,t,S,w,b);break;case"meter":var n=getDataPoints(o,i,r,P,C,b,S,A);drawColumePointText(n,t,S,w,b);break}})}w.restore();return{xAxisPoints:P,calPoints:M,eachSpacing:C}}function drawMountDataPoints(i,r,o,n){let f=arguments.length>4&&arguments[4]!==undefined?arguments[4]:1;let t=r.chartData.xAxisData,p=t.xAxisPoints,l=t.eachSpacing;let s=assign({},{type:"mount",widthRatio:1,borderWidth:1,barBorderCircle:false,barBorderRadius:[],linearType:"none",linearOpacity:1,customColor:[],colorStop:0},r.extra.mount);s.widthRatio=s.widthRatio<=0?0:s.widthRatio;s.widthRatio=s.widthRatio>=2?2:s.widthRatio;let e=[];n.save();let u=-2;let g=p.length+2;if(r._scrollDistance_&&r._scrollDistance_!==0&&r.enableScroll===true){n.translate(r._scrollDistance_,0);u=Math.floor(-r._scrollDistance_/l)-2;g=u+r.xAxis.itemCount+4}s.customColor=fillCustomColor(s.linearType,s.customColor,i,o);let y,v,m;y=[].concat(r.chartData.yAxisData.ranges[0]);v=y.pop();m=y.shift();let T=r.height-r.area[0]-r.area[2];let b=T*(0-v)/(m-v);let h=r.height-Math.round(b)-r.area[2];var c=getMountDataPoints(i,v,m,p,l,r,s,h,f);switch(s.type){case"bar":for(let t=0;tu&&th?h:o.y;const C=o.width;const S=Math.abs(h-o.y);if(s.barBorderCircle){s.barBorderRadius=[C/2,C/2,0,0]}if(o.y>h){s.barBorderRadius=[0,0,C/2,C/2]}let[t,e,a,i]=s.barBorderRadius;let r=Math.min(C/2,S/2);t=t>r?r:t;e=e>r?r:e;a=a>r?r:a;i=i>r?r:i;t=t<0?0:t;e=e<0?0:e;a=a<0?0:a;i=i<0?0:i;n.arc(A+t,P+t,t,-Math.PI,-Math.PI/2);n.arc(A+C-e,P+e,e,-Math.PI/2,0);n.arc(A+C-a,P+S-a,a,0,Math.PI/2);n.arc(A+i,P+S-i,i,Math.PI/2,Math.PI)}else{n.moveTo(d,o.y);n.lineTo(d+o.width,o.y);n.lineTo(d+o.width,h);n.lineTo(d,h);n.lineTo(d,o.y)}n.setStrokeStyle(w);n.setFillStyle(a);if(s.borderWidth>0){n.setLineWidth(s.borderWidth*r.pix);n.closePath();n.stroke()}n.fill()}};break;case"triangle":for(let e=0;eu&&e0){n.setLineWidth(s.borderWidth*r.pix);n.stroke()}n.fill()}};break;case"mount":for(let e=0;eu&&e0){n.setLineWidth(s.borderWidth*r.pix);n.stroke()}n.fill()}};break;case"sharp":for(let e=0;eu&&e0){n.setLineWidth(s.borderWidth*r.pix);n.stroke()}n.fill()}};break}if(r.dataLabel!==false&&f===1){let t,e,a;t=[].concat(r.chartData.yAxisData.ranges[0]);e=t.pop();a=t.shift();var c=getMountDataPoints(i,e,a,p,l,r,s,h,f);drawMountPointText(c,i,o,n,r,h)}n.restore();return{xAxisPoints:p,calPoints:c,eachSpacing:l}}function drawBarDataPoints(y,v,m,T){let b=arguments.length>4&&arguments[4]!==undefined?arguments[4]:1;let S=[];let w=(v.height-v.area[0]-v.area[2])/v.categories.length;for(let t=0;tC&&tr?r:t;e=e>r?r:e;a=a>r?r:a;i=i>r?r:i;t=t<0?0:t;e=e<0?0:e;a=a<0?0:a;i=i<0?0:i;T.arc(g+i,c+i,i,-Math.PI,-Math.PI/2);T.arc(o.x-t,c+t,t,-Math.PI/2,0);T.arc(o.x-e,c+h-e,e,0,Math.PI/2);T.arc(g+a,c+h-a,a,Math.PI/2,Math.PI)}else{T.moveTo(n,r);T.lineTo(o.x,r);T.lineTo(o.x,r+o.width);T.lineTo(n,r+o.width);T.lineTo(n,r);T.setLineWidth(1);T.setStrokeStyle(u)}T.setFillStyle(l);T.closePath();T.fill()}};break;case"stack":var i=getBarStackDataPoints(x,e,d,S,w,v,m,t,y,b);P.push(i);i=fixBarStackData(i,w,y.length,t,m,v,y);for(let e=0;eC&&e5&&arguments[5]!==undefined?arguments[5]:1;var s=assign({},{color:{},average:{}},h.extra.candle);s.color=assign({},{upLine:"#f04864",upFill:"#f04864",downLine:"#2fc25b",downFill:"#2fc25b"},s.color);s.average=assign({},{show:false,name:[],day:[],color:c.color},s.average);h.extra.candle=s;let a=h.chartData.xAxisData,x=a.xAxisPoints,f=a.eachSpacing;let y=[];d.save();let p=-2;let v=x.length+2;let u=0;let m=h.width+f;if(h._scrollDistance_&&h._scrollDistance_!==0&&h.enableScroll===true){d.translate(h._scrollDistance_,0);p=Math.floor(-h._scrollDistance_/f)-2;v=p+h.xAxis.itemCount+4;u=-h._scrollDistance_-f*2+h.area[3];m=u+(h.xAxis.itemCount+4)*f}if(s.average.show||t){t.forEach(function(e,t){let a,i,r;a=[].concat(h.chartData.yAxisData.ranges[e.index]);i=a.pop();r=a.shift();var o=e.data;var n=getDataPoints(o,i,r,x,f,h,c,g);var l=splitPoints(n,e);for(let t=0;tu){d.moveTo(t.x,t.y);a=1}if(e>0&&t.x>u&&t.xp&&e0){d.setStrokeStyle(s.color.upLine);d.setFillStyle(s.color.upFill);d.setLineWidth(1*h.pix);d.moveTo(t[3].x,t[3].y);d.lineTo(t[1].x,t[1].y);d.lineTo(t[1].x-f/4,t[1].y);d.lineTo(t[0].x-f/4,t[0].y);d.lineTo(t[0].x,t[0].y);d.lineTo(t[2].x,t[2].y);d.lineTo(t[0].x,t[0].y);d.lineTo(t[0].x+f/4,t[0].y);d.lineTo(t[1].x+f/4,t[1].y);d.lineTo(t[1].x,t[1].y);d.moveTo(t[3].x,t[3].y)}else{d.setStrokeStyle(s.color.downLine);d.setFillStyle(s.color.downFill);d.setLineWidth(1*h.pix);d.moveTo(t[3].x,t[3].y);d.lineTo(t[0].x,t[0].y);d.lineTo(t[0].x-f/4,t[0].y);d.lineTo(t[1].x-f/4,t[1].y);d.lineTo(t[1].x,t[1].y);d.lineTo(t[2].x,t[2].y);d.lineTo(t[1].x,t[1].y);d.lineTo(t[1].x+f/4,t[1].y);d.lineTo(t[0].x+f/4,t[0].y);d.lineTo(t[0].x,t[0].y);d.moveTo(t[3].x,t[3].y)}d.closePath();d.fill();d.stroke()}}});d.restore();return{xAxisPoints:x,calPoints:y,eachSpacing:f}}function drawAreaDataPoints(t,s,h,c){var d=arguments.length>4&&arguments[4]!==undefined?arguments[4]:1;var x=assign({},{type:"straight",opacity:.2,addLine:false,width:2,gradient:false,activeType:"none"},s.extra.area);let e=s.chartData.xAxisData,f=e.xAxisPoints,p=e.eachSpacing;let y=s.height-s.area[2];let v=[];c.save();let u=0;let g=s.width+p;if(s._scrollDistance_&&s._scrollDistance_!==0&&s.enableScroll===true){c.translate(s._scrollDistance_,0);u=-s._scrollDistance_-p*2+s.area[3];g=u+(s.xAxis.itemCount+4)*p}t.forEach(function(e,t){let a,i,r;a=[].concat(s.chartData.yAxisData.ranges[e.index]);i=a.pop();r=a.shift();let o=e.data;let n=getDataPoints(o,i,r,f,p,s,h,d);v.push(n);let l=splitPoints(n,e);for(let t=0;t1){let t=r[0];let e=r[r.length-1];c.moveTo(t.x,t.y);let i=0;if(x.type==="curve"){for(let a=0;au){c.moveTo(e.x,e.y);i=1}if(a>0&&e.x>u&&e.xu){c.moveTo(t.x,t.y);i=1}if(e>0&&t.x>u&&t.xu){c.moveTo(t.x,t.y);i=1}if(e>0&&t.x>u&&t.xu){c.moveTo(e.x,e.y);i=1}if(a>0&&e.x>u&&e.xu){c.moveTo(t.x,t.y);i=1}if(e>0&&t.x>u&&t.xu){c.moveTo(t.x,t.y);i=1}if(e>0&&t.x>u&&t.x4&&arguments[4]!==undefined?arguments[4]:1;var i=assign({},{type:"circle"},s.extra.scatter);let e=s.chartData.xAxisData,x=e.xAxisPoints,f=e.eachSpacing;var r=[];c.save();let a=0;let o=s.width+f;if(s._scrollDistance_&&s._scrollDistance_!==0&&s.enableScroll===true){c.translate(s._scrollDistance_,0);a=-s._scrollDistance_-f*2+s.area[3];o=a+(s.xAxis.itemCount+4)*f}t.forEach(function(t,e){let a,i,r;a=[].concat(s.chartData.yAxisData.ranges[t.index]);i=a.pop();r=a.shift();var o=t.data;var n=getDataPoints(o,i,r,x,f,s,h,d);c.beginPath();c.setStrokeStyle(t.color);c.setFillStyle(t.color);c.setLineWidth(1*s.pix);var l=t.pointShape;if(l==="diamond"){n.forEach(function(t,e){if(t!==null){c.moveTo(t.x,t.y-4.5);c.lineTo(t.x-4.5,t.y);c.lineTo(t.x,t.y+4.5);c.lineTo(t.x+4.5,t.y);c.lineTo(t.x,t.y-4.5)}})}else if(l==="circle"){n.forEach(function(t,e){if(t!==null){c.moveTo(t.x+2.5*s.pix,t.y);c.arc(t.x,t.y,3*s.pix,0,2*Math.PI,false)}})}else if(l==="square"){n.forEach(function(t,e){if(t!==null){c.moveTo(t.x-3.5,t.y-3.5);c.rect(t.x-3.5,t.y-3.5,7,7)}})}else if(l==="triangle"){n.forEach(function(t,e){if(t!==null){c.moveTo(t.x,t.y-4.5);c.lineTo(t.x-4.5,t.y+4.5);c.lineTo(t.x+4.5,t.y+4.5);c.lineTo(t.x,t.y-4.5)}})}else if(l==="triangle"){return}c.closePath();c.fill();c.stroke()});if(s.dataLabel!==false&&d===1){t.forEach(function(t,e){let a,i,r;a=[].concat(s.chartData.yAxisData.ranges[t.index]);i=a.pop();r=a.shift();var o=t.data;var n=getDataPoints(o,i,r,x,f,s,h,d);drawPointText(n,t,h,c,s)})}c.restore();return{xAxisPoints:x,calPoints:r,eachSpacing:f}}function drawBubbleDataPoints(a,l,s,h){var c=arguments.length>4&&arguments[4]!==undefined?arguments[4]:1;var d=assign({},{opacity:1,border:2},l.extra.bubble);let t=l.chartData.xAxisData,x=t.xAxisPoints,f=t.eachSpacing;var i=[];h.save();let e=0;let r=l.width+f;if(l._scrollDistance_&&l._scrollDistance_!==0&&l.enableScroll===true){h.translate(l._scrollDistance_,0);e=-l._scrollDistance_-f*2+l.area[3];r=e+(l.xAxis.itemCount+4)*f}a.forEach(function(i,t){let e,a,r;e=[].concat(l.chartData.yAxisData.ranges[i.index]);a=e.pop();r=e.shift();var o=i.data;var n=getDataPoints(o,a,r,x,f,l,s,c);h.beginPath();h.setStrokeStyle(i.color);h.setLineWidth(d.border*l.pix);h.setFillStyle(hexToRgb(i.color,d.opacity));n.forEach(function(t,e){h.moveTo(t.x+t.r,t.y);h.arc(t.x,t.y,t.r*l.pix,0,2*Math.PI,false)});h.closePath();h.fill();h.stroke();if(l.dataLabel!==false&&c===1){n.forEach(function(t,e){h.beginPath();var a=i.textSize*l.pix||s.fontSize;h.setFontSize(a);h.setFillStyle(i.textColor||"#FFFFFF");h.setTextAlign("center");h.fillText(String(t.t),t.x,t.y+a/2);h.closePath();h.stroke();h.setTextAlign("left")})}});h.restore();return{xAxisPoints:x,calPoints:i,eachSpacing:f}}function drawLineDataPoints(t,d,x,f){var p=arguments.length>4&&arguments[4]!==undefined?arguments[4]:1;var u=assign({},{type:"straight",width:2,activeType:"none",linearType:"none",onShadow:false,animation:"vertical"},d.extra.line);u.width*=d.pix;let e=d.chartData.xAxisData,g=e.xAxisPoints,y=e.eachSpacing;var T=[];f.save();let v=0;let m=d.width+y;if(d._scrollDistance_&&d._scrollDistance_!==0&&d.enableScroll===true){f.translate(d._scrollDistance_,0);v=-d._scrollDistance_-y*2+d.area[3];m=v+(d.xAxis.itemCount+4)*y}t.forEach(function(e,c){f.beginPath();f.setStrokeStyle(e.color);f.moveTo(-1e4,-1e4);f.lineTo(-10001,-10001);f.stroke();let t,a,i;t=[].concat(d.chartData.yAxisData.ranges[e.index]);a=t.pop();i=t.shift();var r=e.data;var o=getLineDataPoints(r,a,i,g,y,d,x,u,p);T.push(o);var n=splitPoints(o,e);if(e.lineType=="dash"){let t=e.dashLength?e.dashLength:8;t*=d.pix;f.setLineDash([t,t])}f.beginPath();var l=e.color;if(u.linearType!=="none"&&e.linearColor&&e.linearColor.length>0){var s=f.createLinearGradient(d.chartData.xAxisData.startX,d.height/2,d.chartData.xAxisData.endX,d.height/2);for(var h=0;h0){f.setShadow(e.setShadow[0],e.setShadow[1],e.setShadow[2],e.setShadow[3])}else{f.setShadow(0,0,0,"rgba(0,0,0,0)")}f.setLineWidth(u.width);n.forEach(function(i,t){if(i.length===1){f.moveTo(i[0].x,i[0].y)}else{f.moveTo(i[0].x,i[0].y);let a=0;if(u.type==="curve"){for(let e=0;ev){f.moveTo(t.x,t.y);a=1}if(e>0&&t.x>v&&t.xv){f.moveTo(t.x,t.y);a=1}if(e>0&&t.x>v&&t.xv){f.moveTo(t.x,t.y);a=1}if(e>0&&t.x>v&&t.x4&&arguments[4]!==undefined?arguments[4]:1;let e=v.chartData.xAxisData,b=e.xAxisPoints,S=e.eachSpacing;let w=assign({},{width:S/2,barBorderCircle:false,barBorderRadius:[],seriesGap:2,linearType:"none",linearOpacity:1,customColor:[],colorStop:0},v.extra.mix.column);let A=assign({},{opacity:.2,gradient:false},v.extra.mix.area);let M=assign({},{width:2},v.extra.mix.line);let L=v.height-v.area[2];let F=[];var _=0;var k=0;t.forEach(function(t,e){if(t.type=="column"){k+=1}});T.save();let R=-2;let I=b.length+2;let P=0;let C=v.width+S;if(v._scrollDistance_&&v._scrollDistance_!==0&&v.enableScroll===true){T.translate(v._scrollDistance_,0);R=Math.floor(-v._scrollDistance_/S)-2;I=R+v.xAxis.itemCount+4;P=-v._scrollDistance_-S*2+v.area[3];C=P+(v.xAxis.itemCount+4)*S}w.customColor=fillCustomColor(w.linearType,w.customColor,t,m);t.forEach(function(n,t){let o,x,f;o=[].concat(v.chartData.yAxisData.ranges[n.index]);x=o.pop();f=o.shift();var p=n.data;var a=getDataPoints(p,x,f,b,S,v,m,D);F.push(a);if(n.type=="column"){a=fixColumeData(a,S,k,_,m,v);for(let t=0;tR&&tr?r:t;e=e>r?r:e;a=a>r?r:a;i=i>r?r:i;t=t<0?0:t;e=e<0?0:e;a=a<0?0:a;i=i<0?0:i;T.arc(h+t,c+t,t,-Math.PI,-Math.PI/2);T.arc(h+d-e,c+e,e,-Math.PI/2,0);T.arc(h+d-a,c+s-a,a,0,Math.PI/2);T.arc(h+i,c+s-i,i,Math.PI/2,Math.PI)}else{T.moveTo(l,o.y);T.lineTo(l+o.width,o.y);T.lineTo(l+o.width,v.height-v.area[2]);T.lineTo(l,v.height-v.area[2]);T.lineTo(l,o.y);T.setLineWidth(1);T.setStrokeStyle(u)}T.setFillStyle(e);T.closePath();T.fill()}}_+=1}if(n.type=="area"){let e=splitPoints(a,n);for(let t=0;t1){var r=i[0];let t=i[i.length-1];T.moveTo(r.x,r.y);let a=0;if(n.style==="curve"){for(let e=0;eP){T.moveTo(t.x,t.y);a=1}if(e>0&&t.x>P&&t.xP){T.moveTo(t.x,t.y);a=1}if(e>0&&t.x>P&&t.xP){T.moveTo(t.x,t.y);a=1}if(e>0&&t.x>P&&t.xP){T.moveTo(t.x,t.y);a=1}if(e>0&&t.x>P&&t.x1){if(h.extra.mount.widthRatio>2)h.extra.mount.widthRatio=2;l+=(h.extra.mount.widthRatio-1)*f}var s=n*n/l;var y=0;if(h._scrollDistance_){y=-h._scrollDistance_*n/l}d.beginPath();d.setLineCap("round");d.setLineWidth(6*h.pix);d.setStrokeStyle(h.xAxis.scrollBackgroundColor||"#EFEBEF");d.moveTo(t,o);d.lineTo(a,o);d.stroke();d.closePath();d.beginPath();d.setLineCap("round");d.setLineWidth(6*h.pix);d.setStrokeStyle(h.xAxis.scrollColor||"#A6A6A6");d.moveTo(t+y,o);d.lineTo(t+y+s,o);d.stroke();d.closePath();d.setLineCap("butt")}d.save();if(h._scrollDistance_&&h._scrollDistance_!==0){d.translate(h._scrollDistance_,0)}if(h.xAxis.calibration===true){d.setStrokeStyle(h.xAxis.gridColor||"#cccccc");d.setLineCap("butt");d.setLineWidth(1*h.pix);x.forEach(function(t,e){if(e>0){d.beginPath();d.moveTo(t-f/2,u);d.lineTo(t-f/2,u+3*h.pix);d.closePath();d.stroke()}})}if(h.xAxis.disableGrid!==true){d.setStrokeStyle(h.xAxis.gridColor||"#cccccc");d.setLineCap("butt");d.setLineWidth(1*h.pix);if(h.xAxis.gridType=="dash"){d.setLineDash([h.xAxis.dashLength*h.pix,h.xAxis.dashLength*h.pix])}h.xAxis.gridEval=h.xAxis.gridEval||1;x.forEach(function(t,e){if(e%h.xAxis.gridEval==0){d.beginPath();d.moveTo(t,u);d.lineTo(t,i);d.stroke()}});d.setLineDash([])}if(h.xAxis.disabled!==true){let t=r.length;if(h.xAxis.labelCount){if(h.xAxis.itemCount){t=Math.ceil(r.length/h.xAxis.itemCount*h.xAxis.labelCount)}else{t=h.xAxis.labelCount}t-=1}let e=Math.ceil(r.length/t);let a=[];let i=r.length;for(let t=0;t=h.area[3]-1&&n-Math.abs(o)<=h.width-h.area[1]+1){d.beginPath();d.setFontSize(g);d.setFillStyle(h.xAxis.fontColor||h.fontColor);d.fillText(String(a),x[e]+i,u+h.xAxis.marginTop*h.pix+(h.xAxis.lineHeight-h.xAxis.fontSize)*h.pix/2+h.xAxis.fontSize*h.pix);d.closePath();d.stroke()}})}else{a.forEach(function(t,e){var a=h.xAxis.formatter?h.xAxis.formatter(t):t;var i=h._scrollDistance_||0;var r=p=="center"?x[e]+f/2:x[e];if(r-Math.abs(i)>=h.area[3]-1&&r-Math.abs(i)<=h.width-h.area[1]+1){d.save();d.beginPath();d.setFontSize(g);d.setFillStyle(h.xAxis.fontColor||h.fontColor);var o=measureText(String(a),g,d);var n=x[e];if(p=="center"){n=x[e]+f/2}var l=0;if(h.xAxis.scrollShow){l=6*h.pix}var s=u+h.xAxis.marginTop*h.pix+g-g*Math.abs(Math.sin(c._xAxisTextAngle_));if(h.xAxis.rotateAngle<0){n-=g/2;o=0}else{n+=g/2;o=-o}d.translate(n,s);d.rotate(-1*c._xAxisTextAngle_);d.fillText(String(a),o,0);d.closePath();d.stroke();d.restore()}})}}d.restore();if(h.xAxis.title){d.beginPath();d.setFontSize(h.xAxis.titleFontSize*h.pix);d.setFillStyle(h.xAxis.titleFontColor);d.fillText(String(h.xAxis.title),h.width-h.area[1]+h.xAxis.titleOffsetX*h.pix,h.height-h.area[2]+h.xAxis.marginTop*h.pix+(h.xAxis.lineHeight-h.xAxis.titleFontSize)*h.pix/2+(h.xAxis.titleFontSize+h.xAxis.titleOffsetY)*h.pix);d.closePath();d.stroke()}if(h.xAxis.axisLine){d.beginPath();d.setStrokeStyle(h.xAxis.axisLineColor);d.setLineWidth(1*h.pix);d.moveTo(t,h.height-h.area[2]);d.lineTo(a,h.height-h.area[2]);d.stroke()}}function drawYAxisGrid(c,e,d,a){if(e.yAxis.disableGrid===true){return}let t=e.height-e.area[0]-e.area[2];let i=t/e.yAxis.splitNumber;let r=e.area[3];let o=e.chartData.xAxisData.xAxisPoints,n=e.chartData.xAxisData.eachSpacing;let l=n*(o.length-1);if(e.type=="mount"&&e.extra&&e.extra.mount&&e.extra.mount.widthRatio&&e.extra.mount.widthRatio>1){if(e.extra.mount.widthRatio>2)e.extra.mount.widthRatio=2;l+=(e.extra.mount.widthRatio-1)*n}let x=r+l;let s=[];let h=1;if(e.xAxis.axisLine===false){h=0}for(let t=h;t4&&arguments[4]!==undefined?arguments[4]:1;var n=assign({},{activeOpacity:.5,activeRadius:10,offsetAngle:0,labelWidth:15,ringWidth:30,customRadius:0,border:false,borderWidth:2,borderColor:"#FFFFFF",centerColor:"#FFFFFF",linearType:"none",customColor:[]},r.type=="pie"?r.extra.pie:r.extra.ring);var l={x:r.area[3]+(r.width-r.area[1]-r.area[3])/2,y:r.area[0]+(r.height-r.area[0]-r.area[2])/2};if(e.pieChartLinePadding==0){e.pieChartLinePadding=n.activeRadius*r.pix}var i=Math.min((r.width-r.area[1]-r.area[3])/2-e.pieChartLinePadding-e.pieChartTextPadding-e._pieTextMaxLength_,(r.height-r.area[0]-r.area[2])/2-e.pieChartLinePadding-e.pieChartTextPadding);i=i<10?10:i;if(n.customRadius>0){i=n.customRadius*r.pix}t=getPieDataPoints(t,i,a);var h=n.activeRadius*r.pix;n.customColor=fillCustomColor(n.linearType,n.customColor,t,e);t=t.map(function(t){t._start_+=n.offsetAngle*Math.PI/180;return t});t.forEach(function(t,e){if(r.tooltip){if(r.tooltip.index==e){o.beginPath();o.setFillStyle(hexToRgb(t.color,n.activeOpacity||.5));o.moveTo(l.x,l.y);o.arc(l.x,l.y,t._radius_+h,t._start_,t._start_+2*t._proportion_*Math.PI);o.closePath();o.fill()}}o.beginPath();o.setLineWidth(n.borderWidth*r.pix);o.lineJoin="round";o.setStrokeStyle(n.borderColor);var a=t.color;if(n.linearType=="custom"){var i;if(o.createCircularGradient){i=o.createCircularGradient(l.x,l.y,t._radius_)}else{i=o.createRadialGradient(l.x,l.y,0,l.x,l.y,t._radius_)}i.addColorStop(0,hexToRgb(n.customColor[t.linearIndex],1));i.addColorStop(1,hexToRgb(t.color,1));a=i}o.setFillStyle(a);o.moveTo(l.x,l.y);o.arc(l.x,l.y,t._radius_,t._start_,t._start_+2*t._proportion_*Math.PI);o.closePath();o.fill();if(n.border==true){o.stroke()}});if(r.type==="ring"){var s=i*.6;if(typeof n.ringWidth==="number"&&n.ringWidth>0){s=Math.max(0,i-n.ringWidth*r.pix)}o.beginPath();o.setFillStyle(n.centerColor);o.moveTo(l.x,l.y);o.arc(l.x,l.y,s,0,2*Math.PI);o.closePath();o.fill()}if(r.dataLabel!==false&&a===1){drawPieText(t,r,e,o,i,l)}if(a===1&&r.type==="ring"){drawRingTitle(r,e,o,l)}return{center:l,radius:i,series:t}}function drawRoseDataPoints(t,r,e,o){var a=arguments.length>4&&arguments[4]!==undefined?arguments[4]:1;var n=assign({},{type:"area",activeOpacity:.5,activeRadius:10,offsetAngle:0,labelWidth:15,border:false,borderWidth:2,borderColor:"#FFFFFF",linearType:"none",customColor:[]},r.extra.rose);if(e.pieChartLinePadding==0){e.pieChartLinePadding=n.activeRadius*r.pix}var l={x:r.area[3]+(r.width-r.area[1]-r.area[3])/2,y:r.area[0]+(r.height-r.area[0]-r.area[2])/2};var i=Math.min((r.width-r.area[1]-r.area[3])/2-e.pieChartLinePadding-e.pieChartTextPadding-e._pieTextMaxLength_,(r.height-r.area[0]-r.area[2])/2-e.pieChartLinePadding-e.pieChartTextPadding);i=i<10?10:i;var s=n.minRadius||i*.5;if(i4&&arguments[4]!==undefined?arguments[4]:1;var o=assign({},{startAngle:.75,endAngle:.25,type:"default",direction:"cw",lineCap:"round",width:12,gap:2,linearType:"none",customColor:[]},i.extra.arcbar);a=getArcbarDataPoints(a,o,e);var n;if(o.centerX||o.centerY){n={x:o.centerX?o.centerX:i.width/2,y:o.centerY?o.centerY:i.height/2}}else{n={x:i.width/2,y:i.height/2}}var l;if(o.radius){l=o.radius}else{l=Math.min(n.x,n.y);l-=5*i.pix;l-=o.width/2}l=l<10?10:l;o.customColor=fillCustomColor(o.linearType,o.customColor,a,t);for(let e=0;e5&&arguments[5]!==undefined?arguments[5]:1;var f=assign({},{type:"default",startAngle:.75,endAngle:.25,width:15,labelOffset:13,splitLine:{fixRadius:0,splitNumber:10,width:15,color:"#FFFFFF",childNumber:5,childWidth:5},pointer:{width:15,color:"auto"}},c.extra.gauge);if(f.oldAngle==undefined){f.oldAngle=f.startAngle}if(f.oldData==undefined){f.oldData=0}n=getGaugeAxisPoints(n,f.startAngle,f.endAngle);var p={x:c.width/2,y:c.height/2};var u=Math.min(p.x,p.y);u-=5*c.pix;u-=f.width/2;u=u<10?10:u;var g=u-f.width;var y=0;if(f.type=="progress"){var v=u-f.width*3;d.beginPath();let t=d.createLinearGradient(p.x,p.y-v,p.x,p.y+v);t.addColorStop("0",hexToRgb(h[0].color,.3));t.addColorStop("1.0",hexToRgb("#FFFFFF",.1));d.setFillStyle(t);d.arc(p.x,p.y,v,0,2*Math.PI,false);d.fill();d.setLineWidth(f.width);d.setStrokeStyle(hexToRgb(h[0].color,.3));d.setLineCap("round");d.beginPath();d.arc(p.x,p.y,g,f.startAngle*Math.PI,f.endAngle*Math.PI,false);d.stroke();if(f.endAnglet/o){d.setStrokeStyle(hexToRgb(h[0].color,1))}else{d.setStrokeStyle(hexToRgb(h[0].color,.3))}d.setLineWidth(3*c.pix);d.moveTo(i,0);d.lineTo(r,0);d.stroke();d.rotate(a*Math.PI)}d.restore();h=getGaugeArcbarDataPoints(h,f,x);d.setLineWidth(f.width);d.setStrokeStyle(h[0].color);d.setLineCap("round");d.beginPath();d.arc(p.x,p.y,g,f.startAngle*Math.PI,h[0]._proportion_*Math.PI,false);d.stroke();let l=u-f.width*2.5;d.save();d.translate(p.x,p.y);d.rotate((h[0]._proportion_-1)*Math.PI);d.beginPath();d.setLineWidth(f.width/3);let s=d.createLinearGradient(0,-l*.6,0,l*.6);s.addColorStop("0",hexToRgb("#FFFFFF",0));s.addColorStop("0.5",hexToRgb(h[0].color,1));s.addColorStop("1.0",hexToRgb("#FFFFFF",0));d.setStrokeStyle(s);d.arc(0,0,l,.85*Math.PI,1.15*Math.PI,false);d.stroke();d.beginPath();d.setLineWidth(1);d.setStrokeStyle(h[0].color);d.setFillStyle(h[0].color);d.moveTo(-l-f.width/3/2,-4);d.lineTo(-l-f.width/3/2-4,0);d.lineTo(-l-f.width/3/2,4);d.lineTo(-l-f.width/3/2,-4);d.stroke();d.fill();d.restore()}else{d.setLineWidth(f.width);d.setLineCap("butt");for(let e=0;e4&&arguments[4]!==undefined?arguments[4]:1;var s=assign({},{gridColor:"#cccccc",gridType:"radar",gridEval:1,axisLabel:false,axisLabelTofix:0,labelShow:true,labelColor:"#666666",labelPointShow:false,labelPointRadius:3,labelPointColor:"#cccccc",opacity:.2,gridCount:3,border:false,borderWidth:2,linearType:"none",customColor:[]},n.extra.radar);var a=getRadarCoordinateSeries(n.categories.length);var h={x:n.area[3]+(n.width-n.area[1]-n.area[3])/2,y:n.area[0]+(n.height-n.area[0]-n.area[2])/2};var r=(n.width-n.area[1]-n.area[3])/2;var d=(n.height-n.area[0]-n.area[2])/2;var c=Math.min(r-(getMaxTextListLength(n.categories,i.fontSize,l)+i.radarLabelTextMargin),d-i.radarLabelTextMargin);c-=i.radarLabelTextMargin*n.pix;c=c<10?10:c;c=s.radius?s.radius:c;l.beginPath();l.setLineWidth(1*n.pix);l.setStrokeStyle(s.gridColor);a.forEach(function(t,e){var a=convertCoordinateOrigin(c*Math.cos(t),c*Math.sin(t),h);l.moveTo(h.x,h.y);if(e%s.gridEval==0){l.lineTo(a.x,a.y)}});l.stroke();l.closePath();var x=function t(i){var r={};l.beginPath();l.setLineWidth(1*n.pix);l.setStrokeStyle(s.gridColor);if(s.gridType=="radar"){a.forEach(function(t,e){var a=convertCoordinateOrigin(c/s.gridCount*i*Math.cos(t),c/s.gridCount*i*Math.sin(t),h);if(e===0){r=a;l.moveTo(a.x,a.y)}else{l.lineTo(a.x,a.y)}});l.lineTo(r.x,r.y)}else{var e=convertCoordinateOrigin(c/s.gridCount*i*Math.cos(1.5),c/s.gridCount*i*Math.sin(1.5),h);l.arc(h.x,h.y,h.y-e.y,0,2*Math.PI,false)}l.stroke();l.closePath()};for(var e=1;e<=s.gridCount;e++){x(e)}s.customColor=fillCustomColor(s.linearType,s.customColor,o,i);var f=getRadarDataPoints(a,h,c,o,n,t);f.forEach(function(t,e){l.beginPath();l.setLineWidth(s.borderWidth*n.pix);l.setStrokeStyle(t.color);var a=hexToRgb(t.color,s.opacity);if(s.linearType=="custom"){var i;if(l.createCircularGradient){i=l.createCircularGradient(h.x,h.y,c)}else{i=l.createRadialGradient(h.x,h.y,0,h.x,h.y,c)}i.addColorStop(0,hexToRgb(s.customColor[o[e].linearIndex],s.opacity));i.addColorStop(1,hexToRgb(t.color,s.opacity));a=i}l.setFillStyle(a);t.data.forEach(function(t,e){if(e===0){l.moveTo(t.position.x,t.position.y)}else{l.lineTo(t.position.x,t.position.y)}});l.closePath();l.fill();if(s.border===true){l.stroke()}l.closePath();if(n.dataPointShape!==false){var r=t.data.map(function(t){return t.position});drawPointShape(r,t.color,t.pointShape,l,n)}});if(s.axisLabel===true){const p=Math.max(s.max,Math.max.apply(null,dataCombine(o)));const u=c/s.gridCount;const g=n.fontSize*n.pix;l.setFontSize(g);l.setFillStyle(n.fontColor);l.setTextAlign("left");for(var e=0;eh.x?e.xMax:h.x;e.yMin=e.yMinh.y?e.yMax:h.y}}}return e}function coordinateToPoint(t,e,a,i,r,o){return{x:(e-a.xMin)*i+r,y:(a.yMax-t)*i+o}}function pointToCoordinate(t,e,a,i,r,o){return{x:(e-r)/i+a.xMin,y:a.yMax-(t-o)/i}}function isRayIntersectsSegment(t,e,a){if(e[1]==a[1]){return false}if(e[1]>t[1]&&a[1]>t[1]){return false}if(e[1]t[1]){return false}if(a[1]==t[1]&&e[1]>t[1]){return false}if(e[0]a[t].area[2]||e[1]>a[t].area[3]||e[2]i||e[3]>r){o=true;break}else{o=false}}else{o=true;break}}}return o}function getWordCloudPoint(c,t,d){let x=c.series;switch(t){case"normal":for(let l=0;l.7){return true}else{return false}};for(let h=0;h4&&arguments[4]!==undefined?arguments[4]:1;let a=assign({},{type:"normal",autoColors:true},r.extra.word);if(!r.chartData.wordCloudData){r.chartData.wordCloudData=getWordCloudPoint(r,a.type,o)}o.beginPath();o.setFillStyle(r.background);o.rect(0,0,r.width,r.height);o.fill();o.save();let l=r.chartData.wordCloudData;o.translate(r.width/2,r.height/2);for(let i=0;i0){if(r.tooltip){if(r.tooltip.index==i){o.strokeText(t,(l[i].areav[0]+5-r.width/2)*n-a*(1-n)/2,(l[i].areav[1]+5+e-r.height/2)*n)}else{o.fillText(t,(l[i].areav[0]+5-r.width/2)*n-a*(1-n)/2,(l[i].areav[1]+5+e-r.height/2)*n)}}else{o.fillText(t,(l[i].areav[0]+5-r.width/2)*n-a*(1-n)/2,(l[i].areav[1]+5+e-r.height/2)*n)}}}else{if(l[i].area[0]>0){if(r.tooltip){if(r.tooltip.index==i){o.strokeText(t,(l[i].area[0]+5-r.width/2)*n-a*(1-n)/2,(l[i].area[1]+5+e-r.height/2)*n)}else{o.fillText(t,(l[i].area[0]+5-r.width/2)*n-a*(1-n)/2,(l[i].area[1]+5+e-r.height/2)*n)}}else{o.fillText(t,(l[i].area[0]+5-r.width/2)*n-a*(1-n)/2,(l[i].area[1]+5+e-r.height/2)*n)}}}o.stroke();o.restore()}o.restore()}function drawFunnelDataPoints(t,e,c,a){let d=arguments.length>4&&arguments[4]!==undefined?arguments[4]:1;let i=assign({},{type:"funnel",activeWidth:10,activeOpacity:.3,border:false,borderWidth:2,borderColor:"#FFFFFF",fillOpacity:1,minSize:0,labelAlign:"right",linearType:"none",customColor:[]},e.extra.funnel);let r=(e.height-e.area[0]-e.area[2])/t.length;let o={x:e.area[3]+(e.width-e.area[1]-e.area[3])/2,y:e.height-e.area[2]};let n=i.activeWidth*e.pix;let x=Math.min((e.width-e.area[1]-e.area[3])/2-n,(e.height-e.area[0]-e.area[2])/2-n);let l=getFunnelDataPoints(t,x,i,r,d);a.save();a.translate(o.x,o.y);i.customColor=fillCustomColor(i.linearType,i.customColor,t,c);if(i.type=="pyramid"){for(let t=0;t0){l.area[3]+=i[t].width+l.yAxis.padding*l.pix}else{l.area[3]+=i[t].width}a+=1}else if(i[t].position=="right"){if(e>0){l.area[1]+=i[t].width+l.yAxis.padding*l.pix}else{l.area[1]+=i[t].width}e+=1}}}else{n.yAxisWidth=i}l.chartData.yAxisData=f;if(l.categories&&l.categories.length&&l.type!=="radar"&&l.type!=="gauge"&&l.type!=="bar"){l.chartData.xAxisData=getXAxisPoints(l.categories,l,n);let t=calCategoriesData(l.categories,l,n,l.chartData.xAxisData.eachSpacing,s),e=t.xAxisHeight,a=t.angle;n.xAxisHeight=e;n._xAxisTextAngle_=a;l.area[2]+=e;l.chartData.categoriesData=t}else{if(l.type==="line"||l.type==="area"||l.type==="scatter"||l.type==="bubble"||l.type==="bar"){l.chartData.xAxisData=calXAxisData(c,l,n,s);d=l.chartData.xAxisData.rangesFormat;let t=calCategoriesData(d,l,n,l.chartData.xAxisData.eachSpacing,s),e=t.xAxisHeight,a=t.angle;n.xAxisHeight=e;n._xAxisTextAngle_=a;l.area[2]+=e;l.chartData.categoriesData=t}else{l.chartData.xAxisData={xAxisPoints:[]}}}if(l.enableScroll&&l.xAxis.scrollAlign=="right"&&l._scrollDistance_===undefined){let t=0,e=l.chartData.xAxisData.xAxisPoints,a=l.chartData.xAxisData.startX,i=l.chartData.xAxisData.endX,r=l.chartData.xAxisData.eachSpacing;let o=r*(e.length-1);let n=i-a;t=n-o;h.scrollOption.currentOffset=t;h.scrollOption.startTouchX=t;h.scrollOption.distance=0;h.scrollOption.lastMoveTime=0;l._scrollDistance_=t}if(t==="pie"||t==="ring"||t==="rose"){n._pieTextMaxLength_=l.dataLabel===false?0:getPieTextMaxLength(x,n,s,l)}switch(t){case"word":this.animationInstance=new Animation({timing:l.timing,duration:e,onProcess:function(t){s.clearRect(0,0,l.width,l.height);if(l.rotate){contextRotate(s,l)}drawWordCloudDataPoints(c,l,n,s,t);drawCanvas(l,s)},onAnimationFinish:function t(){h.uevent.trigger("renderComplete")}});break;case"map":s.clearRect(0,0,l.width,l.height);drawMapDataPoints(c,l,n,s);setTimeout(()=>{this.uevent.trigger("renderComplete")},50);break;case"funnel":this.animationInstance=new Animation({timing:l.timing,duration:e,onProcess:function(t){s.clearRect(0,0,l.width,l.height);if(l.rotate){contextRotate(s,l)}l.chartData.funnelData=drawFunnelDataPoints(c,l,n,s,t);drawLegend(l.series,l,n,s,l.chartData);drawToolTipBridge(l,n,s,t);drawCanvas(l,s)},onAnimationFinish:function t(){h.uevent.trigger("renderComplete")}});break;case"line":this.animationInstance=new Animation({timing:l.timing,duration:e,onProcess:function t(e){s.clearRect(0,0,l.width,l.height);if(l.rotate){contextRotate(s,l)}drawYAxisGrid(d,l,n,s);drawXAxis(d,l,n,s);var a=drawLineDataPoints(c,l,n,s,e),i=a.xAxisPoints,r=a.calPoints,o=a.eachSpacing;l.chartData.xAxisPoints=i;l.chartData.calPoints=r;l.chartData.eachSpacing=o;drawYAxis(c,l,n,s);if(l.enableMarkLine!==false&&e===1){drawMarkLine(l,n,s)}drawLegend(l.series,l,n,s,l.chartData);drawToolTipBridge(l,n,s,e,o,i);drawCanvas(l,s)},onAnimationFinish:function t(){h.uevent.trigger("renderComplete")}});break;case"scatter":this.animationInstance=new Animation({timing:l.timing,duration:e,onProcess:function t(e){s.clearRect(0,0,l.width,l.height);if(l.rotate){contextRotate(s,l)}drawYAxisGrid(d,l,n,s);drawXAxis(d,l,n,s);var a=drawScatterDataPoints(c,l,n,s,e),i=a.xAxisPoints,r=a.calPoints,o=a.eachSpacing;l.chartData.xAxisPoints=i;l.chartData.calPoints=r;l.chartData.eachSpacing=o;drawYAxis(c,l,n,s);if(l.enableMarkLine!==false&&e===1){drawMarkLine(l,n,s)}drawLegend(l.series,l,n,s,l.chartData);drawToolTipBridge(l,n,s,e,o,i);drawCanvas(l,s)},onAnimationFinish:function t(){h.uevent.trigger("renderComplete")}});break;case"bubble":this.animationInstance=new Animation({timing:l.timing,duration:e,onProcess:function t(e){s.clearRect(0,0,l.width,l.height);if(l.rotate){contextRotate(s,l)}drawYAxisGrid(d,l,n,s);drawXAxis(d,l,n,s);var a=drawBubbleDataPoints(c,l,n,s,e),i=a.xAxisPoints,r=a.calPoints,o=a.eachSpacing;l.chartData.xAxisPoints=i;l.chartData.calPoints=r;l.chartData.eachSpacing=o;drawYAxis(c,l,n,s);if(l.enableMarkLine!==false&&e===1){drawMarkLine(l,n,s)}drawLegend(l.series,l,n,s,l.chartData);drawToolTipBridge(l,n,s,e,o,i);drawCanvas(l,s)},onAnimationFinish:function t(){h.uevent.trigger("renderComplete")}});break;case"mix":this.animationInstance=new Animation({timing:l.timing,duration:e,onProcess:function t(e){s.clearRect(0,0,l.width,l.height);if(l.rotate){contextRotate(s,l)}drawYAxisGrid(d,l,n,s);drawXAxis(d,l,n,s);var a=drawMixDataPoints(c,l,n,s,e),i=a.xAxisPoints,r=a.calPoints,o=a.eachSpacing;l.chartData.xAxisPoints=i;l.chartData.calPoints=r;l.chartData.eachSpacing=o;drawYAxis(c,l,n,s);if(l.enableMarkLine!==false&&e===1){drawMarkLine(l,n,s)}drawLegend(l.series,l,n,s,l.chartData);drawToolTipBridge(l,n,s,e,o,i);drawCanvas(l,s)},onAnimationFinish:function t(){h.uevent.trigger("renderComplete")}});break;case"column":this.animationInstance=new Animation({timing:l.timing,duration:e,onProcess:function t(e){s.clearRect(0,0,l.width,l.height);if(l.rotate){contextRotate(s,l)}drawYAxisGrid(d,l,n,s);drawXAxis(d,l,n,s);var a=drawColumnDataPoints(c,l,n,s,e),i=a.xAxisPoints,r=a.calPoints,o=a.eachSpacing;l.chartData.xAxisPoints=i;l.chartData.calPoints=r;l.chartData.eachSpacing=o;drawYAxis(c,l,n,s);if(l.enableMarkLine!==false&&e===1){drawMarkLine(l,n,s)}drawLegend(l.series,l,n,s,l.chartData);drawToolTipBridge(l,n,s,e,o,i);drawCanvas(l,s)},onAnimationFinish:function t(){h.uevent.trigger("renderComplete")}});break;case"mount":this.animationInstance=new Animation({timing:l.timing,duration:e,onProcess:function t(e){s.clearRect(0,0,l.width,l.height);if(l.rotate){contextRotate(s,l)}drawYAxisGrid(d,l,n,s);drawXAxis(d,l,n,s);var a=drawMountDataPoints(c,l,n,s,e),i=a.xAxisPoints,r=a.calPoints,o=a.eachSpacing;l.chartData.xAxisPoints=i;l.chartData.calPoints=r;l.chartData.eachSpacing=o;drawYAxis(c,l,n,s);if(l.enableMarkLine!==false&&e===1){drawMarkLine(l,n,s)}drawLegend(l.series,l,n,s,l.chartData);drawToolTipBridge(l,n,s,e,o,i);drawCanvas(l,s)},onAnimationFinish:function t(){h.uevent.trigger("renderComplete")}});break;case"bar":this.animationInstance=new Animation({timing:l.timing,duration:e,onProcess:function t(e){s.clearRect(0,0,l.width,l.height);if(l.rotate){contextRotate(s,l)}drawXAxis(d,l,n,s);var a=drawBarDataPoints(c,l,n,s,e),i=a.yAxisPoints,r=a.calPoints,o=a.eachSpacing;l.chartData.yAxisPoints=i;l.chartData.xAxisPoints=l.chartData.xAxisData.xAxisPoints;l.chartData.calPoints=r;l.chartData.eachSpacing=o;drawYAxis(c,l,n,s);if(l.enableMarkLine!==false&&e===1){drawMarkLine(l,n,s)}drawLegend(l.series,l,n,s,l.chartData);drawToolTipBridge(l,n,s,e,o,i);drawCanvas(l,s)},onAnimationFinish:function t(){h.uevent.trigger("renderComplete")}});break;case"area":this.animationInstance=new Animation({timing:l.timing,duration:e,onProcess:function t(e){s.clearRect(0,0,l.width,l.height);if(l.rotate){contextRotate(s,l)}drawYAxisGrid(d,l,n,s);drawXAxis(d,l,n,s);var a=drawAreaDataPoints(c,l,n,s,e),i=a.xAxisPoints,r=a.calPoints,o=a.eachSpacing;l.chartData.xAxisPoints=i;l.chartData.calPoints=r;l.chartData.eachSpacing=o;drawYAxis(c,l,n,s);if(l.enableMarkLine!==false&&e===1){drawMarkLine(l,n,s)}drawLegend(l.series,l,n,s,l.chartData);drawToolTipBridge(l,n,s,e,o,i);drawCanvas(l,s)},onAnimationFinish:function t(){h.uevent.trigger("renderComplete")}});break;case"ring":this.animationInstance=new Animation({timing:l.timing,duration:e,onProcess:function t(e){s.clearRect(0,0,l.width,l.height);if(l.rotate){contextRotate(s,l)}l.chartData.pieData=drawPieDataPoints(c,l,n,s,e);drawLegend(l.series,l,n,s,l.chartData);drawToolTipBridge(l,n,s,e);drawCanvas(l,s)},onAnimationFinish:function t(){h.uevent.trigger("renderComplete")}});break;case"pie":this.animationInstance=new Animation({timing:l.timing,duration:e,onProcess:function t(e){s.clearRect(0,0,l.width,l.height);if(l.rotate){contextRotate(s,l)}l.chartData.pieData=drawPieDataPoints(c,l,n,s,e);drawLegend(l.series,l,n,s,l.chartData);drawToolTipBridge(l,n,s,e);drawCanvas(l,s)},onAnimationFinish:function t(){h.uevent.trigger("renderComplete")}});break;case"rose":this.animationInstance=new Animation({timing:l.timing,duration:e,onProcess:function t(e){s.clearRect(0,0,l.width,l.height);if(l.rotate){contextRotate(s,l)}l.chartData.pieData=drawRoseDataPoints(c,l,n,s,e);drawLegend(l.series,l,n,s,l.chartData);drawToolTipBridge(l,n,s,e);drawCanvas(l,s)},onAnimationFinish:function t(){h.uevent.trigger("renderComplete")}});break;case"radar":this.animationInstance=new Animation({timing:l.timing,duration:e,onProcess:function t(e){s.clearRect(0,0,l.width,l.height);if(l.rotate){contextRotate(s,l)}l.chartData.radarData=drawRadarDataPoints(c,l,n,s,e);drawLegend(l.series,l,n,s,l.chartData);drawToolTipBridge(l,n,s,e);drawCanvas(l,s)},onAnimationFinish:function t(){h.uevent.trigger("renderComplete")}});break;case"arcbar":this.animationInstance=new Animation({timing:l.timing,duration:e,onProcess:function t(e){s.clearRect(0,0,l.width,l.height);if(l.rotate){contextRotate(s,l)}l.chartData.arcbarData=drawArcbarDataPoints(c,l,n,s,e);drawCanvas(l,s)},onAnimationFinish:function t(){h.uevent.trigger("renderComplete")}});break;case"gauge":this.animationInstance=new Animation({timing:l.timing,duration:e,onProcess:function t(e){s.clearRect(0,0,l.width,l.height);if(l.rotate){contextRotate(s,l)}l.chartData.gaugeData=drawGaugeDataPoints(d,c,l,n,s,e);drawCanvas(l,s)},onAnimationFinish:function t(){h.uevent.trigger("renderComplete")}});break;case"candle":this.animationInstance=new Animation({timing:l.timing,duration:e,onProcess:function t(e){s.clearRect(0,0,l.width,l.height);if(l.rotate){contextRotate(s,l)}drawYAxisGrid(d,l,n,s);drawXAxis(d,l,n,s);var a=drawCandleDataPoints(c,x,l,n,s,e),i=a.xAxisPoints,r=a.calPoints,o=a.eachSpacing;l.chartData.xAxisPoints=i;l.chartData.calPoints=r;l.chartData.eachSpacing=o;drawYAxis(c,l,n,s);if(l.enableMarkLine!==false&&e===1){drawMarkLine(l,n,s)}if(x){drawLegend(x,l,n,s,l.chartData)}else{drawLegend(l.series,l,n,s,l.chartData)}drawToolTipBridge(l,n,s,e,o,i);drawCanvas(l,s)},onAnimationFinish:function t(){h.uevent.trigger("renderComplete")}});break}}function uChartsEvent(){this.events={}}uChartsEvent.prototype.addEventListener=function(t,e){this.events[t]=this.events[t]||[];this.events[t].push(e)};uChartsEvent.prototype.delEventListener=function(t){this.events[t]=[]};uChartsEvent.prototype.trigger=function(){for(var t=arguments.length,e=Array(t),a=0;a0&&arguments[0]!==undefined?arguments[0]:{};this.opts=assign({},this.opts,t);this.opts.updateData=true;let c=t.scrollPosition||"current";switch(c){case"current":this.opts._scrollDistance_=this.scrollOption.currentOffset;break;case"left":this.opts._scrollDistance_=0;this.scrollOption={currentOffset:0,startTouchX:0,distance:0,lastMoveTime:0};break;case"right":let t=calYAxisData(this.opts.series,this.opts,this.config,this.context),e=t.yAxisWidth;this.config.yAxisWidth=e;let a=0;let i=getXAxisPoints(this.opts.categories,this.opts,this.config),r=i.xAxisPoints,o=i.startX,n=i.endX,l=i.eachSpacing;let s=l*(r.length-1);let h=n-o;a=h-s;this.scrollOption={currentOffset:a,startTouchX:a,distance:0,lastMoveTime:0};this.opts._scrollDistance_=a;break}drawCharts.call(this,this.opts.type,this.opts,this.config,this.context)};uCharts.prototype.zoom=function(){var t=arguments.length>0&&arguments[0]!==undefined?arguments[0]:this.opts.xAxis.itemCount;if(this.opts.enableScroll!==true){console.log("[uCharts] 请启用滚动条后使用");return}let e=Math.round(Math.abs(this.scrollOption.currentOffset)/this.opts.chartData.eachSpacing)+Math.round(this.opts.xAxis.itemCount/2);this.opts.animation=false;this.opts.xAxis.itemCount=t.itemCount;let a=calYAxisData(this.opts.series,this.opts,this.config,this.context),i=a.yAxisWidth;this.config.yAxisWidth=i;let r=0;let o=getXAxisPoints(this.opts.categories,this.opts,this.config),h=o.xAxisPoints,c=o.startX,d=o.endX,n=o.eachSpacing;let x=n*e;let l=d-c;let s=l-n*(h.length-1);r=l/2-x;if(r>0){r=0}if(r=this.opts.categories.length?this.opts.categories.length:r;this.opts.animation=false;this.opts.xAxis.itemCount=r;let o=0;let n=getXAxisPoints(this.opts.categories,this.opts,this.config),x=n.xAxisPoints,f=n.startX,p=n.endX,l=n.eachSpacing;let u=l*this.scrollOption.moveCurrent1;let g=p-f;let y=g-l*(x.length-1);o=-u+Math.min(i[0].x,i[1].x)-this.opts.area[3]-l;if(o>0){o=0}if(o1&&arguments[1]!==undefined?arguments[1]:{};var a=null;if(t.changedTouches){a=t.changedTouches[0]}else{a=t.mp.changedTouches[0]}if(a){var i=getTouches(a,this.opts,t);var r=this.getLegendDataIndex(t);if(r>=0){if(this.opts.type=="candle"){this.opts.seriesMA[r].show=!this.opts.seriesMA[r].show}else{this.opts.series[r].show=!this.opts.series[r].show}this.opts.animation=e.animation?true:false;this.opts._scrollDistance_=this.scrollOption.currentOffset;drawCharts.call(this,this.opts.type,this.opts,this.config,this.context)}}};uCharts.prototype.showToolTip=function(t){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var c=null;if(t.changedTouches){c=t.changedTouches[0]}else{c=t.mp.changedTouches[0]}if(!c){console.log("[uCharts] 未获取到event坐标信息")}var a=getTouches(c,this.opts,t);var d=this.scrollOption.currentOffset;var i=assign({},this.opts,{_scrollDistance_:d,animation:false});if(this.opts.type==="line"||this.opts.type==="area"||this.opts.type==="column"||this.opts.type==="scatter"||this.opts.type==="bubble"){var r=this.getCurrentDataIndex(t);var o=e.index==undefined?r.index:e.index;if(o>-1||o.length>0){var n=getSeriesDataItem(this.opts.series,o,r.group);if(n.length!==0){var l=getToolTipData(n,this.opts,o,r.group,this.opts.categories,e),s=l.textList,h=l.offset;h.y=a.y;i.tooltip={textList:e.textList!==undefined?e.textList:s,offset:e.offset!==undefined?e.offset:h,option:e,index:o,group:r.group}}}drawCharts.call(this,i.type,i,this.config,this.context)}if(this.opts.type==="mount"){var o=e.index==undefined?this.getCurrentDataIndex(t).index:e.index;if(o>-1){var i=assign({},this.opts,{animation:false});var n=assign({},i._series_[o]);var s=[{text:e.formatter?e.formatter(n,undefined,o,i):n.name+": "+n.data,color:n.color,legendShape:this.opts.extra.tooltip.legendShape=="auto"?n.legendShape:this.opts.extra.tooltip.legendShape}];var h={x:i.chartData.calPoints[o].x,y:a.y};i.tooltip={textList:e.textList?e.textList:s,offset:e.offset!==undefined?e.offset:h,option:e,index:o}}drawCharts.call(this,i.type,i,this.config,this.context)}if(this.opts.type==="bar"){var r=this.getCurrentDataIndex(t);var o=e.index==undefined?r.index:e.index;if(o>-1||o.length>0){var n=getSeriesDataItem(this.opts.series,o,r.group);if(n.length!==0){var l=getToolTipData(n,this.opts,o,r.group,this.opts.categories,e),s=l.textList,h=l.offset;h.x=a.x;i.tooltip={textList:e.textList!==undefined?e.textList:s,offset:e.offset!==undefined?e.offset:h,option:e,index:o}}}drawCharts.call(this,i.type,i,this.config,this.context)}if(this.opts.type==="mix"){var r=this.getCurrentDataIndex(t);var o=e.index==undefined?r.index:e.index;if(o>-1){var d=this.scrollOption.currentOffset;var i=assign({},this.opts,{_scrollDistance_:d,animation:false});var n=getSeriesDataItem(this.opts.series,o);if(n.length!==0){var x=getMixToolTipData(n,this.opts,o,this.opts.categories,e),s=x.textList,h=x.offset;h.y=a.y;i.tooltip={textList:e.textList?e.textList:s,offset:e.offset!==undefined?e.offset:h,option:e,index:o}}}drawCharts.call(this,i.type,i,this.config,this.context)}if(this.opts.type==="candle"){var r=this.getCurrentDataIndex(t);var o=e.index==undefined?r.index:e.index;if(o>-1){var d=this.scrollOption.currentOffset;var i=assign({},this.opts,{_scrollDistance_:d,animation:false});var n=getSeriesDataItem(this.opts.series,o);if(n.length!==0){var l=getCandleToolTipData(this.opts.series[0].data,n,this.opts,o,this.opts.categories,this.opts.extra.candle,e),s=l.textList,h=l.offset;h.y=a.y;i.tooltip={textList:e.textList?e.textList:s,offset:e.offset!==undefined?e.offset:h,option:e,index:o}}}drawCharts.call(this,i.type,i,this.config,this.context)}if(this.opts.type==="pie"||this.opts.type==="ring"||this.opts.type==="rose"||this.opts.type==="funnel"){var o=e.index==undefined?this.getCurrentDataIndex(t):e.index;if(o>-1){var i=assign({},this.opts,{animation:false});var n=assign({},i._series_[o]);var s=[{text:e.formatter?e.formatter(n,undefined,o,i):n.name+": "+n.data,color:n.color,legendShape:this.opts.extra.tooltip.legendShape=="auto"?n.legendShape:this.opts.extra.tooltip.legendShape}];var h={x:a.x,y:a.y};i.tooltip={textList:e.textList?e.textList:s,offset:e.offset!==undefined?e.offset:h,option:e,index:o}}drawCharts.call(this,i.type,i,this.config,this.context)}if(this.opts.type==="map"){var o=e.index==undefined?this.getCurrentDataIndex(t):e.index;if(o>-1){var i=assign({},this.opts,{animation:false});var n=assign({},this.opts.series[o]);n.name=n.properties.name;var s=[{text:e.formatter?e.formatter(n,undefined,o,this.opts):n.name,color:n.color,legendShape:this.opts.extra.tooltip.legendShape=="auto"?n.legendShape:this.opts.extra.tooltip.legendShape}];var h={x:a.x,y:a.y};i.tooltip={textList:e.textList?e.textList:s,offset:e.offset!==undefined?e.offset:h,option:e,index:o}}i.updateData=false;drawCharts.call(this,i.type,i,this.config,this.context)}if(this.opts.type==="word"){var o=e.index==undefined?this.getCurrentDataIndex(t):e.index;if(o>-1){var i=assign({},this.opts,{animation:false});var n=assign({},this.opts.series[o]);var s=[{text:e.formatter?e.formatter(n,undefined,o,this.opts):n.name,color:n.color,legendShape:this.opts.extra.tooltip.legendShape=="auto"?n.legendShape:this.opts.extra.tooltip.legendShape}];var h={x:a.x,y:a.y};i.tooltip={textList:e.textList?e.textList:s,offset:e.offset!==undefined?e.offset:h,option:e,index:o}}i.updateData=false;drawCharts.call(this,i.type,i,this.config,this.context)}if(this.opts.type==="radar"){var o=e.index==undefined?this.getCurrentDataIndex(t):e.index;if(o>-1){var i=assign({},this.opts,{animation:false});var n=getSeriesDataItem(this.opts.series,o);if(n.length!==0){var s=n.map(t=>{return{text:e.formatter?e.formatter(t,this.opts.categories[o],o,this.opts):t.name+": "+t.data,color:t.color,legendShape:this.opts.extra.tooltip.legendShape=="auto"?t.legendShape:this.opts.extra.tooltip.legendShape}});var h={x:a.x,y:a.y};i.tooltip={textList:e.textList?e.textList:s,offset:e.offset!==undefined?e.offset:h,option:e,index:o}}}drawCharts.call(this,i.type,i,this.config,this.context)}};uCharts.prototype.translate=function(t){this.scrollOption={currentOffset:t,startTouchX:t,distance:0,lastMoveTime:0};let e=assign({},this.opts,{_scrollDistance_:t,animation:false});drawCharts.call(this,this.opts.type,e,this.config,this.context)};uCharts.prototype.scrollStart=function(t){var e=null;if(t.changedTouches){e=t.changedTouches[0]}else{e=t.mp.changedTouches[0]}var a=getTouches(e,this.opts,t);if(e&&this.opts.enableScroll===true){this.scrollOption.startTouchX=a.x}};uCharts.prototype.scroll=function(t){if(this.scrollOption.lastMoveTime===0){this.scrollOption.lastMoveTime=Date.now()}let e=this.opts.touchMoveLimit||60;let a=Date.now();let i=a-this.scrollOption.lastMoveTime;if(i(); - - // 用于保存 STOMP 客户端的实例 - const client = ref(null); - // 防止重复连接的标志 - let isConnecting = false; - let isManualDisconnect = false; - - /** - * 初始化 STOMP 客户端 - */ - const initializeClient = () => { - // 如果客户端已存在且正在连接或已连接,直接返回 - if (client.value && (client.value.active || client.value.connected)) { - console.log("STOMP客户端已存在且处于活动状态,跳过初始化"); - return; - } - - // 检查WebSocket端点是否配置 - if (!brokerURL.value) { - console.error("WebSocket连接失败: 未配置WebSocket端点URL"); - return; - } - - // 每次连接前重新获取最新令牌,不依赖之前的token值 - const currentToken = getAccessToken(); - - // 检查令牌是否为空,如果为空则不进行连接 - if (!currentToken) { - console.error("WebSocket连接失败:授权令牌为空,请先登录"); - return; - } - - // 如果有旧的客户端,先清理 - if (client.value) { - try { - client.value.deactivate(); - } catch (error) { - console.warn("清理旧客户端时出错:", error); - } - client.value = null; - } - - // 创建 STOMP 客户端 - client.value = new Client({ - brokerURL: brokerURL.value, - connectHeaders: { - Authorization: `Bearer ${currentToken}`, - }, - debug: options.debug ? console.log : () => {}, - reconnectDelay: 0, // 禁用内置重连机制,使用自定义重连 - heartbeatIncoming: 4000, - heartbeatOutgoing: 4000, - }); - - // 设置连接监听器 - client.value.onConnect = () => { - isConnected.value = true; - isConnecting = false; - reconnectCount.value = 0; - clearTimeout(connectionTimeoutTimer); - clearTimeout(reconnectTimer); - console.log("WebSocket连接已建立"); - }; - - // 设置断开连接监听器 - client.value.onDisconnect = () => { - isConnected.value = false; - isConnecting = false; - console.log("WebSocket连接已断开"); - - // 如果不是手动断开且未达到最大重连次数,则尝试重连 - if (!isManualDisconnect && reconnectCount.value < maxReconnectAttempts) { - handleReconnect(); - } - }; - - // 设置 Web Socket 关闭监听器 - client.value.onWebSocketClose = (event: CloseEvent) => { - isConnected.value = false; - isConnecting = false; - console.log(`WebSocket已关闭: ${event?.code} ${event?.reason}`); - - // 如果是手动断开,不要重连 - if (isManualDisconnect) { - console.log("手动断开连接,不进行重连"); - return; - } - - // 如果是授权问题导致的关闭,尝试重连 - if ((event?.code === 1000 || event?.code === 1006 || event?.code === 1008) && reconnectCount.value < maxReconnectAttempts) { - console.log("检测到连接异常关闭,将尝试重连"); - - // 通过 handleReconnect 统一处理重连,避免重复计数 - handleReconnect(); - } - }; - - // 设置错误监听器 - client.value.onStompError = (frame: any) => { - console.error("STOMP错误:", frame.headers, frame.body); - isConnecting = false; - - // 检查是否是授权错误 - if (frame.headers?.message?.includes("Unauthorized") || frame.body?.includes("Unauthorized") || frame.body?.includes("Token")) { - console.warn("WebSocket授权错误,请检查登录状态"); - // 授权错误不进行重连 - isManualDisconnect = true; - } - }; - }; - - /** - * 处理重连逻辑 - */ - const handleReconnect = () => { - // 如果已经在连接中或手动断开,不重连 - if (isConnecting || isManualDisconnect) { - return; - } - - if (reconnectCount.value >= maxReconnectAttempts) { - console.error(`已达到最大重连次数(${maxReconnectAttempts}),停止重连`); - return; - } - - reconnectCount.value++; - console.log(`准备重连(${reconnectCount.value}/${maxReconnectAttempts})...`); - - // 使用指数退避策略增加重连间隔 - const delay = useExponentialBackoff ? Math.min(reconnectDelay * Math.pow(2, reconnectCount.value - 1), maxReconnectDelay) : reconnectDelay; - - // 清除之前的计时器 - if (reconnectTimer) { - clearTimeout(reconnectTimer); - } - - // 设置重连计时器 - reconnectTimer = setTimeout(() => { - if (!isConnected.value && !isManualDisconnect && !isConnecting) { - console.log(`开始重连...`); - connect(); - } - }, delay); - }; - - // 监听 brokerURL 的变化,若地址改变则重新初始化 - watch(brokerURL, (newURL, oldURL) => { - if (newURL !== oldURL) { - console.log(`brokerURL changed from ${oldURL} to ${newURL}`); - // 断开当前连接,重新激活客户端 - if (client.value && client.value.connected) { - client.value.deactivate(); - } - brokerURL.value = newURL; - initializeClient(); // 重新初始化客户端 - } - }); - - // 初始化客户端 - initializeClient(); - - /** - * 激活连接(如果已经连接或正在激活则直接返回) - */ - const connect = () => { - // 重置手动断开标志 - isManualDisconnect = false; - - // 检查是否有配置WebSocket端点 - if (!brokerURL.value) { - console.error("WebSocket连接失败: 未配置WebSocket端点URL"); - return; - } - - // 防止重复连接 - if (isConnecting) { - console.log("WebSocket正在连接中,跳过重复连接请求"); - return; - } - - if (!client.value) { - initializeClient(); - } - - if (!client.value) { - console.error("STOMP客户端初始化失败"); - return; - } - - // 避免重复连接:检查是否已连接 - if (client.value.connected) { - console.log("WebSocket已经连接,跳过重复连接"); - isConnected.value = true; - return; - } - - // 设置连接标志 - isConnecting = true; - - // 设置连接超时 - clearTimeout(connectionTimeoutTimer); - connectionTimeoutTimer = setTimeout(() => { - if (!isConnected.value && isConnecting) { - console.warn("WebSocket连接超时"); - isConnecting = false; - if (!isManualDisconnect && reconnectCount.value < maxReconnectAttempts) { - handleReconnect(); - } - } - }, connectionTimeout); - - try { - client.value.activate(); - console.log("正在建立WebSocket连接..."); - } catch (error) { - console.error("激活WebSocket连接失败:", error); - isConnecting = false; - } - }; - - /** - * 订阅指定主题 - * @param destination 目标主题地址 - * @param callback 接收到消息时的回调函数 - * @returns 返回订阅 id,用于后续取消订阅 - */ - const subscribe = (destination: string, callback: (_message: IMessage) => void): string => { - if (!client.value || !client.value.connected) { - console.warn(`尝试订阅 ${destination} 失败: 客户端未连接`); - return ""; - } - - try { - const subscription = client.value.subscribe(destination, callback); - const subscriptionId = subscription.id; - subscriptions.set(subscriptionId, subscription); - console.log(`订阅成功: ${destination}, ID: ${subscriptionId}`); - return subscriptionId; - } catch (error) { - console.error(`订阅 ${destination} 失败:`, error); - return ""; - } - }; - - /** - * 取消订阅 - * @param subscriptionId 订阅 id - */ - const unsubscribe = (subscriptionId: string) => { - const subscription = subscriptions.get(subscriptionId); - if (subscription) { - subscription.unsubscribe(); - subscriptions.delete(subscriptionId); - console.log(`已取消订阅: ${subscriptionId}`); - } - }; - - /** - * 断开WebSocket连接 - */ - const disconnect = () => { - // 设置手动断开标志 - isManualDisconnect = true; - - // 清除所有计时器 - if (reconnectTimer) { - clearTimeout(reconnectTimer); - reconnectTimer = null; - } - - if (connectionTimeoutTimer) { - clearTimeout(connectionTimeoutTimer); - connectionTimeoutTimer = null; - } - - // 清除所有订阅 - for (const [id, subscription] of subscriptions.entries()) { - try { - subscription.unsubscribe(); - } catch (error) { - console.warn(`取消订阅 ${id} 时出错:`, error); - } - } - subscriptions.clear(); - - // 断开连接 - if (client.value) { - try { - if (client.value.connected || client.value.active) { - client.value.deactivate(); - console.log("WebSocket连接已主动断开"); - } - } catch (error) { - console.error("断开WebSocket连接时出错:", error); - } - client.value = null; - } - - isConnected.value = false; - isConnecting = false; - reconnectCount.value = 0; - }; - - return { - isConnected, - connect, - subscribe, - unsubscribe, - disconnect, - }; -} diff --git a/fastapp/src/composables/useTabbar.ts b/fastapp/src/composables/useTabbar.ts deleted file mode 100644 index f14dbbcd..00000000 --- a/fastapp/src/composables/useTabbar.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { ref, computed } from "vue"; -import { isLoggedIn } from "@/utils/auth"; - -interface TabbarItem { - name: string; - title: string; - icon: string; -} - -const tabbarItems = ref([ - { name: "index", title: "首页", icon: "home" }, - { name: "work", title: "工作台", icon: "app" }, - { name: "mine", title: "我的", icon: "user" }, -]); - -const activeTabbar = ref("index"); - -export function useTabbar() { - // 根据登录状态动态显示tabbar项 - const tabbarList = computed(() => { - // 检查用户登录状态 - const loggedIn = isLoggedIn(); - - // 未登录时过滤掉工作台项 - if (!loggedIn) { - return tabbarItems.value.filter(item => item.name !== "work"); - } - - // 登录状态下显示所有tabbar项 - return tabbarItems.value; - }); - - const setTabbarItemActive = (name: string) => { - activeTabbar.value = name; - }; - - return { - tabbarList, - activeTabbar, - setTabbarItemActive, - }; -} \ No newline at end of file diff --git a/fastapp/src/constants/index.ts b/fastapp/src/constants/index.ts deleted file mode 100644 index 1e8e3b62..00000000 --- a/fastapp/src/constants/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -/** - * 常量统一导出 - */ - -// 存储相关常量 -export * from "./storage.constant"; diff --git a/fastapp/src/constants/storage.constant.ts b/fastapp/src/constants/storage.constant.ts deleted file mode 100644 index 3c3d22f3..00000000 --- a/fastapp/src/constants/storage.constant.ts +++ /dev/null @@ -1,16 +0,0 @@ -/** - * 存储键常量统一管理 - * 包括 localStorage、sessionStorage 等各种存储的键名 - */ - -// 访问token -export const APP_ACCESS_TOKEN_KEY = "appAccessToken"; - -// 刷新token -export const APP_REFRESH_TOKEN_KEY = "appRefreshToken"; - -// 用户缓存相关 -export const APP_USER_INFO = "appUserInfo"; - -// 全局配置相关 -export const APP_THEME_KEY = "appTheme"; diff --git a/fastapp/src/enums/api-code.enum.ts b/fastapp/src/enums/api-code.enum.ts deleted file mode 100644 index 94ca0dd9..00000000 --- a/fastapp/src/enums/api-code.enum.ts +++ /dev/null @@ -1,44 +0,0 @@ -/** - * API响应码枚举 - */ -export const enum ApiCode { - /** - * 成功 - */ - SUCCESS = 0, - - /** - * 通用错误 - */ - ERROR = 1, - - /** - * 异常 - */ - EXCEPTION = -1, - - /** - * 未授权访问 - */ - UNAUTHORIZED = 10403, - - /** - * 令牌已过期 - */ - TOKEN_EXPIRED = 10401, - - /** - * 参数校验失败 - */ - PARAM_INVALID = 400, - - /** - * 资源不存在 - */ - NOT_FOUND = 404, - - /** - * 服务器内部错误 - */ - INTERNAL_ERROR = 500, -} diff --git a/fastapp/src/enums/api-header.enum.ts b/fastapp/src/enums/api-header.enum.ts deleted file mode 100644 index 4f5ebd4b..00000000 --- a/fastapp/src/enums/api-header.enum.ts +++ /dev/null @@ -1,15 +0,0 @@ -/** - * API 请求头相关枚举封装 - */ -export const enum ApiHeader { - KEY = "Content-Type", - - /* 表单数据 */ - FORM = "application/x-www-form-urlencoded", - - /* JSON 数据 */ - JSON = "application/json", - - /* 多部分数据 */ - MULTIPART = "multipart/form-data", -} diff --git a/fastapp/src/env.d.ts b/fastapp/src/env.d.ts deleted file mode 100644 index fc812394..00000000 --- a/fastapp/src/env.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -/// - -declare module "*.vue" { - import type { DefineComponent } from "vue"; - const component: DefineComponent<{}, {}, any>; - export default component; -} diff --git a/fastapp/src/layouts/default.vue b/fastapp/src/layouts/default.vue deleted file mode 100644 index b0a8b9a7..00000000 --- a/fastapp/src/layouts/default.vue +++ /dev/null @@ -1,30 +0,0 @@ - - - - - \ No newline at end of file diff --git a/fastapp/src/layouts/tabbar.vue b/fastapp/src/layouts/tabbar.vue deleted file mode 100644 index d5f7911b..00000000 --- a/fastapp/src/layouts/tabbar.vue +++ /dev/null @@ -1,66 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/fastapp/src/main.ts b/fastapp/src/main.ts deleted file mode 100644 index d96fd0f0..00000000 --- a/fastapp/src/main.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { createSSRApp } from "vue"; -import App from "./App.vue"; - -import "uno.css"; -import "@/styles/index.scss"; - -import { setupStore } from "@/store"; -import router from "./router"; - -export function createApp() { - const app = createSSRApp(App); - - setupStore(app); - app.use(router); - - return { - app, - }; -} diff --git a/fastapp/src/manifest.json b/fastapp/src/manifest.json deleted file mode 100644 index b377e4fa..00000000 --- a/fastapp/src/manifest.json +++ /dev/null @@ -1,80 +0,0 @@ -{ - "name": "FastApp", - "appid": "", - "description": "FastApp", - "versionName": "2.0.0", - "versionCode": "100", - "transformPx": false, - "app-plus": { - "usingComponents": true, - "nvueStyleCompiler": "uni-app", - "compilerVersion": 3, - "splashscreen": { - "alwaysShowBeforeRender": true, - "waiting": true, - "autoclose": true, - "delay": 0 - }, - /* 模块配置 */ - "modules": {}, - /* 应用发布信息 */ - "distribute": { - /* android打包配置 */ - "android": { - "permissions": [ - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "" - ] - }, - /* ios打包配置 */ - "ios": {}, - /* SDK配置 */ - "sdkConfigs": {} - } - }, - /* 快应用特有相关 */ - "quickapp": {}, - /* 小程序特有相关:"appid": "wx99a151dc43d2637b" */ - "mp-weixin": { - "appid": "微信开发者ID", - "setting": { - "urlCheck": false - }, - "usingComponents": true, - "darkmode": true, - "themeLocation": "theme.json" - }, - /* 抖音小程序特有相关 */ - "mp-alipay": { - "usingComponents": true - }, - /* 百度小程序特有相关 */ - "mp-baidu": { - "usingComponents": true - }, - /* 字节跳动小程序特有相关 */ - "mp-toutiao": { - "usingComponents": true - }, - "uniStatistics": { - "enable": false - }, - "vueVersion": "3", - "h5": { - "darkmode": true, - "themeLocation": "theme.json" - } -} diff --git a/fastapp/src/pages.json b/fastapp/src/pages.json deleted file mode 100644 index 4a399875..00000000 --- a/fastapp/src/pages.json +++ /dev/null @@ -1,149 +0,0 @@ -{ - "pages": [ - { - "path": "pages/index/index", - "type": "home", - "name": "index", - "style": { - "navigationStyle": "custom" - }, - "layout": "tabbar" - }, - { - "path": "pages/login/index", - "type": "page", - "name": "login", - "style": {} - }, - { - "path": "pages/mine/index", - "type": "page", - "name": "mine", - "style": { - "navigationStyle": "custom" - }, - "layout": "tabbar" - }, - { - "path": "pages/work/index", - "type": "page", - "name": "work", - "style": { - "navigationStyle": "custom" - }, - "layout": "tabbar", - "meta": { - "requireAuth": true - } - }, - { - "path": "pages/mine/about/index", - "type": "page", - "name": "about", - "style": {} - }, - { - "path": "pages/mine/faq/index", - "type": "page", - "name": "faq", - "style": {} - }, - { - "path": "pages/mine/feedback/index", - "type": "page", - "name": "feedback", - "style": {} - }, - { - "path": "pages/mine/profile/complete-profile", - "type": "page" - }, - { - "path": "pages/mine/profile/index", - "type": "page", - "name": "profile", - "style": {} - }, - { - "path": "pages/mine/settings/index", - "type": "page", - "name": "settings", - "style": { - "navigationBarTitleText": "设置" - } - }, - { - "path": "pages/mine/settings/account/index", - "type": "page", - "name": "account", - "style": { - "navigationBarTitleText": "账号和安全" - }, - "layout": "tabbar" - }, - { - "path": "pages/mine/settings/agreement/index", - "type": "page", - "name": "agreement", - "style": { - "navigationBarTitleText": "用户协议" - }, - "layout": "tabbar" - }, - { - "path": "pages/mine/settings/network/index", - "type": "page", - "name": "network", - "style": {} - }, - { - "path": "pages/mine/settings/privacy/index", - "type": "page", - "name": "privacy", - "style": {} - }, - { - "path": "pages/mine/settings/theme/index", - "type": "page", - "name": "theme", - "style": { - "navigationBarTitleText": "主题设置" - } - } - ], - "globalStyle": { - "navigationBarBackgroundColor": "@navBgColor", - "navigationBarTextStyle": "@navTxtStyle", - "navigationBarTitleText": "FastApp", - "backgroundColor": "@bgColor", - "backgroundTextStyle": "@bgTxtStyle", - "backgroundColorTop": "@bgColorTop", - "backgroundColorBottom": "@bgColorBottom", - "enablePullDownRefresh": false, - "onReachBottomDistance": 50, - "animationType": "pop-in", - "animationDuration": 300 - }, - "tabBar": { - "custom": true, - "customize": true, - "overlay": true, - "height": "0", - "color": "@tabColor", - "selectedColor": "@tabSelectedColor", - "backgroundColor": "@tabBgColor", - "borderStyle": "@tabBorderStyle", - "list": [ - { - "pagePath": "pages/index/index" - }, - { - "pagePath": "pages/work/index" - }, - { - "pagePath": "pages/mine/index" - } - ] - }, - "subPackages": [] -} \ No newline at end of file diff --git a/fastapp/src/pages/index/index.vue b/fastapp/src/pages/index/index.vue deleted file mode 100644 index 21eadff7..00000000 --- a/fastapp/src/pages/index/index.vue +++ /dev/null @@ -1,248 +0,0 @@ - - - - -{ - "name": "index", - "style": { - "navigationStyle": "custom" - }, - "layout": "tabbar" -} - - \ No newline at end of file diff --git a/fastapp/src/pages/login/index.vue b/fastapp/src/pages/login/index.vue deleted file mode 100644 index b89c487b..00000000 --- a/fastapp/src/pages/login/index.vue +++ /dev/null @@ -1,594 +0,0 @@ - - - - -{ - "name": "login", - "style": {} -} - - diff --git a/fastapp/src/pages/mine/about/index.vue b/fastapp/src/pages/mine/about/index.vue deleted file mode 100644 index 1299a728..00000000 --- a/fastapp/src/pages/mine/about/index.vue +++ /dev/null @@ -1,117 +0,0 @@ - - - - -{ - "name": "about", - "style": {} -} - - diff --git a/fastapp/src/pages/mine/faq/index.vue b/fastapp/src/pages/mine/faq/index.vue deleted file mode 100644 index dff7c558..00000000 --- a/fastapp/src/pages/mine/faq/index.vue +++ /dev/null @@ -1,523 +0,0 @@ - - - - -{ - "name": "faq", - "style": {} -} - - \ No newline at end of file diff --git a/fastapp/src/pages/mine/feedback/index.vue b/fastapp/src/pages/mine/feedback/index.vue deleted file mode 100644 index d13c0775..00000000 --- a/fastapp/src/pages/mine/feedback/index.vue +++ /dev/null @@ -1,188 +0,0 @@ - - - - -{ - "name": "feedback", - "style": {} -} - - diff --git a/fastapp/src/pages/mine/index.vue b/fastapp/src/pages/mine/index.vue deleted file mode 100644 index 84664494..00000000 --- a/fastapp/src/pages/mine/index.vue +++ /dev/null @@ -1,500 +0,0 @@ - - - - -{ - "name": "mine", - "style": { - "navigationStyle": "custom" - }, - "layout": "tabbar" -} - - \ No newline at end of file diff --git a/fastapp/src/pages/mine/profile/complete-profile.vue b/fastapp/src/pages/mine/profile/complete-profile.vue deleted file mode 100644 index baf50649..00000000 --- a/fastapp/src/pages/mine/profile/complete-profile.vue +++ /dev/null @@ -1,584 +0,0 @@ - - - - - diff --git a/fastapp/src/pages/mine/profile/index.vue b/fastapp/src/pages/mine/profile/index.vue deleted file mode 100644 index b3d80e11..00000000 --- a/fastapp/src/pages/mine/profile/index.vue +++ /dev/null @@ -1,343 +0,0 @@ - - - - -{ - "name": "profile", - "style": {} -} - - diff --git a/fastapp/src/pages/mine/settings/account/index.vue b/fastapp/src/pages/mine/settings/account/index.vue deleted file mode 100644 index 01c29bee..00000000 --- a/fastapp/src/pages/mine/settings/account/index.vue +++ /dev/null @@ -1,163 +0,0 @@ - - - - -{ - "name": "account", - "style": { - "navigationBarTitleText": "账号和安全" - }, - "layout": "tabbar" -} - - diff --git a/fastapp/src/pages/mine/settings/agreement/index.vue b/fastapp/src/pages/mine/settings/agreement/index.vue deleted file mode 100644 index a3454ed5..00000000 --- a/fastapp/src/pages/mine/settings/agreement/index.vue +++ /dev/null @@ -1,83 +0,0 @@ - - - - -{ - "name": "agreement", - "style": { - "navigationBarTitleText": "用户协议" - }, - "layout": "tabbar" -} - - diff --git a/fastapp/src/pages/mine/settings/index.vue b/fastapp/src/pages/mine/settings/index.vue deleted file mode 100644 index 9486c628..00000000 --- a/fastapp/src/pages/mine/settings/index.vue +++ /dev/null @@ -1,256 +0,0 @@ - - - - - -{ - "name": "settings", - "style": { - "navigationBarTitleText": "设置" - } -} - - - diff --git a/fastapp/src/pages/mine/settings/network/index.vue b/fastapp/src/pages/mine/settings/network/index.vue deleted file mode 100644 index 26ed8418..00000000 --- a/fastapp/src/pages/mine/settings/network/index.vue +++ /dev/null @@ -1,245 +0,0 @@ - - - - -{ - "name": "network", - "style": {} -} - - diff --git a/fastapp/src/pages/mine/settings/privacy/index.vue b/fastapp/src/pages/mine/settings/privacy/index.vue deleted file mode 100644 index 05654640..00000000 --- a/fastapp/src/pages/mine/settings/privacy/index.vue +++ /dev/null @@ -1,80 +0,0 @@ - - - - -{ - "name": "privacy", - "style": {} -} - - diff --git a/fastapp/src/pages/mine/settings/theme/index.vue b/fastapp/src/pages/mine/settings/theme/index.vue deleted file mode 100644 index a017d556..00000000 --- a/fastapp/src/pages/mine/settings/theme/index.vue +++ /dev/null @@ -1,202 +0,0 @@ - - - - -{ - "name": "theme", - "style": { - "navigationBarTitleText": "主题设置" - } -} - - diff --git a/fastapp/src/pages/work/index.vue b/fastapp/src/pages/work/index.vue deleted file mode 100644 index 767bec1b..00000000 --- a/fastapp/src/pages/work/index.vue +++ /dev/null @@ -1,199 +0,0 @@ - - - - -{ - "name": "work", - "style": { - "navigationStyle": "custom" - }, - "layout": "tabbar", - "meta": { - "requireAuth": true - } -} - - \ No newline at end of file diff --git a/fastapp/src/router/index.ts b/fastapp/src/router/index.ts deleted file mode 100644 index a1e37082..00000000 --- a/fastapp/src/router/index.ts +++ /dev/null @@ -1,85 +0,0 @@ -import { pages, subPackages } from "virtual:uni-pages"; -import { isLoggedIn } from "@/utils/auth"; -import { createRouter } from "uni-mini-router"; - -// 生成路由配置 -function generateRoutes() { - const routes = pages.map((page: { path: string; [key: string]: any }) => { - const newPath = `/${page.path}`; - // 透传 meta 字段(如果 pages.json 中定义了) - const meta = page.meta ?? undefined; - return { ...page, path: newPath, meta }; - }); - - // 处理分包路由 - if (subPackages && subPackages.length > 0) { - subPackages.forEach((subPackage: { root: string; pages: any[] }) => { - const subRoutes = subPackage.pages.map((page: any) => { - const newPath = `/${subPackage.root}/${page.path}`; - const meta = page.meta ?? undefined; - return { ...page, path: newPath, meta }; - }); - routes.push(...subRoutes); - }); - } - return routes; -} - -// 创建路由实例 -const router = createRouter({ - routes: generateRoutes(), -}); - -// 全局前置守卫 -router.beforeEach((to, from, next) => { - console.log("🚀 路由守卫触发:", { - to: to.path, - from: from.path, - requireAuth: to.meta?.requireAuth, - }); - - if (to.meta && to.meta.requireAuth && !isLoggedIn()) { - console.log("🔒 需要登录,但用户未登录"); - - // 先阻止当前导航 - next(false); - - // 然后显示登录提示 - uni.showModal({ - title: "提示", - content: "该功能需要登录后使用", - confirmText: "去登录", - cancelText: "返回", - success: (res) => { - if (res.confirm) { - // 记住原来要去的页面 - uni.setStorageSync("redirect", to.fullPath); - // 使用 uni 原生导航而不是 router - uni.navigateTo({ - url: "/pages/login/index", - }); - } else { - // 取消则返回首页 - uni.switchTab({ - url: "/pages/index/index", - }); - } - }, - fail: () => { - // 失败时也返回首页 - uni.switchTab({ - url: "/pages/index/index", - }); - }, - }); - } else { - // 继续导航 - next(); - } -}); - -router.afterEach((to, from) => { - console.log("🎯 afterEach 钩子触发:", { to, from }); -}); - -export default router; diff --git a/fastapp/src/shime-uni.d.ts b/fastapp/src/shime-uni.d.ts deleted file mode 100644 index c80052b3..00000000 --- a/fastapp/src/shime-uni.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -export {}; - -declare module "vue" { - type Hooks = App.AppInstance & Page.PageInstance; - interface ComponentCustomOptions extends Hooks {} -} diff --git a/fastapp/src/static/icons/browser.png b/fastapp/src/static/icons/browser.png deleted file mode 100644 index fbadaa02..00000000 Binary files a/fastapp/src/static/icons/browser.png and /dev/null differ diff --git a/fastapp/src/static/icons/log.png b/fastapp/src/static/icons/log.png deleted file mode 100644 index e9777dbf..00000000 Binary files a/fastapp/src/static/icons/log.png and /dev/null differ diff --git a/fastapp/src/static/icons/notice.png b/fastapp/src/static/icons/notice.png deleted file mode 100644 index ebde0284..00000000 Binary files a/fastapp/src/static/icons/notice.png and /dev/null differ diff --git a/fastapp/src/static/icons/role.png b/fastapp/src/static/icons/role.png deleted file mode 100644 index 890d96fc..00000000 Binary files a/fastapp/src/static/icons/role.png and /dev/null differ diff --git a/fastapp/src/static/icons/setting.png b/fastapp/src/static/icons/setting.png deleted file mode 100644 index 45c0c1e8..00000000 Binary files a/fastapp/src/static/icons/setting.png and /dev/null differ diff --git a/fastapp/src/static/icons/user.png b/fastapp/src/static/icons/user.png deleted file mode 100644 index 9f58ed01..00000000 Binary files a/fastapp/src/static/icons/user.png and /dev/null differ diff --git a/fastapp/src/static/icons/visitor.png b/fastapp/src/static/icons/visitor.png deleted file mode 100644 index cf23b920..00000000 Binary files a/fastapp/src/static/icons/visitor.png and /dev/null differ diff --git a/fastapp/src/static/icons/weixin.png b/fastapp/src/static/icons/weixin.png deleted file mode 100644 index 1255c57e..00000000 Binary files a/fastapp/src/static/icons/weixin.png and /dev/null differ diff --git a/fastapp/src/static/images/banner01.jpg b/fastapp/src/static/images/banner01.jpg deleted file mode 100644 index 1086afd3..00000000 Binary files a/fastapp/src/static/images/banner01.jpg and /dev/null differ diff --git a/fastapp/src/static/images/banner02.jpg b/fastapp/src/static/images/banner02.jpg deleted file mode 100644 index 092a5fc2..00000000 Binary files a/fastapp/src/static/images/banner02.jpg and /dev/null differ diff --git a/fastapp/src/static/images/default-avatar.png b/fastapp/src/static/images/default-avatar.png deleted file mode 100644 index 4906c083..00000000 Binary files a/fastapp/src/static/images/default-avatar.png and /dev/null differ diff --git a/fastapp/src/static/images/header-bg.png b/fastapp/src/static/images/header-bg.png deleted file mode 100644 index 46478337..00000000 Binary files a/fastapp/src/static/images/header-bg.png and /dev/null differ diff --git a/fastapp/src/static/images/login-bg.svg b/fastapp/src/static/images/login-bg.svg deleted file mode 100644 index eedc1f4a..00000000 --- a/fastapp/src/static/images/login-bg.svg +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/fastapp/src/static/logo.png b/fastapp/src/static/logo.png deleted file mode 100644 index 43eeb762..00000000 Binary files a/fastapp/src/static/logo.png and /dev/null differ diff --git a/fastapp/src/store/index.ts b/fastapp/src/store/index.ts deleted file mode 100644 index d088e0a1..00000000 --- a/fastapp/src/store/index.ts +++ /dev/null @@ -1,13 +0,0 @@ -import type { App } from "vue"; -import { createPinia } from "pinia"; - -const store = createPinia(); - -// 全局注册 store -export function setupStore(app: App) { - app.use(store); -} - -export * from "./modules/user.store"; -export * from "./modules/theme.store"; -export { store }; diff --git a/fastapp/src/store/modules/theme.store.ts b/fastapp/src/store/modules/theme.store.ts deleted file mode 100644 index 7df45fea..00000000 --- a/fastapp/src/store/modules/theme.store.ts +++ /dev/null @@ -1,230 +0,0 @@ -import { defineStore } from "pinia"; -import { useStorage } from "@uni-helper/uni-use"; -import type { ConfigProviderThemeVars } from "wot-design-uni"; -import { nextTick, reactive, computed, watch } from "vue"; - -// 声明uni-app全局API -declare function getCurrentPages(): any[]; - -// 主题色选项接口 -export interface ThemeColorOption { - name: string; - value: string; - primary: string; -} - -// 主题类型 -export type ThemeMode = "light" | "dark"; - -export const useThemeStore = defineStore("appTheme", () => { - const theme = useStorage("app-theme", "dark"); - - // 预定义的主题色选项 - const themeColorOptions: ThemeColorOption[] = [ - { name: "默认蓝", value: "blue", primary: "#4D7FFF" }, - { name: "活力橙", value: "orange", primary: "#FF7D00" }, - { name: "薄荷绿", value: "green", primary: "#07C160" }, - { name: "樱花粉", value: "pink", primary: "#FF69B4" }, - { name: "紫罗兰", value: "purple", primary: "#8A2BE2" }, - { name: "朱砂红", value: "red", primary: "#FF4757" }, - ]; - - // 主题色 - const currentThemeColor = useStorage("app-theme-color", themeColorOptions[0]); - - // 获取当前主题的基础颜色配置 - const getThemeColors = (isDark: boolean) => ({ - // 基础颜色 - colorBg: isDark ? "#0f0f0f" : "#f8f8f8", - colorTitle: isDark ? "#ffffff" : "#1d2129", - colorContent: isDark ? "#e0e0e0" : "#4e5969", - colorSecondary: isDark ? "#a0a0a0" : "#86909c", - colorBorder: isDark ? "#2f2f2f" : "#e5e6eb", - colorBorderLight: isDark ? "#3d3d3d" : "#f2f3f5", - - // 卡片相关变量 - cardBg: isDark ? "#1a1a1a" : "#ffffff", - cardTitleColor: isDark ? "#ffffff" : "#1d2129", - cardContentColor: isDark ? "#e0e0e0" : "#4e5969", - cardContentBorderColor: isDark ? "#2f2f2f" : "#e5e6eb", - }); - - // 主题变量(响应式对象) - const themeVars: ConfigProviderThemeVars = reactive({ - // 暗黑模式背景色 - darkBackground: "#0f0f0f", - darkBackground2: "#1a1a1a", - darkBackground3: "#242424", - darkBackground4: "#2f2f2f", - darkBackground5: "#3d3d3d", - darkBackground6: "#4a4a4a", - darkBackground7: "#606060", - - // 暗黑模式文字颜色 - darkColor: "#ffffff", - darkColor2: "#e0e0e0", - darkColor3: "#a0a0a0", - darkColorGray: "#a0a0a0", - darkBorderColor: "#2f2f2f", - - // 主题色 - colorTheme: currentThemeColor.value.primary, - - // 根据当前主题模式设置基础颜色 - ...getThemeColors(theme.value === 'dark'), - }); - - // 计算属性 - const isDark = computed(() => theme.value === "dark"); - - // 设置导航栏颜色 - const setCustomNavigationBarColor = async () => { - try { - // 检查当前环境是否支持设置导航栏颜色 - // 在非H5环境(如小程序)中,确保页面已加载 - const pages = getCurrentPages(); - if (pages.length === 0) { - // 页面还未加载,稍后重试 - setTimeout(() => { - setCustomNavigationBarColor(); - }, 100); - return; - } - - await uni.setNavigationBarColor({ - frontColor: theme.value === "light" ? "#000000" : "#ffffff", - backgroundColor: theme.value === "light" ? "#ffffff" : "#000000", - }); - } catch (error) { - console.warn('设置导航栏颜色失败,将在下次页面加载时重试:', error); - // 可以在这里添加重试逻辑或降级方案 - } - }; - - // 更新主题变量 - const updateThemeVars = () => { - const isDark = theme.value === 'dark'; - const colors = getThemeColors(isDark); - - // 更新所有主题变量 - Object.assign(themeVars, colors); - }; - - // 更新CSS变量 - const updateCSSVariables = () => { - // 确保在客户端环境且DOM已准备好 - if (typeof window !== 'undefined' && typeof document !== 'undefined' && document.documentElement) { - const root = document.documentElement; - const isDark = theme.value === 'dark'; - - // 更新主题色 - root.style.setProperty('--wot-color-theme', currentThemeColor.value.primary); - - // 更新主题类 - root.classList.toggle('dark', isDark); - root.classList.toggle('light', !isDark); - - } - - // 更新主题变量 - updateThemeVars(); - }; - - // 切换主题, 指定主题模式,不传则自动切换 - const toggleTheme = (mode?: ThemeMode) => { - theme.value = mode || (theme.value === "light" ? "dark" : "light"); - setCustomNavigationBarColor(); - updateCSSVariables(); - - // 触发主题变化事件 - nextTick(() => { - uni.$emit('theme-change', theme.value); - }); - }; - - // 设置主题色 - const setCurrentThemeColor = (color: ThemeColorOption) => { - currentThemeColor.value = color; - - // 强制更新主题变量 - Object.assign(themeVars, { - colorTheme: color.primary - }); - - updateCSSVariables(); - - // 触发主题色变化事件 - nextTick(() => { - uni.$emit('theme-color-change', color); - }); - }; - - // 初始化主题 - const initTheme = () => { - // 强制更新主题变量中的颜色 - Object.assign(themeVars, { - colorTheme: currentThemeColor.value.primary - }); - - // 更新主题变量 - updateThemeVars(); - - // 延迟更新CSS变量,确保DOM已准备好 - nextTick(() => { - updateCSSVariables(); - // 尝试设置导航栏颜色,但不阻止其他初始化流程 - try { - setCustomNavigationBarColor(); - } catch (error) { - console.warn('初始化导航栏颜色失败:', error); - } - }); - - // 为了兼容性,在更长的延迟后再次尝试 - if (typeof window !== 'undefined') { - setTimeout(() => { - updateCSSVariables(); - // 再次尝试设置导航栏颜色 - try { - setCustomNavigationBarColor(); - } catch (error) { - console.warn('延迟重试设置导航栏颜色失败:', error); - } - }, 100); - } - }; - - // 监听主题变化,自动更新CSS变量 - watch(theme, () => { - updateCSSVariables(); - }); - - // 监听主题色变化,自动更新CSS变量 - watch(currentThemeColor, () => { - Object.assign(themeVars, { - colorTheme: currentThemeColor.value.primary - }); - updateCSSVariables(); - }); - - // 注意:全局主题管理已在App.vue中处理 - // 包括:系统主题监听、导航栏颜色同步等 - // 组件中一般不需要再调用initTheme(),除非有特殊需求 - - return { - // 状态 - theme, - currentThemeColor, - themeVars, - themeColorOptions, - - // 计算属性 - isDark, - - // 方法 - toggleTheme, - setCurrentThemeColor, - setCustomNavigationBarColor, - initTheme, - }; -}); diff --git a/fastapp/src/store/modules/user.store.ts b/fastapp/src/store/modules/user.store.ts deleted file mode 100644 index d414f911..00000000 --- a/fastapp/src/store/modules/user.store.ts +++ /dev/null @@ -1,84 +0,0 @@ -import { defineStore } from "pinia"; -import UserAPI, { type UserInfo } from "@/api/user"; -import AuthAPI, { type LoginFormData, type LoginResult, type LogoutBody } from "@/api/auth"; -import { getAccessToken, setAccessToken, setRefreshToken, clearAll, getUserInfo, setUserInfo } from "@/utils/auth"; - -export const useUserStore = defineStore("appUserInfo", () => { - const userInfo = ref(getUserInfo()); - const isLoggingIn = ref(false); - - // 统一的登录处理方法 - const handleLogin = async (loginFn: () => Promise, loginType: string) => { - if (isLoggingIn.value) return; - - isLoggingIn.value = true; - try { - const result = await loginFn(); - setAccessToken(result.access_token); - setRefreshToken(result.refresh_token); - - // 登录成功后获取用户信息 - await getInfo(); - - return result; - } catch (error: any) { - console.error(`${loginType}登录失败`, error); - throw error; - } finally { - isLoggingIn.value = false; - } - }; - - // 账号密码登录 - const login = async (data: LoginFormData) => { - return handleLogin(() => AuthAPI.login(data), "账号密码"); - }; - - // 获取用户信息 - const getInfo = async () => { - try { - const userInfoData = await UserAPI.getCurrentUserInfo(); - setUserInfo(userInfoData); - // 确保响应式数据更新 - userInfo.value = userInfoData; - return userInfoData; - } catch (error) { - console.error("获取用户信息失败", error); - return null; - } - }; - - // 登出 - const logout = async () => { - try { - const logoutBody: LogoutBody = { - token: getAccessToken() || "", - }; - await AuthAPI.logout(logoutBody); // 调用后台注销接口 - } catch (error) { - console.error("登出失败", error); - } finally { - clearAll(); // 清除本地的 token - userInfo.value = undefined; // 清空用户信息 - // 跳转到登录页面 - uni.reLaunch({ - url: "/pages/login/index", - }); - } - }; - - // 判断用户信息是否完整 - const isUserInfoComplete = (): boolean => { - if (!userInfo.value) return false; - return !!(userInfo.value.username && userInfo.value.avatar); - }; - - return { - userInfo, - isLoggingIn, - login, - logout, - getInfo, - isUserInfoComplete, - }; -}); diff --git a/fastapp/src/styles/index.scss b/fastapp/src/styles/index.scss deleted file mode 100644 index f13392ae..00000000 --- a/fastapp/src/styles/index.scss +++ /dev/null @@ -1,304 +0,0 @@ -/** - * 主样式文件 - * 统一管理所有样式,保持简洁清晰 - */ - -html, -body, -#app { - height: 100%; - padding: 0; - margin: 0; -} - -.app-container { - padding: 16rpx; - - :deep(.custom-item) { - height: 100px !important; - } - :deep(.wd-card) { - margin: 16rpx 0 !important; - } -} - -/* ===== 全局主题变量 ===== */ -:root { - /* 主题色系 */ - --primary-color: #165dff; - --primary-color-light: #94bfff; - --primary-color-dark: #0e3c9b; - --wot-color-theme: #165dff; - - /* 功能色系 */ - --success-color: #07c160; - --warning-color: #ff7d00; - --danger-color: #f53f3f; - --info-color: #86909c; - - /* 文字颜色 */ - --text-color: #1d2129; - --text-color-2: #4e5969; - --text-color-3: #86909c; - --text-color-placeholder: #c9cdd4; - --text-color-inverse: #ffffff; - - /* 背景颜色 */ - --bg-color: #ffffff; - --bg-color-2: #f8f8f8; - --bg-color-3: #f2f3f5; - --card-bg-color: #ffffff; - - /* 边框颜色 */ - --border-color: #e5e6eb; - --border-color-light: #f2f3f5; - - /* 阴影 */ - --shadow-light: 0 2rpx 8rpx rgba(0, 0, 0, 0.05); - --shadow-medium: 0 4rpx 16rpx rgba(0, 0, 0, 0.1); - --shadow-heavy: 0 8rpx 32rpx rgba(0, 0, 0, 0.15); - - /* 圆角 */ - --radius-sm: 4rpx; - --radius-md: 8rpx; - --radius-lg: 16rpx; - --radius-xl: 24rpx; - --radius-full: 9999rpx; - - /* 间距 */ - --spacing-xs: 8rpx; - --spacing-sm: 16rpx; - --spacing-md: 24rpx; - --spacing-lg: 32rpx; - --spacing-xl: 48rpx; - --spacing-xxl: 64rpx; - - /* 字体大小 */ - --font-xs: 24rpx; - --font-sm: 28rpx; - --font-md: 32rpx; - --font-lg: 36rpx; - --font-xl: 40rpx; - --font-xxl: 48rpx; - --font-xxxl: 56rpx; - - /* 动画 */ - --transition-fast: 0.15s ease; - --transition-normal: 0.3s ease; - --transition-slow: 0.5s ease; -} - -/* ===== 暗黑模式变量 ===== */ -.dark { - --text-color: #ffffff; - --text-color-2: #e0e0e0; - --text-color-3: #a0a0a0; - --text-color-placeholder: #606060; - --text-color-inverse: #1d2129; - - --bg-color: #0f0f0f; - --bg-color-2: #1a1a1a; - --bg-color-3: #242424; - --card-bg-color: #1a1a1a; - - --border-color: #2f2f2f; - --border-color-light: #3d3d3d; - - --shadow-light: 0 2rpx 8rpx rgba(0, 0, 0, 0.3); - --shadow-medium: 0 4rpx 16rpx rgba(0, 0, 0, 0.4); - --shadow-heavy: 0 8rpx 32rpx rgba(0, 0, 0, 0.5); -} - -/* ===== 主题适配类 ===== */ -.theme-adaptive { - color: var(--text-color); - background-color: var(--bg-color); - border-color: var(--border-color); - transition: - color var(--transition-normal), - background-color var(--transition-normal), - border-color var(--transition-normal); -} - -.theme-card { - background-color: var(--card-bg-color); - border: 1px solid var(--border-color); - border-radius: var(--radius-lg); - box-shadow: var(--shadow-light); - transition: all var(--transition-normal); - - &:hover { - box-shadow: var(--shadow-medium); - } -} - -.theme-text-primary { - color: var(--text-color); -} - -.theme-text-secondary { - color: var(--text-color-2); -} - -.theme-text-tertiary { - color: var(--text-color-3); -} - -.theme-text-muted { - color: var(--text-color-placeholder); -} - -.theme-text-inverse { - color: var(--text-color-inverse); -} - -/* ===== 常用工具类 ===== */ -.text-primary { - color: var(--primary-color) !important; -} -.text-success { - color: var(--success-color) !important; -} -.text-warning { - color: var(--warning-color) !important; -} -.text-danger { - color: var(--danger-color) !important; -} -.text-info { - color: var(--info-color) !important; -} -.text-muted { - color: var(--text-color-3) !important; -} - -.bg-primary { - color: var(--text-color-inverse); - background-color: var(--primary-color) !important; -} -.bg-card { - background-color: var(--card-bg-color) !important; -} -.bg-light { - background-color: var(--bg-color-2) !important; -} - -.rounded { - border-radius: var(--radius-md); -} -.rounded-lg { - border-radius: var(--radius-lg); -} -.rounded-full { - border-radius: var(--radius-full); -} - -.shadow { - box-shadow: var(--shadow-light); -} -.shadow-lg { - box-shadow: var(--shadow-medium); -} - -.transition { - transition: all var(--transition-normal); -} - -.flex { - display: flex !important; -} -.items-center { - align-items: center !important; -} -.justify-center { - justify-content: center !important; -} -.justify-between { - justify-content: space-between !important; -} - -.text-center { - text-align: center !important; -} -.font-bold { - font-weight: 700 !important; -} - -/* ===== 间距工具类 ===== */ -.p-xs { - padding: var(--spacing-xs) !important; -} -.p-sm { - padding: var(--spacing-sm) !important; -} -.p-md { - padding: var(--spacing-md) !important; -} -.p-lg { - padding: var(--spacing-lg) !important; -} -.p-xl { - padding: var(--spacing-xl) !important; -} - -.m-xs { - margin: var(--spacing-xs) !important; -} -.m-sm { - margin: var(--spacing-sm) !important; -} -.m-md { - margin: var(--spacing-md) !important; -} -.m-lg { - margin: var(--spacing-lg) !important; -} -.m-xl { - margin: var(--spacing-xl) !important; -} - -.mt-sm { - margin-top: var(--spacing-sm) !important; -} -.mt-md { - margin-top: var(--spacing-md) !important; -} -.mt-lg { - margin-top: var(--spacing-lg) !important; -} -.mt-xl { - margin-top: var(--spacing-xl) !important; -} - -.mb-sm { - margin-bottom: var(--spacing-sm) !important; -} -.mb-md { - margin-bottom: var(--spacing-md) !important; -} -.mb-lg { - margin-bottom: var(--spacing-lg) !important; -} -.mb-xl { - margin-bottom: var(--spacing-xl) !important; -} - -/* ===== 字体大小类 ===== */ -.text-xs { - font-size: var(--font-xs) !important; -} -.text-sm { - font-size: var(--font-sm) !important; -} -.text-md { - font-size: var(--font-md) !important; -} -.text-lg { - font-size: var(--font-lg) !important; -} -.text-xl { - font-size: var(--font-xl) !important; -} -.text-2xl { - font-size: var(--font-xxl) !important; -} diff --git a/fastapp/src/theme.json b/fastapp/src/theme.json deleted file mode 100644 index 2c2ef366..00000000 --- a/fastapp/src/theme.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "light": { - "bgColor": "#F8F8F8", - "bgColorBottom": "#F8F8F8", - "bgColorTop": "#F8F8F8", - "bgTxtStyle": "dark", - "navBgColor": "#FFF", - "navTxtStyle": "black", - "tabBgColor": "#ffffff", - "tabBorderStyle": "black", - "tabColor": "#bfbfbf", - "tabSelectedColor": "#0165FF" - }, - "dark": { - "bgColor": "#000", - "bgColorBottom": "#000", - "bgColorTop": "#000", - "bgTxtStyle": "light", - "navBgColor": "#000000", - "navTxtStyle": "white", - "tabBgColor": "#1a1a1a", - "tabBorderStyle": "white", - "tabColor": "#bfbfbf", - "tabSelectedColor": "#0165FF" - } -} diff --git a/fastapp/src/types/auto-imports.d.ts b/fastapp/src/types/auto-imports.d.ts deleted file mode 100644 index 4e1cc724..00000000 --- a/fastapp/src/types/auto-imports.d.ts +++ /dev/null @@ -1,318 +0,0 @@ -/* eslint-disable */ -/* prettier-ignore */ -// @ts-nocheck -// noinspection JSUnusedGlobalSymbols -// Generated by unplugin-auto-import -// biome-ignore lint: disable -export {} -declare global { - const CommonUtil: typeof import('wot-design-uni')['CommonUtil'] - const EffectScope: typeof import('vue')['EffectScope'] - const Storage: typeof import('../utils/storage')['Storage'] - const acceptHMRUpdate: typeof import('pinia')['acceptHMRUpdate'] - const auth: typeof import('../api/auth')['default'] - const checkLogin: typeof import('../utils/auth')['checkLogin'] - const clearAll: typeof import('../utils/auth')['clearAll'] - const clearToken: typeof import('../utils/storage')['clearToken'] - const clearTokens: typeof import('../utils/auth')['clearTokens'] - const clearUserInfo: typeof import('../utils/auth')['clearUserInfo'] - const computed: typeof import('vue')['computed'] - const config: typeof import('../api/config')['default'] - const createApp: typeof import('vue')['createApp'] - const createPinia: typeof import('pinia')['createPinia'] - const createRouter: typeof import('uni-mini-router')['createRouter'] - const customRef: typeof import('vue')['customRef'] - const debounce: typeof import('../utils/index')['debounce'] - const defineAsyncComponent: typeof import('vue')['defineAsyncComponent'] - const defineComponent: typeof import('vue')['defineComponent'] - const defineStore: typeof import('pinia')['defineStore'] - const dept: typeof import('../api/dept')['default'] - const dict: typeof import('../api/dict')['default'] - const effectScope: typeof import('vue')['effectScope'] - const file: typeof import('../api/file')['default'] - const getAccessToken: typeof import('../utils/auth')['getAccessToken'] - const getActivePinia: typeof import('pinia')['getActivePinia'] - const getCurrentInstance: typeof import('vue')['getCurrentInstance'] - const getCurrentScope: typeof import('vue')['getCurrentScope'] - const getRefreshToken: typeof import('../utils/auth')['getRefreshToken'] - const getToken: typeof import('../utils/storage')['getToken'] - const getUserInfo: typeof import('../utils/auth')['getUserInfo'] - const guessSerializerType: typeof import('@uni-helper/uni-use')['guessSerializerType'] - const h: typeof import('vue')['h'] - const inject: typeof import('vue')['inject'] - const isLoggedIn: typeof import('../utils/auth')['isLoggedIn'] - const isProxy: typeof import('vue')['isProxy'] - const isReactive: typeof import('vue')['isReactive'] - const isReadonly: typeof import('vue')['isReadonly'] - const isRef: typeof import('vue')['isRef'] - const log: typeof import('../api/log')['default'] - const mapActions: typeof import('pinia')['mapActions'] - const mapGetters: typeof import('pinia')['mapGetters'] - const mapState: typeof import('pinia')['mapState'] - const mapStores: typeof import('pinia')['mapStores'] - const mapWritableState: typeof import('pinia')['mapWritableState'] - const markRaw: typeof import('vue')['markRaw'] - const menu: typeof import('../api/menu')['default'] - const nextTick: typeof import('vue')['nextTick'] - const notice: typeof import('../api/notice')['default'] - const onActivated: typeof import('vue')['onActivated'] - const onAddToFavorites: typeof import('@dcloudio/uni-app')['onAddToFavorites'] - const onBackPress: typeof import('@dcloudio/uni-app')['onBackPress'] - const onBeforeMount: typeof import('vue')['onBeforeMount'] - const onBeforeRouteLeave: (typeof import("vue-router"))["onBeforeRouteLeave"] - const onBeforeRouteUpdate: (typeof import("vue-router"))["onBeforeRouteUpdate"] - const onBeforeUnmount: typeof import('vue')['onBeforeUnmount'] - const onBeforeUpdate: typeof import('vue')['onBeforeUpdate'] - const onDeactivated: typeof import('vue')['onDeactivated'] - const onError: typeof import('@dcloudio/uni-app')['onError'] - const onErrorCaptured: typeof import('vue')['onErrorCaptured'] - const onHide: typeof import('@dcloudio/uni-app')['onHide'] - const onLaunch: typeof import('@dcloudio/uni-app')['onLaunch'] - const onLoad: typeof import('@dcloudio/uni-app')['onLoad'] - const onMounted: typeof import('vue')['onMounted'] - const onNavigationBarButtonTap: typeof import('@dcloudio/uni-app')['onNavigationBarButtonTap'] - const onNavigationBarSearchInputChanged: typeof import('@dcloudio/uni-app')['onNavigationBarSearchInputChanged'] - const onNavigationBarSearchInputClicked: typeof import('@dcloudio/uni-app')['onNavigationBarSearchInputClicked'] - const onNavigationBarSearchInputConfirmed: typeof import('@dcloudio/uni-app')['onNavigationBarSearchInputConfirmed'] - const onNavigationBarSearchInputFocusChanged: typeof import('@dcloudio/uni-app')['onNavigationBarSearchInputFocusChanged'] - const onPageNotFound: typeof import('@dcloudio/uni-app')['onPageNotFound'] - const onPageScroll: typeof import('@dcloudio/uni-app')['onPageScroll'] - const onPullDownRefresh: typeof import('@dcloudio/uni-app')['onPullDownRefresh'] - const onReachBottom: typeof import('@dcloudio/uni-app')['onReachBottom'] - const onReady: typeof import('@dcloudio/uni-app')['onReady'] - const onRenderTracked: typeof import('vue')['onRenderTracked'] - const onRenderTriggered: typeof import('vue')['onRenderTriggered'] - const onResize: typeof import('@dcloudio/uni-app')['onResize'] - const onScopeDispose: typeof import('vue')['onScopeDispose'] - const onServerPrefetch: typeof import('vue')['onServerPrefetch'] - const onShareAppMessage: typeof import('@dcloudio/uni-app')['onShareAppMessage'] - const onShareTimeline: typeof import('@dcloudio/uni-app')['onShareTimeline'] - const onShow: typeof import('@dcloudio/uni-app')['onShow'] - const onTabItemTap: typeof import('@dcloudio/uni-app')['onTabItemTap'] - const onThemeChange: typeof import('@dcloudio/uni-app')['onThemeChange'] - const onUnhandledRejection: typeof import('@dcloudio/uni-app')['onUnhandledRejection'] - const onUnload: typeof import('@dcloudio/uni-app')['onUnload'] - const onUnmounted: typeof import('vue')['onUnmounted'] - const onUpdated: typeof import('vue')['onUpdated'] - const onWatcherCleanup: typeof import('vue')['onWatcherCleanup'] - const provide: typeof import('vue')['provide'] - const publicRequest: typeof import('../utils/request')['publicRequest'] - const reactive: typeof import('vue')['reactive'] - const readonly: typeof import('vue')['readonly'] - const ref: typeof import('vue')['ref'] - const request: typeof import('../utils/request')['default'] - const requireLogin: typeof import('../utils/auth')['requireLogin'] - const resolveComponent: typeof import('vue')['resolveComponent'] - const role: typeof import('../api/role')['default'] - const setAccessToken: typeof import('../utils/auth')['setAccessToken'] - const setActivePinia: typeof import('pinia')['setActivePinia'] - const setMapStoreSuffix: typeof import('pinia')['setMapStoreSuffix'] - const setRefreshToken: typeof import('../utils/auth')['setRefreshToken'] - const setToken: typeof import('../utils/storage')['setToken'] - const setUserInfo: typeof import('../utils/auth')['setUserInfo'] - const setupStore: typeof import('../store/index')['setupStore'] - const shallowReactive: typeof import('vue')['shallowReactive'] - const shallowReadonly: typeof import('vue')['shallowReadonly'] - const shallowRef: typeof import('vue')['shallowRef'] - const store: typeof import('../store/index')['store'] - const storeToRefs: typeof import('pinia')['storeToRefs'] - const toRaw: typeof import('vue')['toRaw'] - const toRef: typeof import('vue')['toRef'] - const toRefs: typeof import('vue')['toRefs'] - const toValue: typeof import('vue')['toValue'] - const triggerRef: typeof import('vue')['triggerRef'] - const tryOnBackPress: typeof import('@uni-helper/uni-use')['tryOnBackPress'] - const tryOnHide: typeof import('@uni-helper/uni-use')['tryOnHide'] - const tryOnInit: typeof import('@uni-helper/uni-use')['tryOnInit'] - const tryOnLoad: typeof import('@uni-helper/uni-use')['tryOnLoad'] - const tryOnReady: typeof import('@uni-helper/uni-use')['tryOnReady'] - const tryOnScopeDispose: typeof import('@uni-helper/uni-use')['tryOnScopeDispose'] - const tryOnShow: typeof import('@uni-helper/uni-use')['tryOnShow'] - const tryOnUnload: typeof import('@uni-helper/uni-use')['tryOnUnload'] - const unref: typeof import('vue')['unref'] - const useActionSheet: typeof import('@uni-helper/uni-use')['useActionSheet'] - const useAttrs: typeof import('vue')['useAttrs'] - const useClipboardData: typeof import('@uni-helper/uni-use')['useClipboardData'] - const useCssModule: typeof import('vue')['useCssModule'] - const useCssVars: typeof import('vue')['useCssVars'] - const useDictStore: typeof import('../store/modules/dict.store')['useDictStore'] - const useDownloadFile: typeof import('@uni-helper/uni-use')['useDownloadFile'] - const useGlobalData: typeof import('@uni-helper/uni-use')['useGlobalData'] - const useId: typeof import('vue')['useId'] - const useInterceptor: typeof import('@uni-helper/uni-use')['useInterceptor'] - const useLink: (typeof import("vue-router"))["useLink"] - const useLoading: typeof import('@uni-helper/uni-use')['useLoading'] - const useMessage: typeof import('wot-design-uni')['useMessage'] - const useModal: typeof import('@uni-helper/uni-use')['useModal'] - const useModel: typeof import('vue')['useModel'] - const useNetwork: typeof import('@uni-helper/uni-use')['useNetwork'] - const useNotify: typeof import('wot-design-uni')['useNotify'] - const useOnline: typeof import('@uni-helper/uni-use')['useOnline'] - const usePage: typeof import('@uni-helper/uni-use')['usePage'] - const usePageScroll: typeof import('@uni-helper/uni-use')['usePageScroll'] - const usePages: typeof import('@uni-helper/uni-use')['usePages'] - const usePreferredDark: typeof import('@uni-helper/uni-use')['usePreferredDark'] - const usePreferredLanguage: typeof import('@uni-helper/uni-use')['usePreferredLanguage'] - const usePrevPage: typeof import('@uni-helper/uni-use')['usePrevPage'] - const usePrevRoute: typeof import('@uni-helper/uni-use')['usePrevRoute'] - const useProvider: typeof import('@uni-helper/uni-use')['useProvider'] - const useRequest: typeof import('@uni-helper/uni-use')['useRequest'] - const useRoute: typeof import('uni-mini-router')['useRoute'] - const useRouter: typeof import('uni-mini-router')['useRouter'] - const useScanCode: typeof import('@uni-helper/uni-use')['useScanCode'] - const useScreenBrightness: typeof import('@uni-helper/uni-use')['useScreenBrightness'] - const useSelectorQuery: typeof import('@uni-helper/uni-use')['useSelectorQuery'] - const useSlots: typeof import('vue')['useSlots'] - const useSocket: typeof import('@uni-helper/uni-use')['useSocket'] - const useStomp: typeof import('../composables/useStomp')['useStomp'] - const useStorage: typeof import('@uni-helper/uni-use')['useStorage'] - const useStorageAsync: typeof import('@uni-helper/uni-use')['useStorageAsync'] - const useStorageSync: typeof import('@uni-helper/uni-use')['useStorageSync'] - const useTabbar: typeof import('../composables/useTabbar')['useTabbar'] - const useTemplateRef: typeof import('vue')['useTemplateRef'] - const useThemeStore: typeof import('../store/modules/theme.store')['useThemeStore'] - const useToast: typeof import('wot-design-uni')['useToast'] - const useUserStore: typeof import('../store/modules/user.store')['useUserStore'] - const user: typeof import('../api/user')['default'] - const watch: typeof import('vue')['watch'] - const watchEffect: typeof import('vue')['watchEffect'] - const watchPostEffect: typeof import('vue')['watchPostEffect'] - const watchSyncEffect: typeof import('vue')['watchSyncEffect'] -} -// for type re-export -declare global { - // @ts-ignore - export type { Component, ComponentPublicInstance, ComputedRef, DirectiveBinding, ExtractDefaultPropTypes, ExtractPropTypes, ExtractPublicPropTypes, InjectionKey, PropType, Ref, MaybeRef, MaybeRefOrGetter, VNode, WritableComputedRef } from 'vue' - import('vue') -} - -// for vue template auto import -import { UnwrapRef } from 'vue' -declare module 'vue' { - interface GlobalComponents {} - interface ComponentCustomProperties { - readonly CommonUtil: UnwrapRef - readonly EffectScope: UnwrapRef - readonly Storage: UnwrapRef - readonly acceptHMRUpdate: UnwrapRef - readonly auth: UnwrapRef - readonly checkLogin: UnwrapRef - readonly clearAll: UnwrapRef - readonly clearTokens: UnwrapRef - readonly clearUserInfo: UnwrapRef - readonly computed: UnwrapRef - readonly createApp: UnwrapRef - readonly createPinia: UnwrapRef - readonly createRouter: UnwrapRef - readonly customRef: UnwrapRef - readonly debounce: UnwrapRef - readonly defineAsyncComponent: UnwrapRef - readonly defineComponent: UnwrapRef - readonly defineStore: UnwrapRef - readonly effectScope: UnwrapRef - readonly file: UnwrapRef - readonly getAccessToken: UnwrapRef - readonly getActivePinia: UnwrapRef - readonly getCurrentInstance: UnwrapRef - readonly getCurrentScope: UnwrapRef - readonly getRefreshToken: UnwrapRef - readonly getUserInfo: UnwrapRef - readonly h: UnwrapRef - readonly inject: UnwrapRef - readonly isLoggedIn: UnwrapRef - readonly isProxy: UnwrapRef - readonly isReactive: UnwrapRef - readonly isReadonly: UnwrapRef - readonly isRef: UnwrapRef - readonly mapActions: UnwrapRef - readonly mapGetters: UnwrapRef - readonly mapState: UnwrapRef - readonly mapStores: UnwrapRef - readonly mapWritableState: UnwrapRef - readonly markRaw: UnwrapRef - readonly nextTick: UnwrapRef - readonly onActivated: UnwrapRef - readonly onAddToFavorites: UnwrapRef - readonly onBackPress: UnwrapRef - readonly onBeforeMount: UnwrapRef - readonly onBeforeUnmount: UnwrapRef - readonly onBeforeUpdate: UnwrapRef - readonly onDeactivated: UnwrapRef - readonly onError: UnwrapRef - readonly onErrorCaptured: UnwrapRef - readonly onHide: UnwrapRef - readonly onLaunch: UnwrapRef - readonly onLoad: UnwrapRef - readonly onMounted: UnwrapRef - readonly onNavigationBarButtonTap: UnwrapRef - readonly onNavigationBarSearchInputChanged: UnwrapRef - readonly onNavigationBarSearchInputClicked: UnwrapRef - readonly onNavigationBarSearchInputConfirmed: UnwrapRef - readonly onNavigationBarSearchInputFocusChanged: UnwrapRef - readonly onPageNotFound: UnwrapRef - readonly onPageScroll: UnwrapRef - readonly onPullDownRefresh: UnwrapRef - readonly onReachBottom: UnwrapRef - readonly onReady: UnwrapRef - readonly onRenderTracked: UnwrapRef - readonly onRenderTriggered: UnwrapRef - readonly onResize: UnwrapRef - readonly onScopeDispose: UnwrapRef - readonly onServerPrefetch: UnwrapRef - readonly onShareAppMessage: UnwrapRef - readonly onShareTimeline: UnwrapRef - readonly onShow: UnwrapRef - readonly onTabItemTap: UnwrapRef - readonly onThemeChange: UnwrapRef - readonly onUnhandledRejection: UnwrapRef - readonly onUnload: UnwrapRef - readonly onUnmounted: UnwrapRef - readonly onUpdated: UnwrapRef - readonly onWatcherCleanup: UnwrapRef - readonly provide: UnwrapRef - readonly reactive: UnwrapRef - readonly readonly: UnwrapRef - readonly ref: UnwrapRef - readonly request: UnwrapRef - readonly requireLogin: UnwrapRef - readonly resolveComponent: UnwrapRef - readonly setAccessToken: UnwrapRef - readonly setActivePinia: UnwrapRef - readonly setMapStoreSuffix: UnwrapRef - readonly setRefreshToken: UnwrapRef - readonly setUserInfo: UnwrapRef - readonly setupStore: UnwrapRef - readonly shallowReactive: UnwrapRef - readonly shallowReadonly: UnwrapRef - readonly shallowRef: UnwrapRef - readonly store: UnwrapRef - readonly storeToRefs: UnwrapRef - readonly toRaw: UnwrapRef - readonly toRef: UnwrapRef - readonly toRefs: UnwrapRef - readonly toValue: UnwrapRef - readonly triggerRef: UnwrapRef - readonly unref: UnwrapRef - readonly useAttrs: UnwrapRef - readonly useCssModule: UnwrapRef - readonly useCssVars: UnwrapRef - readonly useId: UnwrapRef - readonly useMessage: UnwrapRef - readonly useModel: UnwrapRef - readonly useNotify: UnwrapRef - readonly useRoute: UnwrapRef - readonly useRouter: UnwrapRef - readonly useSlots: UnwrapRef - readonly useStomp: UnwrapRef - readonly useTabbar: UnwrapRef - readonly useTemplateRef: UnwrapRef - readonly useThemeStore: UnwrapRef - readonly useToast: UnwrapRef - readonly useUserStore: UnwrapRef - readonly user: UnwrapRef - readonly watch: UnwrapRef - readonly watchEffect: UnwrapRef - readonly watchPostEffect: UnwrapRef - readonly watchSyncEffect: UnwrapRef - } -} \ No newline at end of file diff --git a/fastapp/src/types/components.d.ts b/fastapp/src/types/components.d.ts deleted file mode 100644 index 1982630a..00000000 --- a/fastapp/src/types/components.d.ts +++ /dev/null @@ -1,55 +0,0 @@ -/* eslint-disable */ -/* prettier-ignore */ -// @ts-nocheck -// Generated by vite-plugin-uni-components -// Read more: https://github.com/vuejs/core/pull/3399 -export {} - -declare module 'vue' { - export interface GlobalComponents { - CuDateQuery: typeof import('./../components/cu-date-query/index.vue')['default'] - CuPicker: typeof import('./../components/cu-picker/index.vue')['default'] - Loading1: typeof import('./../components/qiun-loading/loading1.vue')['default'] - Loading2: typeof import('./../components/qiun-loading/loading2.vue')['default'] - Loading3: typeof import('./../components/qiun-loading/loading3.vue')['default'] - Loading4: typeof import('./../components/qiun-loading/loading4.vue')['default'] - Loading5: typeof import('./../components/qiun-loading/loading5.vue')['default'] - QiunDataCharts: typeof import('./../components/qiun-data-charts/qiun-data-charts.vue')['default'] - QiunError: typeof import('./../components/qiun-error/qiun-error.vue')['default'] - QiunLoading: typeof import('./../components/qiun-loading/qiun-loading.vue')['default'] - WdBadge: typeof import('wot-design-uni/components/wd-badge/wd-badge.vue')['default'] - WdButton: typeof import('wot-design-uni/components/wd-button/wd-button.vue')['default'] - WdCard: typeof import('wot-design-uni/components/wd-card/wd-card.vue')['default'] - WdCell: typeof import('wot-design-uni/components/wd-cell/wd-cell.vue')['default'] - WdCellGroup: typeof import('wot-design-uni/components/wd-cell-group/wd-cell-group.vue')['default'] - WdCheckbox: typeof import('wot-design-uni/components/wd-checkbox/wd-checkbox.vue')['default'] - WdCollapse: typeof import('wot-design-uni/components/wd-collapse/wd-collapse.vue')['default'] - WdCollapseItem: typeof import('wot-design-uni/components/wd-collapse-item/wd-collapse-item.vue')['default'] - WdConfigProvider: typeof import('wot-design-uni/components/wd-config-provider/wd-config-provider.vue')['default'] - WdDivider: typeof import('wot-design-uni/components/wd-divider/wd-divider.vue')['default'] - WdForm: typeof import('wot-design-uni/components/wd-form/wd-form.vue')['default'] - WdGrid: typeof import('wot-design-uni/components/wd-grid/wd-grid.vue')['default'] - WdGridItem: typeof import('wot-design-uni/components/wd-grid-item/wd-grid-item.vue')['default'] - WdIcon: typeof import('wot-design-uni/components/wd-icon/wd-icon.vue')['default'] - WdImg: typeof import('wot-design-uni/components/wd-img/wd-img.vue')['default'] - WdImgCropper: typeof import('wot-design-uni/components/wd-img-cropper/wd-img-cropper.vue')['default'] - WdInput: typeof import('wot-design-uni/components/wd-input/wd-input.vue')['default'] - WdLoading: typeof import('wot-design-uni/components/wd-loading/wd-loading.vue')['default'] - WdMessageBox: typeof import('wot-design-uni/components/wd-message-box/wd-message-box.vue')['default'] - WdNoticeBar: typeof import('wot-design-uni/components/wd-notice-bar/wd-notice-bar.vue')['default'] - WdNotify: typeof import('wot-design-uni/components/wd-notify/wd-notify.vue')['default'] - WdPopup: typeof import('wot-design-uni/components/wd-popup/wd-popup.vue')['default'] - WdProgress: typeof import('wot-design-uni/components/wd-progress/wd-progress.vue')['default'] - WdRadio: typeof import('wot-design-uni/components/wd-radio/wd-radio.vue')['default'] - WdRadioGroup: typeof import('wot-design-uni/components/wd-radio-group/wd-radio-group.vue')['default'] - WdSwiper: typeof import('wot-design-uni/components/wd-swiper/wd-swiper.vue')['default'] - WdSwitch: typeof import('wot-design-uni/components/wd-switch/wd-switch.vue')['default'] - WdTabbar: typeof import('wot-design-uni/components/wd-tabbar/wd-tabbar.vue')['default'] - WdTabbarItem: typeof import('wot-design-uni/components/wd-tabbar-item/wd-tabbar-item.vue')['default'] - WdTag: typeof import('wot-design-uni/components/wd-tag/wd-tag.vue')['default'] - WdText: typeof import('wot-design-uni/components/wd-text/wd-text.vue')['default'] - WdTextarea: typeof import('wot-design-uni/components/wd-textarea/wd-textarea.vue')['default'] - WdToast: typeof import('wot-design-uni/components/wd-toast/wd-toast.vue')['default'] - WdUpload: typeof import('wot-design-uni/components/wd-upload/wd-upload.vue')['default'] - } -} diff --git a/fastapp/src/types/env.d.ts b/fastapp/src/types/env.d.ts deleted file mode 100644 index 0f196dc3..00000000 --- a/fastapp/src/types/env.d.ts +++ /dev/null @@ -1,26 +0,0 @@ -// src/types/env.d.ts -/** - * 环境变量类型声明 - */ -interface ImportMetaEnv { - /** - * 应用端口 - */ - readonly VITE_APP_PORT: number; - /** 超时时间 */ - readonly VITE_TIMEOUT: number; - /** API基础路径 */ - readonly VITE_APP_BASE_API: string; - /** API服务器URL */ - readonly VITE_API_BASE_URL: string; - /** 环境 */ - readonly VITE_APP_ENV: string; - /** 项目名称 */ - readonly VITE_APP_TITLE: string; - /** WebSocket 端点 */ - readonly VITE_APP_WS_ENDPOINT?: string; -} - -interface ImportMeta { - readonly env: ImportMetaEnv; -} diff --git a/fastapp/src/types/global.d.ts b/fastapp/src/types/global.d.ts deleted file mode 100644 index 39fe44c1..00000000 --- a/fastapp/src/types/global.d.ts +++ /dev/null @@ -1,66 +0,0 @@ -declare global { - /** - * 响应数据 - */ - interface ApiResponse { - code: number; - data: T; - msg: string; - status_code: number; - } - - /** - * 分页查询参数 - */ - interface PageQuery { - /** 当前页码 */ - page_no: number; - /** 每页条数 */ - page_size: number; - } - - /** - * 分页响应对象 - */ - interface PageResult { - /** 数据列表 */ - items: T; - /** 总数 */ - total: number; - page_no: number; - page_size: number; - has_next: boolean; - } - - /** - * 下拉选项数据类型 - */ - interface OptionType { - /** 值 */ - value: string | number; - /** 文本 */ - label: string; - /** 子列表 */ - children?: OptionType[]; - } - - /** - * 创建人 - */ - interface creatorType { - id?: number; - name?: string; - username?: string; - } - - /** - * 上传文件返回 - */ - interface UploadFileResult { - file_path: string; - file_name: string; - origin_name: string; - file_url: string; - } -} -export {}; diff --git a/fastapp/src/types/uni-mini-router.d.ts b/fastapp/src/types/uni-mini-router.d.ts deleted file mode 100644 index fcd52b4d..00000000 --- a/fastapp/src/types/uni-mini-router.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -import "uni-mini-router"; - -declare module "uni-mini-router" { - interface Route { - path: string; - fullPath: string; - meta?: { - requireAuth?: boolean; - [key: string]: any; - }; - } -} diff --git a/fastapp/src/types/uni-pages.d.ts b/fastapp/src/types/uni-pages.d.ts deleted file mode 100644 index c92faa9b..00000000 --- a/fastapp/src/types/uni-pages.d.ts +++ /dev/null @@ -1,36 +0,0 @@ -/* eslint-disable */ -/* prettier-ignore */ -// @ts-nocheck -// Generated by vite-plugin-uni-pages - -interface NavigateToOptions { - url: "/pages/index/index" | - "/pages/login/index" | - "/pages/mine/index" | - "/pages/work/index" | - "/pages/mine/about/index" | - "/pages/mine/faq/index" | - "/pages/mine/feedback/index" | - "/pages/mine/profile/complete-profile" | - "/pages/mine/profile/index" | - "/pages/mine/settings/index" | - "/pages/mine/settings/account/index" | - "/pages/mine/settings/agreement/index" | - "/pages/mine/settings/network/index" | - "/pages/mine/settings/privacy/index" | - "/pages/mine/settings/theme/index"; -} -interface RedirectToOptions extends NavigateToOptions {} - -interface SwitchTabOptions { - url: "/pages/index/index" | "/pages/work/index" | "/pages/mine/index" -} - -type ReLaunchOptions = NavigateToOptions | SwitchTabOptions; - -declare interface Uni { - navigateTo(options: UniNamespace.NavigateToOptions & NavigateToOptions): void; - redirectTo(options: UniNamespace.RedirectToOptions & RedirectToOptions): void; - switchTab(options: UniNamespace.SwitchTabOptions & SwitchTabOptions): void; - reLaunch(options: UniNamespace.ReLaunchOptions & ReLaunchOptions): void; -} diff --git a/fastapp/src/types/virtual-uni-pages.d.ts b/fastapp/src/types/virtual-uni-pages.d.ts deleted file mode 100644 index 11267d87..00000000 --- a/fastapp/src/types/virtual-uni-pages.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -declare module "virtual:uni-pages" { - interface Page { - path: string; - style?: Record; - [key: string]: any; - } - - interface SubPackage { - root: string; - pages: Page[]; - [key: string]: any; - } - - export const pages: Page[]; - export const subPackages: SubPackage[]; -} diff --git a/fastapp/src/types/vite-plugin-uni-pages.d.ts b/fastapp/src/types/vite-plugin-uni-pages.d.ts deleted file mode 100644 index 2d632fd4..00000000 --- a/fastapp/src/types/vite-plugin-uni-pages.d.ts +++ /dev/null @@ -1,59 +0,0 @@ -// Type definitions for vite-plugin-uni-pages -// This file provides type definitions for the uni-pages plugin - -declare module "@uni-helper/vite-plugin-uni-pages" { - import { Plugin } from "vite"; - - export interface UniPagesOptions { - /** - * Subpackage directory - * @default 'src/pages' - */ - subPackages?: string[]; - - /** - * Global style file - */ - globalStyle?: Record; - - /** - * Tabbar configuration - */ - tabBar?: Record; - - /** - * Whether to merge pages.json - * @default true - */ - mergePages?: boolean; - - /** - * Whether to use uni-cloud-router - * @default false - */ - uniCloudRouter?: boolean; - } - - export default function UniPages(options?: UniPagesOptions): Plugin; -} - -// Augment Uni namespace for type-safe routing -declare global { - namespace UniNamespace { - interface NavigateToOptions { - url: string; - } - - interface RedirectToOptions { - url: string; - } - - interface SwitchTabOptions { - url: string; - } - - interface ReLaunchOptions { - url: string; - } - } -} diff --git a/fastapp/src/uni.scss b/fastapp/src/uni.scss deleted file mode 100644 index d0551103..00000000 --- a/fastapp/src/uni.scss +++ /dev/null @@ -1,76 +0,0 @@ -/** - * 这里是uni-app内置的常用样式变量 - * - * uni-app 官方扩展插件及插件市场(https://ext.dcloud.net.cn)上很多三方插件均使用了这些样式变量 - * 如果你是插件开发者,建议你使用scss预处理,并在插件代码中直接使用这些变量(无需 import 这个文件),方便用户通过搭积木的方式开发整体风格一致的App - * - */ - -/** - * 如果你是App开发者(插件使用者),你可以通过修改这些变量来定制自己的插件主题,实现自定义主题功能 - * - * 如果你的项目同样使用了scss预处理,你也可以直接在你的 scss 代码中使用如下变量,同时无需 import 这个文件 - */ - -/* 颜色变量 */ - -/* 行为相关颜色 */ -$uni-color-primary: #007aff; -$uni-color-success: #4cd964; -$uni-color-warning: #f0ad4e; -$uni-color-error: #dd524d; - -/* 文字基本颜色 */ -$uni-text-color: #333; // 基本色 -$uni-text-color-inverse: #fff; // 反色 -$uni-text-color-grey: #999; // 辅助灰色,如加载更多的提示信息 -$uni-text-color-placeholder: #808080; -$uni-text-color-disable: #c0c0c0; - -/* 背景颜色 */ -$uni-bg-color: #fff; -$uni-bg-color-grey: #f8f8f8; -$uni-bg-color-hover: #f1f1f1; // 点击状态颜色 -$uni-bg-color-mask: rgba(0, 0, 0, 0.4); // 遮罩颜色 - -/* 边框颜色 */ -$uni-border-color: #c8c7cc; - -/* 尺寸变量 */ - -/* 文字尺寸 */ -$uni-font-size-sm: 12px; -$uni-font-size-base: 14px; -$uni-font-size-lg: 16; - -/* 图片尺寸 */ -$uni-img-size-sm: 20px; -$uni-img-size-base: 26px; -$uni-img-size-lg: 40px; - -/* Border Radius */ -$uni-border-radius-sm: 2px; -$uni-border-radius-base: 3px; -$uni-border-radius-lg: 6px; -$uni-border-radius-circle: 50%; - -/* 水平间距 */ -$uni-spacing-row-sm: 5px; -$uni-spacing-row-base: 10px; -$uni-spacing-row-lg: 15px; - -/* 垂直间距 */ -$uni-spacing-col-sm: 4px; -$uni-spacing-col-base: 8px; -$uni-spacing-col-lg: 12px; - -/* 透明度 */ -$uni-opacity-disabled: 0.3; // 组件禁用态的透明度 - -/* 文章场景相关 */ -$uni-color-title: #2c405a; // 文章标题颜色 -$uni-font-size-title: 20px; -$uni-color-subtitle: #555; // 二级标题颜色 -$uni-font-size-subtitle: 18px; -$uni-color-paragraph: #3f536e; // 文章段落颜色 -$uni-font-size-paragraph: 15px; diff --git a/fastapp/src/utils/auth.ts b/fastapp/src/utils/auth.ts deleted file mode 100644 index c4d64e51..00000000 --- a/fastapp/src/utils/auth.ts +++ /dev/null @@ -1,124 +0,0 @@ -import { useUserStore } from "@/store"; -import { Storage } from "./storage"; -import { APP_ACCESS_TOKEN_KEY, APP_REFRESH_TOKEN_KEY, APP_USER_INFO } from "@/constants"; - -// 获取访问 token -export function getAccessToken(): string | null { - return Storage.get(APP_ACCESS_TOKEN_KEY) || null; -} - -// 设置 token -export function setAccessToken(token: string): void { - return Storage.set(APP_ACCESS_TOKEN_KEY, token); -} - -// 获取刷新 token -export function getRefreshToken(): string | null { - return Storage.get(APP_REFRESH_TOKEN_KEY) || null; -} - -// 设置刷新 token -export function setRefreshToken(token: string): void { - return Storage.set(APP_REFRESH_TOKEN_KEY, token); -} - -// 清除 token -export function clearTokens() { - Storage.remove(APP_ACCESS_TOKEN_KEY); - Storage.remove(APP_REFRESH_TOKEN_KEY); -} - -// 获取用户信息 -export function getUserInfo(): T | undefined { - return Storage.get(APP_USER_INFO); -} - -// 设置用户信息 -export function setUserInfo(userInfo: any): void { - return Storage.set(APP_USER_INFO, userInfo); -} - -// 清除用户信息 -export function clearUserInfo() { - return Storage.remove(APP_USER_INFO); -} - -// 清除所有缓存信息 -export function clearAll() { - Storage.remove(APP_ACCESS_TOKEN_KEY); - Storage.remove(APP_REFRESH_TOKEN_KEY); - Storage.remove(APP_USER_INFO); -} - -// 检查用户登录状态,未登录则跳转到登录页面 -export function checkLogin(silent: boolean = false): boolean { - const userStore = useUserStore(); - const accessToken = getAccessToken(); - - // 检查 token 和用户信息是否都存在 - const isLoggedIn = !!(accessToken && userStore.userInfo); - - if (!isLoggedIn && !silent) { - try { - // 获取当前页面路径 - let currentPagePath = "/pages/index/index"; // 默认路径 - - const pages = getCurrentPages(); - if (pages && pages.length > 0) { - const currentPage = pages[pages.length - 1]; - if (currentPage && currentPage.route) { - currentPagePath = `/${currentPage.route}`; - - // 处理页面参数 - 使用类型断言 - const pageOptions = (currentPage as any).options; - if (pageOptions && Object.keys(pageOptions).length > 0) { - const params = new URLSearchParams(pageOptions as Record); - currentPagePath += `?${params.toString()}`; - } - } - } - - // 跳转到登录页面 - uni.navigateTo({ - url: `/pages/login/index?redirect=${encodeURIComponent(currentPagePath)}`, - fail: (error) => { - console.error("跳转登录页面失败:", error); - // 如果 navigateTo 失败,尝试使用 reLaunch - uni.reLaunch({ - url: "/pages/login/index", - }); - }, - }); - } catch (error) { - console.error("检查登录状态时发生错误:", error); - // 发生错误时,尝试直接跳转到登录页 - uni.reLaunch({ - url: "/pages/login/index", - }); - } - } - - return isLoggedIn; -} - -// 检查用户是否已登录(静默检查,不跳转) -export function isLoggedIn(): boolean { - return checkLogin(true); -} - -// 强制用户登录,清除无效的登录状态 -export function requireLogin(): void { - const userStore = useUserStore(); - const accessToken = getAccessToken(); - - if (!accessToken || !userStore.userInfo) { - // 清除可能存在的无效状态 - clearTokens(); - userStore.logout(); - - // 跳转到登录页 - uni.reLaunch({ - url: "/pages/login/index", - }); - } -} diff --git a/fastapp/src/utils/index.ts b/fastapp/src/utils/index.ts deleted file mode 100644 index 283b7561..00000000 --- a/fastapp/src/utils/index.ts +++ /dev/null @@ -1,17 +0,0 @@ -/** - * 防抖函数 - * @param fn 函数 - * @param delay 延迟时间 - * @returns - */ -const debounce = any>(fn: T, delay: number) => { - let timer: ReturnType | null = null; - return function (this: any, ...args: Parameters) { - if (timer) clearTimeout(timer); - timer = setTimeout(() => { - fn.apply(this, args); - }, delay); - }; -}; - -export { debounce }; diff --git a/fastapp/src/utils/request.ts b/fastapp/src/utils/request.ts deleted file mode 100644 index cfe5c490..00000000 --- a/fastapp/src/utils/request.ts +++ /dev/null @@ -1,87 +0,0 @@ -import { ApiCode } from "@/enums/api-code.enum"; - -import { getAccessToken, clearAll } from "@/utils/auth"; -/** - * 请求拦截器 - 添加 Authorization 头 - */ -function request(options: UniApp.RequestOptions): Promise { - uni.showLoading({ - title: "加载中...", - }); - return new Promise((resolve, reject) => { - // H5 使用 VITE_APP_BASE_API 作为代理路径,其他平台使用 VITE_API_BASE_URL 作为请求路径 - let baseApi = import.meta.env.VITE_API_BASE_URL; - // #ifdef H5 - baseApi = import.meta.env.VITE_APP_BASE_API; - // #endif - - let timeout = Number(import.meta.env.VITE_TIMEOUT); - if (options.timeout) { - timeout = options.timeout; - } - - // 统一处理请求 - uni.request({ - url: `${baseApi}${options.url}`, - method: options.method, - data: options.data, - header: { - ...options.header, - Authorization: getAccessToken() ? `Bearer ${getAccessToken()}` : "", - }, - timeout: timeout, - responseType: options.responseType, - success: (res: UniApp.RequestSuccessCallbackResult) => { - const result = res.data as ApiResponse; - // 请求成功 - if (result.code === ApiCode.SUCCESS) { - resolve(result.data); - } - // 令牌过期 - else if (result.code === ApiCode.TOKEN_EXPIRED) { - // 清除所有缓存 - clearAll(); - // 跳转登录 - uni.reLaunch({ url: "/pages/login/index" }); - // 提示 - uni.showToast({ - title: result.msg || "登录已过期,请重新登录", - icon: "error", - }); - reject(new Error(result.msg || "登录已过期,请重新登录")); - } - // 未授权访问 - else if (result.code === ApiCode.UNAUTHORIZED) { - uni.showToast({ - title: result.msg || "未授权访问", - icon: "error", - }); - reject(new Error(result.msg || "未授权访问")); - } - // 其他错误 - else { - uni.showToast({ - title: result.msg || "请求失败", - icon: "error", - }); - reject(new Error(result.msg || "请求失败")); - } - }, - fail: (err: UniApp.GeneralCallbackResult) => { - console.log("请求失败", err); - uni.showToast({ - title: "网络请求失败", - icon: "none", - duration: 2000, - }); - reject(new Error(err.errMsg || "网络请求失败")); - }, - complete: () => { - // 请求完成,隐藏loading - uni.hideLoading(); - }, - }); - }); -} - -export default request; diff --git a/fastapp/src/utils/storage.ts b/fastapp/src/utils/storage.ts deleted file mode 100644 index 758d8642..00000000 --- a/fastapp/src/utils/storage.ts +++ /dev/null @@ -1,33 +0,0 @@ -/** - * 存储工具类 - * 提供localStorage和sessionStorage操作方法 - */ - -/** - * localStorage 存储 - */ -function set(key: string, value: any): void { - uni.setStorageSync(key, JSON.stringify(value)); -} - -function get(key: string, defaultValue?: T): T { - const value = uni.getStorageSync(key); - if (!value) return defaultValue as T; - - try { - return JSON.parse(value); - } catch { - // 如果解析失败,返回原始字符串 - return value as unknown as T; - } -} - -function remove(key: string): void { - uni.removeStorageSync(key); -} - -export const Storage = { - set, - get, - remove, -}; diff --git a/fastapp/theme.json b/fastapp/theme.json deleted file mode 100644 index 2c2ef366..00000000 --- a/fastapp/theme.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "light": { - "bgColor": "#F8F8F8", - "bgColorBottom": "#F8F8F8", - "bgColorTop": "#F8F8F8", - "bgTxtStyle": "dark", - "navBgColor": "#FFF", - "navTxtStyle": "black", - "tabBgColor": "#ffffff", - "tabBorderStyle": "black", - "tabColor": "#bfbfbf", - "tabSelectedColor": "#0165FF" - }, - "dark": { - "bgColor": "#000", - "bgColorBottom": "#000", - "bgColorTop": "#000", - "bgTxtStyle": "light", - "navBgColor": "#000000", - "navTxtStyle": "white", - "tabBgColor": "#1a1a1a", - "tabBorderStyle": "white", - "tabColor": "#bfbfbf", - "tabSelectedColor": "#0165FF" - } -} diff --git a/fastapp/tsconfig.json b/fastapp/tsconfig.json deleted file mode 100644 index c6223b4a..00000000 --- a/fastapp/tsconfig.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "compilerOptions": { - "module": "esnext", - "moduleResolution": "node", - "target": "esnext", - "allowJs": true, - "skipLibCheck": true, - "strict": true, - - "sourceMap": true, - "baseUrl": ".", - "paths": { - "@/*": ["./src/*"] - }, - "lib": ["esnext", "dom"], - "types": ["@dcloudio/types", "@uni-helper/uni-types", "wot-design-uni/global"] - }, - "vueCompilerOptions": { - // 调整 Volar(Vue 语言服务工具)解析行为,用于为 uni-app 组件提供 TypeScript 类型 - "plugins": ["@uni-helper/uni-types/volar-plugin"] - }, - "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"], - "exclude": ["node_modules", "dist"] -} diff --git a/fastapp/uni-pages.d.ts b/fastapp/uni-pages.d.ts deleted file mode 100644 index 2065725a..00000000 --- a/fastapp/uni-pages.d.ts +++ /dev/null @@ -1,35 +0,0 @@ -/* eslint-disable */ -/* prettier-ignore */ -// @ts-nocheck -// Generated by vite-plugin-uni-pages - -interface NavigateToOptions { - url: "/pages/index/index" | - "/pages/login/index" | - "/pages/mine/index" | - "/pages/work/index" | - "/pages/mine/about/index" | - "/pages/mine/faq/index" | - "/pages/mine/feedback/index" | - "/pages/mine/profile/complete-profile" | - "/pages/mine/profile/index" | - "/pages/mine/settings/index" | - "/pages/mine/settings/account/index" | - "/pages/mine/settings/agreement/index" | - "/pages/mine/settings/network/index" | - "/pages/mine/settings/theme/index"; -} -interface RedirectToOptions extends NavigateToOptions {} - -interface SwitchTabOptions { - url: "/pages/index/index" | "/pages/mine/index" -} - -type ReLaunchOptions = NavigateToOptions | SwitchTabOptions; - -declare interface Uni { - navigateTo(options: UniNamespace.NavigateToOptions & NavigateToOptions): void; - redirectTo(options: UniNamespace.RedirectToOptions & RedirectToOptions): void; - switchTab(options: UniNamespace.SwitchTabOptions & SwitchTabOptions): void; - reLaunch(options: UniNamespace.ReLaunchOptions & ReLaunchOptions): void; -} diff --git a/fastapp/unocss.config.ts b/fastapp/unocss.config.ts deleted file mode 100644 index b64ba13b..00000000 --- a/fastapp/unocss.config.ts +++ /dev/null @@ -1,39 +0,0 @@ -import presetWeapp from "unocss-preset-weapp"; -import { extractorAttributify, transformerClass } from "unocss-preset-weapp/transformer"; - -const { presetWeappAttributify, transformerAttributify } = extractorAttributify(); - -export default { - presets: [ - // https://github.com/MellowCo/unocss-preset-weapp - presetWeapp(), - // attributify autocomplete - presetWeappAttributify(), - ], - shortcuts: [ - { - "flex-center": "flex justify-center items-center", - - "flex-start": "flex justify-start items-center", - "flex-end": "flex justify-end items-center", - "flex-between": "flex justify-between items-center", - "flex-around": "flex justify-around items-center", - "flex-evenly": "flex justify-evenly items-center", - "flex-stretch": "flex justify-stretch items-center", - "flex-baseline": "flex justify-baseline items-center", - "flex-column": "flex flex-col", - "flex-row": "flex flex-row", - - // 垂直布局并居中对齐 - "flex-col-center": "flex flex-col items-center", - }, - ], - - transformers: [ - // https://github.com/MellowCo/unocss-preset-weapp/tree/main/src/transformer/transformerAttributify - transformerAttributify(), - - // https://github.com/MellowCo/unocss-preset-weapp/tree/main/src/transformer/transformerClass - transformerClass(), - ], -}; diff --git a/fastapp/vite.config.ts b/fastapp/vite.config.ts deleted file mode 100644 index f6317bd0..00000000 --- a/fastapp/vite.config.ts +++ /dev/null @@ -1,80 +0,0 @@ -import { defineConfig, type UserConfig, type ConfigEnv, loadEnv } from "vite"; -import uni from "@dcloudio/vite-plugin-uni"; -import AutoImport from "unplugin-auto-import/vite"; -import UniLayouts from "@uni-helper/vite-plugin-uni-layouts"; -import UniPages from "@uni-helper/vite-plugin-uni-pages"; - -import Components from "@uni-helper/vite-plugin-uni-components"; -import { WotResolver } from "@uni-helper/vite-plugin-uni-components/resolvers"; - -export default defineConfig(async ({ mode }: ConfigEnv): Promise => { - const UnoCss = await import("unocss/vite").then((i) => i.default); - const env = loadEnv(mode, process.cwd()); - - return { - base: "/app", - server: { - host: true, - port: Number(env.VITE_APP_PORT), - open: true, - // 代理配置只在 H5(浏览器)开发时生效。 其他平台(如小程序、App)在开发时不使用 Vite 的开发服务器,它们直接运行在各自的环境中。 - proxy: { - [env.VITE_APP_BASE_API]: { - changeOrigin: true, - target: env.VITE_API_BASE_URL, - // rewrite: (path) => path.replace(new RegExp("^" + env.VITE_APP_BASE_API), ""), - }, - }, - }, - build: { - target: "es6" - }, - optimizeDeps: { - include: ["wot-design-uni"], - exclude: ["vue-demi"], - }, - plugins: [ - // make sure put it before `Uni()` - UnoCss(), - UniLayouts(), - UniPages({ - dts: "src/types/uni-pages.d.ts", - subPackages: ["src/subPages"], - /** - * 排除的页面,相对于 dir 和 subPackages - * @default [] - */ - exclude: ["**/components/**/*.*"], - }), - - Components({ - resolvers: [WotResolver()], - // 指定自定义组件位置(默认:src/components) - dirs: ["src/components", "src/**/components"], - // 导入组件类型声明文件路径 (false:关闭自动生成) - dts: "src/types/components.d.ts", - }), - - AutoImport({ - imports: [ - "vue", - "uni-app", - "pinia", - { - from: "uni-mini-router", - imports: ["createRouter", "useRouter", "useRoute"], - }, - { - from: "wot-design-uni", - imports: ["useToast", "useMessage", "useNotify", "CommonUtil"], - }, - ], - dts: "src/types/auto-imports.d.ts", // 自动生成的类型声明文件 - dirs: ["src/composables", "src/store", "src/utils", "src/api"], - vueTemplate: true, - }), - - uni.default(), - ], - }; -});