Skip to content

Commit cfdcb16

Browse files
committed
Textual cutoff select for linux #27
1 parent b8e50a4 commit cfdcb16

File tree

2 files changed

+95
-8
lines changed

2 files changed

+95
-8
lines changed

MangaPrinter.WpfGUI/Dialogs/dlgChooseCutoffRatio.xaml

+44-8
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,62 @@
66
xmlns:local="clr-namespace:MangaPrinter.WpfGUI.Dialogs"
77
xmlns:d3="clr-namespace:InteractiveDataDisplay.WPF;assembly=InteractiveDataDisplay.WPF"
88
mc:Ignorable="d"
9-
Title="Choose cutoff ratio for double-page" Height="500" Width="800" WindowStartupLocation="CenterScreen"
9+
Title="Choose cutoff ratio for double-page" Height="550" Width="1000" WindowStartupLocation="CenterScreen"
1010
Loaded="Window_Loaded" Closing="Window_Closing" FontSize="14">
1111
<Grid>
1212
<Grid.RowDefinitions>
1313
<RowDefinition/>
1414
<RowDefinition Height="auto"></RowDefinition>
1515
<RowDefinition Height="auto"></RowDefinition>
1616
</Grid.RowDefinitions>
17-
<d3:Chart BottomTitle="Ratio (Page Width/Height)" LeftTitle="Count" Grid.Row="0" Margin="5,5">
18-
<Grid>
19-
<d3:LineGraph x:Name="gRatio" Description="Ratio Distribution" Stroke="Blue" StrokeThickness="3"/>
20-
<d3:LineGraph x:Name="gCutoff" Description="Cutoff" Stroke="Red" StrokeThickness="3"/>
21-
</Grid>
22-
</d3:Chart>
23-
17+
18+
<TabControl Grid.Row="0">
19+
<TabItem >
20+
<TabItem.Header>
21+
<TextBlock FontSize="15pt">Visual</TextBlock>
22+
</TabItem.Header>
23+
<d3:Chart BottomTitle="Ratio (Page Width/Height)" LeftTitle="Count" Margin="5,5">
24+
<Grid>
25+
<d3:LineGraph x:Name="gRatio" Description="Ratio Distribution" Stroke="Blue" StrokeThickness="3"/>
26+
<d3:LineGraph x:Name="gCutoff" Description="Cutoff" Stroke="Red" StrokeThickness="3"/>
27+
</Grid>
28+
</d3:Chart>
29+
</TabItem>
30+
<TabItem >
31+
<TabItem.Header>
32+
<TextBlock FontSize="15pt">Textual</TextBlock>
33+
</TabItem.Header>
34+
<StackPanel>
35+
<TextBlock x:Name="x20x100">
36+
37+
</TextBlock>
38+
<RichTextBox>
39+
<RichTextBox.Document>
40+
<FlowDocument>
41+
<Paragraph>
42+
<TextBlock FontWeight="Bold">Value:</TextBlock>
43+
<TextBlock x:Name="txtValue"></TextBlock>
44+
<TextBlock FontWeight="Bold">Count:</TextBlock>
45+
<TextBlock x:Name="txtValueCount"></TextBlock>
46+
<LineBreak/>
47+
<TextBlock FontWeight="Bold">Count Before:</TextBlock>
48+
<TextBlock x:Name="txtCountBfr"></TextBlock>
49+
<TextBlock FontWeight="Bold">Count After:</TextBlock>
50+
<TextBlock x:Name="txtCountAftr"></TextBlock>
51+
</Paragraph>
52+
</FlowDocument>
53+
</RichTextBox.Document>
54+
</RichTextBox>
55+
</StackPanel>
56+
</TabItem>
57+
</TabControl>
58+
2459
<StackPanel Grid.Row="1" Margin="5,5">
2560
<Label>Choose cutoff (in the middle?)</Label>
2661
<Slider Name="sldCutoff" Minimum="0" Maximum="99" SmallChange="1" LargeChange="1"
2762
Value="{Binding BucketIndex}" ValueChanged="Slider_ValueChanged"/>
2863
</StackPanel>
64+
2965
<DockPanel Grid.Row="2" LastChildFill="False">
3066
<Button DockPanel.Dock="Right" Margin="5" Padding="5"
3167
Name="btnAccept" Click="BtnAccept_Click">Accept</Button>

MangaPrinter.WpfGUI/Dialogs/dlgChooseCutoffRatio.xaml.cs

+51
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,69 @@ private void Window_Loaded(object sender, RoutedEventArgs e)
4141
InputBuckets.Select((b)=>b.value),
4242
InputBuckets.Select((b)=>b.count)
4343
);
44+
45+
makeTextualGraph(0);
4446
}
4547
}
4648

49+
const int textualGraphRows = 17;
50+
void makeTextualGraph(int selectedIndex)
51+
{
52+
string result = "";
53+
54+
int maxCount = InputBuckets.Select(b => b.count).Max();
55+
int minCount = InputBuckets.Select(b => b.count).Min();
56+
float countStep = 1.0f * (maxCount - minCount) / textualGraphRows;
57+
58+
for (int row = 0; row < textualGraphRows; row++)
59+
{
60+
for (int bucket = 0; bucket < InputBuckets.Count; bucket++)
61+
{
62+
result += InputBuckets[bucket].count > (textualGraphRows - row -1) * (countStep) ?
63+
"#" : "- ";
64+
65+
}
66+
result += "\n";
67+
}
68+
69+
int countBefore = 0;
70+
int countAfter = 0;
71+
for (int bucket = 0; bucket < InputBuckets.Count; bucket++)
72+
{
73+
result += (selectedIndex == bucket) ? "^" : "- ";
74+
75+
if (bucket < selectedIndex)
76+
{
77+
countBefore += InputBuckets[bucket].count;
78+
}
79+
if (bucket > selectedIndex)
80+
{
81+
countAfter += InputBuckets[bucket].count;
82+
}
83+
}
84+
85+
x20x100.Text = result;
86+
txtValue.Text = Math.Round(InputBuckets[selectedIndex].value,2).ToString();
87+
txtValueCount.Text = InputBuckets[selectedIndex].count.ToString();
88+
txtCountAftr.Text = countAfter.ToString();
89+
txtCountBfr.Text = countBefore.ToString();
90+
91+
92+
93+
}
94+
4795
private void Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
4896
{
4997
if (InputBuckets != null && InputBuckets.Count > 0)
5098
{
5199
BucketIndex = (int)sldCutoff.Value;
100+
52101
IEnumerable<double> _x2 = new double[] { InputBuckets[BucketIndex].value, InputBuckets[BucketIndex].value };
53102
IEnumerable<double> _y2 = new double[] { 0, maxCount };
54103

55104
gCutoff.Plot(_x2, _y2);
105+
106+
makeTextualGraph(BucketIndex);
56107
}
57108
}
58109

0 commit comments

Comments
 (0)