当前位置: 首页 > news >正文

来自echarts的灵感

刻度定位

在图表的类别轴上找到一个给定刻度值 (targetTickId) 的位置 (coord)

coord:Number;=>像素值 为空间位置
targetValue:Number;=> 刻度线某处所代表的值

遍历刻度线

  • 如果 tickValue 等于 targetTickId,则找到了目标位置,赋值给 coord 并退出循环。
  • 如果 tickValue 小于 targetTickId,更新 leftCoord 为当前遍历处刻度的位置。
  • 如果 tickValue 大于 targetTickId,并且 leftCoord 已经有值,说明 targetTickId 在 leftCoord 和当前刻度之间。计算它们的中间位置作为 coord 并退出循环。
 getMarkerPosition(value: ScaleDataValue[],dims?: typeof dimPermutations[number],startingAtTick?: boolean) {const coordSys = this.coordinateSystem;if (coordSys && coordSys.clampData) {// PENDING if clamp ?const clampData = coordSys.clampData(value);const pt = coordSys.dataToPoint(clampData);if (startingAtTick) {each(coordSys.getAxes(), function (axis: Axis2D, idx: number) {// If axis type is category, use tick coords insteadif (axis.type === 'category' && dims != null) {const tickCoords = axis.getTicksCoords();const alignTicksWithLabel = axis.getTickModel().get('alignWithLabel');//targetTickValue 作为变量名比 targetTickId 更能准确地表达其含义let targetTickId = clampData[idx];// The index of rightmost tick of markArea is 1 larger than x1/y1 indexconst isEnd = dims[idx] === 'x1' || dims[idx] === 'y1';if (isEnd && !alignTicksWithLabel) {targetTickId += 1;}// The only contains one tick, tickCoords is// like [{coord: 0, tickValue: 0}, {coord: 0}]// to the length should always be larger than 1if (tickCoords.length < 2) {return;}else if (tickCoords.length === 2) {// The left value and right value of the axis are// the same. coord is 0 in both items. Use the max// value of the axis as the coordpt[idx] = axis.toGlobalCoord(axis.getExtent()[isEnd ? 1 : 0]);return;}let leftCoord;let coord;let stepTickValue = 1;for (let i = 0; i < tickCoords.length; i++) {const tickCoord = tickCoords[i].coord;// The last item of tickCoords doesn't contain// tickValueconst tickValue = i === tickCoords.length - 1? tickCoords[i - 1].tickValue + stepTickValue//对于最后一个刻度(i === tickCoords.length - 1),由于它通常表示轴的边界,//所以我们用前一个刻度的 tickValue 加上步长 (stepTickValue) 来模拟最后一个刻度的值。: tickCoords[i].tickValue;if (tickValue === targetTickId) {coord = tickCoord;break;}else if (tickValue < targetTickId) {leftCoord = tickCoord;}else if (leftCoord != null && tickValue > targetTickId) {coord = (tickCoord + leftCoord) / 2;break;}if (i === 1) {// Here we assume the step of category axes is// the samestepTickValue = tickValue - tickCoords[0].tickValue;}}if (coord == null) {if (!leftCoord) {// targetTickId is smaller than all tick ids in the// visible area, use the leftmost tick coordcoord = tickCoords[0].coord;}else if (leftCoord) {// targetTickId is larger than all tick ids in the// visible area, use the rightmost tick coordcoord = tickCoords[tickCoords.length - 1].coord;}}pt[idx] = axis.toGlobalCoord(coord);}});}else {const data = this.getData();const offset = data.getLayout('offset');const size = data.getLayout('size');const offsetIndex = (coordSys as Cartesian2D).getBaseAxis().isHorizontal() ? 0 : 1;pt[offsetIndex] += offset + size / 2;}return pt;}return [NaN, NaN];}

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 《Linux从入门到进阶》第一节 初识Linux
  • 科普文:JUC系列之ForkJoinPool源码解读ForkJoinWorkerThread
  • 悠易科技周文彪:创始人专注度很重要,一旦战略分散无法形成合力 | 中国广告营销行业资本报告深访④
  • LeetCode | 441 | 排列硬币 | 二分查找
  • 计算机组成原理 —— 指令流水线影响因素分类
  • 提示词工程
  • 微信小程序--实现地图定位---获取经纬度
  • 打造智能障碍物检测系统:从零开始的深度学习项目
  • 【启明智显方案分享】6.86寸高清显示屏音频效果器解决方案
  • 基于NSGAII的的柔性作业调度优化算法MATLAB仿真,仿真输出甘特图
  • shell常用命令
  • 超越标注:合成数据引领下的文本嵌入技术革新
  • 科普文:JUC系列之多线程门闩同步器Semaphore的使用和源码解读
  • FreeRTOS实现低功耗管理
  • 如何将PostgreSQL的数据实时迁移到SelectDB?
  • 《剑指offer》分解让复杂问题更简单
  • 【Under-the-hood-ReactJS-Part0】React源码解读
  • 2017-09-12 前端日报
  • 345-反转字符串中的元音字母
  • Dubbo 整合 Pinpoint 做分布式服务请求跟踪
  • gulp 教程
  • HashMap剖析之内部结构
  • Linux编程学习笔记 | Linux IO学习[1] - 文件IO
  • MySQL常见的两种存储引擎:MyISAM与InnoDB的爱恨情仇
  • Vim 折腾记
  • vue-cli在webpack的配置文件探究
  • Webpack4 学习笔记 - 01:webpack的安装和简单配置
  • 阿里云爬虫风险管理产品商业化,为云端流量保驾护航
  • 对JS继承的一点思考
  • 模仿 Go Sort 排序接口实现的自定义排序
  • 七牛云假注销小指南
  • 我这样减少了26.5M Java内存!
  • 异步
  • 用element的upload组件实现多图片上传和压缩
  • 正则学习笔记
  • 3月27日云栖精选夜读 | 从 “城市大脑”实践,瞭望未来城市源起 ...
  • ​Benvista PhotoZoom Pro 9.0.4新功能介绍
  • #pragam once 和 #ifndef 预编译头
  • $L^p$ 调和函数恒为零
  • (1)(1.9) MSP (version 4.2)
  • (10)ATF MMU转换表
  • (Matlab)基于蝙蝠算法实现电力系统经济调度
  • (二十六)Java 数据结构
  • (四)七种元启发算法(DBO、LO、SWO、COA、LSO、KOA、GRO)求解无人机路径规划MATLAB
  • (一)SvelteKit教程:hello world
  • (轉貼) VS2005 快捷键 (初級) (.NET) (Visual Studio)
  • .net core 管理用户机密
  • .NET高级面试指南专题十一【 设计模式介绍,为什么要用设计模式】
  • .NET轻量级ORM组件Dapper葵花宝典
  • .Net转前端开发-启航篇,如何定制博客园主题
  • @TableId注解详细介绍 mybaits 实体类主键注解
  • [1204 寻找子串位置] 解题报告
  • [51nod1610]路径计数
  • [C++]指针与结构体
  • [ERROR] ocp-server-ce-py_script_start_check-4.2.1 RuntimeError: ‘tenant_name‘