private void UpdateEntryIndicatorInstances(int requiredCount) { int currentCount = entryIdicators.Count; // Add missing indicators int missingCount = requiredCount - currentCount; while (missingCount > 0) { LineEntryIdicator indicator = viewCreator.InstantiateCircleImage("dot", contentView.transform); entryIdicators.Add(indicator); missingCount--; } // Remove redundant indicators int redundantCount = currentCount - requiredCount; while (redundantCount > 0) { LineEntryIdicator target = entryIdicators[entryIdicators.Count - 1]; DestroyImmediate(target.gameObject); entryIdicators.Remove(target); redundantCount--; } }
private void OnEntryClick(LineEntryIdicator indicator, int dataSetIndex) { if (Config.OnValueClickAction != null) { Config.OnValueClickAction.Invoke(indicator.entry, dataSetIndex); } ShowHideValuePopup(indicator); }
public LineEntryIdicator InstantiateCircleImage(string name, Transform parent) { GameObject gameObject = CreateBaseGameObject(name, parent, PivotValue.CENTER); LineEntryIdicator indicator = gameObject.AddComponent <LineEntryIdicator> (); indicator.button = gameObject.AddComponent <Button> (); indicator.image = gameObject.AddComponent <Image> (); indicator.image.sprite = Resources.Load <Sprite> ("sprites/line_chart_circle"); indicator.button.targetGraphic = indicator.image; return(indicator); }
private void ShowHideValuePopup(LineEntryIdicator indicator) { if (currentValuePopup == null) { currentValuePopup = viewCreator.InstantiateChartPopup(contentView.transform, Config.PopupPrefab); } if (indicator.entry != currentValuePopupEntry) { UpdateValuePopup(indicator); currentValuePopupEntry = indicator.entry; } else { HideCurrentValuePopup(); } }
private int UpdateCirclesAtPosition(Vector2[] positions, LineEntry[] entries, Color32 color, int firstAvailableIndicatorPosition, int dataSetIndex) { Vector2 contentSize = GetContentSize(); for (int i = 0; i < positions.Length; i++) { Vector2 position = positions[i]; bool indicatorOutside = position.x <0 || position.x> contentSize.x || position.y <0 || position.y> contentSize.y; LineEntryIdicator indicator = entryIdicators[firstAvailableIndicatorPosition + i]; indicator.GetComponent <RectTransform> ().sizeDelta = new Vector2(Config.ValueIndicatorSize, Config.ValueIndicatorSize); indicator.transform.localPosition = position; indicator.entry = entries[i]; indicator.image.color = color; indicator.gameObject.SetActive(!indicatorOutside); indicator.button.onClick.RemoveAllListeners(); indicator.button.onClick.AddListener(delegate { OnEntryClick(indicator, dataSetIndex); }); } return(firstAvailableIndicatorPosition + positions.Length); }
private Vector3 PopupPositionFromEntry(LineEntryIdicator indicator) { return(new Vector3(indicator.transform.localPosition.x, indicator.transform.localPosition.y + Config.ValueIndicatorSize / 2, 0)); }
private void UpdateValuePopup(LineEntryIdicator indicator) { currentValuePopup.transform.localPosition = PopupPositionFromEntry(indicator); currentValuePopup.text.text = "" + indicator.entry.Value; currentValuePopup.gameObject.SetActive(true); }