From a893355e49afbd0b122a0485fa24bf933ab253b2 Mon Sep 17 00:00:00 2001 From: Michael Sevestre Date: Tue, 15 Feb 2022 17:33:44 +0100 Subject: [PATCH] 2055 old values not scaled (#2092) * WIP * fixes #2055 old values not scaled * Remove dummy change * Remove dummy change * Run styler --- .../ProteinExpressionsPresenter.cs | 16 +- .../UICommands/AddBuildingBlockUICommand.cs | 5 +- .../ProteinExpression/ExpressionDataView.cs | 147 ++++++++++----- .../Views/ProteinExpression/TransferView.cs | 174 +++++++++++------- 4 files changed, 215 insertions(+), 127 deletions(-) diff --git a/src/PKSim.Presentation/Presenters/ProteinExpression/ProteinExpressionsPresenter.cs b/src/PKSim.Presentation/Presenters/ProteinExpression/ProteinExpressionsPresenter.cs index 7089d7bf6..fa942d606 100644 --- a/src/PKSim.Presentation/Presenters/ProteinExpression/ProteinExpressionsPresenter.cs +++ b/src/PKSim.Presentation/Presenters/ProteinExpression/ProteinExpressionsPresenter.cs @@ -19,14 +19,16 @@ namespace PKSim.Presentation.Presenters.ProteinExpression { - public enum ColumnNamesOfTransferTable + public static class ColumnNamesOfTransferTable { - Container, - DisplayName, - RelativeExpressionOld, - ExpressionValue, - RelativeExpressionNew, - Unit + public static string Container = "Container"; + public static string DisplayName = "DisplayName"; + public static string RelativeExpressionOld = "RelativeExpressionOld"; + public static string RelativeExpressionOldPercentage = "RelativeExpressionOldPercentage"; + public static string ExpressionValue = "ExpressionValue"; + public static string RelativeExpressionNew = "RelativeExpressionNew"; + public static string RelativeExpressionNewPercentage = "RelativeExpressionNewPercentage"; + public static string Unit = "Unit"; }; public interface IProteinExpressionsPresenter : IWizardPresenter, IPresenter diff --git a/src/PKSim.Presentation/UICommands/AddBuildingBlockUICommand.cs b/src/PKSim.Presentation/UICommands/AddBuildingBlockUICommand.cs index e5375621b..f7796a149 100644 --- a/src/PKSim.Presentation/UICommands/AddBuildingBlockUICommand.cs +++ b/src/PKSim.Presentation/UICommands/AddBuildingBlockUICommand.cs @@ -29,11 +29,11 @@ public AddCompoundUICommand(ICompoundTask compoundTask) : base(compoundTask) } } - public class AddExpressionProfileCommand:IUICommand where TMolecule : IndividualMolecule + public class AddExpressionProfileCommand : IUICommand where TMolecule : IndividualMolecule { private readonly IExpressionProfileTask _expressionProfileTask; - public AddExpressionProfileCommand(IExpressionProfileTask expressionProfileTask) + public AddExpressionProfileCommand(IExpressionProfileTask expressionProfileTask) { _expressionProfileTask = expressionProfileTask; } @@ -92,5 +92,4 @@ public AddSimulationCommand(ISimulationTask simulationTask) : base(simulationTas { } } - } \ No newline at end of file diff --git a/src/PKSim.UI/Views/ProteinExpression/ExpressionDataView.cs b/src/PKSim.UI/Views/ProteinExpression/ExpressionDataView.cs index 298492517..88019228d 100644 --- a/src/PKSim.UI/Views/ProteinExpression/ExpressionDataView.cs +++ b/src/PKSim.UI/Views/ProteinExpression/ExpressionDataView.cs @@ -3,21 +3,19 @@ using System.Data; using System.Drawing; using System.IO; -using OSPSuite.UI.Services; -using OSPSuite.Assets; -using DevExpress.Charts.Native; using DevExpress.Data; using DevExpress.Data.Filtering; using DevExpress.Data.PivotGrid; using DevExpress.Utils; using DevExpress.XtraCharts; using DevExpress.XtraPivotGrid; +using OSPSuite.Assets; +using OSPSuite.UI.Controls; +using OSPSuite.UI.Extensions; +using OSPSuite.UI.Services; using PKSim.Assets; using PKSim.Presentation.Presenters.ProteinExpression; using PKSim.Presentation.Views.ProteinExpression; -using OSPSuite.Presentation; -using OSPSuite.UI.Controls; -using OSPSuite.UI.Extensions; namespace PKSim.UI.Views.ProteinExpression { @@ -47,8 +45,8 @@ internal partial class ExpressionDataView : BaseUserControl, IExpressionDataView private string _selectedUnit; private bool _isFieldFilterChanging; private bool _isPrefilterCriteriaChanging; - - public ExpressionDataView(IImageListRetriever imageListRetriever, IProteinExpressionToolTipCreator toolTipCreator ) + + public ExpressionDataView(IImageListRetriever imageListRetriever, IProteinExpressionToolTipCreator toolTipCreator) { _toolTipCreator = toolTipCreator; InitializeComponent(); @@ -69,7 +67,6 @@ public ExpressionDataView(IImageListRetriever imageListRetriever, IProteinExpres ApplicationIcon = ApplicationIcons.Histogram; } - public override void InitializeResources() { base.InitializeResources(); @@ -77,7 +74,7 @@ public override void InitializeResources() } /// - /// This event handler hides the unused reload data menu entry. + /// This event handler hides the unused reload data menu entry. /// private void onPopupMenuShowing(object sender, PopupMenuShowingEventArgs e) { @@ -97,9 +94,9 @@ void onFieldAreaChanging(object sender, PivotAreaChangingEventArgs e) } /// - /// This function handle the event which takes care of tool tips. - /// The code checks on which area the mouse currently is positioned. - /// Depending on the area and the field and the field value different tool tips are generated. + /// This function handle the event which takes care of tool tips. + /// The code checks on which area the mouse currently is positioned. + /// Depending on the area and the field and the field value different tool tips are generated. /// /// The object reference for a new ToolTipControlInfo object can be any unique string. private void onGetActiveObjectInfo(object sender, ToolTipControllerGetActiveObjectInfoEventArgs e) @@ -129,7 +126,9 @@ private void onGetActiveObjectInfo(object sender, ToolTipControllerGetActiveObje e.Info.SuperTip = _toolTipCreator.GetTipForVariantHeader(_fieldVariantName.Caption); e.Info.ToolTipType = ToolTipType.SuperTip; } + #endregion; + #region Database else if (hi.HeaderField == _fieldDataBase) @@ -137,7 +136,9 @@ private void onGetActiveObjectInfo(object sender, ToolTipControllerGetActiveObje e.Info.SuperTip = _toolTipCreator.GetTipForDataBaseHeader(_fieldDataBase.Caption); e.Info.ToolTipType = ToolTipType.SuperTip; } + #endregion + #region DatabaseRecId else if (hi.HeaderField == _fieldDataBaseRecId) @@ -145,7 +146,9 @@ private void onGetActiveObjectInfo(object sender, ToolTipControllerGetActiveObje e.Info.SuperTip = _toolTipCreator.GetTipForDataBaseRecIdHeader(_fieldDataBaseRecId.Caption); e.Info.ToolTipType = ToolTipType.SuperTip; } + #endregion + #region Gender else if (hi.HeaderField == _fieldGender) @@ -153,7 +156,9 @@ private void onGetActiveObjectInfo(object sender, ToolTipControllerGetActiveObje e.Info.SuperTip = _toolTipCreator.GetTipForGenderHeader(_fieldGender.Caption); e.Info.ToolTipType = ToolTipType.SuperTip; } + #endregion + #region Tissue else if (hi.HeaderField == _fieldTissue) @@ -161,7 +166,9 @@ private void onGetActiveObjectInfo(object sender, ToolTipControllerGetActiveObje e.Info.SuperTip = _toolTipCreator.GetTipForTissueHeader(_fieldTissue.Caption); e.Info.ToolTipType = ToolTipType.SuperTip; } + #endregion + #region HealthState else if (hi.HeaderField == _fieldHealthState) @@ -169,7 +176,9 @@ private void onGetActiveObjectInfo(object sender, ToolTipControllerGetActiveObje e.Info.SuperTip = _toolTipCreator.GetTipForTissueHeader(_fieldHealthState.Caption); e.Info.ToolTipType = ToolTipType.SuperTip; } + #endregion; + #region SampleSource else if (hi.HeaderField == _fieldSampleSource) @@ -177,7 +186,9 @@ private void onGetActiveObjectInfo(object sender, ToolTipControllerGetActiveObje e.Info.SuperTip = _toolTipCreator.GetTipForSampleSourceHeader(_fieldSampleSource.Caption); e.Info.ToolTipType = ToolTipType.SuperTip; } + #endregion; + #region Age else if (hi.HeaderField == _fieldAge) @@ -185,7 +196,9 @@ private void onGetActiveObjectInfo(object sender, ToolTipControllerGetActiveObje e.Info.SuperTip = _toolTipCreator.GetTipForAgeHeader(_fieldAge.Caption, _fieldAgeMin.Caption, _fieldAgeMax.Caption); e.Info.ToolTipType = ToolTipType.SuperTip; } + #endregion; + #region AgeMin else if (hi.HeaderField == _fieldAgeMin) @@ -193,7 +206,9 @@ private void onGetActiveObjectInfo(object sender, ToolTipControllerGetActiveObje e.Info.SuperTip = _toolTipCreator.GetTipForAgeMinHeader(_fieldAgeMin.Caption); e.Info.ToolTipType = ToolTipType.SuperTip; } + #endregion + #region AgeMax else if (hi.HeaderField == _fieldAgeMax) @@ -201,7 +216,9 @@ private void onGetActiveObjectInfo(object sender, ToolTipControllerGetActiveObje e.Info.SuperTip = _toolTipCreator.GetTipForAgeMaxHeader(_fieldAgeMax.Caption); e.Info.ToolTipType = ToolTipType.SuperTip; } + #endregion + #region Ratio else if (hi.HeaderField == _fieldRatio) @@ -209,7 +226,9 @@ private void onGetActiveObjectInfo(object sender, ToolTipControllerGetActiveObje e.Info.SuperTip = _toolTipCreator.GetTipForRatioHeader(_fieldRatio.Caption, _fieldSampleCount.Caption, _fieldTotalCount.Caption); e.Info.ToolTipType = ToolTipType.SuperTip; } + #endregion + #region SampleCount else if (hi.HeaderField == _fieldSampleCount) @@ -217,7 +236,9 @@ private void onGetActiveObjectInfo(object sender, ToolTipControllerGetActiveObje e.Info.SuperTip = _toolTipCreator.GetTipForSampleCountHeader(_fieldSampleCount.Caption); e.Info.ToolTipType = ToolTipType.SuperTip; } + #endregion + #region TotalCount else if (hi.HeaderField == _fieldTotalCount) @@ -225,7 +246,9 @@ private void onGetActiveObjectInfo(object sender, ToolTipControllerGetActiveObje e.Info.SuperTip = _toolTipCreator.GetTipForTotalCountHeader(_fieldTotalCount.Caption); e.Info.ToolTipType = ToolTipType.SuperTip; } + #endregion + #region Unit else if (hi.HeaderField == _fieldUnit) @@ -233,7 +256,9 @@ private void onGetActiveObjectInfo(object sender, ToolTipControllerGetActiveObje e.Info.SuperTip = _toolTipCreator.GetTipForUnitHeader(_fieldUnit.Caption); e.Info.ToolTipType = ToolTipType.SuperTip; } + #endregion + #region Container else if (hi.HeaderField == _fieldContainer) @@ -300,7 +325,7 @@ private void onGetActiveObjectInfo(object sender, ToolTipControllerGetActiveObje // Get the database of that record id PivotDrillDownDataSource ds = hi.ValueInfo.CreateDrillDownDataSource(); PivotDrillDownDataRow row = ds[0]; - var database = (string)row[_fieldDataBase]; + var database = (string) row[_fieldDataBase]; if (hi.ValueInfo.Value != null) { @@ -309,7 +334,9 @@ private void onGetActiveObjectInfo(object sender, ToolTipControllerGetActiveObje e.Info.ToolTipType = ToolTipType.SuperTip; } } + #endregion + #region Gender else if (hi.ValueInfo.Field == _fieldGender) @@ -320,8 +347,11 @@ private void onGetActiveObjectInfo(object sender, ToolTipControllerGetActiveObje e.Info.ToolTipType = ToolTipType.SuperTip; } } + #endregion + #region Tissue + else if (hi.ValueInfo.Field == _fieldTissue) { if (hi.ValueInfo.Value != null) @@ -330,8 +360,11 @@ private void onGetActiveObjectInfo(object sender, ToolTipControllerGetActiveObje e.Info.ToolTipType = ToolTipType.SuperTip; } } + #endregion + #region Container + else if (hi.ValueInfo.Field == _fieldContainer) { if (hi.ValueInfo.Value != null) @@ -340,7 +373,9 @@ private void onGetActiveObjectInfo(object sender, ToolTipControllerGetActiveObje e.Info.ToolTipType = ToolTipType.SuperTip; } } + #endregion + #region Health State else if (hi.ValueInfo.Field == _fieldHealthState) @@ -351,7 +386,9 @@ private void onGetActiveObjectInfo(object sender, ToolTipControllerGetActiveObje e.Info.ToolTipType = ToolTipType.SuperTip; } } + #endregion + #region Sample Source else if (hi.ValueInfo.Field == _fieldSampleSource) @@ -401,7 +438,9 @@ private void onGetActiveObjectInfo(object sender, ToolTipControllerGetActiveObje e.Info.ToolTipType = ToolTipType.SuperTip; } } + #endregion + #region Unit else if (hi.ValueInfo.Field == _fieldUnit) @@ -432,6 +471,7 @@ private void onGetActiveObjectInfo(object sender, ToolTipControllerGetActiveObje object o = string.Format("Cell:{0}-{1}-{2}-{3}", hi.CellInfo.RowField, hi.CellInfo.Item.RowIndex, hi.CellInfo.ColumnField, hi.CellInfo.Item.ColumnIndex); e.Info = new ToolTipControlInfo(o, hi.CellInfo.Value.ToString()); } + e.Info.SuperTip = new SuperToolTip() {AllowHtmlText = DefaultBoolean.True}; e.Info.SuperTip.Items.AddTitle(hi.CellInfo.DataField.Caption); e.Info.SuperTip.Items.Add(hi.CellInfo.Value.ToString()); @@ -540,7 +580,7 @@ public void SetData(string proteinName, DataTable expressionDataTable, string se public void SetLayoutSettings(string layoutSettings) { - Stream ms = new MemoryStream(); + Stream ms = new MemoryStream(); var sw = new StreamWriter(ms); sw.Write(layoutSettings, 0, layoutSettings.Length); sw.Flush(); @@ -559,7 +599,7 @@ public string GetLayoutSettings() ms.Position = 0; string layoutSettings = sr.ReadToEnd(); sr.Close(); - return layoutSettings; + return layoutSettings; } public void ActualizeData(DataTable expressionDataTable) @@ -624,6 +664,7 @@ public DataTable GetSelectedData() if (value <= maximum) continue; maximum = value; } + foreach (SeriesPoint point in expSeries.Points) { double value = point.Values[0]; @@ -631,7 +672,7 @@ public DataTable GetSelectedData() if (maximum == 0) values.Add(0); else - values.Add(value/maximum); + values.Add(value / maximum); values.Add(expSeries.Name); ret.Rows.Add(values.ToArray()); } @@ -643,10 +684,11 @@ public DataTable GetSelectedData() chrtExpressionData.SeriesDataMember = oldDataMember; chrtExpressionData.SeriesTemplate.ArgumentDataMember = oldArgument; } + return ret; } - private SeriesPoint[] customSummary(Series series, object argument, string[] functionArguments, + private SeriesPoint[] customSummary(Series series, object argument, string[] functionArguments, DataSourceValues[] values, object[] colors) { double sumCount = 0; @@ -663,8 +705,9 @@ private SeriesPoint[] customSummary(Series series, object argument, string[] fun { double average = Convert.ToDouble(values[i][functionArguments[0]]); double count = Convert.ToDouble(values[i][functionArguments[1]]); - weightedAverage += average*count/sumCount; + weightedAverage += average * count / sumCount; } + // Create an array of the resulting series points. var points = new SeriesPoint[1]; points[0] = new SeriesPoint(argument, weightedAverage); @@ -685,10 +728,10 @@ private void configChart(string titleText) chart.SeriesTemplate.ArgumentDataMember = _fieldContainer.FieldName; setTitleForXAxes(_fieldContainer.HeaderDisplayText); chart.SeriesTemplate.ValueDataMembers.AddRange(new[] - { - _fieldNormValue.FieldName + "_" + - _fieldNormValue.SummaryType - }); + { + _fieldNormValue.FieldName + "_" + + _fieldNormValue.SummaryType + }); //set chart data PivotSummaryDataSource chartData = pgrdExpressionData.CreateSummaryDataSource(); @@ -705,15 +748,15 @@ private void configChart(string titleText) // Count var argument2Description = new SummaryFunctionArgumentDescription("Count", ScaleType.Numerical); - + // Register the summary function in chart. const string STR_CUSTOM_SUMMARY_FUNCTION_NAME = "WeightedAverage"; const string STR_CUSTOM_SUMMARY_FUNCTION_DISPLAY_NAME = "WeightedAverage"; chart.RegisterSummaryFunction(STR_CUSTOM_SUMMARY_FUNCTION_NAME, STR_CUSTOM_SUMMARY_FUNCTION_DISPLAY_NAME, 1, - new[] {argument1Description, argument2Description}, - customSummary); - - chart.SeriesTemplate.QualitativeSummaryOptions.SummaryFunction = + new[] {argument1Description, argument2Description}, + customSummary); + + chart.SeriesTemplate.QualitativeSummaryOptions.SummaryFunction = $"{STR_CUSTOM_SUMMARY_FUNCTION_NAME}([{_fieldNormValue.FieldName + "_" + _fieldNormValue.SummaryType}],[{_fieldNormValue2.FieldName + "_" + _fieldNormValue2.SummaryType}])"; //config layout @@ -722,7 +765,7 @@ private void configChart(string titleText) chart.Legend.EnableAntialiasing = DefaultBoolean.True; chart.Legend.Border.Thickness = 1; chart.SeriesSorting = SortingMode.Ascending; - chart.SeriesTemplate.LabelsVisibility =DefaultBoolean.True; + chart.SeriesTemplate.LabelsVisibility = DefaultBoolean.True; //Axis Layout barView.AxisX.Label.Angle = 270; @@ -735,16 +778,16 @@ private void configChart(string titleText) var barLabel = chart.SeriesTemplate.Label as BarSeriesLabel; if (barLabel != null) - chart.SeriesTemplate.LabelsVisibility = DefaultBoolean.False; + chart.SeriesTemplate.LabelsVisibility = DefaultBoolean.False; chart.Titles.Clear(); var title = new ChartTitle - { - Text = titleText, - TextColor = Color.Blue, - EnableAntialiasing = DefaultBoolean.True, - Alignment = StringAlignment.Center - }; + { + Text = titleText, + TextColor = Color.Blue, + EnableAntialiasing = DefaultBoolean.True, + Alignment = StringAlignment.Center + }; chart.Titles.Add(title); chart.SelectionMode = ElementSelectionMode.Multiple; @@ -752,8 +795,6 @@ private void configChart(string titleText) chart.ObjectHotTracked += onChartControlObjectHotTracked; } - - private static void onChartControlObjectSelected(object sender, HotTrackEventArgs e) { if (e.HitInfo.Series == null) e.Cancel = true; @@ -908,11 +949,11 @@ private void createPivotGridFields() //create an unbound field for the age grouping const string STR_AGE = "AGE"; _fieldAge = new PivotGridField(STR_AGE, PivotArea.FilterArea) - { - UnboundType = UnboundColumnType.String, - UnboundFieldName = STR_AGE, - Caption = PKSimConstants.ProteinExpressions.ColumnCaptions.ExpressionData.COL_AGE - }; + { + UnboundType = UnboundColumnType.String, + UnboundFieldName = STR_AGE, + Caption = PKSimConstants.ProteinExpressions.ColumnCaptions.ExpressionData.COL_AGE + }; pgrdExpressionData.Fields.Add(_fieldAge); pgrdExpressionData.RefreshData(); @@ -995,10 +1036,11 @@ private void onCustomSummary(object sender, PivotGridCustomSummaryEventArgs e) sampleSum += (double) row[_fieldSampleCount]; totalSum += (double) row[_fieldTotalCount]; } + // Calculate the ratio. if (ds.RowCount > 0) { - e.CustomValue = sampleSum/totalSum; + e.CustomValue = sampleSum / totalSum; } } @@ -1072,10 +1114,12 @@ private void setFieldsToDefaultArea() } /// - /// In this event all data filters are displayed as prefilters. + /// In this event all data filters are displayed as prefilters. /// - /// Has been adopted from DevExpress help page. - /// http://www.devexpress.com/Support/Center/e/E1678.aspx + /// + /// Has been adopted from DevExpress help page. + /// http://www.devexpress.com/Support/Center/e/E1678.aspx + /// private void onFieldFilterChanged(object sender, PivotFieldEventArgs e) { if (_isPrefilterCriteriaChanging) return; @@ -1104,6 +1148,7 @@ private void onFieldFilterChanged(object sender, PivotFieldEventArgs e) { newFilter = new InOperator(field.FieldName, filterValues.ValuesIncluded); } + if (field.FilterValues.ShowBlanks) { var newGroup = new GroupOperator(GroupOperatorType.Or); @@ -1115,6 +1160,7 @@ private void onFieldFilterChanged(object sender, PivotFieldEventArgs e) { rootGroup.Operands.Add(newFilter); } + pgrdExpressionData.Prefilter.Enabled = true; } @@ -1152,7 +1198,7 @@ private void onFieldFilterChanged(object sender, PivotFieldEventArgs e) } /// - /// Remove recursively all operands according to given fieldName. + /// Remove recursively all operands according to given fieldName. /// private static void removeCriteria(GroupOperator parent, String fieldName, CriteriaOperator criteria) { @@ -1211,12 +1257,13 @@ private static void removeCriteria(GroupOperator parent, String fieldName, Crite for (int i = op.Operands.Count - 1; i >= 0; i--) removeCriteria(op, fieldName, op.Operands[i]); if (op.Operands.Count == 0) - if (!ReferenceEquals(parent, op)) parent.Operands.Remove(op); + if (!ReferenceEquals(parent, op)) + parent.Operands.Remove(op); } } /// - /// If the prefilter has been changed all field filters are resetted to no filter. + /// If the prefilter has been changed all field filters are resetted to no filter. /// private void onPrefilterCriteriaChanged(object sender, EventArgs e) { diff --git a/src/PKSim.UI/Views/ProteinExpression/TransferView.cs b/src/PKSim.UI/Views/ProteinExpression/TransferView.cs index ac5b89f45..4340b60a7 100644 --- a/src/PKSim.UI/Views/ProteinExpression/TransferView.cs +++ b/src/PKSim.UI/Views/ProteinExpression/TransferView.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Data; -using OSPSuite.Assets; +using System.Linq; using DevExpress.Data; using DevExpress.Utils; using DevExpress.XtraEditors.Controls; @@ -9,25 +9,31 @@ using DevExpress.XtraGrid.Columns; using DevExpress.XtraGrid.Views.Grid; using DevExpress.XtraGrid.Views.Grid.ViewInfo; +using OSPSuite.Assets; +using OSPSuite.Core.Domain; +using OSPSuite.UI.Controls; +using OSPSuite.Utility.Extensions; using PKSim.Assets; using PKSim.Presentation.Presenters.ProteinExpression; using PKSim.Presentation.Views.ProteinExpression; -using OSPSuite.Presentation; -using OSPSuite.UI.Controls; +using static PKSim.Assets.PKSimConstants.ProteinExpressions.ColumnCaptions.Transfer; +using static PKSim.Presentation.Presenters.ProteinExpression.ColumnNamesOfTransferTable; +using UxGridView = PKSim.UI.Views.Core.UxGridView; namespace PKSim.UI.Views.ProteinExpression { internal partial class TransferView : BaseUserControl, ITransferView { private readonly IProteinExpressionToolTipCreator _toolTipCreator; - private const string STR_Percentage = "Percentage"; private DataTable _transferData; private string _selectedUnit; private ITransferPresenter _presenter; + private readonly DoubleFormatter _doubleFormatter; public TransferView(IProteinExpressionToolTipCreator toolTipCreator) { _toolTipCreator = toolTipCreator; + _doubleFormatter = new DoubleFormatter(); InitializeComponent(); grdTransfer.ToolTipController = new ToolTipController(); @@ -37,7 +43,7 @@ public TransferView(IProteinExpressionToolTipCreator toolTipCreator) radioGroup.Properties.AllowMouseWheel = false; //option settings - var view = grdTransfer.MainView as Core.UxGridView; + var view = grdTransfer.MainView as UxGridView; if (view != null) { view.OptionsView.ShowGroupPanel = false; @@ -61,12 +67,12 @@ public TransferView(IProteinExpressionToolTipCreator toolTipCreator) void OnRadioGroupSelectedIndexChanged(object sender, EventArgs e) { _selectedUnit = radioGroup.Properties.Items[radioGroup.SelectedIndex].Description; - BindDataToGrid(); + bindDataToGrid(); } /// - /// This function handle the event which takes care of tool tips. - /// The code checks on which cell the mouse currently is positioned. + /// This function handle the event which takes care of tool tips. + /// The code checks on which cell the mouse currently is positioned. /// /// The object reference for a new ToolTipControlInfo object can be any unique string. private void OnGetActiveObjectInfo(object sender, ToolTipControllerGetActiveObjectInfoEventArgs e) @@ -81,15 +87,15 @@ private void OnGetActiveObjectInfo(object sender, ToolTipControllerGetActiveObje //Tool Tips if (hi.InRowCell) { - if (hi.Column.FieldName == ColumnNamesOfTransferTable.RelativeExpressionNew.ToString() || - hi.Column.FieldName == string.Concat(ColumnNamesOfTransferTable.RelativeExpressionNew.ToString(), STR_Percentage)) + if (hi.Column.FieldName == RelativeExpressionNew || + hi.Column.FieldName == RelativeExpressionNewPercentage) { string cellKey = string.Concat(hi.RowHandle.ToString(), "-", hi.Column.ColumnHandle.ToString()); string text = view.GetRowCellDisplayText(hi.RowHandle, hi.Column); if (e.Info == null) e.Info = new ToolTipControlInfo(cellKey, text); e.Info.SuperTip = new SuperToolTip(); - e.Info.SuperTip.Items.AddTitle(string.Concat(ColumnNamesOfTransferTable.ExpressionValue.ToString(), ":")); - e.Info.SuperTip.Items.Add(view.GetRowCellDisplayText(hi.RowHandle, ColumnNamesOfTransferTable.ExpressionValue.ToString())); + e.Info.SuperTip.Items.AddTitle(string.Concat(ExpressionValue, ":")); + e.Info.SuperTip.Items.Add(view.GetRowCellDisplayText(hi.RowHandle, ExpressionValue)); e.Info.ToolTipType = ToolTipType.SuperTip; } } @@ -110,19 +116,20 @@ public void SetData(DataTable transferTable, string selectedUnit) radioGroup.Properties.Items.Clear(); var dataView = _transferData.DefaultView; - dataView.Sort = ColumnNamesOfTransferTable.Unit.ToString(); + dataView.Sort = Unit; var units = new List(); - foreach (DataRow unit in dataView.ToTable(true, new[] { ColumnNamesOfTransferTable.Unit.ToString() }).Rows) + foreach (DataRow unit in dataView.ToTable(true, new[] {Unit}).Rows) { - var unitString = unit[ColumnNamesOfTransferTable.Unit.ToString()].ToString(); + var unitString = unit[Unit].ToString(); if (String.IsNullOrEmpty(unitString)) continue; - var newRadioItem = new RadioGroupItem {Description = unitString }; + var newRadioItem = new RadioGroupItem {Description = unitString}; radioGroup.Properties.Items.Add(newRadioItem); units.Add(unitString); if (unitString != selectedUnit) continue; radioGroup.SelectedIndex = radioGroup.Properties.Items.IndexOf(newRadioItem); } + radioGroup.SuperTip = _toolTipCreator.GetTipForUnits(units.ToArray()); if (radioGroup.Properties.Items.Count == 0) _selectedUnit = String.Empty; @@ -133,58 +140,87 @@ public void SetData(DataTable transferTable, string selectedUnit) _selectedUnit = radioGroup.Properties.Items[radioGroup.SelectedIndex].Description; } - BindDataToGrid(); - ConfigGridColumns(); + bindDataToGrid(); } - private void BindDataToGrid() + private void bindDataToGrid() { var transferTable = _transferData.Copy(); transferTable.Columns.Add( - string.Concat(ColumnNamesOfTransferTable.RelativeExpressionOld.ToString(), STR_Percentage), - typeof(double), string.Concat(ColumnNamesOfTransferTable.RelativeExpressionOld.ToString(), "*100")); + RelativeExpressionOldPercentage, + typeof(double), string.Concat(RelativeExpressionOld, "*100")); transferTable.Columns.Add( - string.Concat(ColumnNamesOfTransferTable.RelativeExpressionNew.ToString(), STR_Percentage), - typeof(double), string.Concat(ColumnNamesOfTransferTable.RelativeExpressionNew.ToString(), "*100")); + RelativeExpressionNewPercentage, + typeof(double), string.Concat(RelativeExpressionNew, "*100")); var bindData = transferTable.DefaultView; - if (!String.IsNullOrEmpty(_selectedUnit)) - bindData.RowFilter = String.Format("[{0}] = '{1}'", ColumnNamesOfTransferTable.Unit, - _selectedUnit); + if (!string.IsNullOrEmpty(_selectedUnit)) + bindData.RowFilter = $"[{Unit}] = '{_selectedUnit}'"; + grdTransfer.BeginUpdate(); grdTransfer.DataSource = null; grdTransfer.ResetBindings(); grdTransfer.DataSource = bindData; grdTransfer.RefreshDataSource(); - ConfigGridColumns(); + configGridColumns(bindData); grdTransfer.EndUpdate(); } - private void ConfigGridColumns() + private RepositoryItemBaseProgressBar initProgressBarEditor(int max) + { + return new RepositoryItemProgressBar + { + ReadOnly = true, + Enabled = false, + BorderStyle = BorderStyles.NoBorder, + Maximum = max, + Minimum = 0, + NullText = string.Empty, + PercentView = false, + ShowTitle = true, + DisplayFormat = {FormatType = FormatType.Numeric} + }; + } + + private int getPercentageMax(DataView dataView, string columnName) + { + try + { + var allValues = dataView.Cast() + .Select(row => row[columnName]) + .Where(x => x != null && x != DBNull.Value) + .Select(x => x.ConvertedTo()); + + return Convert.ToInt32(allValues.Max()); + } + catch (Exception e) + { + return 100; + } + } + + private void configGridColumns(DataView dataView) { var view = grdTransfer.MainView as GridView; - if (view == null) return; - var itemProgressBar = new RepositoryItemProgressBar - { - ReadOnly = true, - Enabled = false, - BorderStyle = BorderStyles.NoBorder, - Maximum = 100, - Minimum = 0, - NullText = string.Empty, - PercentView = false, - ShowTitle = true - }; - itemProgressBar.DisplayFormat.FormatType = FormatType.Numeric; - itemProgressBar.CustomDisplayText += OnProgressBarCustomDisplayText; + if (view == null) + return; + + var maxOldExpression = getPercentageMax(dataView, RelativeExpressionOldPercentage); + var maxNewExpression = getPercentageMax(dataView, RelativeExpressionNewPercentage); + + var itemProgressBarOldExpression = initProgressBarEditor(maxOldExpression); + itemProgressBarOldExpression.CustomDisplayText += OnProgressBarCustomDisplayText; + + var itemProgressBarNewExpression = initProgressBarEditor(maxNewExpression); + itemProgressBarNewExpression.CustomDisplayText += OnProgressBarCustomDisplayText; foreach (GridColumn col in view.Columns) { col.OptionsColumn.AllowEdit = false; - if (col.FieldName == ColumnNamesOfTransferTable.Container.ToString()) + if (col.FieldName == ColumnNamesOfTransferTable.Container) { col.Visible = true; - col.Caption = PKSimConstants.ProteinExpressions.ColumnCaptions.Transfer.COL_CONTAINER; + col.Caption = COL_CONTAINER; var itemImageComboBox = new RepositoryItemImageComboBox {ReadOnly = true}; var smallImages = new ImageCollection(); itemImageComboBox.SmallImages = smallImages; @@ -195,67 +231,71 @@ private void ConfigGridColumns() var dt = dv.ToTable(); foreach (DataRow dr in dt.Rows) { - string container = dr[ColumnNamesOfTransferTable.Container.ToString()].ToString(); - string displayName = dr[ColumnNamesOfTransferTable.DisplayName.ToString()].ToString(); + string container = dr[ColumnNamesOfTransferTable.Container].ToString(); + string displayName = dr[DisplayName].ToString(); ApplicationIcon icon = ApplicationIcons.IconByName(container); if (icon != null && icon != ApplicationIcons.EmptyIcon) { smallImages.AddImage(icon.ToImage()); - itemImageComboBox.Items.Add(new ImageComboBoxItem(displayName, container, smallImages.Images.Count-1)); - } else - itemImageComboBox.Items.Add(new ImageComboBoxItem(displayName, container)); + itemImageComboBox.Items.Add(new ImageComboBoxItem(displayName, container, smallImages.Images.Count - 1)); + } + else + itemImageComboBox.Items.Add(new ImageComboBoxItem(displayName, container)); } } + itemImageComboBox.Items.EndUpdate(); col.ColumnEdit = itemImageComboBox; col.SortOrder = ColumnSortOrder.Ascending; } - else if (col.FieldName == ColumnNamesOfTransferTable.DisplayName.ToString()) + else if (col.FieldName == DisplayName) { col.Visible = false; } - else if (col.FieldName == ColumnNamesOfTransferTable.RelativeExpressionOld.ToString()) + else if (col.FieldName == RelativeExpressionOld) { col.Visible = false; } - else if (col.FieldName == ColumnNamesOfTransferTable.ExpressionValue.ToString()) + else if (col.FieldName == ExpressionValue) { col.Visible = false; } - else if (col.FieldName == ColumnNamesOfTransferTable.Unit.ToString()) + else if (col.FieldName == Unit) { col.Visible = false; } - else if (col.FieldName == string.Concat(ColumnNamesOfTransferTable.RelativeExpressionOld.ToString(), STR_Percentage)) + else if (col.FieldName == RelativeExpressionOldPercentage) { - col.Caption = PKSimConstants.ProteinExpressions.ColumnCaptions.Transfer.COL_OLDVALUE; + col.Caption = COL_OLDVALUE; col.Visible = _presenter.ShowOldValues; col.OptionsColumn.AllowEdit = false; - col.ColumnEdit = itemProgressBar; + col.ColumnEdit = itemProgressBarOldExpression; } - else if (col.FieldName == ColumnNamesOfTransferTable.RelativeExpressionNew.ToString()) + else if (col.FieldName == RelativeExpressionNew) { col.Visible = false; } - else if (col.FieldName == string.Concat(ColumnNamesOfTransferTable.RelativeExpressionNew.ToString(), STR_Percentage)) + else if (col.FieldName == RelativeExpressionNewPercentage) { - col.Caption = PKSimConstants.ProteinExpressions.ColumnCaptions.Transfer.COL_NEWVALUE; + col.Caption = COL_NEWVALUE; col.OptionsColumn.AllowEdit = false; - col.ColumnEdit = itemProgressBar; + col.ColumnEdit = itemProgressBarNewExpression; } } } - static void OnProgressBarCustomDisplayText(object sender, CustomDisplayTextEventArgs e) + private void OnProgressBarCustomDisplayText(object sender, CustomDisplayTextEventArgs e) { try { - if (e.Value == DBNull.Value || e.Value == null) e.DisplayText = string.Empty; - else e.DisplayText = ((double) e.Value).ToString("F2"); + if (e.Value == DBNull.Value || e.Value == null) + e.DisplayText = string.Empty; + else + //divide by 100 again to ensure that we show values formatted between 0 and 1 + e.DisplayText = _doubleFormatter.Format(((double) e.Value) / 100); } - catch (Exception ) + catch (Exception) { - } } @@ -266,13 +306,13 @@ public string GetSelectedUnit() public bool HasData() { - return _transferData != null && _transferData.Columns.Count > 0 && _transferData.Rows.Count > 0; + return _transferData != null && _transferData.Columns.Count > 0 && _transferData.Rows.Count > 0; } public DataTable GetData() { var retData = _transferData.DefaultView; - retData.RowFilter = $"[{ColumnNamesOfTransferTable.Unit}] = '{_selectedUnit}'"; + retData.RowFilter = $"[{Unit}] = '{_selectedUnit}'"; return retData.ToTable(); }