Exemplo n.º 1
0
 private void selectEvent(DatedEvent ev, int x)
 {
     if(m_descrById != null && ev.ids() != null)
     {
         m_selectedId = ev.ids()[0];
         m_messageMain = m_descrById(m_selectedId);
         m_messageSecondary = ev.toTableString();
     }
     else
     {
         m_selectedId = -1;
         m_messageMain = ev.toTableString1();
         m_messageSecondary = ev.toTableString();
     }
     string[] properties = ev.sValues();
     if(m_selectedId != -1)
     {
         if(properties != null && properties[0].IndexOf("w") != -1)
         {
             m_enDis.enable(ED_BROWSE);
         }
         else
         {
             m_enDis.disable(ED_BROWSE);
         }
         m_enDis.enable(ED_ZOOM);
     }
     m_selected = x;
     m_lastX = m_selected;
     this.Invalidate();
 }
Exemplo n.º 2
0
 public bool Equals(DatedEvent de)
 {
     return de.toString().Equals(this.toString());
 }
Exemplo n.º 3
0
        private void GraphByTimeControl_Paint(object sender, System.Windows.Forms.PaintEventArgs pe)
        {
            //Brush bb = new LinearGradientBrush(this.ClientRectangle, Color.Red, Color.Yellow, 90, false);
            Brush bb = new SolidBrush(Color.Black);

            Graphics g = pe.Graphics;
            g.FillRectangle(bb, this.ClientRectangle);

            if(dragging)
            {
                g.FillRectangle(m_selectionBrush, currentRubberRect);
                prevRubberRect = currentRubberRect;
            }

            m_currSize = this.ClientRectangle.Size;

            Pen pen = new Pen(m_colorBright);
            g.DrawRectangle(pen, 1, 1, m_currSize.Width-3, m_currSize.Height-3);
            if(m_iconMode)
            {
                pen = new Pen(m_colorDim);
            }

            if(m_format == Project.FORMAT_UNKNOWN)
            {
                Brush brush = new SolidBrush(m_colorBright);
                string msg = m_messageInitial;
                int len = msg.Length;
                int msgWidth = m_charWidthLarge * len;
                int msgPos = (m_currSize.Width - msgWidth)/2;
                if(len > 0)
                {
                    g.DrawString(msg, m_fontLarge, brush, msgPos, 16);
                }
                if(!m_iconMode)
                {
                    msgWidth = m_charWidthSmall * m_messageSecondary.Length;
                    msgPos = (m_currSize.Width - msgWidth)/2;
                    brush = new SolidBrush(Color.Yellow);
                    g.DrawString(m_messageSecondary, m_fontSmall, brush, msgPos, m_yMarginTop - 3);
                }
                return;
            }

            if(m_allEvents == null || m_allEvents.Count < 1 || m_graphEvents == null)
            {
                // can't draw any more until events are defined
                m_messageMain = "        No data to display";
                m_messageSecondary = "";
                drawMessages(g);
                return;
            }

            if(!markSelectedArea(g))
            {
                drawMessages(g);
            }
            else
            {
                m_messageMain = "        " + m_selHint;
                m_messageSecondary = "";
                m_enDis.disable(ED_ZOOM);
                m_enDis.disable(ED_BROWSE);
                drawMessages(g);
            }

            if(m_selected > 0 && m_selected < m_graphEvents.Length)
            {
                pen = new Pen(Color.Red);
                int x = m_xZeroMark + m_selected;
                g.DrawLine(pen, x, m_yMarginTop, x, m_yZeroMark + 1);
            }

            if(!m_iconMode)
            {
                drawTitle(g);
                drawLegend(g);
                drawGrid(g);
            }

            int indexCap = m_graphEvents.Length;
            int lastGoodEvent = indexCap - 1;
            while(lastGoodEvent >= 0 && m_graphEvents[lastGoodEvent--] == null)
            {
                ;
            }

            int nullEventCount = 0;
            for(int i=0; i < m_graphsCount ;i++)
            {
                pen = new Pen(m_colors[i]);
                m_lastEvent = null;
                int lastX = -10000;
                int lastY = -10000;
                bool startplot = false;
                for (int x=0; x < indexCap ;x++)
                {
                    DatedEvent currEvent = m_graphEvents[x];
                    if(currEvent != null)
                    {
                        startplot = true;
                    }
                    else
                    {
                        nullEventCount++;
                    }
                    int currValue = graphValue(currEvent, i);
                    DatedEvent nextEvent = m_graphEvents[x == indexCap-1 ? x : x + 1];
                    int nextValue = graphValue(nextEvent, i);
                    switch(m_graphMode)
                    {
                        case GRAPH_MODE_INTERPOLATE:
                        {
                            if(currEvent != null && nextEvent != null)
                            {
                                int xx = x + m_xZeroMark;
                                int xxx = x + m_xZeroMark + 1;
                                g.DrawLine(pen, xx, currValue, xxx, nextValue);
                                lastX = xxx;
                                lastY = nextValue;
                            }
                            else if(nextEvent != null)
                            {
                                int xxx = x + m_xZeroMark + 1;
                                if(lastX != -10000 && lastY != -10000)
                                {
                                    g.DrawLine(pen, lastX, lastY, xxx, nextValue);
                                }
                                lastX = xxx;
                                lastY = nextValue;
                            }
                        }
                            break;
                        case GRAPH_MODE_PEAK:
                            if(currValue != m_yZeroMark)
                            {
                                g.DrawLine(pen, x + m_xZeroMark, currValue,	x + m_xZeroMark, m_yZeroMark);
                            }
                            break;
                        case GRAPH_MODE_STEPPED:
                            if(startplot)
                            {
                                g.DrawLine(pen, x + m_xZeroMark, currValue,
                                    x + m_xZeroMark + 1, currValue);
                                if(currValue != nextValue)
                                {
                                    g.DrawLine(pen, x + m_xZeroMark + 1, currValue,
                                        x + m_xZeroMark + 1, nextValue);
                                }
                                if(currEvent != null && nullEventCount > 20)
                                {
                                    g.DrawEllipse(pen, x + m_xZeroMark - 1, currValue - 1, 3, 3);
                                }
                            }
                            break;
                    }
                    if(currEvent != null)
                    {
                        nullEventCount = 0;
                    }
                    if(m_graphMode == GRAPH_MODE_STEPPED)
                    {
                        if( x >= lastGoodEvent )
                        {
                            // all events till end are null. stop drawing lines.
                            m_lastEvent = null;
                            break;	// the inner "for" loop
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        protected int graphValue(DatedEvent ev, int index)
        {
            // the Server Availability graph requires interpolated (stepped) line;
            // others require peaks where the data actually is:
            if(ev == null)
            {		// no data at this point.
                switch(m_graphMode)
                {
                    case GRAPH_MODE_STEPPED:
                        ev = m_lastEvent;	// may be null too
                        break;
                }
            }

            int value;
            if(ev == null || (index+1) > ev.nValues())
            {
                value = m_yZeroMark;
            }
            else
            {
                double evValue = ev.values(m_format)[index];
                if(m_format == Project.FORMAT_EARTHQUAKES_STRONGEST && evValue == 0.0d)
                {
                    evValue = 0.5d; // quakes with unknown magnitude will be small bumps on the graph
                }
                value = m_yZeroMark - (int)(evValue * m_valueFactor);
            }
            m_lastEvent = ev;
            return value;
        }
Exemplo n.º 5
0
 public bool Equals(DatedEvent de)
 {
     return(de.toString().Equals(this.toString()));
 }
Exemplo n.º 6
0
        private void rebuildGraphTab(ArrayList selectedTracksRows)
        {
            Cursor.Current = Cursors.WaitCursor;

            makeTrackpointsDS(selectedTracksRows);

            double maxElev = -1000.0d;		// feet
            double maxSpeed = -1000.0d;		// miles per hour

            SortedList events = new SortedList();
            DataTable table = m_trackpointsDS.Tables["trackpoints"];
            foreach(DataRow row in table.Rows)
            {
                /*
                 * this is what the columns are:
                myDataRow["id"];
                myDataRow["trackid"];
                myDataRow["wptidx"];
                myDataRow["name"];
                myDataRow["time"] = new SortableDateTime(wpt.DateTime);
                myDataRow["location"] = wpt.Location.ToStringWithElev();

                myDataRow["speed"] = new Speed();
                myDataRow["heading"] = string;
                myDataRow["leg"] = Distance;
                myDataRow["track"] = string;
                myDataRow["source"] = string;
                myDataRow["displayed"] = string;
                */

                DateTime time = ((SortableDateTime)row["time"]).DateTime;
                long id = (long)((int)row["id"]);

                double elev = 0.0d;		// feet
                try
                {
                    elev = Math.Round((Double)row["elevation"] / Distance.METERS_PER_FOOT);	// * factor;
                }
                catch {}

                double speed = 0.0d;	// miles per hour
                try
                {
                    speed = Math.Round(((Speed)row["speed"]).Meters / Distance.METERS_PER_MILE);	// * factor;
                }
                catch {}

                maxElev = Math.Max(elev, maxElev);
                maxSpeed = Math.Max(speed, maxSpeed);

                string url = "";
                string properties = (url.Length == 0) ? "" : "w";

                long[] ids = new long[2];
                ids[0] = id;
                ids[1] = id;
                double[] values = new double[2];
                values[0] = elev;
                values[1] = speed;
                string[] sValues = new string[2];
                sValues[0] = properties;
                sValues[1] = "";

                DatedEvent ev = new DatedEvent(time, values, sValues, ids, 2);

                while(true)
                {
                    try
                    {
                        events.Add(time, ev);
                        break;
                    }
                    catch
                    {
                        time = time.AddTicks(1);
                    }
                }
            }

            if(maxElev > 0.0d && maxSpeed > 0.0d)
            {
                // make speed graph match the elevation:
                double speedFactor = 0.6d * maxElev / maxSpeed;
                foreach(DatedEvent ev in events.Values)
                {
                    double[] values = ev.values(Project.FORMAT_TRACK_ELEVATION);
                    values[1] = Math.Round(values[1] * speedFactor);
                }
            }

            string selHint = "Click into grey area to see selected interval";
            StringById dZoomById = new StringById(zoomById);
            StringById dDescrById = new StringById(descrById);

            double rounder = 200.0d;
            if(this.m_elevMax > 10000.0d)
            {
                rounder = 2000.0d;
            }
            else if(this.m_elevMax > 1000.0d)
            {
                rounder = 1000.0d;
            }
            else if(this.m_elevMax <= 50.0d)
            {
                this.m_elevMax = 50.0d;
                rounder = 100.0d;
            }
            double graphGridMaxValue = Math.Ceiling(this.m_elevMax / (Distance.METERS_PER_FOOT * rounder)) * rounder;
            int steps = (int) (graphGridMaxValue / rounder);
            graphByTimeControl.MaxValueY = graphGridMaxValue;
            graphByTimeControl.MinTimeMargin = 1 * 60 * 1000;	// ms - 1 min
            graphByTimeControl.StepY = graphGridMaxValue / steps;

            graphByTimeControl.MarginLeft = 45;
            graphByTimeControl.MarginRight = 30;

            graphByTimeControl.initialHint = "Click on graph to see details. Use arrow keys. Drag mouse to select time interval, click into it to zoom.";

            graphByTimeControl.init(this, "", "", selHint, dDescrById, dZoomById, dBrowseById, new MethodInvoker(showSelected));
            graphByTimeControl.setGraphData(events, Project.FORMAT_TRACK_ELEVATION, 2, false);

            graphByTimeControl.resetLegends();
            graphByTimeControl.setLegend(0, "elevation");
            graphByTimeControl.setLegend(1, "speed");

            m_selectedTracksRows = selectedTracksRows;

            Cursor.Current = Cursors.Default;
        }
Exemplo n.º 7
0
        private void rebuildGraphTab()
        {
            // we need to have m_eqDS in place and current - we use it's data for the graph
            Cursor.Current = Cursors.WaitCursor;
            SortedList events = new SortedList();
            DataTable table = m_eqDS.Tables["eq"];
            foreach(DataRow row in table.Rows)
            {
                /*
                 * this is what the columns are:
                myDataRow["id"] = eq.Id;
                myDataRow["magn"] = eq.Magn;
                myDataRow["location"] = eq.Location.ToString();
                myDataRow["quality"] = eq.Quality;
                myDataRow["comment"] = eq.Comment;
                myDataRow["time"] = new SortableDateTime(eq.DateTime);
                myDataRow["displayed"] = eq.Enabled;
                myDataRow["source"] = eq.Source;
                myDataRow["url"] = eq.Url;
                */

                DateTime time = ((SortableDateTime)row["time"]).DateTime;
                long id = (long)((int)row["id"]);
                double magn = (double)row["magn"];
                string url = "" + (string)row["url"];
                string properties = (url.Length == 0) ? "" : "w";

                long[] ids = new long[1];
                ids[0] = id;
                double[] values = new double[1];
                values[0] = magn;
                string[] sValues = new string[1];
                sValues[0] = properties;
                // depending on how DS was created, we may need to convert it to UTC. DatedEvent is always UTC:
                DatedEvent ev = new DatedEvent(dsUseUtcTime ? time : Project.localToZulu(time), values, sValues, ids, 1);

                while(true)
                {
                    try
                    {
                        events.Add(time, ev);
                        break;
                    }
                    catch
                    {
                        time = time.AddTicks(1);
                    }
                }
            }
            string selHint = "Click on \"Show Selected\" to see selected interval";
            StringById dZoomById = new StringById(zoomById);
            StringById dDescrById = new StringById(descrById);
            graphByTimeControl.init(this, "", "", selHint, dDescrById, dZoomById, dBrowseById, new MethodInvoker(showSelected));
            graphByTimeControl.setGraphData(events, Project.FORMAT_EARTHQUAKES_STRONGEST, 1, false);
            //Cursor.Current = Cursors.Default;
        }