No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DataZoom.cs 28KB

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