Skip to content

Commit abb091f

Browse files
committed
Revert c2b93c1. Allow mix IsXValueIndexed settings per axis.
1 parent 8a8e1d0 commit abb091f

File tree

4 files changed

+36
-47
lines changed

4 files changed

+36
-47
lines changed

src/System.Windows.Forms.DataVisualization/DataManager/DataManager.cs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,6 @@ internal sealed class DataManager : ChartElement, IServiceProvider, IDisposable
2929
// Service container reference
3030
internal IServiceContainer serviceContainer;
3131

32-
/// <summary>
33-
/// Indicates if at least one series is indexed (in this case we tread that all series are indexed). null if not checked yet.
34-
/// </summary>
35-
internal bool? indexedSeries;
36-
37-
/// <summary>
38-
/// Indicates if all series has all X values set to 0. null if not checked yet.
39-
/// </summary>
40-
internal bool? xValuesZeros;
41-
4232
#endregion
4333

4434
#region Constructors and initialization
@@ -102,12 +92,13 @@ private void ChartPicture_BeforePaint(object sender, ChartPaintEventArgs e)
10292
{
10393
// Prepare series for drawing
10494
int markerIndex = 1;
105-
indexedSeries = null;
106-
xValuesZeros = null;
107-
10895
for (int index = 0; index < this.Series.Count; index++)
10996
{
11097
Series series = this.Series[index];
98+
99+
// Reset series "X values are zeros" flag
100+
series.xValuesZeros = null;
101+
111102
// Set series colors from palette
112103
IChartType chartType = e.CommonElements.ChartTypeRegistry.GetChartType(series.ChartTypeName);
113104
bool paletteColorsInPoints = chartType.ApplyPaletteColorsToPoints;

src/System.Windows.Forms.DataVisualization/DataManager/DataSeries.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@ public class Series : DataPointCustomProperties, IDisposable
249249
// Indicates that there is no custom axis labels in data points or series
250250
internal bool noLabelsInPoints = true;
251251

252+
// Indicates if series has all X values set to 0
253+
internal bool? xValuesZeros;
254+
252255

253256
// fake data points for selector service in design time.
254257
// note: in design time fake points are generated

src/System.Windows.Forms.DataVisualization/General/ChartAreaAxes.cs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,25 +1414,26 @@ internal void SetData(bool initializeAxes, bool checkIndexedAligned)
14141414
}
14151415
}
14161416

1417+
// Now we allow IsXValueIndexed flag for some (not for all) series.
14171418
// Check that all primary X axis series are aligned if use the IsXValueIndexed flag
1418-
if (checkIndexedAligned)
1419-
{
1420-
for (int axisIndex = 0; axisIndex <= 1; axisIndex++)
1421-
{
1422-
List<string> seriesArray = this.GetXAxesSeries((axisIndex == 0) ? AxisType.Primary : AxisType.Secondary, string.Empty);
1423-
if (seriesArray.Count > 0 && seriesArray.Any(sn => Common.DataManager.Series[sn].IsXValueIndexed))
1424-
{
1425-
try
1426-
{
1427-
Common.DataManipulator.CheckXValuesAlignment(Common.DataManipulator.ConvertToSeriesArray(seriesArray, false));
1428-
}
1429-
catch (Exception e)
1430-
{
1431-
throw new ArgumentException(SR.ExceptionAxisSeriesNotAligned + e.Message);
1432-
}
1433-
}
1434-
}
1435-
}
1419+
//if (checkIndexedAligned)
1420+
//{
1421+
// for (int axisIndex = 0; axisIndex <= 1; axisIndex++)
1422+
// {
1423+
// List<string> seriesArray = this.GetXAxesSeries((axisIndex == 0) ? AxisType.Primary : AxisType.Secondary, string.Empty);
1424+
// if (seriesArray.Count > 0 && seriesArray.Any(sn => Common.DataManager.Series[sn].IsXValueIndexed))
1425+
// {
1426+
// try
1427+
// {
1428+
// Common.DataManipulator.CheckXValuesAlignment(Common.DataManipulator.ConvertToSeriesArray(seriesArray, false));
1429+
// }
1430+
// catch (Exception e)
1431+
// {
1432+
// throw new ArgumentException(SR.ExceptionAxisSeriesNotAligned + e.Message);
1433+
// }
1434+
// }
1435+
// }
1436+
//}
14361437

14371438
if (initializeAxes)
14381439
{

src/System.Windows.Forms.DataVisualization/General/ChartElement.cs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -777,23 +777,15 @@ internal static double GetIntervalSize(
777777
/// <returns>True if any series is indexed.</returns>
778778
internal static bool IndexedSeries(CommonElements common, List<string> series)
779779
{
780-
if (common.DataManager.indexedSeries is not null)
781-
return common.DataManager.indexedSeries.Value;
782-
783780
// Data series loop
784781
foreach (string ser in series)
785782
{
786783
Series localSeries = common.DataManager.Series[ser];
787784
// Check series indexed flag
788785
if (localSeries.IsXValueIndexed)
789-
{
790-
// If flag set in at least one series - all series are indexed
791-
common.DataManager.indexedSeries = true;
792-
return true;
793-
}
786+
return true; // If flag set in at least one series - all series are indexed
794787
}
795788

796-
common.DataManager.indexedSeries = false;
797789
return false;
798790
}
799791

@@ -803,13 +795,22 @@ internal static bool IndexedSeries(CommonElements common, List<string> series)
803795
/// <param name="series">Data series to check.</param>
804796
private static bool SeriesXValuesZeros(Series series)
805797
{
798+
// Check if X value zeros check was already done
799+
if (series.xValuesZeros is not null)
800+
return series.xValuesZeros.Value;
801+
806802
// Data point loop
807803
foreach (DataPoint point in series.Points)
808804
{
809805
if (point.XValue != 0.0)
806+
{
807+
// If any data point has value different than 0 return false
808+
series.xValuesZeros = false;
810809
return false;
810+
}
811811
}
812812

813+
series.xValuesZeros = true;
813814
return true;
814815
}
815816

@@ -821,21 +822,14 @@ private static bool SeriesXValuesZeros(Series series)
821822
/// <returns>True if all data points have value 0.</returns>
822823
internal static bool SeriesXValuesZeros(CommonElements common, List<string> series)
823824
{
824-
if (common.DataManager.xValuesZeros is not null)
825-
return common.DataManager.xValuesZeros.Value;
826-
827825
// Data series loop
828826
foreach (string ser in series)
829827
{
830828
// Check one series X values
831829
if (!SeriesXValuesZeros(common.DataManager.Series[ser]))
832-
{
833-
common.DataManager.xValuesZeros = false;
834830
return false;
835-
}
836831
}
837832

838-
common.DataManager.xValuesZeros = true;
839833
return true;
840834
}
841835

0 commit comments

Comments
 (0)