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.

Tooltip.cs 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  1. using System.Collections.Generic;
  2. using System.Text;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using XUGL;
  6. namespace XCharts.Runtime
  7. {
  8. /// <summary>
  9. /// Tooltip component.
  10. /// |提示框组件。
  11. /// </summary>
  12. [System.Serializable]
  13. [ComponentHandler(typeof(TooltipHandler), true)]
  14. public class Tooltip : MainComponent
  15. {
  16. /// <summary>
  17. /// Indicator type.
  18. /// |指示器类型。
  19. /// </summary>
  20. public enum Type
  21. {
  22. /// <summary>
  23. /// line indicator.
  24. /// |直线指示器
  25. /// </summary>
  26. Line,
  27. /// <summary>
  28. /// shadow crosshair indicator.
  29. /// |阴影指示器
  30. /// </summary>
  31. Shadow,
  32. /// <summary>
  33. /// no indicator displayed.
  34. /// |无指示器
  35. /// </summary>
  36. None,
  37. /// <summary>
  38. /// crosshair indicator, which is actually the shortcut of enable two axisPointers of two orthometric axes.
  39. /// |十字准星指示器。坐标轴显示Label和交叉线。
  40. /// </summary>
  41. Corss
  42. }
  43. /// <summary>
  44. /// Trigger strategy.
  45. /// |触发类型。
  46. /// </summary>
  47. public enum Trigger
  48. {
  49. /// <summary>
  50. /// Triggered by data item, which is mainly used for charts that don't have a category axis like scatter charts or pie charts.
  51. /// |数据项图形触发,主要在散点图,饼图等无类目轴的图表中使用。
  52. /// </summary>
  53. Item,
  54. /// <summary>
  55. /// Triggered by axes, which is mainly used for charts that have category axes, like bar charts or line charts.
  56. /// |坐标轴触发,主要在柱状图,折线图等会使用类目轴的图表中使用。
  57. /// </summary>
  58. Axis,
  59. /// <summary>
  60. /// Trigger nothing.
  61. /// |什么都不触发。
  62. /// </summary>
  63. None
  64. }
  65. /// <summary>
  66. /// Position type.
  67. /// |坐标类型。
  68. /// </summary>
  69. public enum Position
  70. {
  71. /// <summary>
  72. /// Auto. The mobile platform is displayed at the top, and the non-mobile platform follows the mouse position.
  73. /// |自适应。移动平台靠顶部显示,非移动平台跟随鼠标位置。
  74. /// </summary>
  75. Auto,
  76. /// <summary>
  77. /// Custom. Fully customize display position (x,y).
  78. /// |自定义。完全自定义显示位置(x,y)。
  79. /// </summary>
  80. Custom,
  81. /// <summary>
  82. /// Just fix the coordinate X. Y follows the mouse position.
  83. /// |只固定坐标X。Y跟随鼠标位置。
  84. /// </summary>
  85. FixedX,
  86. /// <summary>
  87. /// Just fix the coordinate Y. X follows the mouse position.
  88. /// |只固定坐标Y。X跟随鼠标位置。
  89. FixedY
  90. }
  91. [SerializeField] private bool m_Show = true;
  92. [SerializeField] private Type m_Type;
  93. [SerializeField] private Trigger m_Trigger = Trigger.Item;
  94. [SerializeField][Since("v3.3.0")] private Position m_Position = Position.Auto;
  95. [SerializeField] private string m_ItemFormatter;
  96. [SerializeField] private string m_TitleFormatter;
  97. [SerializeField] private string m_Marker = "●";
  98. [SerializeField] private float m_FixedWidth = 0;
  99. [SerializeField] private float m_FixedHeight = 0;
  100. [SerializeField] private float m_MinWidth = 0;
  101. [SerializeField] private float m_MinHeight = 0;
  102. [SerializeField] private string m_NumericFormatter = "";
  103. [SerializeField] private int m_PaddingLeftRight = 10;
  104. [SerializeField] private int m_PaddingTopBottom = 10;
  105. [SerializeField] private bool m_IgnoreDataShow = false;
  106. [SerializeField] private string m_IgnoreDataDefaultContent = "-";
  107. [SerializeField] private bool m_ShowContent = true;
  108. [SerializeField] private bool m_AlwayShowContent = false;
  109. [SerializeField] private Vector2 m_Offset = new Vector2(18f, -25f);
  110. [SerializeField] private Sprite m_BackgroundImage;
  111. [SerializeField] private Image.Type m_BackgroundType = Image.Type.Simple;
  112. [SerializeField] private Color m_BackgroundColor;
  113. [SerializeField] private float m_BorderWidth = 2f;
  114. [SerializeField] private float m_FixedX = 0f;
  115. [SerializeField] private float m_FixedY = 0.7f;
  116. [SerializeField] private float m_TitleHeight = 25f;
  117. [SerializeField] private float m_ItemHeight = 25f;
  118. [SerializeField] private Color32 m_BorderColor = new Color32(230, 230, 230, 255);
  119. [SerializeField] private LineStyle m_LineStyle = new LineStyle(LineStyle.Type.None);
  120. [SerializeField]
  121. private LabelStyle m_TitleLabelStyle = new LabelStyle()
  122. {
  123. textStyle = new TextStyle() { alignment = TextAnchor.MiddleLeft }
  124. };
  125. [SerializeField]
  126. private List<LabelStyle> m_ContentLabelStyles = new List<LabelStyle>()
  127. {
  128. new LabelStyle() { textPadding = new TextPadding(0, 5, 0, 0), textStyle = new TextStyle() { alignment = TextAnchor.MiddleLeft } },
  129. new LabelStyle() { textPadding = new TextPadding(0, 20, 0, 0), textStyle = new TextStyle() { alignment = TextAnchor.MiddleLeft } },
  130. new LabelStyle() { textPadding = new TextPadding(0, 0, 0, 0), textStyle = new TextStyle() { alignment = TextAnchor.MiddleRight } }
  131. };
  132. public TooltipContext context = new TooltipContext();
  133. public TooltipView view;
  134. /// <summary>
  135. /// Whether to show the tooltip component.
  136. /// |是否显示提示框组件。
  137. /// </summary>
  138. public bool show
  139. {
  140. get { return m_Show; }
  141. set { if (PropertyUtil.SetStruct(ref m_Show, value)) { SetAllDirty(); SetActive(value); } }
  142. }
  143. /// <summary>
  144. /// Indicator type.
  145. /// |提示框指示器类型。
  146. /// </summary>
  147. public Type type
  148. {
  149. get { return m_Type; }
  150. set { if (PropertyUtil.SetStruct(ref m_Type, value)) SetAllDirty(); }
  151. }
  152. /// <summary>
  153. /// Type of triggering.
  154. /// |触发类型。
  155. /// </summary>
  156. public Trigger trigger
  157. {
  158. get { return m_Trigger; }
  159. set { if (PropertyUtil.SetStruct(ref m_Trigger, value)) SetAllDirty(); }
  160. }
  161. /// <summary>
  162. /// Type of position.
  163. /// |显示位置类型。
  164. /// </summary>
  165. public Position position
  166. {
  167. get { return m_Position; }
  168. set { if (PropertyUtil.SetStruct(ref m_Position, value)) SetAllDirty(); }
  169. }
  170. /// <summary>
  171. /// The string template formatter for the tooltip title content. Support for wrapping lines with \n.
  172. /// The placeholder {I} can be set separately to indicate that the title is ignored and not displayed.
  173. /// Template see itemFormatter.
  174. /// |提示框标题内容的字符串模版格式器。支持用 \n 换行。可以单独设置占位符{i}表示忽略不显示title。
  175. /// 模板变量有{.}、{a}、{b}、{c}、{d}、{e}、{f}、{g}。<br/>
  176. /// {.}为当前所指示或index为0的serie的对应颜色的圆点。<br/>
  177. /// {a}为当前所指示或index为0的serie的系列名name。<br/>
  178. /// {b}为当前所指示或index为0的serie的数据项serieData的name,或者类目值(如折线图的X轴)。<br/>
  179. /// {c}为当前所指示或index为0的serie的y维(dimesion为1)的数值。<br/>
  180. /// {d}为当前所指示或index为0的serie的y维(dimesion为1)百分比值,注意不带%号。<br/>
  181. /// {e}为当前所指示或index为0的serie的数据项serieData的name。<br/>
  182. /// {h}为当前所指示或index为0的serie的数据项serieData的十六进制颜色值。<br/>
  183. /// {f}为数据总和。<br/>
  184. /// {g}为数据总个数。<br/>
  185. /// {.1}表示指定index为1的serie对应颜色的圆点。<br/>
  186. /// {a1}、{b1}、{c1}中的1表示指定index为1的serie。<br/>
  187. /// {c1:2}表示索引为1的serie的当前指示数据项的第3个数据(一个数据项有多个数据,index为2表示第3个数据)。<br/>
  188. /// {c1:2-2}表示索引为1的serie的第3个数据项的第3个数据(也就是要指定第几个数据项时必须要指定第几个数据)。<br/>
  189. /// {d1:2:f2}表示单独指定了数值的格式化字符串为f2(不指定时用numericFormatter)。<br/>
  190. /// {d:0.##} 表示单独指定了数值的格式化字符串为 0.## (用于百分比,保留2位有效数同时又能避免使用 f2 而出现的类似于"100.00%"的情况 )。<br/>
  191. /// 示例:"{a}:{c}"、"{a1}:{c1:f1}"、"{a1}:{c1:0:f1}"、"{a1}:{c1:1-1:f1}"
  192. /// </summary>
  193. /// </summary>
  194. public string titleFormatter { get { return m_TitleFormatter; } set { m_TitleFormatter = value; } }
  195. /// <summary>
  196. /// a string template formatter for a single Serie or data item content. Support for wrapping lines with \n.
  197. /// Template variables are {.}, {a}, {b}, {c}, {d}.<br/>
  198. /// {.} is the dot of the corresponding color of a Serie that is currently indicated or whose index is 0.<br/>
  199. /// {a} is the series name of the serie that is currently indicated or whose index is 0.<br/>
  200. /// {b} is the name of the data item serieData that is currently indicated or whose index is 0, or a category value (such as the X-axis of a line chart).<br/>
  201. /// {c} is the value of a Y-dimension (dimesion is 1) from a Serie that is currently indicated or whose index is 0.<br/>
  202. /// {d} is the percentage value of Y-dimensions (dimesion is 1) from serie that is currently indicated or whose index is 0, with no % sign.<br/>
  203. /// {e} is the name of the data item serieData that is currently indicated or whose index is 0.<br/>
  204. /// {f} is sum of data.<br/>
  205. /// {.1} represents a dot from serie corresponding color that specifies index as 1.<br/>
  206. /// 1 in {a1}, {b1}, {c1} represents a serie that specifies an index of 1.<br/>
  207. /// {c1:2} represents the third data from serie's current indication data item indexed to 1 (a data item has multiple data, index 2 represents the third data).<br/>
  208. /// {c1:2-2} represents the third data item from serie's third data item indexed to 1 (i.e., which data item must be specified to specify).<br/>
  209. /// {d1:2: F2} indicates that a formatted string with a value specified separately is F2 (numericFormatter is used when numericFormatter is not specified).<br/>
  210. /// {d:0.##} indicates that a formatted string with a value specified separately is 0.## (used for percentage, reserved 2 valid digits while avoiding the situation similar to "100.00%" when using f2 ).<br/>
  211. /// Example: "{a}, {c}", "{a1}, {c1: f1}", "{a1}, {c1:0: f1}", "{a1} : {c1:1-1: f1}"<br/>
  212. /// |提示框单个serie或数据项内容的字符串模版格式器。支持用 \n 换行。用|来表示多个列的分隔。
  213. /// 模板变量有{.}、{a}、{b}、{c}、{d}、{e}、{f}、{g}。<br/>
  214. /// {i}或-表示忽略当前项。
  215. /// {.}为当前所指示的serie或数据项的对应颜色的圆点。<br/>
  216. /// {a}为当前所指示的serie或数据项的系列名name。<br/>
  217. /// {b}为当前所指示的serie或数据项的数据项serieData的name,或者类目值(如折线图的X轴)。<br/>
  218. /// {c}为当前所指示的serie或数据项的y维(dimesion为1)的数值。<br/>
  219. /// {d}为当前所指示的serie或数据项的y维(dimesion为1)百分比值,注意不带%号。<br/>
  220. /// {e}为当前所指示的serie或数据项的数据项serieData的name。<br/>
  221. /// {f}为当前所指示的serie的默认维度的数据总和。<br/>
  222. /// {g}为当前所指示的serie的数据总个数。<br/>
  223. /// {h}为当前所指示的serie的十六进制颜色值。<br/>
  224. /// {c0}表示当前数据项维度为0的数据。<br/>
  225. /// {c1}表示当前数据项维度为1的数据。<br/>
  226. /// {d3}表示维度3的数据的百分比。它的分母是默认维度(一般是1维度)数据。<br/>
  227. /// |表示多个列的分隔。<br>
  228. /// 示例:"{i}", "{.}|{a}|{c}", "{.}|{b}|{c2:f2}"
  229. /// </summary>
  230. public string itemFormatter { get { return m_ItemFormatter; } set { m_ItemFormatter = value; } }
  231. /// <summary>
  232. /// the marker of serie.
  233. /// |serie的符号标志。
  234. /// </summary>
  235. public string marker { get { return m_Marker; } set { m_Marker = value; } }
  236. /// <summary>
  237. /// Fixed width. Higher priority than minWidth.
  238. /// |固定宽度。比 minWidth 优先。
  239. /// </summary>
  240. public float fixedWidth { get { return m_FixedWidth; } set { m_FixedWidth = value; } }
  241. /// <summary>
  242. /// Fixed height. Higher priority than minHeight.
  243. /// |固定高度。比 minHeight 优先。
  244. /// </summary>
  245. public float fixedHeight { get { return m_FixedHeight; } set { m_FixedHeight = value; } }
  246. /// <summary>
  247. /// Minimum width. If fixedWidth has a value, get fixedWidth first.
  248. /// |最小宽度。如若 fixedWidth 设有值,优先取 fixedWidth。
  249. /// </summary>
  250. public float minWidth { get { return m_MinWidth; } set { m_MinWidth = value; } }
  251. /// <summary>
  252. /// Minimum height. If fixedHeight has a value, take priority over fixedHeight.
  253. /// |最小高度。如若 fixedHeight 设有值,优先取 fixedHeight。
  254. /// </summary>
  255. public float minHeight { get { return m_MinHeight; } set { m_MinHeight = value; } }
  256. /// <summary>
  257. /// Standard numeric format string. Used to format numeric values to display as strings.
  258. /// Using 'Axx' form: 'A' is the single character of the format specifier, supporting 'C' currency,
  259. /// 'D' decimal, 'E' exponent, 'F' number of vertices, 'G' regular, 'N' digits, 'P' percentage,
  260. /// 'R' round tripping, 'X' hex etc. 'XX' is the precision specification, from '0' - '99'.
  261. /// |标准数字格式字符串。用于将数值格式化显示为字符串。
  262. /// 使用Axx的形式:A是格式说明符的单字符,支持C货币、D十进制、E指数、F定点数、G常规、N数字、P百分比、R往返、X十六进制的。xx是精度说明,从0-99。
  263. /// 参考:https://docs.microsoft.com/zh-cn/dotnet/standard/base-types/standard-numeric-format-strings
  264. /// </summary>
  265. /// <value></value>
  266. public string numericFormatter
  267. {
  268. get { return m_NumericFormatter; }
  269. set { if (PropertyUtil.SetClass(ref m_NumericFormatter, value)) SetComponentDirty(); }
  270. }
  271. /// <summary>
  272. /// the text padding of left and right. defaut:5.
  273. /// |左右边距。
  274. /// </summary>
  275. public int paddingLeftRight { get { return m_PaddingLeftRight; } set { m_PaddingLeftRight = value; } }
  276. /// <summary>
  277. /// the text padding of top and bottom. defaut:5.
  278. /// |上下边距。
  279. /// </summary>
  280. public int paddingTopBottom { get { return m_PaddingTopBottom; } set { m_PaddingTopBottom = value; } }
  281. /// <summary>
  282. /// Whether to show ignored data on tooltip.
  283. /// |是否显示忽略数据在tooltip上。
  284. /// </summary>
  285. public bool ignoreDataShow { get { return m_IgnoreDataShow; } set { m_IgnoreDataShow = value; } }
  286. /// <summary>
  287. /// The default display character information for ignored data.
  288. /// |被忽略数据的默认显示字符信息。如果设置为空,则表示完全不显示忽略数据。
  289. /// </summary>
  290. public string ignoreDataDefaultContent { get { return m_IgnoreDataDefaultContent; } set { m_IgnoreDataDefaultContent = value; } }
  291. /// <summary>
  292. /// The background image of tooltip.
  293. /// |提示框的背景图片。
  294. /// </summary>
  295. public Sprite backgroundImage { get { return m_BackgroundImage; } set { m_BackgroundImage = value; SetComponentDirty(); } }
  296. /// <summary>
  297. /// The background type of tooltip.
  298. /// |提示框的背景图片显示类型。
  299. /// </summary>
  300. public Image.Type backgroundType { get { return m_BackgroundType; } set { m_BackgroundType = value; SetComponentDirty(); } }
  301. /// <summary>
  302. /// The background color of tooltip.
  303. /// |提示框的背景颜色。
  304. /// </summary>
  305. public Color backgroundColor { get { return m_BackgroundColor; } set { m_BackgroundColor = value; SetComponentDirty(); } }
  306. /// <summary>
  307. /// Whether to trigger after always display.
  308. /// |是否触发后一直显示提示框浮层。
  309. /// </summary>
  310. public bool alwayShowContent { get { return m_AlwayShowContent; } set { m_AlwayShowContent = value; } }
  311. /// <summary>
  312. /// Whether to show the tooltip floating layer, whose default value is true.
  313. /// It should be configurated to be false, if you only need tooltip to trigger the event or show the axisPointer without content.
  314. /// |是否显示提示框浮层,默认显示。只需tooltip触发事件或显示axisPointer而不需要显示内容时可配置该项为false。
  315. /// </summary>
  316. public bool showContent { get { return m_ShowContent; } set { m_ShowContent = value; } }
  317. /// <summary>
  318. /// The position offset of tooltip relative to the mouse position.
  319. /// |提示框相对于鼠标位置的偏移。
  320. /// </summary>
  321. public Vector2 offset { get { return m_Offset; } set { m_Offset = value; } }
  322. /// <summary>
  323. /// the width of tooltip border.
  324. /// |边框线宽。
  325. /// </summary>
  326. public float borderWidth
  327. {
  328. get { return m_BorderWidth; }
  329. set { if (PropertyUtil.SetStruct(ref m_BorderWidth, value)) SetVerticesDirty(); }
  330. }
  331. /// <summary>
  332. /// the color of tooltip border.
  333. /// |边框颜色。
  334. /// </summary>
  335. public Color32 borderColor
  336. {
  337. get { return m_BorderColor; }
  338. set { if (PropertyUtil.SetColor(ref m_BorderColor, value)) SetVerticesDirty(); }
  339. }
  340. /// <summary>
  341. /// the x positionn of fixedX.
  342. /// |固定X位置的坐标。
  343. /// </summary>
  344. public float fixedX
  345. {
  346. get { return m_FixedX; }
  347. set { if (PropertyUtil.SetStruct(ref m_FixedX, value)) SetVerticesDirty(); }
  348. }
  349. /// <summary>
  350. /// the y position of fixedY.
  351. /// |固定Y位置的坐标。
  352. /// </summary>
  353. public float fixedY
  354. {
  355. get { return m_FixedY; }
  356. set { if (PropertyUtil.SetStruct(ref m_FixedY, value)) SetVerticesDirty(); }
  357. }
  358. /// <summary>
  359. /// height of title text.
  360. /// |标题文本的高。
  361. /// </summary>
  362. public float titleHeight
  363. {
  364. get { return m_TitleHeight; }
  365. set { if (PropertyUtil.SetStruct(ref m_TitleHeight, value)) SetComponentDirty(); }
  366. }
  367. /// <summary>
  368. /// height of content text.
  369. /// |数据项文本的高。
  370. /// </summary>
  371. public float itemHeight
  372. {
  373. get { return m_ItemHeight; }
  374. set { if (PropertyUtil.SetStruct(ref m_ItemHeight, value)) SetComponentDirty(); }
  375. }
  376. /// <summary>
  377. /// the textstyle of title.
  378. /// |标题的文本样式。
  379. /// </summary>
  380. public LabelStyle titleLabelStyle
  381. {
  382. get { return m_TitleLabelStyle; }
  383. set { if (value != null) { m_TitleLabelStyle = value; SetComponentDirty(); } }
  384. }
  385. /// <summary>
  386. /// the textstyle list of content.
  387. /// |内容部分的文本样式列表。和列一一对应。
  388. /// </summary>
  389. public List<LabelStyle> contentLabelStyles
  390. {
  391. get { return m_ContentLabelStyles; }
  392. set { if (value != null) { m_ContentLabelStyles = value; SetComponentDirty(); } }
  393. }
  394. /// <summary>
  395. /// the line style of indicator line.
  396. /// |指示线样式。
  397. /// </summary>
  398. public LineStyle lineStyle
  399. {
  400. get { return m_LineStyle; }
  401. set { if (value != null) m_LineStyle = value; SetComponentDirty(); }
  402. }
  403. /// <summary>
  404. /// 组件是否需要刷新
  405. /// </summary>
  406. public override bool componentDirty
  407. {
  408. get { return m_ComponentDirty || lineStyle.componentDirty; }
  409. }
  410. public override void ClearComponentDirty()
  411. {
  412. base.ClearComponentDirty();
  413. lineStyle.ClearComponentDirty();
  414. }
  415. /// <summary>
  416. /// 当前提示框所指示的Serie索引(目前只对散点图有效)。
  417. /// </summary>
  418. public Dictionary<int, List<int>> runtimeSerieIndex = new Dictionary<int, List<int>>();
  419. /// <summary>
  420. /// The data index currently indicated by Tooltip.
  421. /// |当前提示框所指示的数据项索引。
  422. /// </summary>
  423. public List<int> runtimeDataIndex { get { return m_RuntimeDateIndex; } internal set { m_RuntimeDateIndex = value; } }
  424. private List<int> m_RuntimeDateIndex = new List<int>() {-1, -1 };
  425. /// <summary>
  426. /// Keep Tooltiop displayed at the top.
  427. /// |保持Tooltiop显示在最顶上
  428. /// </summary>
  429. public void KeepTop()
  430. {
  431. gameObject.transform.SetAsLastSibling();
  432. }
  433. public override void ClearData()
  434. {
  435. ClearValue();
  436. }
  437. /// <summary>
  438. /// 清除提示框指示数据
  439. /// </summary>
  440. internal void ClearValue()
  441. {
  442. for (int i = 0; i < runtimeDataIndex.Count; i++) runtimeDataIndex[i] = -1;
  443. }
  444. /// <summary>
  445. /// 提示框是否显示
  446. /// </summary>
  447. /// <returns></returns>
  448. public bool IsActive()
  449. {
  450. return gameObject != null && gameObject.activeInHierarchy;
  451. }
  452. /// <summary>
  453. /// 设置Tooltip组件是否显示
  454. /// </summary>
  455. /// <param name="flag"></param>
  456. public void SetActive(bool flag)
  457. {
  458. if (gameObject && gameObject.activeInHierarchy != flag)
  459. {
  460. gameObject.SetActive(alwayShowContent ? true : flag);
  461. }
  462. SetContentActive(flag);
  463. }
  464. /// <summary>
  465. /// 更新文本框位置
  466. /// </summary>
  467. /// <param name="pos"></param>
  468. public void UpdateContentPos(Vector2 pos, float width, float height)
  469. {
  470. if (view != null)
  471. {
  472. switch (m_Position)
  473. {
  474. case Position.Auto:
  475. #if UNITY_ANDROID || UNITY_IOS
  476. if (m_FixedY == 0) pos.y = ChartHelper.GetActualValue(0.7f, height);
  477. else pos.y = ChartHelper.GetActualValue(m_FixedY, height);
  478. #endif
  479. break;
  480. case Position.Custom:
  481. pos.x = ChartHelper.GetActualValue(m_FixedX, width);
  482. pos.y = ChartHelper.GetActualValue(m_FixedY, height);
  483. break;
  484. case Position.FixedX:
  485. pos.x = ChartHelper.GetActualValue(m_FixedX, width);
  486. break;
  487. case Position.FixedY:
  488. pos.y = ChartHelper.GetActualValue(m_FixedY, height);
  489. break;
  490. }
  491. view.UpdatePosition(pos);
  492. }
  493. }
  494. /// <summary>
  495. /// 设置文本框是否显示
  496. /// </summary>
  497. /// <param name="flag"></param>
  498. public void SetContentActive(bool flag)
  499. {
  500. if (view == null)
  501. return;
  502. view.SetActive(alwayShowContent ? true : flag);
  503. }
  504. /// <summary>
  505. /// 当前提示框是否选中数据项
  506. /// </summary>
  507. /// <returns></returns>
  508. public bool IsSelected()
  509. {
  510. foreach (var index in runtimeDataIndex)
  511. if (index >= 0) return true;
  512. return false;
  513. }
  514. /// <summary>
  515. /// 指定索引的数据项是否被提示框选中
  516. /// </summary>
  517. /// <param name="index"></param>
  518. /// <returns></returns>
  519. public bool IsSelected(int index)
  520. {
  521. foreach (var temp in runtimeDataIndex)
  522. if (temp == index) return true;
  523. return false;
  524. }
  525. public void ClearSerieDataIndex()
  526. {
  527. foreach (var kv in runtimeSerieIndex)
  528. {
  529. kv.Value.Clear();
  530. }
  531. }
  532. public void AddSerieDataIndex(int serieIndex, int dataIndex)
  533. {
  534. if (!runtimeSerieIndex.ContainsKey(serieIndex))
  535. {
  536. runtimeSerieIndex[serieIndex] = new List<int>();
  537. }
  538. runtimeSerieIndex[serieIndex].Add(dataIndex);
  539. }
  540. public bool isAnySerieDataIndex()
  541. {
  542. foreach (var kv in runtimeSerieIndex)
  543. {
  544. if (kv.Value.Count > 0) return true;
  545. }
  546. return false;
  547. }
  548. public bool IsTriggerItem()
  549. {
  550. return trigger == Trigger.Item;
  551. }
  552. public bool IsTriggerAxis()
  553. {
  554. return trigger == Trigger.Axis;
  555. }
  556. public LabelStyle GetContentLabelStyle(int index)
  557. {
  558. if (m_ContentLabelStyles.Count == 0)
  559. return null;
  560. if (index < 0)
  561. index = 0;
  562. else if (index > m_ContentLabelStyles.Count - 1)
  563. index = m_ContentLabelStyles.Count - 1;
  564. return m_ContentLabelStyles[index];
  565. }
  566. }
  567. }