private void itemsRangeSelectedHandler(GraphItem fromGi, GraphItem toGi) { try { Waypoint fromTrkpt = (Waypoint)fromGi.itemKeyObj; Waypoint toTrkpt = (Waypoint)toGi.itemKeyObj; if(fromTrkpt != null && toTrkpt != null) { SelectFilter.track = this.tgc.Track; SelectFilter.fromTrkpt = fromTrkpt; SelectFilter.toTrkpt = toTrkpt; SelectFilter.Enabled = true; } else { SelectFilter.reset(); } } catch { SelectFilter.reset(); } PictureManager.This.Refresh(); }
private void itemSelectedHandler(GraphItem gi) { resetSelection(); try { Waypoint trkpt = (Waypoint)gi.itemKeyObj; PictureManager.This.CameraManager.MarkLocation(trkpt.Location, 3); } catch {} }
protected int graphValue(GraphItem 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_lastItem; // 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_lastItem = ev; return value; }
private void selectItem(GraphItem gi, int x) { if(m_descrById != null && gi.ids() != null) { m_selectedId = gi.ids()[0]; m_messageMain = m_descrById(m_selectedId); m_messageSecondary = gi.toTableString(); } else { m_selectedId = -1; m_messageMain = gi.toTableString1(); m_messageSecondary = gi.toTableString(); } string[] properties = gi.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; if(itemSelected != null) { itemSelected(gi); } this.Invalidate(); }
private void GraphControl_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_allItems == null || m_allItems.Count < 1 || m_graphItems == null) { // can't draw any more until items 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_graphItems.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_graphItems.Length; int lastGoodItem = indexCap - 1; while(lastGoodItem >= 0 && m_graphItems[lastGoodItem--] == null) { ; } int nullItemCount = 0; for(int i=0; i < m_graphsCount ;i++) { pen = new Pen(m_colors[i]); m_lastItem = null; int lastX = -10000; int lastY = -10000; bool startplot = false; for (int x=0; x < indexCap ;x++) { GraphItem currItem = m_graphItems[x]; if(currItem != null) { startplot = true; } else { nullItemCount++; } int currValue = graphValue(currItem, i); GraphItem nextItem = m_graphItems[x == indexCap-1 ? x : x + 1]; int nextValue = graphValue(nextItem, i); switch(m_graphMode) { case GRAPH_MODE_INTERPOLATE: { if(currItem != null && nextItem != 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(nextItem != 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(currItem != null && nullItemCount > 20) { g.DrawEllipse(pen, x + m_xZeroMark - 1, currValue - 1, 3, 3); } } break; } if(currItem != null) { nullItemCount = 0; } if(m_graphMode == GRAPH_MODE_STEPPED) { if( x >= lastGoodItem ) { // all items till end are null. stop drawing lines. m_lastItem = null; break; // the inner "for" loop } } } } }
private void rebuildGraph() { if(m_track == null) { m_allItems = null; m_graphItems = null; this.Invalidate(); return; } Cursor.Current = Cursors.WaitCursor; m_elevMax = -100000.0d; // feet m_elevMin = 100000.0d; m_speedMax = -1000.0d; SortedList graphItems = new SortedList(); Waypoint prevWpt = null; double odometer = 0.0d; // meters for(int i=0; i < m_track.Trackpoints.Count ;i++) { Waypoint wpt = (Waypoint)m_track.Trackpoints.GetByIndex(i); Speed speed = null; Distance leg = null; double dSpeedCurrentUnits = 0.0d; if(prevWpt != null) { // compute odometer and speed: TimeSpan dt = wpt.DateTime - prevWpt.DateTime; leg = wpt.Location.distanceFrom(prevWpt.Location); // meters double legMeters = leg.Meters; odometer += legMeters; double legMetersPerHour = legMeters * 36000000000.0d / dt.Ticks; // meters per hour if(!m_track.isRoute && legMetersPerHour > 1000.0d && legMetersPerHour < 330.0d * 3600.0d) // sanity check - speed of sound, m/hr { speed = new Speed(legMetersPerHour); dSpeedCurrentUnits = speed.ToDouble(); } } odometer = (float)odometer; long id = (long)i; double elevCurrentUnits = new Distance(wpt.Location.Elev).ToDoubleCompl(); string properties = wpt.toTableString(); m_elevMax = Math.Max(elevCurrentUnits, m_elevMax); m_elevMin = Math.Min(elevCurrentUnits, m_elevMin); m_speedMax = Math.Max(dSpeedCurrentUnits, m_speedMax); long[] ids = new long[2]; ids[0] = id; ids[1] = id; double[] values = new double[2]; values[0] = elevCurrentUnits; values[1] = dSpeedCurrentUnits; string[] sValues = new string[2]; sValues[0] = properties; sValues[1] = ""; GraphItem ev = new GraphItem(odometer, wpt, values, sValues, ids, 2); while(true) { try { graphItems.Add(odometer, ev); break; } catch { odometer += 0.01d; } } prevWpt = wpt; } if(m_elevMax > 0.0d && m_speedMax > 0.0d) { // make speed graph match the elevation: double speedFactor = 0.6d * m_elevMax / m_speedMax; foreach(GraphItem ev in graphItems.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 / rounder) * rounder; int steps = (int) (graphGridMaxValue / rounder); this.MaxValueY = graphGridMaxValue; this.MinKeyDblMargin = 100.0d; this.StepY = graphGridMaxValue / steps; this.MarginLeft = 45; this.MarginRight = 30; this.initialHint = "Click on graph to see details. Use arrow keys. Drag mouse to select a " + (m_track.isRoute ? "route" : "track") + " segment, click into it to zoom."; this.init(this.enableDisable, "", "", selHint, dDescrById, dZoomById, dBrowseById, new MethodInvoker(showSelected)); this.setGraphData(graphItems, Project.FORMAT_TRACK_ELEVATION, 2, false); this.SelectItemByObject(m_trkpt); this.resetLegends(); this.setLegend(0, "elevation"); this.setLegend(1, "speed"); this.Invalidate(); Cursor.Current = Cursors.Default; }