Example #1
0
 private float GetItemCenter(LineChartItemVO itemVO)
 {
     if (Data.dir == ChartVO.Directions.H)
     {
         return((1 - (itemVO.value / itemVO.range)) * boundary.width);
     }
     else
     {
         return((1 - (itemVO.value / itemVO.range)) * boundary.height);
     }
 }
Example #2
0
    protected override void BeforeDrawItems(float lerp)
    {
        if (DrawLinkage)
        {
            canvas.strokeStyle.stroke      = true;
            canvas.strokeStyle.fill        = false;
            canvas.strokeStyle.strokeColor = LineColor;
            canvas.strokeStyle.thickness   = 5;
            for (int i = 0; i < Data.Items.Length; i++)
            {
                var             item = Data.Items[i];
                LineChartItemVO vo   = item as LineChartItemVO;
                // Vector2 siz = GetItemSize(item);
                // Vector2 sizLerp = Vector2.Lerp(Vector2.zero, siz, lerp);
                Vector2 pos = GetItemPos(i);
                // if (Data.dir == ChartVO.Directions.H)
                //  siz.x = sizLerp.x;
                // else
                //  siz.y = sizLerp.y;

                float range = GetItemCenter(vo) * lerp;
                if (Data.dir == ChartVO.Directions.V)
                {
                    if (i == 0)
                    {
                        canvas.MoveTo(pos.x + BarSize / 2, range);
                    }
                    else
                    {
                        canvas.LineTo(pos.x + BarSize / 2, range);
                    }
                }
                else
                {
                    if (i == 0)
                    {
                        canvas.MoveTo(range, pos.y + BarSize / 2);
                    }
                    else
                    {
                        canvas.LineTo(range, pos.y + BarSize / 2);
                    }
                }
            }
            canvas.Stroke();
            canvas.strokeStyle.fill      = true;
            canvas.strokeStyle.fillColor = Color.white;
            canvas.strokeStyle.stroke    = false;
        }
    }
Example #3
0
    protected override Vector2[] FillItem(ChartItemVO item, Vector2 pos, Vector2 size, float lerp)
    {
        LineChartItemVO vo = item as LineChartItemVO;

        canvas.strokeStyle.fill      = true;
        canvas.strokeStyle.fillColor = Color.white;
        canvas.strokeStyle.stroke    = false;
        List <Vector2> allV = new List <Vector2>();
        float          siz  = GetItemCenter(vo) * lerp;

        if (Data.dir == ChartVO.Directions.V)
        {
            var rect = canvas.Rect(pos.x, 0, BarSize, boundary.height);
            rect.name = SLIDER_BACKGROUND;
            rect      = canvas.Rect(pos.x, 0, BarSize, siz);
            rect.name = SLIDER_FOREGROUND;
            rect      = canvas.Rect(pos.x - Radius + BarSize / 2, siz - Radius, Radius * 2, Radius * 2);
            rect.name = SLIDER;
            allV.Add(new Vector2(pos.x, pos.y));
            allV.Add(new Vector2(pos.x + BarSize, pos.y));
            allV.Add(new Vector2(pos.x + BarSize, pos.y + boundary.height));
            allV.Add(new Vector2(pos.x, pos.y + boundary.height));
        }
        else
        {
            // float siz = GetItemCenter(vo) * lerp;
            var rect = canvas.Rect(0, pos.y, boundary.width, BarSize);
            rect.name = SLIDER_BACKGROUND;
            rect      = canvas.Rect(0, pos.y, siz, BarSize);
            rect.name = SLIDER_FOREGROUND;
            rect      = canvas.Rect(siz - Radius, pos.y - Radius + BarSize / 2, Radius * 2, Radius * 2);
            rect.name = SLIDER;
            allV.Add(new Vector2(pos.x, pos.y));
            allV.Add(new Vector2(pos.x + boundary.width, pos.y));
            allV.Add(new Vector2(pos.x + boundary.width, pos.y + BarSize));
            allV.Add(new Vector2(pos.x, pos.y + BarSize));
        }

        return(allV.ToArray());
    }
Example #4
0
    protected override void DrawScale()
    {
        if (!ShowScale)
        {
            return;
        }
        RecycleLabel();
        // Draw info text
        int           Len  = Data.Items.Length;
        RectTransform rect = transform as RectTransform;
        float         gap  = RangeLabelGap;

        for (int i = 0; i < Len; i++)
        {
            Text nameLabel  = CreateLabel(Data.Items[i].label);
            Text rangeLabel = CreateLabel(string.Format(RangeLabelFormat, (Data.Items[i] as LineChartItemVO).range.ToString()));
            Text valueLabel = CreateLabel(string.Format(ValueLabelFormat, Data.Items[i].value.ToString()));
            rangeLabel.gameObject.SetActive(ShowRangeLabel);
            valueLabel.gameObject.SetActive(ShowValueLabel);
            Vector2         pos = GetItemPos(i);
            LineChartItemVO vo  = Data.Items[i] as LineChartItemVO;

            switch (ValueLabelPlacement)
            {
            case Placement.L:
                valueLabel.alignment           = TextAnchor.MiddleRight;
                valueLabel.rectTransform.pivot = new Vector2(1, 0.5f);
                if (Data.dir == ChartVO.Directions.H)
                {
                    valueLabel.rectTransform.localPosition = new Vector2(GetItemCenter(vo) - Radius, pos.y);
                }
                else
                {
                    valueLabel.rectTransform.localPosition = new Vector2(pos.x - Radius + BarSize / 2, GetItemCenter(vo));
                }
                break;

            case Placement.R:
                valueLabel.alignment           = TextAnchor.MiddleLeft;
                valueLabel.rectTransform.pivot = new Vector2(0, 0.5f);
                if (Data.dir == ChartVO.Directions.H)
                {
                    valueLabel.rectTransform.localPosition = new Vector2(GetItemCenter(vo) + Radius, pos.y);
                }
                else
                {
                    valueLabel.rectTransform.localPosition = new Vector2(pos.x + Radius + BarSize / 2, GetItemCenter(vo));
                }
                break;

            case Placement.T:
                valueLabel.alignment           = TextAnchor.LowerCenter;
                valueLabel.rectTransform.pivot = new Vector2(0.5f, 0);
                if (Data.dir == ChartVO.Directions.H)
                {
                    valueLabel.rectTransform.localPosition = new Vector2(GetItemCenter(vo), pos.y + Radius);
                }
                else
                {
                    valueLabel.rectTransform.localPosition = new Vector2(pos.x + BarSize / 2, GetItemCenter(vo) + Radius);
                }
                break;

            case Placement.B:
                valueLabel.alignment           = TextAnchor.UpperCenter;
                valueLabel.rectTransform.pivot = new Vector2(0.5f, 0);
                if (Data.dir == ChartVO.Directions.H)
                {
                    valueLabel.rectTransform.localPosition = new Vector2(GetItemCenter(vo), pos.y - Radius);
                }
                else
                {
                    valueLabel.rectTransform.localPosition = new Vector2(pos.x + BarSize / 2, GetItemCenter(vo) - Radius * 2);
                }
                break;
            }

            if (Data.dir == ChartVO.Directions.H)
            {
                nameLabel.alignment                   = TextAnchor.MiddleRight;
                nameLabel.rectTransform.pivot         = new Vector2(1, 0.5f);
                nameLabel.rectTransform.localPosition = new Vector2(-Radius, pos.y + BarSize / 2);

                rangeLabel.alignment                   = TextAnchor.MiddleLeft;
                rangeLabel.rectTransform.pivot         = new Vector2(0, 0.5f);
                rangeLabel.rectTransform.localPosition = new Vector2(rect.sizeDelta.x + gap, pos.y + BarSize / 2);

                // valueLabel.alignment = TextAnchor.MiddleCenter;
                // valueLabel.rectTransform.pivot = new Vector2(0.5f, 0);
                // valueLabel.rectTransform.localPosition = new Vector2(GetItemCenter(vo), pos.y + Radius * 2);
            }
            else
            {
                nameLabel.alignment                   = TextAnchor.LowerCenter;
                nameLabel.rectTransform.pivot         = new Vector2(0.5f, 1);
                nameLabel.rectTransform.localPosition = new Vector2(pos.x + BarSize / 2, pos.y);

                rangeLabel.alignment                   = TextAnchor.LowerCenter;
                rangeLabel.rectTransform.pivot         = new Vector2(0.5f, 0);
                rangeLabel.rectTransform.localPosition = new Vector2(pos.x + BarSize / 2, pos.y + rect.sizeDelta.y + gap);

                // valueLabel.alignment = TextAnchor.MiddleLeft;
                // valueLabel.rectTransform.pivot = new Vector2(0, 0.5f);
                // valueLabel.rectTransform.localPosition = new Vector2(pos.x + Radius * 2, GetItemCenter(vo));
            }
        }
    }