Нет описания
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

DataZoom.cs 29KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. namespace XCharts.Runtime
  4. {
  5. /// <summary>
  6. /// DataZoom component is used for zooming a specific area,
  7. /// which enables user to investigate data in detail,
  8. /// or get an overview of the data, or get rid of outlier points.
  9. /// |DataZoom 组件 用于区域缩放,从而能自由关注细节的数据信息,或者概览数据整体,或者去除离群点的影响。
  10. /// </summary>
  11. [System.Serializable]
  12. [ComponentHandler(typeof(DataZoomHandler), true)]
  13. public class DataZoom : MainComponent, IUpdateRuntimeData
  14. {
  15. /// <summary>
  16. /// Generally dataZoom component zoom or roam coordinate system through data filtering
  17. /// and set the windows of axes internally.
  18. /// Its behaviours vary according to filtering mode settings.
  19. /// |dataZoom 的运行原理是通过 数据过滤 来达到 数据窗口缩放 的效果。数据过滤模式的设置不同,效果也不同。
  20. /// </summary>
  21. public enum FilterMode
  22. {
  23. /// <summary>
  24. /// data that outside the window will be filtered, which may lead to some changes of windows of other axes.
  25. /// For each data item, it will be filtered if one of the relevant dimensions is out of the window.
  26. /// |当前数据窗口外的数据,被 过滤掉。即 会 影响其他轴的数据范围。每个数据项,只要有一个维度在数据窗口外,整个数据项就会被过滤掉。
  27. /// </summary>
  28. Filter,
  29. /// <summary>
  30. /// data that outside the window will be filtered, which may lead to some changes of windows of other axes.
  31. /// For each data item, it will be filtered only if all of the relevant dimensions are out of the same side of the window.
  32. /// |当前数据窗口外的数据,被 过滤掉。即 会 影响其他轴的数据范围。每个数据项,只有当全部维度都在数据窗口同侧外部,整个数据项才会被过滤掉。
  33. /// </summary>
  34. WeakFilter,
  35. /// <summary>
  36. /// data that outside the window will be set to NaN, which will not lead to changes of windows of other axes.
  37. /// |当前数据窗口外的数据,被 设置为空。即 不会 影响其他轴的数据范围。
  38. /// </summary>
  39. Empty,
  40. /// <summary>
  41. /// Do not filter data.
  42. /// |不过滤数据,只改变数轴范围。
  43. /// </summary>
  44. None
  45. }
  46. /// <summary>
  47. /// The value type of start and end.取值类型
  48. /// </summary>
  49. public enum RangeMode
  50. {
  51. //Value,
  52. /// <summary>
  53. /// percent value.
  54. /// |百分比。
  55. /// </summary>
  56. Percent
  57. }
  58. [SerializeField] private bool m_Enable = true;
  59. [SerializeField] private FilterMode m_FilterMode;
  60. [SerializeField] private List<int> m_XAxisIndexs = new List<int>() { 0 };
  61. [SerializeField] private List<int> m_YAxisIndexs = new List<int>() { };
  62. [SerializeField] private bool m_SupportInside;
  63. [SerializeField] private bool m_SupportInsideScroll = true;
  64. [SerializeField] private bool m_SupportInsideDrag = true;
  65. [SerializeField] private bool m_SupportSlider;
  66. [SerializeField] private bool m_SupportMarquee;
  67. [SerializeField] private bool m_ShowDataShadow;
  68. [SerializeField] private bool m_ShowDetail;
  69. [SerializeField] private bool m_ZoomLock;
  70. //[SerializeField] private bool m_Realtime;
  71. [SerializeField] protected Color32 m_FillerColor;
  72. [SerializeField] protected Color32 m_BorderColor;
  73. [SerializeField] protected float m_BorderWidth;
  74. [SerializeField] protected Color32 m_BackgroundColor;
  75. [SerializeField] private float m_Left;
  76. [SerializeField] private float m_Right;
  77. [SerializeField] private float m_Top;
  78. [SerializeField] private float m_Bottom;
  79. [SerializeField] private RangeMode m_RangeMode;
  80. [SerializeField] private float m_Start;
  81. [SerializeField] private float m_End;
  82. [SerializeField] private int m_MinShowNum = 1;
  83. [Range(1f, 20f)]
  84. [SerializeField] private float m_ScrollSensitivity = 1.1f;
  85. [SerializeField] private Orient m_Orient = Orient.Horizonal;
  86. [SerializeField] private LabelStyle m_LabelStyle = new LabelStyle();
  87. [SerializeField] private LineStyle m_LineStyle = new LineStyle(LineStyle.Type.Solid);
  88. [SerializeField] private AreaStyle m_AreaStyle = new AreaStyle();
  89. [SerializeField][Since("v3.5.0")] private MarqueeStyle m_MarqueeStyle = new MarqueeStyle();
  90. [SerializeField][Since("v3.6.0")] private bool m_StartLock;
  91. [SerializeField][Since("v3.6.0")] private bool m_EndLock;
  92. public DataZoomContext context = new DataZoomContext();
  93. private CustomDataZoomStartEndFunction m_StartEndFunction;
  94. /// <summary>
  95. /// Whether to show dataZoom.
  96. /// |是否显示缩放区域。
  97. /// </summary>
  98. public bool enable
  99. {
  100. get { return m_Enable; }
  101. set { if (PropertyUtil.SetStruct(ref m_Enable, value)) SetVerticesDirty(); }
  102. }
  103. /// <summary>
  104. /// The mode of data filter.
  105. /// |数据过滤类型。
  106. /// </summary>
  107. public FilterMode filterMode
  108. {
  109. get { return m_FilterMode; }
  110. set { if (PropertyUtil.SetStruct(ref m_FilterMode, value)) SetVerticesDirty(); }
  111. }
  112. /// <summary>
  113. /// Specify which xAxis is controlled by the dataZoom.
  114. /// |控制的 x 轴索引列表。
  115. /// </summary>
  116. public List<int> xAxisIndexs
  117. {
  118. get { return m_XAxisIndexs; }
  119. set { if (PropertyUtil.SetClass(ref m_XAxisIndexs, value)) SetVerticesDirty(); }
  120. }
  121. /// <summary>
  122. /// Specify which yAxis is controlled by the dataZoom.
  123. /// |控制的 y 轴索引列表。
  124. /// </summary>
  125. public List<int> yAxisIndexs
  126. {
  127. get { return m_YAxisIndexs; }
  128. set { if (PropertyUtil.SetClass(ref m_YAxisIndexs, value)) SetVerticesDirty(); }
  129. }
  130. /// <summary>
  131. /// Whether built-in support is supported.
  132. /// Built into the coordinate system to allow the user to zoom in and out of the coordinate system by mouse dragging,
  133. /// mouse wheel, finger swiping (on the touch screen).
  134. /// |是否支持内置。内置于坐标系中,使用户可以在坐标系上通过鼠标拖拽、鼠标滚轮、手指滑动(触屏上)来缩放或漫游坐标系。
  135. /// </summary>
  136. public bool supportInside
  137. {
  138. get { return m_SupportInside; }
  139. set { if (PropertyUtil.SetStruct(ref m_SupportInside, value)) SetVerticesDirty(); }
  140. }
  141. /// <summary>
  142. /// Whether inside scrolling is supported.
  143. /// |是否支持坐标系内滚动
  144. /// </summary>
  145. public bool supportInsideScroll
  146. {
  147. get { return m_SupportInsideScroll; }
  148. set { if (PropertyUtil.SetStruct(ref m_SupportInsideScroll, value)) SetVerticesDirty(); }
  149. }
  150. /// <summary>
  151. /// Whether insde drag is supported.
  152. /// |是否支持坐标系内拖拽
  153. /// </summary>
  154. public bool supportInsideDrag
  155. {
  156. get { return m_SupportInsideDrag; }
  157. set { if (PropertyUtil.SetStruct(ref m_SupportInsideDrag, value)) SetVerticesDirty(); }
  158. }
  159. /// <summary>
  160. /// Whether a slider is supported. There are separate sliders on which the user zooms or roams.
  161. /// |是否支持滑动条。有单独的滑动条,用户在滑动条上进行缩放或漫游。
  162. /// </summary>
  163. public bool supportSlider
  164. {
  165. get { return m_SupportSlider; }
  166. set { if (PropertyUtil.SetStruct(ref m_SupportSlider, value)) SetVerticesDirty(); }
  167. }
  168. /// <summary>
  169. /// Supported Box Selected. Provides a marquee for scaling the data area.
  170. /// |是否支持框选。提供一个选框进行数据区域缩放。
  171. /// </summary>
  172. public bool supportMarquee
  173. {
  174. get { return m_SupportMarquee; }
  175. set { if (PropertyUtil.SetStruct(ref m_SupportMarquee, value)) SetVerticesDirty(); }
  176. }
  177. /// <summary>
  178. /// Whether to show data shadow, to indicate the data tendency in brief.
  179. /// |是否显示数据阴影。数据阴影可以简单地反应数据走势。
  180. /// </summary>
  181. public bool showDataShadow
  182. {
  183. get { return m_ShowDataShadow; }
  184. set { if (PropertyUtil.SetStruct(ref m_ShowDataShadow, value)) SetVerticesDirty(); }
  185. }
  186. /// <summary>
  187. /// Whether to show detail, that is, show the detailed data information when dragging.
  188. /// |是否显示detail,即拖拽时候显示详细数值信息。
  189. /// </summary>
  190. public bool showDetail
  191. {
  192. get { return m_ShowDetail; }
  193. set { if (PropertyUtil.SetStruct(ref m_ShowDetail, value)) SetVerticesDirty(); }
  194. }
  195. /// <summary>
  196. /// Specify whether to lock the size of window (selected area).
  197. /// |是否锁定选择区域(或叫做数据窗口)的大小。
  198. /// 如果设置为 true 则锁定选择区域的大小,也就是说,只能平移,不能缩放。
  199. /// </summary>
  200. public bool zoomLock
  201. {
  202. get { return m_ZoomLock; }
  203. set { if (PropertyUtil.SetStruct(ref m_ZoomLock, value)) SetVerticesDirty(); }
  204. }
  205. /// <summary>
  206. /// Whether to show data shadow in dataZoom-silder component, to indicate the data tendency in brief.
  207. /// |拖动时,是否实时更新系列的视图。如果设置为 false,则只在拖拽结束的时候更新。默认为true,暂不支持修改。
  208. /// </summary>
  209. public bool realtime { get { return true; } }
  210. /// <summary>
  211. /// The background color of the component.
  212. /// |组件的背景颜色。
  213. /// </summary>
  214. public Color backgroundColor
  215. {
  216. get { return m_BackgroundColor; }
  217. set { if (PropertyUtil.SetStruct(ref m_BackgroundColor, value)) SetVerticesDirty(); }
  218. }
  219. /// <summary>
  220. /// the color of dataZoom data area.
  221. /// |数据区域颜色。
  222. /// </summary>
  223. public Color32 fillerColor
  224. {
  225. get { return m_FillerColor; }
  226. set { if (PropertyUtil.SetColor(ref m_FillerColor, value)) SetVerticesDirty(); }
  227. }
  228. /// <summary>
  229. /// the color of dataZoom border.
  230. /// |边框颜色。
  231. /// </summary>
  232. public Color32 borderColor
  233. {
  234. get { return m_BorderColor; }
  235. set { if (PropertyUtil.SetColor(ref m_BorderColor, value)) SetComponentDirty(); }
  236. }
  237. /// <summary>
  238. /// 边框宽。
  239. /// </summary>
  240. public float borderWidth
  241. {
  242. get { return m_BorderWidth; }
  243. set { if (PropertyUtil.SetStruct(ref m_BorderWidth, value)) SetComponentDirty(); }
  244. }
  245. /// <summary>
  246. /// Distance between dataZoom component and the bottom side of the container.
  247. /// bottom value is a instant pixel value like 10 or float value [0-1].
  248. /// |组件离容器下侧的距离。
  249. /// </summary>
  250. public float bottom
  251. {
  252. get { return m_Bottom; }
  253. set { if (PropertyUtil.SetStruct(ref m_Bottom, value)) SetVerticesDirty(); }
  254. }
  255. /// <summary>
  256. /// Distance between dataZoom component and the top side of the container.
  257. /// top value is a instant pixel value like 10 or float value [0-1].
  258. /// |组件离容器上侧的距离。
  259. /// </summary>
  260. public float top
  261. {
  262. get { return m_Top; }
  263. set { if (PropertyUtil.SetStruct(ref m_Top, value)) SetVerticesDirty(); }
  264. }
  265. /// <summary>
  266. /// Distance between dataZoom component and the left side of the container.
  267. /// left value is a instant pixel value like 10 or float value [0-1].
  268. /// |组件离容器左侧的距离。
  269. /// </summary>
  270. public float left
  271. {
  272. get { return m_Left; }
  273. set { if (PropertyUtil.SetStruct(ref m_Left, value)) SetVerticesDirty(); }
  274. }
  275. /// <summary>
  276. /// Distance between dataZoom component and the right side of the container.
  277. /// right value is a instant pixel value like 10 or float value [0-1].
  278. /// |组件离容器右侧的距离。
  279. /// </summary>
  280. public float right
  281. {
  282. get { return m_Right; }
  283. set { if (PropertyUtil.SetStruct(ref m_Right, value)) SetVerticesDirty(); }
  284. }
  285. /// <summary>
  286. /// Use absolute value or percent value in DataZoom.start and DataZoom.end.
  287. /// |取绝对值还是百分比。
  288. /// </summary>
  289. public RangeMode rangeMode
  290. {
  291. get { return m_RangeMode; }
  292. set { if (PropertyUtil.SetStruct(ref m_RangeMode, value)) SetVerticesDirty(); }
  293. }
  294. /// <summary>
  295. /// The start percentage of the window out of the data extent, in the range of 0 ~ 100.
  296. /// |数据窗口范围的起始百分比。范围是:0 ~ 100。
  297. /// </summary>
  298. public float start
  299. {
  300. get { return m_Start; }
  301. set { m_Start = value; if (m_Start < 0) m_Start = 0; if (m_Start > 100) m_Start = 100; SetVerticesDirty(); }
  302. }
  303. /// <summary>
  304. /// Lock start value.
  305. /// |固定起始值,不让改变。
  306. /// </summary>
  307. public bool startLock
  308. {
  309. get { return m_StartLock; }
  310. set { if (PropertyUtil.SetStruct(ref m_StartLock, value)) SetVerticesDirty(); }
  311. }
  312. /// <summary>
  313. /// Lock end value.
  314. /// |固定结束值,不让改变。
  315. /// </summary>
  316. public bool endLock
  317. {
  318. get { return m_EndLock; }
  319. set { if (PropertyUtil.SetStruct(ref m_EndLock, value)) SetVerticesDirty(); }
  320. }
  321. /// <summary>
  322. /// The end percentage of the window out of the data extent, in the range of 0 ~ 100.
  323. /// |数据窗口范围的结束百分比。范围是:0 ~ 100。
  324. /// </summary>
  325. public float end
  326. {
  327. get { return m_End; }
  328. set { m_End = value; if (m_End < 0) m_End = 0; if (m_End > 100) m_End = 100; SetVerticesDirty(); }
  329. }
  330. /// <summary>
  331. /// Minimum number of display data. Minimum number of data displayed when DataZoom is enlarged to maximum.
  332. /// |最小显示数据个数。当DataZoom放大到最大时,最小显示的数据个数。
  333. /// </summary>
  334. public int minShowNum
  335. {
  336. get { return m_MinShowNum; }
  337. set { if (PropertyUtil.SetStruct(ref m_MinShowNum, value)) SetVerticesDirty(); }
  338. }
  339. /// <summary>
  340. /// The sensitivity of dataZoom scroll.
  341. /// The larger the number, the more sensitive it is.
  342. /// |缩放区域组件的敏感度。值越高每次缩放所代表的数据越多。
  343. /// </summary>
  344. public float scrollSensitivity
  345. {
  346. get { return m_ScrollSensitivity; }
  347. set { if (PropertyUtil.SetStruct(ref m_ScrollSensitivity, value)) SetVerticesDirty(); }
  348. }
  349. /// <summary>
  350. /// Specify whether the layout of dataZoom component is horizontal or vertical. What's more,
  351. /// it indicates whether the horizontal axis or vertical axis is controlled by default in catesian coordinate system.
  352. /// |布局方式是横还是竖。不仅是布局方式,对于直角坐标系而言,也决定了,缺省情况控制横向数轴还是纵向数轴。
  353. /// </summary>
  354. public Orient orient
  355. {
  356. get { return m_Orient; }
  357. set { if (PropertyUtil.SetStruct(ref m_Orient, value)) SetVerticesDirty(); }
  358. }
  359. /// <summary>
  360. /// label style.
  361. /// |文本标签格式。
  362. /// </summary>
  363. public LabelStyle labelStyle
  364. {
  365. get { return m_LabelStyle; }
  366. set { if (PropertyUtil.SetClass(ref m_LabelStyle, value)) SetComponentDirty(); }
  367. }
  368. /// <summary>
  369. /// 阴影线条样式。
  370. /// </summary>
  371. public LineStyle lineStyle
  372. {
  373. get { return m_LineStyle; }
  374. set { if (PropertyUtil.SetClass(ref m_LineStyle, value)) SetComponentDirty(); }
  375. }
  376. /// <summary>
  377. /// 阴影填充样式。
  378. /// </summary>
  379. public AreaStyle areaStyle
  380. {
  381. get { return m_AreaStyle; }
  382. set { if (PropertyUtil.SetClass(ref m_AreaStyle, value)) SetComponentDirty(); }
  383. }
  384. /// <summary>
  385. /// 选取框样式。
  386. /// </summary>
  387. public MarqueeStyle marqueeStyle
  388. {
  389. get { return m_MarqueeStyle; }
  390. set { if (PropertyUtil.SetClass(ref m_MarqueeStyle, value)) SetAllDirty(); }
  391. }
  392. /// <summary>
  393. /// start和end变更委托。
  394. /// </summary>
  395. public CustomDataZoomStartEndFunction startEndFunction { get { return m_StartEndFunction; } set { m_StartEndFunction = value; } }
  396. class AxisIndexValueInfo
  397. {
  398. public double rawMin;
  399. public double rawMax;
  400. public double min;
  401. public double max;
  402. }
  403. private Dictionary<int, AxisIndexValueInfo> m_XAxisIndexInfos = new Dictionary<int, AxisIndexValueInfo>();
  404. private Dictionary<int, AxisIndexValueInfo> m_YAxisIndexInfos = new Dictionary<int, AxisIndexValueInfo>();
  405. /// <summary>
  406. /// The start label.
  407. /// |组件的开始信息文本。
  408. /// </summary>
  409. private ChartLabel m_StartLabel { get; set; }
  410. /// <summary>
  411. /// The end label.
  412. /// |组件的结束信息文本。
  413. /// </summary>
  414. private ChartLabel m_EndLabel { get; set; }
  415. public override void SetDefaultValue()
  416. {
  417. supportInside = true;
  418. supportSlider = true;
  419. filterMode = FilterMode.None;
  420. xAxisIndexs = new List<int>() { 0 };
  421. yAxisIndexs = new List<int>() { };
  422. showDataShadow = true;
  423. showDetail = false;
  424. zoomLock = false;
  425. m_Bottom = 10;
  426. m_Left = 10;
  427. m_Right = 10;
  428. m_Top = 0.9f;
  429. rangeMode = RangeMode.Percent;
  430. start = 30;
  431. end = 70;
  432. m_Orient = Orient.Horizonal;
  433. m_ScrollSensitivity = 10;
  434. m_LabelStyle = new LabelStyle();
  435. m_LineStyle = new LineStyle(LineStyle.Type.Solid)
  436. {
  437. opacity = 0.3f
  438. };
  439. m_AreaStyle = new AreaStyle()
  440. {
  441. show = true,
  442. opacity = 0.3f
  443. };
  444. m_MarqueeStyle = new MarqueeStyle();
  445. }
  446. /// <summary>
  447. /// 给定的坐标是否在缩放区域内
  448. /// </summary>
  449. /// <param name="pos"></param>
  450. /// <param name="startX"></param>
  451. /// <param name="width"></param>
  452. /// <returns></returns>
  453. public bool IsInZoom(Vector2 pos)
  454. {
  455. if (pos.x < context.x - 1 || pos.x > context.x + context.width + 1 ||
  456. pos.y < context.y - 1 || pos.y > context.y + context.height + 1)
  457. {
  458. return false;
  459. }
  460. return true;
  461. }
  462. /// <summary>
  463. /// 给定的坐标是否在选中区域内
  464. /// </summary>
  465. /// <param name="pos"></param>
  466. /// <returns></returns>
  467. public bool IsInSelectedZoom(Vector2 pos)
  468. {
  469. switch (m_Orient)
  470. {
  471. case Orient.Horizonal:
  472. var start = context.x + context.width * m_Start / 100;
  473. var end = context.x + context.width * m_End / 100;
  474. return ChartHelper.IsInRect(pos, start, end, context.y, context.y + context.height);
  475. case Orient.Vertical:
  476. start = context.y + context.height * m_Start / 100;
  477. end = context.y + context.height * m_End / 100;
  478. return ChartHelper.IsInRect(pos, context.x, context.x + context.width, start, end);
  479. default:
  480. return false;
  481. }
  482. }
  483. public bool IsInSelectedZoom(int totalIndex, int index, bool invert)
  484. {
  485. if (totalIndex <= 0)
  486. return false;
  487. var tstart = invert ? 100 - end : start;
  488. var tend = invert ? 100 - start : end;
  489. var range = Mathf.RoundToInt(totalIndex * (tend - tstart) / 100);
  490. var min = Mathf.FloorToInt(totalIndex * tstart / 100);
  491. var max = Mathf.CeilToInt(totalIndex * tend / 100);
  492. if (min == 0) max = min + range;
  493. if (max == totalIndex) min = max - range;
  494. var flag = index >= min && index < min + range;
  495. return flag;
  496. }
  497. /// <summary>
  498. /// 给定的坐标是否在开始活动条触发区域内
  499. /// </summary>
  500. /// <param name="pos"></param>
  501. /// <param name="startX"></param>
  502. /// <param name="width"></param>
  503. /// <returns></returns>
  504. public bool IsInStartZoom(Vector2 pos)
  505. {
  506. switch (m_Orient)
  507. {
  508. case Orient.Horizonal:
  509. var start = context.x + context.width * m_Start / 100;
  510. return ChartHelper.IsInRect(pos, start - 10, start + 10, context.y, context.y + context.height);
  511. case Orient.Vertical:
  512. start = context.y + context.height * m_Start / 100;
  513. return ChartHelper.IsInRect(pos, context.x, context.x + context.width, start - 10, start + 10);
  514. default:
  515. return false;
  516. }
  517. }
  518. /// <summary>
  519. /// 给定的坐标是否在结束活动条触发区域内
  520. /// </summary>
  521. /// <param name="pos"></param>
  522. /// <param name="startX"></param>
  523. /// <param name="width"></param>
  524. /// <returns></returns>
  525. public bool IsInEndZoom(Vector2 pos)
  526. {
  527. switch (m_Orient)
  528. {
  529. case Orient.Horizonal:
  530. var end = context.x + context.width * m_End / 100;
  531. return ChartHelper.IsInRect(pos, end - 10, end + 10, context.y, context.y + context.height);
  532. case Orient.Vertical:
  533. end = context.y + context.height * m_End / 100;
  534. return ChartHelper.IsInRect(pos, context.x, context.x + context.width, end - 10, end + 10);
  535. default:
  536. return false;
  537. }
  538. }
  539. public bool IsInMarqueeArea(SerieData serieData)
  540. {
  541. return IsInMarqueeArea(serieData.context.position);
  542. }
  543. public bool IsInMarqueeArea(Vector2 pos)
  544. {
  545. if (!supportMarquee) return false;
  546. if (context.marqueeRect.width >= 0)
  547. {
  548. return context.marqueeRect.Contains(pos);
  549. }
  550. else
  551. {
  552. var rect = context.marqueeRect;
  553. return (new Rect(rect.x + rect.width, rect.y, -rect.width, rect.height)).Contains(pos);
  554. }
  555. }
  556. public bool IsContainsAxis(Axis axis)
  557. {
  558. if (axis == null)
  559. return false;
  560. else if (axis is XAxis)
  561. return xAxisIndexs.Contains(axis.index);
  562. else if (axis is YAxis)
  563. return yAxisIndexs.Contains(axis.index);
  564. else
  565. return false;
  566. }
  567. public bool IsContainsXAxis(int index)
  568. {
  569. return xAxisIndexs != null && xAxisIndexs.Contains(index);
  570. }
  571. public bool IsContainsYAxis(int index)
  572. {
  573. return yAxisIndexs != null && yAxisIndexs.Contains(index);
  574. }
  575. public Color32 GetFillerColor(Color32 themeColor)
  576. {
  577. if (ChartHelper.IsClearColor(fillerColor))
  578. return themeColor;
  579. else
  580. return fillerColor;
  581. }
  582. public Color32 GetBackgroundColor(Color32 themeColor)
  583. {
  584. if (ChartHelper.IsClearColor(backgroundColor))
  585. return themeColor;
  586. else
  587. return backgroundColor;
  588. }
  589. public Color32 GetBorderColor(Color32 themeColor)
  590. {
  591. if (ChartHelper.IsClearColor(borderColor))
  592. return themeColor;
  593. else
  594. return borderColor;
  595. }
  596. /// <summary>
  597. /// 是否显示文本
  598. /// </summary>
  599. /// <param name="flag"></param>
  600. internal void SetLabelActive(bool flag)
  601. {
  602. m_StartLabel.SetActive(flag);
  603. m_EndLabel.SetActive(flag);
  604. }
  605. /// <summary>
  606. /// 设置开始文本内容
  607. /// </summary>
  608. /// <param name="text"></param>
  609. internal void SetStartLabelText(string text)
  610. {
  611. if (m_StartLabel != null) m_StartLabel.SetText(text);
  612. }
  613. /// <summary>
  614. /// 设置结束文本内容
  615. /// </summary>
  616. /// <param name="text"></param>
  617. internal void SetEndLabelText(string text)
  618. {
  619. if (m_EndLabel != null) m_EndLabel.SetText(text);
  620. }
  621. internal void SetStartLabel(ChartLabel startLabel)
  622. {
  623. m_StartLabel = startLabel;
  624. }
  625. internal void SetEndLabel(ChartLabel endLabel)
  626. {
  627. m_EndLabel = endLabel;
  628. }
  629. internal void UpdateStartLabelPosition(Vector3 pos)
  630. {
  631. if (m_StartLabel != null) m_StartLabel.SetPosition(pos);
  632. }
  633. internal void UpdateEndLabelPosition(Vector3 pos)
  634. {
  635. if (m_EndLabel != null) m_EndLabel.SetPosition(pos);
  636. }
  637. public void UpdateRuntimeData(float chartX, float chartY, float chartWidth, float chartHeight)
  638. {
  639. var runtimeLeft = left <= 1 ? left * chartWidth : left;
  640. var runtimeBottom = bottom <= 1 ? bottom * chartHeight : bottom;
  641. var runtimeTop = top <= 1 ? top * chartHeight : top;
  642. var runtimeRight = right <= 1 ? right * chartWidth : right;
  643. context.x = chartX + runtimeLeft;
  644. context.y = chartY + runtimeBottom;
  645. context.width = chartWidth - runtimeLeft - runtimeRight;
  646. context.height = chartHeight - runtimeTop - runtimeBottom;
  647. }
  648. internal void SetXAxisIndexValueInfo(int xAxisIndex, ref double min, ref double max)
  649. {
  650. AxisIndexValueInfo info;
  651. if (!m_XAxisIndexInfos.TryGetValue(xAxisIndex, out info))
  652. {
  653. info = new AxisIndexValueInfo();
  654. m_XAxisIndexInfos[xAxisIndex] = info;
  655. }
  656. info.rawMin = min;
  657. info.rawMax = max;
  658. info.min = min + (max - min) * start / 100;
  659. info.max = min + (max - min) * end / 100;
  660. min = info.min;
  661. max = info.max;
  662. }
  663. internal void SetYAxisIndexValueInfo(int yAxisIndex, ref double min, ref double max)
  664. {
  665. AxisIndexValueInfo info;
  666. if (!m_YAxisIndexInfos.TryGetValue(yAxisIndex, out info))
  667. {
  668. info = new AxisIndexValueInfo();
  669. m_YAxisIndexInfos[yAxisIndex] = info;
  670. }
  671. info.rawMin = min;
  672. info.rawMax = max;
  673. info.min = min + (max - min) * start / 100;
  674. info.max = min + (max - min) * end / 100;
  675. min = info.min;
  676. max = info.max;
  677. }
  678. internal bool IsXAxisIndexValue(int axisIndex)
  679. {
  680. return m_XAxisIndexInfos.ContainsKey(axisIndex);
  681. }
  682. internal bool IsYAxisIndexValue(int axisIndex)
  683. {
  684. return m_YAxisIndexInfos.ContainsKey(axisIndex);
  685. }
  686. internal void GetXAxisIndexValue(int axisIndex, out double min, out double max)
  687. {
  688. AxisIndexValueInfo info;
  689. if (m_XAxisIndexInfos.TryGetValue(axisIndex, out info))
  690. {
  691. var range = info.rawMax - info.rawMin;
  692. min = info.rawMin + range * m_Start / 100;
  693. max = info.rawMin + range * m_End / 100;
  694. }
  695. else
  696. {
  697. min = 0;
  698. max = 0;
  699. }
  700. }
  701. internal void GetYAxisIndexValue(int axisIndex, out double min, out double max)
  702. {
  703. AxisIndexValueInfo info;
  704. if (m_YAxisIndexInfos.TryGetValue(axisIndex, out info))
  705. {
  706. var range = info.rawMax - info.rawMin;
  707. min = info.rawMin + range * m_Start / 100;
  708. max = info.rawMin + range * m_End / 100;
  709. }
  710. else
  711. {
  712. min = 0;
  713. max = 0;
  714. }
  715. }
  716. }
  717. }