protected override ISeries ConvertInternal(IDataObject data, ResourceDictionary availableResources, Color resolvedColor, ObservableCollection<IDataObject> pointCollection, Control tooltip)
 {
     var series = new SeriesDefinition {
         Title = GetSeriesId(data),
         Opacity = GetSeriesOpacity(data),
         ItemsSource = pointCollection,
         DependentValueBinding = CreateBinding(DataToSeriesConverterBase.YParameter),
         IndependentValueBinding = CreateBinding(DataToSeriesConverterBase.XParameter),
         Tag = data
     };
     #if !SILVERLIGHT
     series.ToolTip = tooltip;
     #endif
     SetSeriesStyle(series, resolvedColor);
     return series;
 }
 /// <summary>
 /// Creates and adds DataItems for the specified SeriesDefinition's items.
 /// </summary>
 /// <param name="definition">Specified SeriesDefinition.</param>
 /// <param name="items">Sequence of items.</param>
 /// <param name="startingIndex">Starting index.</param>
 private void AddDataItems(SeriesDefinition definition, IEnumerable<object> items, int startingIndex)
 {
     int index = startingIndex;
     foreach (object item in items)
     {
         DataItems.Add(new DataItem(definition) { Value = item, Index = index });
         index++;
     }
     // Because properties (like DependentValueBinding) may still be getting set
     Dispatcher.BeginInvoke((Action)AddedDataItems);
 }
        internal void SeriesDefinitionItemsSourceCollectionChanged(SeriesDefinition definition, NotifyCollectionChangedAction action, IList oldItems, int oldStartingIndex, IList newItems, int newStartingIndex)
        {
            if (NotifyCollectionChangedAction.Replace == action)
            {
                // Perform in-place replacements
                foreach (DataItem dataItem in DataItems.Where(di => (di.SeriesDefinition == definition) && (newStartingIndex <= di.Index) && (di.Index < newStartingIndex + newItems.Count)))
                {
                    dataItem.Value = newItems[dataItem.Index - newStartingIndex];
                }
            }
            else
            {
                if (NotifyCollectionChangedAction.Reset == action)
                {
                    // Set up parameters to allow normal old/new item handling to be used
                    Debug.Assert(null == oldItems, "Reset action with non-null oldItems.");
                    oldItems = DataItems.Where(di => (di.SeriesDefinition == definition)).ToArray();
                    oldStartingIndex = 0;
                    newItems = definition.ItemsSource.CastWrapper<object>().ToArray();
                    newStartingIndex = 0;
                }
                if (null != oldItems)
                {
                    // Get rid of old items
                    foreach (DataItem oldDataItem in DataItems.Where(di => (di.SeriesDefinition == definition) && (oldStartingIndex <= di.Index) && (di.Index < oldStartingIndex + oldItems.Count)))
                    {
                        oldDataItem.Index = -1;
                        if (null != oldDataItem.DataPoint)
                        {
                            oldDataItem.DataPoint.State = DataPointState.Hiding;
                        }
                    }
                    // Adjust index of shifted items
                    foreach (DataItem dataItem in DataItems.Where(di => (di.SeriesDefinition == definition) && (oldStartingIndex + oldItems.Count <= di.Index)))
                    {
                        dataItem.Index -= oldItems.Count;
                    }
                }
                if (null != newItems)
                {
                    // Adjust index of shifted items
                    foreach (DataItem dataItem in DataItems.Where(di => (di.SeriesDefinition == definition) && (newStartingIndex <= di.Index)))
                    {
                        dataItem.Index += newItems.Count;
                    }
                    // Add new items
                    AddDataItems(definition, newItems.CastWrapper<object>(), newStartingIndex);
                }
            }
#if DEBUG
            // Validate all DataItem index and value properties
            foreach (var group in DataItems.Where(di => 0 <= di.Index).OrderBy(di => di.Index).GroupBy(di => di.SeriesDefinition))
            {
                object[] items = group.Key.ItemsSource.CastWrapper<object>().ToArray();
                int i = 0;
                foreach (DataItem dataItem in group)
                {
                    Debug.Assert(i == dataItem.Index, "DataItem index mis-match.");
                    Debug.Assert(dataItem.Value.Equals(items[i]), "DataItem value mis-match.");
                    i++;
                }
            }
#endif
        }
 /// <summary>
 /// Handles changes to the ItemsSource of a SeriesDefinition.
 /// </summary>
 /// <param name="definition">SeriesDefinition owner.</param>
 /// <param name="oldValue">Old value.</param>
 /// <param name="newValue">New value.</param>
 internal void SeriesDefinitionItemsSourceChanged(SeriesDefinition definition, IEnumerable oldValue, IEnumerable newValue)
 {
     if (null != oldValue)
     {
         foreach (DataItem dataItem in DataItems.Where(di => di.SeriesDefinition == definition).ToArray())
         {
             DataItems.Remove(dataItem);
         }
         RemovedDataItems();
     }
     if (null != newValue)
     {
         // No need to add items if SeriesHost null; setting SeriesHost will take care of that
         if (null != SeriesHost)
         {
             AddDataItems(definition, newValue.CastWrapper<object>(), 0);
         }
     }
 }
 /// <summary>
 /// Updates the palette properties of the specified SeriesDefinition.
 /// </summary>
 /// <param name="definition">Specified SeriesDefinition.</param>
 private void UpdatePaletteProperties(SeriesDefinition definition)
 {
     ResourceDictionary resources = null;
     if (null != SeriesHost)
     {
         Type dataPointType = CreateDataPoint().GetType();
         using (IEnumerator<ResourceDictionary> enumerator = SeriesHost.GetResourceDictionariesWhere(dictionary =>
         {
             Style style = dictionary["DataPointStyle"] as Style;
             if (null != style)
             {
                 return (null != style.TargetType) && (style.TargetType.IsAssignableFrom(dataPointType));
             }
             return false;
         }))
         {
             if (enumerator.MoveNext())
             {
                 resources = enumerator.Current;
             }
         }
     }
     definition.PaletteDataPointStyle = (null != resources) ? resources["DataPointStyle"] as Style : null;
     definition.PaletteDataShapeStyle = (null != resources) ? resources["DataShapeStyle"] as Style : null;
     definition.PaletteLegendItemStyle = (null != resources) ? resources["LegendItemStyle"] as Style : null;
 }
 /// <summary>
 /// Initializes a new instance of the DataItem class.
 /// </summary>
 /// <param name="seriesDefinition">SeriesDefinition owner.</param>
 public DataItem(SeriesDefinition seriesDefinition)
 {
     SeriesDefinition = seriesDefinition;
     CenterPoint = new Point(double.NaN, double.NaN);
 }
        private void SetItemSources()
        {
            if (this.Stack == null || this.Stack.SeriesDefinitions == null)
                return;
            int count = this.Stack.SeriesDefinitions.Count;
            for (int c = 0; c < count; c++)
                this.Stack.SeriesDefinitions.RemoveAt(this.Stack.SeriesDefinitions.Count - 1);

            if (_isValue)
            {

                if (_valKm == KilooMega.None || _isSelectedKilooMegaChanged)
                {
                    KilooMega from = _valKm;
                    if (_isSelectedKilooMegaChanged)
                    {
                        _isSelectedKilooMegaChanged = false;
                        _valKm = GetSelectedKilooMega();
                    }
                    else
                    {
                        SetUnitCombobox();
                        _valKm = Utils.Get_KilooMega(_maxVal);
                    }

                    _maxVal = Utils.Implement_KilooMega(from, _valKm, _maxVal);
                    foreach (string dn in _valViewSource.Keys)
                        foreach (StringDoubleStringChartObj item in _valViewSource[dn])
                        {
                            double value = Utils.Implement_KilooMega(from, _valKm, item.YAxisValue);
                            item.YAxisValue = value;
                        }

                    for (int i = 0; i < _quartersMaxVal.Count; i++)
                        _quartersMaxVal[_quartersMaxVal.Keys.ElementAt<string>(i)] = Utils.Implement_KilooMega(from, _valKm, _quartersMaxVal[_quartersMaxVal.Keys.ElementAt<string>(i)]);
                }

                int counter = 0;
                foreach (string ch in _valViewSource.Keys)
                {
                    foreach (StringDoubleStringChartObj item in _valViewSource[ch])
                        item.ExtraInfo = Utils.Round_to_One_Fraction_Except_Zero((item.YAxisValue / _quartersMaxVal[item.XAxisValue]) * 100) + " %";

                    SeriesDefinition sd = new SeriesDefinition();
                    sd.IndependentValueBinding = new System.Windows.Data.Binding("XAxisValue");
                    sd.DependentValueBinding = new System.Windows.Data.Binding("YAxisValue");
                    sd.Title = ch;
                    Style style = Application.Current.Resources["ColumnStyle" + Utils.GetStyleNumber(ch, counter)] as Style;
                    sd.DataPointStyle = style;
                    sd.ItemsSource = _valViewSource[ch];
                    this.Stack.SeriesDefinitions.Add(sd);
                    counter++;
                }
            }
            else
            {

                if (_qtyKm == KilooMega.None || _isSelectedKilooMegaChanged)
                {
                    KilooMega from = _qtyKm;
                    if (_isSelectedKilooMegaChanged)
                    {
                        _isSelectedKilooMegaChanged = false;
                        _qtyKm = GetSelectedKilooMega();
                    }
                    else
                    {
                        SetUnitCombobox();
                        _qtyKm = Utils.Get_KilooMega(_maxQty);
                    }

                    _maxQty = Utils.Implement_KilooMega(from, _qtyKm, _maxQty);
                    foreach (string dn in _qtyViewSource.Keys)
                        foreach (StringDoubleStringChartObj item in _qtyViewSource[dn])
                        {
                            double value = Utils.Implement_KilooMega(from, _qtyKm, item.YAxisValue);
                            item.YAxisValue = value;
                        }

                    for (int i = 0; i < _quartersMaxQty.Count; i++)
                        _quartersMaxQty[_quartersMaxQty.Keys.ElementAt<string>(i)] = Utils.Implement_KilooMega(from, _qtyKm, _quartersMaxQty[_quartersMaxQty.Keys.ElementAt<string>(i)]);
                }
                int counter = 0;
                foreach (string ch in _qtyViewSource.Keys)
                {
                    foreach (StringDoubleStringChartObj item in _qtyViewSource[ch])
                        item.ExtraInfo = Utils.Round_to_One_Fraction_Except_Zero((item.YAxisValue / _quartersMaxQty[item.XAxisValue]) * 100) + " %";

                    SeriesDefinition sd = new SeriesDefinition();
                    sd.IndependentValueBinding = new System.Windows.Data.Binding("XAxisValue");
                    sd.DependentValueBinding = new System.Windows.Data.Binding("YAxisValue");
                    Style style = Application.Current.Resources["ColumnStyle" + Utils.GetStyleNumber(ch, counter)] as Style;
                    sd.DataPointStyle = style;
                    sd.Title = ch;
                    sd.ItemsSource = _qtyViewSource[ch];
                    this.Stack.SeriesDefinitions.Add(sd);
                    counter++;
                }
            }
            SetAxisLabel();
            EnableValueVolumRadios();
        }
 private void SetSeriesStyle(SeriesDefinition seriesDefinition, Color color)
 {
     var polygonStyle = new Style(typeof(Polygon));
     polygonStyle.Setters.Add(new Setter(Polygon.FillProperty, CreateGradientBrush(color)));
     seriesDefinition.DataShapeStyle = polygonStyle;
 }
예제 #9
0
        private void RenderFinishStackedChart(List<List<StringDataValue>> dataValues, DataTable data)
        {
            StackedColumnSeries stackedSeries;
            if (((ComboBoxItem)cbxColumnAggregateFunc.SelectedItem).Content.ToString().Equals("Count %"))
                stackedSeries = new Stacked100ColumnSeries();
            else
                stackedSeries = new StackedColumnSeries();

            int counter = 1;
            foreach (var values in dataValues)
            {
                SeriesDefinition definition = new SeriesDefinition();
                definition.DependentValuePath = "DependentValue";
                definition.IndependentValuePath = "IndependentValue";
                if (DashboardHelper.IsUsingEpiProject && (View.Fields[cbxColumnYAxisField.SelectedItem.ToString()] is YesNoField || View.Fields[cbxColumnYAxisField.SelectedItem.ToString()] is CheckBoxField))
                {
                    if (data.Columns[counter].ColumnName.Equals(DashboardHelper.Config.Settings.RepresentationOfYes))
                        definition.Title = cbxColumnYAxisField.SelectedItem.ToString();
                    else
                        definition.Title = "Not " + cbxColumnYAxisField.SelectedItem.ToString();
                }
                else
                    definition.Title = data.Columns[counter].ColumnName;
                definition.ItemsSource = values;
                stackedSeries.SeriesDefinitions.Add(definition);
                counter++;
            }

            chart = new Chart();
            chart.Loaded += new RoutedEventHandler(chart_Loaded);
            chart.BorderThickness = new Thickness(0);
            chart.Series.Add(stackedSeries);
            chart.Height = 600;

            chart.PlotAreaStyle = new Style();
            chart.PlotAreaStyle.Setters.Add(new Setter(Chart.BackgroundProperty, Brushes.White));

            chart.Palette = (System.Collections.ObjectModel.Collection<ResourceDictionary>)this.Resources["defaultColumnPalette"];

            if (data.Rows.Count > 20)
                chart.Width = data.Rows.Count * 40;
            else
                chart.Width = 800;
            pnlMain.Children.Clear();
            pnlMain.Children.Add(chart);
        }
예제 #10
0
        private void RenderFinishEpiCurve(DataTable data, List<List<StringDataValue>> dataValues)
        {
            waitPanel.Visibility = System.Windows.Visibility.Collapsed;

            StackedHistogramSeries stackedSeries = new StackedHistogramSeries();
            LinearAxis axis = new LinearAxis();
            axis.Orientation = AxisOrientation.Y;
            axis.Minimum = 0;
            axis.ShowGridLines = (bool)checkboxShowHorizontalGridLines.IsChecked; //true;
            stackedSeries.DependentAxis = axis;
            CategoryAxis independentAxis = new CategoryAxis();
            independentAxis.Orientation = AxisOrientation.X;

            double extraRightPadding = 0;

            if (!DashboardHelper.IsColumnNumeric(cbxDateField.SelectedItem.ToString()))
            {
                if (cbxXAxisLabelRotation.SelectedIndex == -1 || ((ComboBoxItem)cbxXAxisLabelRotation.SelectedItem).Content.ToString().Equals("90"))
                {
                    independentAxis.AxisLabelStyle = Resources["RotateAxisStyle90"] as Style;
                }
                else if (cbxXAxisLabelRotation.SelectedIndex >= 0 && ((ComboBoxItem)cbxXAxisLabelRotation.SelectedItem).Content.ToString().Equals("45"))
                {
                    independentAxis.AxisLabelStyle = Resources["RotateAxisStyle45"] as Style;
                    extraRightPadding = 50;
                }
            }

            stackedSeries.IndependentAxis = independentAxis;

            int counter = 1;
            foreach (var values in dataValues)
            {
                SeriesDefinition definition = new SeriesDefinition();
                definition.DependentValuePath = "DependentValue";
                definition.IndependentValuePath = "IndependentValue";
                if (cbxCaseStatusField.SelectedIndex >= 0 && !string.IsNullOrEmpty(cbxCaseStatusField.SelectedItem.ToString()))
                {
                    Field field = null;
                    foreach (DataRow fieldRow in DashboardHelper.FieldTable.Rows)
                    {
                        if (fieldRow["columnname"].Equals(cbxCaseStatusField.SelectedItem.ToString()))
                        {
                            if (fieldRow["epifieldtype"] is Field)
                            {
                                field = fieldRow["epifieldtype"] as Field;
                            }
                            break;
                        }
                    }

                    if (field != null && (field is YesNoField || field is CheckBoxField))
                    {
                        string value = data.Columns[counter].ColumnName;

                        if (value.ToLower().Equals("true") || value.Equals("1"))
                        {
                            definition.Title = DashboardHelper.Config.Settings.RepresentationOfYes;
                        }
                        else if (value.ToLower().Equals("false") || value.Equals("0"))
                        {
                            definition.Title = DashboardHelper.Config.Settings.RepresentationOfNo;
                        }
                        else
                        {
                            definition.Title = cbxCaseStatusField.SelectedItem.ToString();
                        }
                    }
                    else
                    {
                        definition.Title = data.Columns[counter].ColumnName;
                    }
                }
                else
                {
                    definition.Title = SharedStrings.DEFAULT_CHART_LEGEND_ITEM;
                }
                definition.ItemsSource = values;
                //definition.DataPointStyle = this.Resources["epiCurveDataPointStyle"] as Style;

                stackedSeries.SeriesDefinitions.Add(definition);
                counter++;
            }

            Chart chart = new Chart();

            if (dataValues.Count == 1)
            {
                chart.LegendStyle = this.Resources["noLegendStyle"] as Style;
            }

            chart.PlotAreaStyle = new Style();
            chart.PlotAreaStyle.Setters.Add(new Setter(Chart.BackgroundProperty, Brushes.White));

            axis.GridLineStyle = new Style();
            axis.GridLineStyle.Setters.Add(new Setter(Line.StrokeProperty, Brushes.LightGray));

            chart.Palette = (System.Collections.ObjectModel.Collection<ResourceDictionary>)this.Resources["defaultColumnPalette"];

            //stackedSeries

            chart.BorderThickness = new Thickness(0);
            chart.Loaded += new RoutedEventHandler(chart_Loaded);
            chart.Series.Add(stackedSeries);
            chart.Height = 500;
            chart.Width = (stackedSeries.IndependentValueCount * 25) + 150;

            chart.Margin = new Thickness(chart.Margin.Left, chart.Margin.Top, chart.Margin.Right + extraRightPadding, chart.Margin.Bottom);

            pnlMain.Children.Clear();
            pnlMain.Children.Add(chart);

            SetChartLabels(ChartTitle, LegendTitle, XAxisLabel, YAxisLabel);
        }
        private void SetItemSources2()
        {
            if (this.Stack2 == null || this.Stack2.SeriesDefinitions == null)
                return;
            int count = this.Stack2.SeriesDefinitions.Count;
            for (int c = 0; c < count; c++)
                this.Stack2.SeriesDefinitions.RemoveAt(this.Stack2.SeriesDefinitions.Count - 1);

            if (_isValue)
            {
                if (_valKm2 == KilooMega.None || _isSelectedKilooMegaChanged)
                {
                    KilooMega from = _valKm2;
                    if (_isSelectedKilooMegaChanged)
                    {
                        _isSelectedKilooMegaChanged = false;
                        _valKm2 = GetSelectedKilooMega();
                    }
                    else
                        _valKm2 = Utils.Get_KilooMega(_maxVal2);
                    _maxVal2 = Utils.Implement_KilooMega(from, _valKm2, _maxVal2);
                    foreach (string dn in _valCollections2.Keys)
                        foreach (DistributorObj item in _valCollections2[dn])
                            item.YAxisValue = Utils.Implement_KilooMega(from, _valKm2, item.YAxisValue);
                }

                int counter = 0;
                foreach (string dn in _valCollections2.Keys)
                {
                    SeriesDefinition sd = new SeriesDefinition();
                    sd.IndependentValueBinding = new System.Windows.Data.Binding("XAxisValue");
                    sd.DependentValueBinding = new System.Windows.Data.Binding("YAxisValue");
                    sd.Title = dn;
                    Style style = Application.Current.Resources["ColumnStyle" + Utils.GetStyleNumber(dn, 0)] as Style;
                    sd.DataPointStyle = style;
                    sd.ItemsSource = _valCollections2[dn];
                    this.Stack2.SeriesDefinitions.Add(sd);
                    counter++;
                }
            }
            else
            {

                if (_qtyKm2 == KilooMega.None || _isSelectedKilooMegaChanged)
                {
                    KilooMega from = _qtyKm2;
                    if (_isSelectedKilooMegaChanged)
                    {
                        _isSelectedKilooMegaChanged = false;
                        _qtyKm2 = GetSelectedKilooMega();
                    }
                    else
                        _qtyKm2 = Utils.Get_KilooMega(_maxQty2);
                    _maxQty2 = Utils.Implement_KilooMega(from, _qtyKm2, _maxQty2);
                    foreach (string dn in _qtyCollections2.Keys)
                        foreach (DistributorObj item in _qtyCollections2[dn])
                            item.YAxisValue = Utils.Implement_KilooMega(from, _qtyKm2, item.YAxisValue);
                }

                int counter = 0;
                foreach (string dn in _qtyCollections2.Keys)
                {
                    SeriesDefinition sd = new SeriesDefinition();
                    sd.IndependentValueBinding = new System.Windows.Data.Binding("XAxisValue");
                    sd.DependentValueBinding = new System.Windows.Data.Binding("YAxisValue");
                    Style style = Application.Current.Resources["ColumnStyle" + Utils.GetStyleNumber(dn, 0)] as Style;
                    sd.DataPointStyle = style;
                    sd.Title = dn;
                    sd.ItemsSource = _qtyCollections2[dn];
                    this.Stack2.SeriesDefinitions.Add(sd);
                    counter++;
                }
            }
            SetAxisLabel2();
            EnableValueVolumRadios();
        }