protected void UpdateChart()
    {
        if (m_fd.Data == null)
        {
            return;
        }

        gcData.XLabel  = (cmbXAxis.SelectedItem == null) ? "" : cmbXAxis.SelectedItem.Text;
        gcData.YLabel  = (cmbYAxis1.SelectedItem == null) ? "" : cmbYAxis1.SelectedItem.Text;
        gcData.Y2Label = (cmbYAxis2.SelectedIndex == 0 || cmbYAxis2 == null) ? "" : cmbYAxis2.SelectedItem.Text;

        gcData.Clear();

        gcData.XDataType  = gcData.GoogleTypeFromKnownColumnType(KnownColumn.GetKnownColumn(cmbXAxis.SelectedValue).Type);
        gcData.YDataType  = gcData.GoogleTypeFromKnownColumnType(KnownColumn.GetKnownColumn(cmbYAxis1.SelectedValue).Type);
        gcData.Y2DataType = gcData.GoogleTypeFromKnownColumnType(KnownColumn.GetKnownColumn(cmbYAxis2.SelectedValue).Type);

        if (cmbYAxis1.SelectedItem == null || cmbYAxis2.SelectedItem == null)
        {
            gcData.Visible = false;
            return;
        }

        if (m_fd.HasLatLongInfo)
        {
            gcData.ClickHandlerJS = String.Format(CultureInfo.InvariantCulture, "dropPin({0}[selectedItem.row], xvalue + ': ' + ((selectedItem.column == 1) ? '{1}' : '{2}') + ' = ' + value);", PathLatLongArrayID, cmbYAxis1.SelectedItem.Text, cmbYAxis2.SelectedItem.Text);
        }

        foreach (DataRow dr in m_fd.Data.Rows)
        {
            gcData.XVals.Add(dr[cmbXAxis.SelectedValue]);

            if (!String.IsNullOrEmpty(cmbYAxis1.SelectedValue))
            {
                gcData.YVals.Add(dr[cmbYAxis1.SelectedValue]);
            }
            if (cmbYAxis2.SelectedValue.Length > 0 && cmbYAxis2.SelectedValue != cmbYAxis1.SelectedValue)
            {
                gcData.Y2Vals.Add(dr[cmbYAxis2.SelectedValue]);
            }
        }
        gcData.TickSpacing = 1; // Math.Max(1, m_fd.Data.Rows.Count / 20);

        // Clear out the grid.
        gvData.DataSource = null;
        gvData.DataBind();
        apcRaw.LazyLoad = true;

        int idx = mfbAccordionProxyExtender.IndexForProxyID(apcRaw.ID);

        mfbAccordionProxyExtender.SetJavascriptForControl(apcRaw, idx == AccordionCtrl.SelectedIndex, idx);
    }
    protected void UpdateChart()
    {
        decimal max  = decimal.MinValue;
        decimal min  = decimal.MaxValue;
        decimal max2 = decimal.MinValue;
        decimal min2 = decimal.MaxValue;

        TelemetryDataTable tdt = TelemetryData;

        if (tdt == null)
        {
            return;
        }

        gcData.XLabel  = (cmbXAxis.SelectedItem == null) ? "" : cmbXAxis.SelectedItem.Text;
        gcData.YLabel  = (cmbYAxis1.SelectedItem == null) ? "" : cmbYAxis1.SelectedItem.Text;
        gcData.Y2Label = (cmbYAxis2.SelectedIndex == 0 || cmbYAxis2 == null) ? "" : cmbYAxis2.SelectedItem.Text;

        gcData.Clear();

        gcData.XDataType  = gcData.GoogleTypeFromKnownColumnType(KnownColumn.GetKnownColumn(cmbXAxis.SelectedValue).Type);
        gcData.YDataType  = gcData.GoogleTypeFromKnownColumnType(KnownColumn.GetKnownColumn(cmbYAxis1.SelectedValue).Type);
        gcData.Y2DataType = gcData.GoogleTypeFromKnownColumnType(KnownColumn.GetKnownColumn(cmbYAxis2.SelectedValue).Type);

        if (cmbYAxis1.SelectedItem == null || cmbYAxis2.SelectedItem == null)
        {
            gcData.Visible = false;
            return;
        }

        if (m_fd.HasLatLongInfo)
        {
            gcData.ClickHandlerJS = String.Format(CultureInfo.InvariantCulture, "dropPin({0}[selectedItem.row], xvalue + ': ' + ((selectedItem.column == 1) ? '{1}' : '{2}') + ' = ' + value);", PathLatLongArrayID, cmbYAxis1.SelectedItem.Text, cmbYAxis2.SelectedItem.Text);
        }

        foreach (DataRow dr in tdt.Rows)
        {
            gcData.XVals.Add(dr[cmbXAxis.SelectedValue]);

            if (!String.IsNullOrEmpty(cmbYAxis1.SelectedValue))
            {
                object o = dr[cmbYAxis1.SelectedValue];
                gcData.YVals.Add(o);
                if (gcData.YDataType == Controls_GoogleChart.GoogleColumnDataType.number)
                {
                    decimal d = Convert.ToDecimal(o, CultureInfo.InvariantCulture);
                    max = Math.Max(max, d);
                    min = Math.Min(min, d);
                }
            }
            if (cmbYAxis2.SelectedValue.Length > 0 && cmbYAxis2.SelectedValue != cmbYAxis1.SelectedValue)
            {
                object o = dr[cmbYAxis2.SelectedValue];
                gcData.Y2Vals.Add(o);
                if (gcData.Y2DataType == Controls_GoogleChart.GoogleColumnDataType.number)
                {
                    decimal d = Convert.ToDecimal(o, CultureInfo.InvariantCulture);
                    max2 = Math.Max(max2, d);
                    min2 = Math.Min(min2, d);
                }
            }
        }
        gcData.TickSpacing = 1; // Math.Max(1, m_fd.Data.Rows.Count / 20);

        // Clear out the grid.
        gvData.DataSource = null;
        gvData.DataBind();
        apcRaw.LazyLoad = true;

        int idx = mfbAccordionProxyExtender.IndexForProxyID(apcRaw.ID);

        mfbAccordionProxyExtender.SetJavascriptForControl(apcRaw, idx == AccordionCtrl.SelectedIndex, idx);

        lblMaxY.Text  = max > decimal.MinValue && !String.IsNullOrEmpty(gcData.YLabel) ? String.Format(CultureInfo.CurrentCulture, Resources.LocalizedText.ChartMaxX, gcData.YLabel, max) : string.Empty;
        lblMinY.Text  = min < decimal.MaxValue && !String.IsNullOrEmpty(gcData.YLabel) ? String.Format(CultureInfo.CurrentCulture, Resources.LocalizedText.ChartMinX, gcData.YLabel, min) : string.Empty;
        lblMaxY2.Text = max2 > decimal.MinValue && !String.IsNullOrEmpty(gcData.Y2Label) ? String.Format(CultureInfo.CurrentCulture, Resources.LocalizedText.ChartMaxX, gcData.Y2Label, max2) : string.Empty;
        lblMinY2.Text = min2 < decimal.MaxValue && !String.IsNullOrEmpty(gcData.Y2Label) ? String.Format(CultureInfo.CurrentCulture, Resources.LocalizedText.ChartMinX, gcData.Y2Label, min2) : string.Empty;
    }
    protected void SetUpChart(DataTable data)
    {
        if (data == null)
        {
            return;
        }

        // now set up the chart
        cmbXAxis.Items.Clear();
        cmbYAxis1.Items.Clear();
        cmbYAxis2.Items.Clear();
        cmbYAxis2.Items.Add(new ListItem(Resources.FlightData.GraphNoData, ""));
        cmbYAxis2.SelectedIndex = 0;

        foreach (DataColumn dc in data.Columns)
        {
            KnownColumn kc = KnownColumn.GetKnownColumn(dc.Caption);

            if (kc.Type.CanGraph())
            {
                cmbXAxis.Items.Add(new ListItem(kc.FriendlyName, kc.Column));
            }
            if (kc.Type == KnownColumnTypes.ctDec || kc.Type == KnownColumnTypes.ctFloat || kc.Type == KnownColumnTypes.ctInt)
            {
                cmbYAxis1.Items.Add(new ListItem(kc.FriendlyName, kc.Column));
                cmbYAxis2.Items.Add(new ListItem(kc.FriendlyName, kc.Column));
            }
        }

        // Select a date or time column for the X axis if possible; if not, select "SAMPLES"
        if (cmbXAxis.Items.Count > 0)
        {
            if (data.Columns["DATE"] != null)
            {
                cmbXAxis.SelectedValue = "DATE";
            }
            else if (data.Columns["TIME"] != null)
            {
                cmbXAxis.SelectedValue = "TIME";
            }
            else if (data.Columns["SAMPLE"] != null)
            {
                cmbXAxis.SelectedValue = "SAMPLE";
            }
            else
            {
                cmbXAxis.SelectedIndex = 0;
            }
        }

        // if there is something numeric for the Y axis, select it.  Otherwise, default to the first item.
        if (cmbYAxis1.Items.Count > 0)
        {
            cmbYAxis1.SelectedIndex = 0;
        }

        foreach (ListItem li in cmbYAxis1.Items)
        {
            KnownColumn kc = KnownColumn.GetKnownColumn(li.Value);
            if (kc.Type != KnownColumnTypes.ctDateTime && kc.Type != KnownColumnTypes.ctLatLong && kc.Column != "SAMPLE")
            {
                cmbYAxis1.SelectedValue = kc.Column;
                break;
            }
        }
    }
Пример #4
0
    protected static void UpdateChart(TelemetryDataTable tdt, Controls_GoogleChart gcData, FlightData fd, string PathLatLongArrayID, ListItem xAxis, ListItem yAxis1, ListItem yAxis2, out decimal max, out decimal min, out decimal max2, out decimal min2)
    {
        max  = decimal.MinValue;
        min  = decimal.MaxValue;
        max2 = decimal.MinValue;
        min2 = decimal.MaxValue;

        if (tdt == null)
        {
            return;
        }

        if (gcData == null)
        {
            throw new ArgumentNullException(nameof(gcData));
        }

        if (yAxis1 == null || yAxis2 == null || xAxis == null)
        {
            gcData.Visible = false;
            return;
        }

        gcData.XLabel  = xAxis.Text;
        gcData.YLabel  = yAxis1.Text;
        gcData.Y2Label = yAxis2.Text;

        gcData.Clear();

        gcData.XDataType  = GoogleChart.GoogleTypeFromKnownColumnType(KnownColumn.GetKnownColumn(xAxis.Value).Type);
        gcData.YDataType  = GoogleChart.GoogleTypeFromKnownColumnType(KnownColumn.GetKnownColumn(yAxis1.Value).Type);
        gcData.Y2DataType = GoogleChart.GoogleTypeFromKnownColumnType(KnownColumn.GetKnownColumn(yAxis2.Value).Type);

        if (fd == null)
        {
            throw new ArgumentNullException(nameof(fd));
        }

        if (fd.HasLatLongInfo)
        {
            gcData.ClickHandlerJS = String.Format(CultureInfo.InvariantCulture, "dropPin({0}[selectedItem.row], xvalue + ': ' + ((selectedItem.column == 1) ? '{1}' : '{2}') + ' = ' + value);", PathLatLongArrayID, yAxis1, yAxis2);
        }

        foreach (DataRow dr in tdt.Rows)
        {
            gcData.XVals.Add(dr[xAxis.Value]);

            if (!String.IsNullOrEmpty(yAxis1.Value))
            {
                object o = dr[yAxis1.Value];
                gcData.YVals.Add(o);
                if (gcData.YDataType == GoogleColumnDataType.number)
                {
                    decimal d = Convert.ToDecimal(o, CultureInfo.InvariantCulture);
                    max = Math.Max(max, d);
                    min = Math.Min(min, d);
                }
            }
            if (yAxis2.Value.Length > 0 && yAxis2 != yAxis1)
            {
                object o = dr[yAxis2.Value];
                gcData.Y2Vals.Add(o);
                if (gcData.Y2DataType == GoogleColumnDataType.number)
                {
                    decimal d = Convert.ToDecimal(o, CultureInfo.InvariantCulture);
                    max2 = Math.Max(max2, d);
                    min2 = Math.Min(min2, d);
                }
            }
        }
        gcData.TickSpacing = 1; // Math.Max(1, m_fd.Data.Rows.Count / 20);
    }
Пример #5
0
        private void SetUpContextFromHeaderRow(CSVParsingContext pc, string[] rgszHeader)
        {
            // This is a hack for JPI date, which has a "DATE" and a "TIME" column, which are actually both naked.  So effectively re-name them to indicate naked
            int iDateCol = -1;
            int iTimeCol = -1;

            for (int i = 0; i < rgszHeader.Length; i++)
            {
                if (String.Compare(rgszHeader[i], KnownColumnNames.DATE, StringComparison.CurrentCultureIgnoreCase) == 0)
                {
                    iDateCol = i;
                }
                if (String.Compare(rgszHeader[i], KnownColumnNames.TIME, StringComparison.CurrentCultureIgnoreCase) == 0)
                {
                    iTimeCol = i;
                }
            }
            if (iDateCol >= 0 && iTimeCol >= 0)
            {
                rgszHeader[iDateCol] = "LOCAL DATE";
                rgszHeader[iTimeCol] = "LOCAL TIME";
            }

            for (int i = 0; i < rgszHeader.Length; i++)
            {
                KnownColumn kc = KnownColumn.GetKnownColumn(rgszHeader[i].Trim());
                pc.ColumnList.Add(kc);
                if (kc.Type == KnownColumnTypes.ctNakedDate)
                {
                    pc.fHasNakedDate = true;
                }
                if (kc.Type == KnownColumnTypes.ctNakedTime)
                {
                    pc.fHasNakedTime = true;
                }
                ParsedData.Columns.Add(new DataColumn(kc.ColumnHeaderName, KnownColumn.ColumnDataType(kc.Type)));
            }

            pc.fDeriveDateTime = pc.fHasNakedTime && pc.fHasNakedDate && !ParsedData.HasDateTime;
            if (pc.fDeriveDateTime)
            {
                KnownColumn kc = KnownColumn.GetKnownColumn(KnownColumnNames.UTCDateTime);
                pc.ColumnList.Add(kc);
                DataColumn dc = new DataColumn(kc.Column, KnownColumn.ColumnDataType(kc.Type));
                ParsedData.Columns.Add(dc);
                dc.DateTimeMode = DataSetDateTime.Utc;
                pc.derivedColumnCount++;
            }

            pc.fHasDateTime = ParsedData.HasDateTime;
            pc.fHasTimezone = ParsedData.HasTimezone;

            pc.szDateCol = ParsedData.DateColumn;                                 // Set this before deriving a UTCDateTime so that when we derive UTCDateTime, we don't try to read from it.

            if (pc.fHasDateTime && pc.fHasTimezone && !ParsedData.HasUTCDateTime) // add a UTC time as well
            {
                pc.fDeriveUTCDateTime = true;
                KnownColumn kc = KnownColumn.GetKnownColumn(KnownColumnNames.UTCDateTime);
                pc.ColumnList.Add(kc);
                ParsedData.Columns.Add(new DataColumn(kc.Column, KnownColumn.ColumnDataType(kc.Type)));
                pc.derivedColumnCount++;
            }

            pc.fDeriveSpeed = (ParsedData.HasLatLongInfo && pc.fHasDateTime && !ParsedData.HasSpeed);
            if (pc.fDeriveSpeed)
            {
                KnownColumn kc = KnownColumn.GetKnownColumn(KnownColumnNames.DERIVEDSPEED);
                pc.ColumnList.Add(kc);
                ParsedData.Columns.Add(new DataColumn(kc.Column, KnownColumn.ColumnDataType(kc.Type)));
                pc.derivedColumnCount++;
            }
        }
    /// <summary>
    /// Loads the data for the specified flight, parsing the CSV file, and thus initializing m_fd.  This is cached, so it's OK to call multiple times.
    /// </summary>
    /// <param name="idFlight">ID of the flight with data to load</param>
    protected void LoadData(LogbookEntry le)
    {
        if (le == null)
        {
            throw new ArgumentNullException("le");
        }
        string szCacheKey = KeyCacheData(le.FlightID);

        TelemetryDataTable dt = (TelemetryDataTable)Session[szCacheKey];

        if (dt != null)
        {
            m_fd.Data = dt;
        }

        if (m_fd.NeedsComputing)
        {
            if (!m_fd.ParseFlightData(le.FlightData) && (lblErr.Text = m_fd.ErrorString.Replace("\r\n", "<br />")).Length > 0)
            {
                pnlErrors.Visible = true;
            }

            if (m_fd.Data != null)
            {
                Session[szCacheKey] = m_fd.Data; // cache the results.

                // now set up the chart
                cmbXAxis.Items.Clear();
                cmbYAxis1.Items.Clear();
                cmbYAxis2.Items.Clear();
                cmbYAxis2.Items.Add(new ListItem(Resources.FlightData.GraphNoData, ""));
                cmbYAxis2.SelectedIndex = 0;

                foreach (DataColumn dc in m_fd.Data.Columns)
                {
                    KnownColumn kc = KnownColumn.GetKnownColumn(dc.Caption);

                    if (kc.Type.CanGraph())
                    {
                        cmbXAxis.Items.Add(new ListItem(kc.FriendlyName, kc.Column));
                    }
                    if (kc.Type == KnownColumnTypes.ctDec || kc.Type == KnownColumnTypes.ctFloat || kc.Type == KnownColumnTypes.ctInt)
                    {
                        cmbYAxis1.Items.Add(new ListItem(kc.FriendlyName, kc.Column));
                        cmbYAxis2.Items.Add(new ListItem(kc.FriendlyName, kc.Column));
                    }
                }

                // Select a date or time column for the X axis if possible; if not, select "SAMPLES"
                if (cmbXAxis.Items.Count > 0)
                {
                    if (m_fd.Data.Columns["DATE"] != null)
                    {
                        cmbXAxis.SelectedValue = "DATE";
                    }
                    else if (m_fd.Data.Columns["TIME"] != null)
                    {
                        cmbXAxis.SelectedValue = "TIME";
                    }
                    else if (m_fd.Data.Columns["SAMPLE"] != null)
                    {
                        cmbXAxis.SelectedValue = "SAMPLE";
                    }
                    else
                    {
                        cmbXAxis.SelectedIndex = 0;
                    }
                }

                // if there is something numeric for the Y axis, select it.  Otherwise, default to the first item.
                if (cmbYAxis1.Items.Count > 0)
                {
                    cmbYAxis1.SelectedIndex = 0;
                }

                foreach (ListItem li in cmbYAxis1.Items)
                {
                    KnownColumn kc = KnownColumn.GetKnownColumn(li.Value);
                    if (kc.Type != KnownColumnTypes.ctDateTime && kc.Type != KnownColumnTypes.ctLatLong && kc.Column != "SAMPLE")
                    {
                        cmbYAxis1.SelectedValue = kc.Column;
                        break;
                    }
                }
            }
        }
    }