Exemplo n.º 1
0
        private int HandleFrameSelectionEvents(int selectedFrame, int chartControlID, Rect chartFrame, ChartViewData cdata)
        {
            Event evt = Event.current;

            switch (evt.type)
            {
            case EventType.MouseDown:
                if (chartFrame.Contains(evt.mousePosition))
                {
                    GUIUtility.keyboardControl = chartControlID;
                    GUIUtility.hotControl      = chartControlID;
                    Vector2 domain = cdata.GetDataDomain();
                    int     len    = (int)(domain.y - domain.x);
                    selectedFrame = DoFrameSelectionDrag(evt.mousePosition.x, chartFrame, cdata, len);
                    evt.Use();
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == chartControlID)
                {
                    Vector2 domain = cdata.GetDataDomain();
                    int     len    = (int)(domain.y - domain.x);
                    selectedFrame = DoFrameSelectionDrag(evt.mousePosition.x, chartFrame, cdata, len);
                    evt.Use();
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == chartControlID)
                {
                    GUIUtility.hotControl = 0;
                    evt.Use();
                }
                break;

            case EventType.KeyDown:
                if (GUIUtility.keyboardControl != chartControlID || selectedFrame < 0)
                {
                    break;
                }

                if (evt.keyCode == KeyCode.LeftArrow)
                {
                    selectedFrame = MoveSelectedFrame(selectedFrame, cdata, -1);
                    evt.Use();
                }
                else if (evt.keyCode == KeyCode.RightArrow)
                {
                    selectedFrame = MoveSelectedFrame(selectedFrame, cdata, 1);
                    evt.Use();
                }
                break;
            }

            return(selectedFrame);
        }
Exemplo n.º 2
0
        private void DrawChartStacked(int selectedFrame, ChartViewData cdata, Rect r, bool chartActive)
        {
            HandleUtility.ApplyWireMaterial();

            Vector2 domain     = cdata.GetDataDomain();
            int     numSamples = (int)(domain.y - domain.x);

            if (numSamples <= 0)
            {
                return;
            }

            if (m_StackedSampleSums == null || m_StackedSampleSums.Length < numSamples)
            {
                m_StackedSampleSums = new float[numSamples];
            }
            for (int i = 0; i < numSamples; ++i)
            {
                m_StackedSampleSums[i] = 0f;
            }

            for (int i = 0; i < cdata.numSeries; i++)
            {
                if (cdata.hasOverlay)
                {
                    DrawChartItemStackedOverlay(r, i, cdata, m_StackedSampleSums);
                }
                DrawChartItemStacked(r, i, cdata, m_StackedSampleSums);
            }
            DrawOverlayBoxes(cdata, r, chartActive);

            DrawSelectedFrame(selectedFrame, cdata, r);

            DrawGridStacked(r, cdata);
            DrawLabels(r, cdata, selectedFrame, ChartType.StackedFill);

            // Show selected property name
            //@TODO: not the best place to put this code.

            if (!cdata.hasOverlay)
            {
                return;
            }

            string selectedName = ProfilerDriver.selectedPropertyPath;

            if (selectedName.Length > 0)
            {
                int selectedNameBegin = selectedName.LastIndexOf('/');
                if (selectedNameBegin != -1)
                {
                    selectedName = selectedName.Substring(selectedNameBegin + 1);
                }

                GUIContent content = EditorGUIUtility.TempContent("Selected: " + selectedName);
                Vector2    size    = EditorStyles.whiteBoldLabel.CalcSize(content);
                EditorGUI.DropShadowLabel(new Rect(r.x + r.width - size.x - 3.0f, r.y + 3.0f, size.x, size.y), content,
                                          Styles.selectedLabel);
            }
        }
Exemplo n.º 3
0
        internal static void DrawVerticalLine(int frame, ChartViewData cdata, Rect r, Color color, float minWidth, float maxWidth = 0)
        {
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }

            frame -= cdata.chartDomainOffset;
            if (frame < 0)
            {
                return;
            }


            Vector2 domain     = cdata.GetDataDomain();
            float   domainSize = domain.y - domain.x;
            float   lineWidth  = Mathf.Max(minWidth, r.width / domainSize);

            if (maxWidth > 0)
            {
                lineWidth = Mathf.Min(maxWidth, lineWidth);
            }

            HandleUtility.ApplyWireMaterial();
            GL.Begin(GL.QUADS);
            GL.Color(color);
            GL.Vertex3(r.x + r.width / domainSize * frame, r.y + 1, 0);
            GL.Vertex3(r.x + r.width / domainSize * frame + lineWidth, r.y + 1, 0);

            GL.Vertex3(r.x + r.width / domainSize * frame + lineWidth, r.yMax, 0);
            GL.Vertex3(r.x + r.width / domainSize * frame, r.yMax, 0);
            GL.End();
        }
Exemplo n.º 4
0
        internal static void DrawVerticalLine(int frame, ChartViewData cdata, Rect r, Color color1, Color color2, float widthFactor)
        {
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }

            frame -= cdata.chartDomainOffset;
            if (frame < 0)
            {
                return;
            }


            Vector2 domain     = cdata.GetDataDomain();
            float   domainSize = domain.y - domain.x;

            HandleUtility.ApplyWireMaterial();
            GL.Begin(GL.QUADS);
            GL.Color(color1);
            GL.Vertex3(r.x + r.width / domainSize * frame, r.y + 1, 0);
            GL.Vertex3(r.x + r.width / domainSize * frame + r.width / domainSize, r.y + 1, 0);

            GL.Color(color2);
            GL.Vertex3(r.x + r.width / domainSize * frame + r.width / domainSize, r.yMax, 0);
            GL.Vertex3(r.x + r.width / domainSize * frame, r.yMax, 0);
            GL.End();
        }
Exemplo n.º 5
0
        private void DrawChartItemLine(Rect r, ChartViewData cdata, int index)
        {
            ChartSeriesViewData chartSeriesViewData = cdata.series[index];

            if (chartSeriesViewData.enabled)
            {
                if (this.m_LineDrawingPoints == null || chartSeriesViewData.numDataPoints > this.m_LineDrawingPoints.Length)
                {
                    this.m_LineDrawingPoints = new Vector3[chartSeriesViewData.numDataPoints];
                }
                Vector2 dataDomain = cdata.GetDataDomain();
                float   num        = dataDomain.y - dataDomain.x;
                if (num > 0f)
                {
                    float num2 = 1f / num * r.width;
                    float num3 = (cdata.series[index].rangeAxis.sqrMagnitude != 0f) ? (1f / (cdata.series[index].rangeAxis.y - cdata.series[index].rangeAxis.x) * r.height) : 0f;
                    float num4 = r.y + r.height;
                    for (int i = 0; i < chartSeriesViewData.numDataPoints; i++)
                    {
                        this.m_LineDrawingPoints[i].Set((chartSeriesViewData.xValues[i] - dataDomain.x) * num2 + r.x, num4 - (chartSeriesViewData.yValues[i] - chartSeriesViewData.rangeAxis.x) * num3, 0f);
                    }
                    using (new Handles.DrawingScope(cdata.series[index].color))
                    {
                        Handles.DrawAAPolyLine(2f, chartSeriesViewData.numDataPoints, this.m_LineDrawingPoints);
                    }
                }
            }
        }
Exemplo n.º 6
0
        private void DrawChartItemStackedOverlay(Rect r, int index, ChartViewData cdata, float[] stackedSampleSums)
        {
            Vector2 dataDomain = cdata.GetDataDomain();
            int     num        = (int)(dataDomain.y - dataDomain.x);
            float   num2       = r.width / (float)num;
            int     num3       = cdata.order[index];

            if (cdata.series[num3].enabled)
            {
                Color color = cdata.series[num3].color;
                GL.Begin(5);
                float num4 = r.x + num2 * 0.5f;
                float num5 = (cdata.series[0].rangeAxis.sqrMagnitude != 0f) ? (1f / (cdata.series[0].rangeAxis.y - cdata.series[0].rangeAxis.x) * r.height) : 0f;
                float num6 = r.y + r.height;
                int   i    = 0;
                while (i < num)
                {
                    float num7 = num6 - stackedSampleSums[i];
                    float num8 = cdata.overlays[num3].yValues[i];
                    if (num8 != -1f)
                    {
                        float num9 = (num8 - cdata.series[0].rangeAxis.x) * num5;
                        GL.Color(color);
                        GL.Vertex3(num4, num7 - num9, 0f);
                        GL.Vertex3(num4, num7, 0f);
                    }
                    i++;
                    num4 += num2;
                }
                GL.End();
            }
        }
Exemplo n.º 7
0
        private int MoveSelectedFrame(int selectedFrame, ChartViewData cdata, int direction)
        {
            Vector2 domain           = cdata.GetDataDomain();
            int     length           = (int)(domain.y - domain.x);
            int     newSelectedFrame = selectedFrame + direction;

            if (newSelectedFrame < cdata.firstSelectableFrame || newSelectedFrame > cdata.chartDomainOffset + length)
            {
                return(selectedFrame);
            }

            return(newSelectedFrame);
        }
Exemplo n.º 8
0
        private void DrawChartItemStacked(Rect r, int index, ChartViewData cdata, float[] stackedSampleSums)
        {
            Vector2 domain     = cdata.GetDataDomain();
            int     numSamples = (int)(domain.y - domain.x);

            float step = r.width / numSamples;

            index = cdata.order[index];

            if (!cdata.series[index].enabled)
            {
                return;
            }

            Color color = cdata.series[index].color;

            if (cdata.hasOverlay)
            {
                color *= s_OverlayBackgroundDimFactor;
            }

            GL.Begin(GL.TRIANGLE_STRIP);

            float x          = r.x + step * 0.5f;
            float rangeScale = cdata.series[0].rangeAxis.sqrMagnitude == 0f ?
                               0f : 1f / (cdata.series[0].rangeAxis.y - cdata.series[0].rangeAxis.x) * r.height;
            float rectBottom = r.y + r.height;

            for (int i = 0; i < numSamples; i++, x += step)
            {
                float y     = rectBottom - stackedSampleSums[i];
                var   serie = cdata.series[index];
                float value = serie.yValues[i] * serie.yScale;
                if (value == -1f)
                {
                    continue;
                }

                float val = (value - cdata.series[0].rangeAxis.x) * rangeScale;
                if (y - val < r.yMin)
                {
                    val = y - r.yMin; // Clamp the values to be inside drawrect
                }
                GL.Color(color);
                GL.Vertex3(x, y - val, 0f); // clip chart top
                GL.Vertex3(x, y, 0f);

                stackedSampleSums[i] += val;
            }
            GL.End();
        }
Exemplo n.º 9
0
        private int MoveSelectedFrame(int selectedFrame, ChartViewData cdata, int direction)
        {
            Vector2 dataDomain = cdata.GetDataDomain();
            int     num        = (int)(dataDomain.y - dataDomain.x);
            int     num2       = selectedFrame + direction;
            int     result;

            if (num2 < cdata.firstSelectableFrame || num2 > cdata.chartDomainOffset + num)
            {
                result = selectedFrame;
            }
            else
            {
                result = num2;
            }
            return(result);
        }
Exemplo n.º 10
0
        private void DrawChartStacked(int selectedFrame, ChartViewData cdata, Rect r)
        {
            HandleUtility.ApplyWireMaterial();
            Vector2 dataDomain = cdata.GetDataDomain();
            int     num        = (int)(dataDomain.y - dataDomain.x);

            if (num > 0)
            {
                if (this.m_StackedSampleSums == null || this.m_StackedSampleSums.Length < num)
                {
                    this.m_StackedSampleSums = new float[num];
                }
                for (int i = 0; i < num; i++)
                {
                    this.m_StackedSampleSums[i] = 0f;
                }
                for (int j = 0; j < cdata.numSeries; j++)
                {
                    if (cdata.hasOverlay)
                    {
                        this.DrawChartItemStackedOverlay(r, j, cdata, this.m_StackedSampleSums);
                    }
                    this.DrawChartItemStacked(r, j, cdata, this.m_StackedSampleSums);
                }
                this.DrawSelectedFrame(selectedFrame, cdata, r);
                this.DrawGridStacked(r, cdata);
                this.DrawLabels(r, cdata, selectedFrame, Chart.ChartType.StackedFill);
                if (cdata.hasOverlay)
                {
                    string text = ProfilerDriver.selectedPropertyPath;
                    if (text.Length > 0)
                    {
                        int num2 = text.LastIndexOf('/');
                        if (num2 != -1)
                        {
                            text = text.Substring(num2 + 1);
                        }
                        GUIContent content = EditorGUIUtility.TempContent("Selected: " + text);
                        Vector2    vector  = EditorStyles.whiteBoldLabel.CalcSize(content);
                        EditorGUI.DropShadowLabel(new Rect(r.x + r.width - vector.x - 3f, r.y + 3f, vector.x, vector.y), content, Chart.Styles.selectedLabel);
                    }
                }
            }
        }
Exemplo n.º 11
0
        private void DrawChartItemStacked(Rect r, int index, ChartViewData cdata, float[] stackedSampleSums)
        {
            Vector2 dataDomain = cdata.GetDataDomain();
            int     num        = (int)(dataDomain.y - dataDomain.x);
            float   num2       = r.width / (float)num;

            index = cdata.order[index];
            if (cdata.series[index].enabled)
            {
                Color color = cdata.series[index].color;
                if (cdata.hasOverlay)
                {
                    color *= Chart.s_OverlayBackgroundDimFactor;
                }
                GL.Begin(5);
                float num3 = r.x + num2 * 0.5f;
                float num4 = (cdata.series[0].rangeAxis.sqrMagnitude != 0f) ? (1f / (cdata.series[0].rangeAxis.y - cdata.series[0].rangeAxis.x) * r.height) : 0f;
                float num5 = r.y + r.height;
                int   i    = 0;
                while (i < num)
                {
                    float num6 = num5 - stackedSampleSums[i];
                    float num7 = cdata.series[index].yValues[i];
                    if (num7 != -1f)
                    {
                        float num8 = (num7 - cdata.series[0].rangeAxis.x) * num4;
                        if (num6 - num8 < r.yMin)
                        {
                            num8 = num6 - r.yMin;
                        }
                        GL.Color(color);
                        GL.Vertex3(num3, num6 - num8, 0f);
                        GL.Vertex3(num3, num6, 0f);
                        stackedSampleSums[i] += num8;
                    }
                    i++;
                    num3 += num2;
                }
                GL.End();
            }
        }
Exemplo n.º 12
0
 internal static void DrawVerticalLine(int frame, ChartViewData cdata, Rect r, Color color1, Color color2, float widthFactor)
 {
     if (Event.current.type == EventType.Repaint)
     {
         frame -= cdata.chartDomainOffset;
         if (frame >= 0)
         {
             Vector2 dataDomain = cdata.GetDataDomain();
             float   num        = dataDomain.y - dataDomain.x;
             HandleUtility.ApplyWireMaterial();
             GL.Begin(7);
             GL.Color(color1);
             GL.Vertex3(r.x + r.width / num * (float)frame, r.y + 1f, 0f);
             GL.Vertex3(r.x + r.width / num * (float)frame + r.width / num, r.y + 1f, 0f);
             GL.Color(color2);
             GL.Vertex3(r.x + r.width / num * (float)frame + r.width / num, r.yMax, 0f);
             GL.Vertex3(r.x + r.width / num * (float)frame, r.yMax, 0f);
             GL.End();
         }
     }
 }
Exemplo n.º 13
0
        private void DrawChartItemLine(Rect r, ChartViewData cdata, int index)
        {
            ChartSeriesViewData series = cdata.series[index];

            if (!series.enabled)
            {
                return;
            }

            if (m_LineDrawingPoints == null || series.numDataPoints > m_LineDrawingPoints.Length)
            {
                m_LineDrawingPoints = new Vector3[series.numDataPoints];
            }

            Vector2 domain     = cdata.GetDataDomain();
            float   domainSize = domain.y - domain.x;

            if (domainSize <= 0f)
            {
                return;
            }

            float domainScale = 1f / domainSize * r.width;
            float rangeScale  = cdata.series[index].rangeAxis.sqrMagnitude == 0f ?
                                0f : 1f / (cdata.series[index].rangeAxis.y - cdata.series[index].rangeAxis.x) * r.height;
            float rectBottom = r.y + r.height;

            for (int i = 0; i < series.numDataPoints; ++i)
            {
                float yValue = series.yValues[i] * series.yScale;
                m_LineDrawingPoints[i].Set(
                    (series.xValues[i] - domain.x) * domainScale + r.x,
                    rectBottom - (Mathf.Clamp(yValue, graphRange.x, graphRange.y) - series.rangeAxis.x) * rangeScale,
                    0f
                    );
            }

            using (new Handles.DrawingScope(cdata.series[index].color))
                Handles.DrawAAPolyLine(k_LineWidth, series.numDataPoints, m_LineDrawingPoints);
        }
Exemplo n.º 14
0
        private void DrawChartItemStackedOverlay(Rect r, int index, ChartViewData cdata, float[] stackedSampleSums)
        {
            Vector2 domain     = cdata.GetDataDomain();
            int     numSamples = (int)(domain.y - domain.x);
            float   step       = r.width / numSamples;

            int orderIdx = cdata.order[index];

            if (!cdata.series[orderIdx].enabled)
            {
                return;
            }

            Color color = cdata.series[orderIdx].color;

            GL.Begin(GL.TRIANGLE_STRIP);

            float x          = r.x + step * 0.5f;
            float rangeScale = cdata.series[0].rangeAxis.sqrMagnitude == 0f ?
                               0f : 1f / (cdata.series[0].rangeAxis.y - cdata.series[0].rangeAxis.x) * r.height;
            float rectBottom = r.y + r.height;

            for (int i = 0; i < numSamples; i++, x += step)
            {
                float y       = rectBottom - stackedSampleSums[i];
                var   overlay = cdata.overlays[orderIdx];
                float value   = overlay.yValues[i] * overlay.yScale;
                if (value == -1f)
                {
                    continue;
                }

                float val = (value - cdata.series[0].rangeAxis.x) * rangeScale;
                GL.Color(color);
                GL.Vertex3(x, y - val, 0f);
                GL.Vertex3(x, y, 0f);
            }
            GL.End();
        }
Exemplo n.º 15
0
        private void DrawLabels(Rect chartPosition, ChartViewData data, int selectedFrame, ChartType chartType)
        {
            if (data.selectedLabels == null || Event.current.type != EventType.Repaint)
            {
                return;
            }

            // exit early if the selected frame is outside the domain of the chart
            var domain = data.GetDataDomain();

            if (
                selectedFrame < data.firstSelectableFrame ||
                selectedFrame > data.chartDomainOffset + (int)(domain.y - domain.x) ||
                domain.y - domain.x == 0f
                )
            {
                return;
            }

            var selectedIndex = selectedFrame - data.chartDomainOffset;

            m_LabelOrder.Clear();
            m_LabelOrder.AddRange(data.order);

            // get values of all series and cumulative value of all enabled stacks
            m_SelectedFrameValues.Clear();
            var stacked   = chartType == ChartType.StackedFill;
            var numLabels = 0;

            for (int s = 0; s < data.numSeries; ++s)
            {
                var chartData = data.hasOverlay ? data.overlays[s] : data.series[s];
                var value     = chartData.yValues[selectedIndex] * chartData.yScale;
                m_SelectedFrameValues.Add(value);
                if (data.series[s].enabled)
                {
                    ++numLabels;
                }
            }

            if (numLabels == 0)
            {
                return;
            }

            // populate layout data array with default data
            m_LabelData.Clear();
            var selectedFrameMidline =
                chartPosition.x + chartPosition.width * ((selectedIndex + 0.5f) / (domain.y - domain.x));
            var maxLabelWidth = 0f;

            numLabels = 0;
            for (int s = 0; s < data.numSeries; ++s)
            {
                var labelData = new LabelLayoutData();
                var chartData = data.series[s];
                var value     = m_SelectedFrameValues[s];

                if (chartData.enabled && value >= labelRange.x && value <= labelRange.y)
                {
                    var rangeAxis = chartData.rangeAxis;
                    var rangeSize = rangeAxis.sqrMagnitude == 0f ? 1f : rangeAxis.y * chartData.yScale - rangeAxis.x;

                    // convert stacked series to cumulative value of enabled series
                    if (stacked)
                    {
                        var accumulatedValues = 0f;
                        int currentChartIndex = m_LabelOrder.FindIndex(x => x == s);

                        for (int i = currentChartIndex - 1; i >= 0; --i)
                        {
                            var  otherSeriesIdx = data.order[i];
                            var  otherChartData = data.hasOverlay ? data.overlays[otherSeriesIdx] : data.series[otherSeriesIdx];
                            bool enabled        = data.series[otherSeriesIdx].enabled;

                            if (enabled)
                            {
                                accumulatedValues += otherChartData.yValues[selectedIndex] * otherChartData.yScale;
                            }
                        }
                        // labels for stacked series will be in the middle of their stacks
                        value = accumulatedValues + (0.5f * value);
                    }

                    // default position is left aligned to midline
                    var position = new Vector2(
                        // offset by half a point so there is a 1-point gap down the midline if labels are on both sides
                        selectedFrameMidline + 0.5f,
                        chartPosition.y + chartPosition.height * (1.0f - ((value * chartData.yScale - rangeAxis.x) / rangeSize))
                        );
                    var size = Styles.whiteLabel.CalcSize(EditorGUIUtility.TempContent(data.selectedLabels[s]));
                    position.y -= 0.5f * size.y;
                    position.y  = Mathf.Clamp(position.y, chartPosition.yMin, chartPosition.yMax - size.y);

                    labelData.position         = new Rect(position, size);
                    labelData.desiredYPosition = labelData.position.center.y;

                    ++numLabels;
                }

                m_LabelData.Add(labelData);

                maxLabelWidth = Mathf.Max(maxLabelWidth, labelData.position.width);
            }

            if (numLabels == 0)
            {
                return;
            }

            // line charts order labels based on series values
            if (!stacked)
            {
                m_LabelOrder.Sort(SortLineLabelIndices);
            }

            // right align labels to the selected frame midline if approaching right border
            if (selectedFrameMidline > chartPosition.x + chartPosition.width - maxLabelWidth)
            {
                for (int s = 0; s < data.numSeries; ++s)
                {
                    var label = m_LabelData[s];
                    label.position.x -= label.position.width;
                    m_LabelData[s]    = label;
                }
            }
            // alternate right/left alignment if in the middle
            else if (selectedFrameMidline > chartPosition.x + maxLabelWidth)
            {
                var processed = 0;
                for (int s = 0; s < data.numSeries; ++s)
                {
                    var labelIndex = m_LabelOrder[s];

                    if (m_LabelData[labelIndex].position.size.sqrMagnitude == 0f)
                    {
                        continue;
                    }

                    if ((processed & 1) == 0)
                    {
                        var label = m_LabelData[labelIndex];
                        // ensure there is a 1-point gap down the midline
                        label.position.x       -= label.position.width + 1f;
                        m_LabelData[labelIndex] = label;
                    }

                    ++processed;
                }
            }

            // separate overlapping labels
            for (int it = 0; it < k_LabelLayoutMaxIterations; ++it)
            {
                m_MostOverlappingLabels.Clear();

                // work on the biggest cluster of overlapping rects
                for (int s1 = 0; s1 < data.numSeries; ++s1)
                {
                    m_OverlappingLabels.Clear();
                    m_OverlappingLabels.Add(s1);

                    if (m_LabelData[s1].position.size.sqrMagnitude == 0f)
                    {
                        continue;
                    }

                    for (int s2 = 0; s2 < data.numSeries; ++s2)
                    {
                        if (m_LabelData[s2].position.size.sqrMagnitude == 0f)
                        {
                            continue;
                        }

                        if (s1 != s2 && m_LabelData[s1].position.Overlaps(m_LabelData[s2].position))
                        {
                            m_OverlappingLabels.Add(s2);
                        }
                    }

                    if (m_OverlappingLabels.Count > m_MostOverlappingLabels.Count)
                    {
                        m_MostOverlappingLabels.Clear();
                        m_MostOverlappingLabels.AddRange(m_OverlappingLabels);
                    }
                }

                // finish if there are no more overlapping rects
                if (m_MostOverlappingLabels.Count == 1)
                {
                    break;
                }

                float totalHeight;
                var   geometricCenter = GetGeometricCenter(m_MostOverlappingLabels, m_LabelData, out totalHeight);

                // account for other rects that will overlap after expanding
                var foundOverlaps = true;
                while (foundOverlaps)
                {
                    foundOverlaps = false;
                    var minY = geometricCenter - 0.5f * totalHeight;
                    var maxY = geometricCenter + 0.5f * totalHeight;
                    for (int s = 0; s < data.numSeries; ++s)
                    {
                        if (m_MostOverlappingLabels.Contains(s))
                        {
                            continue;
                        }

                        var testRect = m_LabelData[s].position;

                        if (testRect.size.sqrMagnitude == 0f)
                        {
                            continue;
                        }

                        var x = testRect.xMax < selectedFrameMidline ? testRect.xMax : testRect.xMin;
                        if (
                            testRect.Contains(new Vector2(x, minY)) ||
                            testRect.Contains(new Vector2(x, maxY))
                            )
                        {
                            m_MostOverlappingLabels.Add(s);
                            foundOverlaps = true;
                        }
                    }

                    GetGeometricCenter(m_MostOverlappingLabels, m_LabelData, out totalHeight);

                    // keep labels inside chart rect
                    if (geometricCenter - 0.5f * totalHeight < chartPosition.yMin)
                    {
                        geometricCenter = chartPosition.yMin + 0.5f * totalHeight;
                    }
                    else if (geometricCenter + 0.5f * totalHeight > chartPosition.yMax)
                    {
                        geometricCenter = chartPosition.yMax - 0.5f * totalHeight;
                    }
                }

                // separate overlapping rects and distribute them away from their geometric center
                m_MostOverlappingLabels.Sort(SortOverlappingRectIndices);
                var heightAllotted = 0f;
                for (int i = 0; i < m_MostOverlappingLabels.Count; ++i)
                {
                    var labelIndex = m_MostOverlappingLabels[i];
                    var label      = m_LabelData[labelIndex];
                    label.position.y        = geometricCenter - totalHeight * 0.5f + heightAllotted;
                    m_LabelData[labelIndex] = label;
                    heightAllotted         += label.position.height;
                }
            }

            // draw the labels
            var oldContentColor = GUI.contentColor;

            for (int s = 0; s < data.numSeries; ++s)
            {
                var labelIndex = m_LabelOrder[s];

                if (m_LabelData[labelIndex].position.size.sqrMagnitude == 0f)
                {
                    continue;
                }

                GUI.contentColor = Color.Lerp(data.series[labelIndex].color, Color.white, Styles.labelLerpToWhiteAmount);
                var layoutData = m_LabelData[labelIndex];
                EditorGUI.DoDropShadowLabel(
                    layoutData.position,
                    EditorGUIUtility.TempContent(data.selectedLabels[labelIndex]),
                    Styles.whiteLabel,
                    Styles.labelDropShadowOpacity
                    );
            }
            GUI.contentColor = oldContentColor;
        }
Exemplo n.º 16
0
 private void DrawLabels(Rect chartPosition, ChartViewData data, int selectedFrame, Chart.ChartType chartType)
 {
     if (data.selectedLabels != null && Event.current.type == EventType.Repaint)
     {
         Vector2 dataDomain = data.GetDataDomain();
         if (selectedFrame >= data.firstSelectableFrame && selectedFrame <= data.chartDomainOffset + (int)(dataDomain.y - dataDomain.x) && dataDomain.y - dataDomain.x != 0f)
         {
             int num = selectedFrame - data.chartDomainOffset;
             this.m_LabelOrder.Clear();
             this.m_LabelOrder.AddRange(data.order);
             this.m_SelectedFrameValues.Clear();
             float num2      = 0f;
             bool  flag      = chartType == Chart.ChartType.StackedFill;
             int   num3      = 0;
             int   i         = 0;
             int   numSeries = data.numSeries;
             while (i < numSeries)
             {
                 float num4 = data.series[i].yValues[num];
                 this.m_SelectedFrameValues.Add(num4);
                 if (data.series[i].enabled)
                 {
                     num2 += num4;
                     num3++;
                 }
                 i++;
             }
             if (num3 != 0)
             {
                 this.m_LabelData.Clear();
                 float num5 = chartPosition.x + chartPosition.width * (((float)num + 0.5f) / (dataDomain.y - dataDomain.x));
                 float num6 = 0f;
                 num3 = 0;
                 int j          = 0;
                 int numSeries2 = data.numSeries;
                 while (j < numSeries2)
                 {
                     Chart.LabelLayoutData item = default(Chart.LabelLayoutData);
                     float num7 = this.m_SelectedFrameValues[j];
                     if (data.series[j].enabled && num7 >= this.labelRange.x && num7 <= this.labelRange.y)
                     {
                         Vector2 rangeAxis = data.series[j].rangeAxis;
                         float   num8      = (rangeAxis.sqrMagnitude != 0f) ? (rangeAxis.y - rangeAxis.x) : 1f;
                         if (flag)
                         {
                             float num9 = 0f;
                             for (int k = 0; k < numSeries2; k++)
                             {
                                 int num10 = data.order[k];
                                 if (num10 < j && data.series[num10].enabled)
                                 {
                                     num9 += data.series[num10].yValues[num];
                                 }
                             }
                             num7 = num2 - num9 - 0.5f * num7;
                         }
                         Vector2 position = new Vector2(num5 + 0.5f, chartPosition.y + chartPosition.height * (1f - (num7 - rangeAxis.x) / num8));
                         Vector2 size     = Chart.Styles.whiteLabel.CalcSize(EditorGUIUtility.TempContent(data.selectedLabels[j]));
                         position.y           -= 0.5f * size.y;
                         position.y            = Mathf.Clamp(position.y, chartPosition.yMin, chartPosition.yMax - size.y);
                         item.position         = new Rect(position, size);
                         item.desiredYPosition = item.position.center.y;
                         num3++;
                     }
                     this.m_LabelData.Add(item);
                     num6 = Mathf.Max(num6, item.position.width);
                     j++;
                 }
                 if (num3 != 0)
                 {
                     if (!flag)
                     {
                         this.m_LabelOrder.Sort(new Comparison <int>(this.SortLineLabelIndices));
                     }
                     if (num5 > chartPosition.x + chartPosition.width - num6)
                     {
                         int l          = 0;
                         int numSeries3 = data.numSeries;
                         while (l < numSeries3)
                         {
                             Chart.LabelLayoutData value = this.m_LabelData[l];
                             value.position.x    = value.position.x - value.position.width;
                             this.m_LabelData[l] = value;
                             l++;
                         }
                     }
                     else if (num5 > chartPosition.x + num6)
                     {
                         int num11      = 0;
                         int m          = 0;
                         int numSeries4 = data.numSeries;
                         while (m < numSeries4)
                         {
                             int index = this.m_LabelOrder[m];
                             if (this.m_LabelData[index].position.size.sqrMagnitude != 0f)
                             {
                                 if ((num11 & 1) == 0)
                                 {
                                     Chart.LabelLayoutData value2 = this.m_LabelData[index];
                                     value2.position.x       = value2.position.x - (value2.position.width + 1f);
                                     this.m_LabelData[index] = value2;
                                 }
                                 num11++;
                             }
                             m++;
                         }
                     }
                     for (int n = 0; n < 5; n++)
                     {
                         this.m_MostOverlappingLabels.Clear();
                         int num12      = 0;
                         int numSeries5 = data.numSeries;
                         while (num12 < numSeries5)
                         {
                             this.m_OverlappingLabels.Clear();
                             this.m_OverlappingLabels.Add(num12);
                             if (this.m_LabelData[num12].position.size.sqrMagnitude != 0f)
                             {
                                 for (int num13 = 0; num13 < numSeries5; num13++)
                                 {
                                     if (this.m_LabelData[num13].position.size.sqrMagnitude != 0f)
                                     {
                                         if (num12 != num13 && this.m_LabelData[num12].position.Overlaps(this.m_LabelData[num13].position))
                                         {
                                             this.m_OverlappingLabels.Add(num13);
                                         }
                                     }
                                 }
                                 if (this.m_OverlappingLabels.Count > this.m_MostOverlappingLabels.Count)
                                 {
                                     this.m_MostOverlappingLabels.Clear();
                                     this.m_MostOverlappingLabels.AddRange(this.m_OverlappingLabels);
                                 }
                             }
                             num12++;
                         }
                         if (this.m_MostOverlappingLabels.Count == 1)
                         {
                             break;
                         }
                         float num15;
                         float num14 = this.GetGeometricCenter(this.m_MostOverlappingLabels, this.m_LabelData, out num15);
                         bool  flag2 = true;
                         while (flag2)
                         {
                             flag2 = false;
                             float y          = num14 - 0.5f * num15;
                             float y2         = num14 + 0.5f * num15;
                             int   num16      = 0;
                             int   numSeries6 = data.numSeries;
                             while (num16 < numSeries6)
                             {
                                 if (!this.m_MostOverlappingLabels.Contains(num16))
                                 {
                                     Rect position2 = this.m_LabelData[num16].position;
                                     if (position2.size.sqrMagnitude != 0f)
                                     {
                                         float x = (position2.xMax >= num5) ? position2.xMin : position2.xMax;
                                         if (position2.Contains(new Vector2(x, y)) || position2.Contains(new Vector2(x, y2)))
                                         {
                                             this.m_MostOverlappingLabels.Add(num16);
                                             flag2 = true;
                                         }
                                     }
                                 }
                                 num16++;
                             }
                             this.GetGeometricCenter(this.m_MostOverlappingLabels, this.m_LabelData, out num15);
                             if (num14 - 0.5f * num15 < chartPosition.yMin)
                             {
                                 num14 = chartPosition.yMin + 0.5f * num15;
                             }
                             else if (num14 + 0.5f * num15 > chartPosition.yMax)
                             {
                                 num14 = chartPosition.yMax - 0.5f * num15;
                             }
                         }
                         this.m_MostOverlappingLabels.Sort(new Comparison <int>(this.SortOverlappingRectIndices));
                         float num17 = 0f;
                         int   num18 = 0;
                         int   count = this.m_MostOverlappingLabels.Count;
                         while (num18 < count)
                         {
                             int index2 = this.m_MostOverlappingLabels[num18];
                             Chart.LabelLayoutData value3 = this.m_LabelData[index2];
                             value3.position.y        = num14 - num15 * 0.5f + num17;
                             this.m_LabelData[index2] = value3;
                             num17 += value3.position.height;
                             num18++;
                         }
                     }
                     Color contentColor = GUI.contentColor;
                     for (int num19 = 0; num19 < data.numSeries; num19++)
                     {
                         int num20 = this.m_LabelOrder[num19];
                         if (this.m_LabelData[num20].position.size.sqrMagnitude != 0f)
                         {
                             GUI.contentColor = Color.Lerp(data.series[num20].color, Color.white, Chart.Styles.labelLerpToWhiteAmount);
                             EditorGUI.DoDropShadowLabel(this.m_LabelData[num20].position, EditorGUIUtility.TempContent(data.selectedLabels[num20]), Chart.Styles.whiteLabel, Chart.Styles.labelDropShadowOpacity);
                         }
                     }
                     GUI.contentColor = contentColor;
                 }
             }
         }
     }
 }