Skip to content

Commit

Permalink
Slider added;
Browse files Browse the repository at this point in the history
  • Loading branch information
Aliuser11 committed Dec 7, 2024
1 parent 5eced9e commit 27d56d0
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 4 deletions.
5 changes: 4 additions & 1 deletion WPFGraphMaker/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
<Border Grid.Row="1">
<ContentControl Content="{Binding WpfPlot1}" Visibility="Visible"/>
</Border>

<Slider
Width="500" Value="0" Orientation="Horizontal" HorizontalAlignment="Stretch"
IsSnapToTickEnabled="True" Maximum="5000" TickPlacement="BottomRight"
AutoToolTipPlacement="BottomRight" TickFrequency="20" ValueChanged="Slider_ValueChanged"/>
</Grid>

</Window>
63 changes: 60 additions & 3 deletions WPFGraphMaker/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,14 @@ public MainWindow()
CanContentScroll = true
};
var st = new ScaleTransform();
Point p = e.GetPosition(WpfPlot1);
int index = (int)p.X;
Pixel mousePixel = new();
Coordinates mouseCoordinates = WpfPlot1.Plot.GetCoordinates(mousePixel);
cross.Position = mouseCoordinates;
WpfPlot1.Plot.ScaleFactor = 3;
scrollViewer.ScrollToTop();
WpfPlot1.Plot.Axes.SetLimitsY(200, 240);
WpfPlot1.Plot.Axes.AutoScaleY();
WpfPlot1.Plot.Axes.SetLimitsX(-1, 40);
WpfPlot1.Refresh();
};
Expand Down Expand Up @@ -182,8 +184,6 @@ private void ViewGraph(List<ZigZagObject> points)
myScatter.LinePattern = LinePattern.Solid;
WpfPlot1.Plot.Axes.Margins(.15, .15);
WpfPlot1.Plot.Axes.AutoScale();
//WpfPlot1.Plot.Axes.SetLimitsY(0,(double)pointsPlot.Max());
//WpfPlot1.Plot.Axes.SetLimitsX(0,(double)pointsPlot.Length);
WpfPlot1.Refresh();
}

Expand Down Expand Up @@ -213,5 +213,62 @@ protected void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
private void Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
var points = GetPoints().Result;
var pointsPlot = points.Select(x => x.Close).ToArray();
var signals = points.Select(x => x.Signal).ToArray();
var numbers = new List<double>();
for (int i = 0; i < points.Count; i++)
{
numbers.Add((double)i);
}

ScottPlot.Palettes.Category20 palette = new();
if (e.NewValue >= 0 && e.NewValue < pointsPlot.Length)
{
int index = (int)e.NewValue;
var item = points[index];
if (item.Signal == true)
{
var mp = WpfPlot1.Plot.Add.Marker(index, (double)item.Close);
mp.MarkerShape = MarkerShape.OpenDiamond;

mp.MarkerStyle.FillColor = palette.GetColor(8);
mp.MarkerStyle.Size = 1.5F;
mp.MarkerStyle.OutlineColor = palette.GetColor(8);
mp.MarkerStyle.OutlineWidth = 2;
mp.MarkerStyle.LineWidth = 2f;
mp.MarkerStyle.LineColor = palette.GetColor(10);
}
double xVal = (double)numbers[index];
double yVal = (double)pointsPlot[index];

WpfPlot1.Plot.Clear();
WpfPlot1.Plot.Axes.Margins(.15, .15);
WpfPlot1.Plot.Axes.AutoScale();

var myScatter = WpfPlot1.Plot.Add.Scatter(numbers.ToArray(), pointsPlot);
myScatter.Color = ScottPlot.Colors.Green;
myScatter.LineWidth = 1;
myScatter.MarkerSize = 1.2F;
myScatter.MarkerShape = MarkerShape.OpenSquare;
myScatter.LinePattern = LinePattern.Solid;
WpfPlot1.Refresh();
}
}
private async Task<List<ZigZagObject>> GetPoints()
{
var url = "https://gist.github.com/przemyslawbak/92c3d4bba27cfd2b88d0dd916bbdad14/raw/AAL_1min.json";

HttpClient client = new HttpClient();
HttpResponseMessage response = await client.GetAsync(url);
response.EnsureSuccessStatusCode();
string json = await response.Content.ReadAsStringAsync();

var patternName = patternNameTextBox.Text == string.Empty ? "BullishButterfly" : patternNameTextBox.Text;
List<ZigZagObject> points = GetGraphData(patternName, json);
return points;
}
}
}

0 comments on commit 27d56d0

Please sign in to comment.