Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Axis"/> class
        /// mostly with default values.
        /// </summary>
        /// <param name="TextInstance">The text instance.</param>
        public Axis(TextInstance TextInstance)
        {
            _majorTic = new MajorTic();
            _minorTic = new MinorTic();

            _zoomCorrection = Default.zoomCorrection;
            _zoomDiff       = Default.zoomDiff;

            _axisGap  = Default.AxisGap;
            _numSpace = Default.numSpace;
            _scale    = new Scale(this, TextInstance);

            _textInstance = TextInstance;
        }
Exemple #2
0
        /// <summary>
        /// Draws the minor tics.
        /// </summary>
        /// <param name="chart">The chart.</param>
        public void DrawMinorTics(Chart chart)
        {
            MinorTic tic = _ownerAxis._minorTic;

            // Minor tics start at the minimum value and step all the way through
            // the full scale.  This means that if the minor step size is not
            // an even division of the major step size, the minor tics won't
            // line up with all of the scale labels and major tics.
            double first = _min, last = _max;
            int    k = 0;

            double dVal = first;
            float  pixVal;

            int iTic     = (int)(_min / _minorStep);
            int firstTic = iTic;

            _ticsArray = new Vector2[600];

            int    MajorTic = 0;
            double majorVal = _majorStep * MajorTic;

            // Draw the minor tic marks
            while (dVal < last && iTic < 300 + firstTic)
            {
                // Calculate the scale value for the current tic
                dVal = _minorStep * iTic;
                // Maintain a value for the current major tic
                if (dVal > majorVal)
                {
                    majorVal = _majorStep * (++MajorTic);
                }

                // Make sure that the current value does not match up with a major tic
                if (((Math.Abs(dVal) < 1e-20 && Math.Abs(dVal - majorVal) > 1e-20) ||
                     (Math.Abs(dVal) > 1e-20 && Math.Abs((dVal - majorVal) / dVal) > 1e-10)))
                {
                    pixVal = LocalTransform(dVal);

                    if (this._ownerAxis is XAxis)
                    {
                        _ticsArray[k].X     = -2 * pixVal / chart.Rect.Width + 1;
                        _ticsArray[k + 1].X = -2 * pixVal / chart.Rect.Width + 1;
                        _ticsArray[k].Y     = -1;
                        _ticsArray[k + 1].Y = 1;
                    }
                    else if (this._ownerAxis is YAxis)
                    {
                        _ticsArray[k].X     = -1;
                        _ticsArray[k + 1].X = 1;
                        _ticsArray[k].Y     = -2 * pixVal / chart.Rect.Height + 1;
                        _ticsArray[k + 1].Y = -2 * pixVal / chart.Rect.Height + 1;
                    }
                    k += 2;
                }

                iTic++;
            }
            if (this._ownerAxis is XAxis)
            {//the Viewports are directly put over the axis, so the _ticsArray has numbers rangig from -1 to 1 int one direction, just fitting the rectangle
                GL.Viewport((int)chart.Rect.X, (int)(chart.Rect.Y - tic.Size), (int)chart.Rect.Width, (int)(2 * tic.Size));
            }
            else if (this._ownerAxis is YAxis)
            {
                GL.Viewport((int)(chart.Rect.X - tic.Size - _ownerAxis._fixedSpace * (this._ownerAxis as YAxis).Index), (int)chart.Rect.Y, (int)(2 * tic.Size), (int)chart.Rect.Height);
            }

            _linesShader.Use();
            GL.BindVertexArray(_VAO);

            GL.BindBuffer(BufferTarget.ArrayBuffer, _VBO);
            GL.BufferData <Vector2>(BufferTarget.ArrayBuffer, (IntPtr)(Vector2.SizeInBytes * _ticsArray.Length), _ticsArray, BufferUsageHint.StaticDraw);

            GL.VertexAttribPointer(_linesShader.VertexLocation, 2, VertexAttribPointerType.Float, false, Vector2.SizeInBytes, 0);

            GL.Uniform4(_linesShader.ColorLocation, Color.Black);
            GL.UniformMatrix4(_linesShader.MatrixLocation, false, ref _mat);

            GL.DrawArrays(PrimitiveType.Lines, 0, k);
            GL.BindVertexArray(0);
            _linesShader.StopUse();
        }