Skip to content

Commit

Permalink
Merge pull request #119 from africanmathsinitiative/master
Browse files Browse the repository at this point in the history
updating branch
  • Loading branch information
shadrackkibet authored Jun 27, 2017
2 parents 777d62c + cda915b commit c2afba0
Show file tree
Hide file tree
Showing 61 changed files with 5,407 additions and 3,790 deletions.
1 change: 1 addition & 0 deletions _config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
theme: jekyll-theme-minimal
1 change: 1 addition & 0 deletions docs/_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
theme: jekyll-theme-minimal
1 change: 1 addition & 0 deletions docs/foo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

32 changes: 26 additions & 6 deletions instat/clsGridLink.vb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Public Class clsGridLink
dfTemp = frmMain.clsRLink.RunInternalScriptGetValue(clsGetDataFrame.ToScript()).AsDataFrame
clsFilterApplied.AddParameter("data_name", Chr(34) & strDataName & Chr(34))
If frmMain.clsRLink.RunInternalScriptGetValue(clsFilterApplied.ToScript()).AsLogical(0) Then
FillSheet(dfTemp, strDataName, grdData, bInstatObjectDataFrame:=True, bIncludeDataTypes:=True, iNewPosition:=i, bFilterApplied:=True, bCheckFreezeColumns:=True)
FillSheet(dfTemp, strDataName, grdData, bInstatObjectDataFrame:=True, bIncludeDataTypes:=True, iNewPosition:=i, bFilterApplied:=True, bCheckFreezeColumns:=True, iRowMax:=iMaxRows, iColMax:=iMaxCols)
Else
FillSheet(dfTemp, strDataName, grdData, bInstatObjectDataFrame:=True, bIncludeDataTypes:=True, iNewPosition:=i, bFilterApplied:=False, bCheckFreezeColumns:=True)
End If
Expand All @@ -121,7 +121,8 @@ Public Class clsGridLink
expVarMetadata = frmMain.clsRLink.RunInternalScriptGetValue(clsGetVariablesMetadata.ToScript())
If expVarMetadata IsNot Nothing AndAlso expVarMetadata.Type <> Internals.SymbolicExpressionType.Null Then
dfTemp = expVarMetadata.AsDataFrame()
FillSheet(dfTemp, strDataName, grdVariablesMetadata)
'TODO test if column limit is needed for stability in metadata grids
FillSheet(dfTemp, strDataName, grdVariablesMetadata, iColMax:=iMaxCols)
clsSetVariablesMetadataChanged.AddParameter("data_name", Chr(34) & strDataName & Chr(34))
clsSetVariablesMetadataChanged.AddParameter("new_val", "TRUE")
frmMain.clsRLink.RunInternalScript(clsSetVariablesMetadataChanged.ToScript())
Expand Down Expand Up @@ -175,8 +176,9 @@ Public Class clsGridLink

If bGrdMetadataExists And (bGrdMetadataChanged Or bRMetadataChanged) Then
clsGetCombinedMetadata.AddParameter("convert_to_character", "TRUE")
dfTemp = frmMain.clsRLink.RunInternalScriptGetValue(clsGetCombinedMetadata.ToScript()).AsDataFrame()
FillSheet(dfTemp, "metadata", grdMetadata)
dfTemp = frmMain.clsRLink.RunInternalScriptGetValue(clsGetCombinedMetadata.ToScript()).AsDataFrame()
'TODO test if column limit is needed for stability in metadata grids
FillSheet(dfTemp, "metadata", grdMetadata, iColMax:=iMaxCols)
clsSetMetadataChanged.AddParameter("new_val", "TRUE")
frmMain.clsRLink.RunInternalScript(clsSetMetadataChanged.ToScript())
End If
Expand Down Expand Up @@ -239,7 +241,7 @@ Public Class clsGridLink
UpdateGrids()
End Sub

Public Sub FillSheet(dfTemp As DataFrame, strName As String, grdCurr As ReoGridControl, Optional bInstatObjectDataFrame As Boolean = False, Optional bIncludeDataTypes As Boolean = False, Optional iNewPosition As Integer = -1, Optional bFilterApplied As Boolean = False, Optional bCheckFreezeColumns As Boolean = False, Optional iRowMax As Integer = -1)
Public Sub FillSheet(dfTemp As DataFrame, strName As String, grdCurr As ReoGridControl, Optional bInstatObjectDataFrame As Boolean = False, Optional bIncludeDataTypes As Boolean = False, Optional iNewPosition As Integer = -1, Optional bFilterApplied As Boolean = False, Optional bCheckFreezeColumns As Boolean = False, Optional iRowMax As Integer = -1, Optional iColMax As Integer = -1)
Dim bFoundWorksheet As Boolean = False
Dim tempWorkSheet As Worksheet
Dim fillWorkSheet As Worksheet
Expand Down Expand Up @@ -282,7 +284,12 @@ Public Class clsGridLink
If iNewPosition <> -1 AndAlso iNewPosition <> iCurrPosition AndAlso iNewPosition < grdCurr.Worksheets.Count Then
grdCurr.MoveWorksheet(fillWorkSheet, iNewPosition)
End If
fillWorkSheet.Columns = dfTemp.ColumnCount
'replaced this to fill columns with the iMaxCols
If iColMax <> -1 Then
fillWorkSheet.Columns = Math.Min(iColMax, dfTemp.ColumnCount)
Else
fillWorkSheet.Columns = dfTemp.ColumnCount
End If
strColumnNames = dfTemp.ColumnNames
If dfTemp.RowCount = 0 Then
fillWorkSheet.Rows = 1
Expand Down Expand Up @@ -452,6 +459,19 @@ Public Class clsGridLink
UpdateGrids()
End Sub

Public Sub SetMaxCols(iCols As Integer)
iMaxCols = iCols
bGrdDataChanged = True
bGrdMetadataChanged = True
bGrdVariablesMetadataChanged = True
'TODO This causes the last sheet to be current sheet after running this.
' Need to change how this is done so that the current sheet is remembered before changing.
If frmMain.clsRLink.bInstatObjectExists Then
frmMain.clsRLink.RunInternalScript(frmMain.clsRLink.strInstatDataObject & "$data_objects_changed <- TRUE")
End If
UpdateGrids()
End Sub

Public Sub SetFormatDataView(fntNew As Font, clrNew As Color)
fntText = fntNew
clrText = clrNew
Expand Down
165 changes: 100 additions & 65 deletions instat/clsInstatOptions.vb
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
Imports System.Threading
' Instat-R
' Copyright (C) 2015
'
' This program is free software: you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation, either version 3 of the License, or
' (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License k
' along with this program. If not, see <http://www.gnu.org/licenses/>.

Imports System.Threading
Imports System.Globalization
Imports unvell.ReoGrid
Imports RDotNet

'Serializable allows the class to be exported as a file
<Serializable()> Public Class InstatOptions
Public bIncludeRDefaultParameters As Boolean
Public fntOutput, fntScript, fntComment, fntEditor As Font
Public clrOutput, clrScript, clrComment, clrEditor As Color
Public strComment, strLanguageCultureCode As String
Public strWorkingDirectory As String
' Nullable allows us to have integers and booleans with value = Nothing
' Needed so we can check if variable has been specified, not just has default value
Public bIncludeRDefaultParameters As Nullable(Of Boolean)
Public iPreviewRows As Nullable(Of Integer)
Public iMaxRows As Nullable(Of Integer)
Public iMaxCols As Nullable(Of Integer)
Public lstColourPalette As List(Of Color)
Public strGraphDisplayOption As String
Public bCommandsinOutput As Nullable(Of Boolean)
Expand All @@ -22,53 +39,29 @@ Imports RDotNet
Public bShowSignifStars As Nullable(Of Boolean)
Public bChangeDataFrame As Nullable(Of Boolean)

'Factory defaults
Private DEFAULTbIncludeRDefaultParameters As Boolean = False
Private DEFAULTbCommandsinOutput As Boolean = True
Private DEFAULTbIncludeCommentDefault As Boolean = True
Private DEFAULTfntOutput As Font = New Font(FontFamily.GenericMonospace, 11, FontStyle.Regular)
Private DEFAULTclrOutput As Color = Color.Blue
Private DEFAULTfntComment As Font = New Font(FontFamily.GenericSansSerif, 11, FontStyle.Regular)
Private DEFAULTclrComment As Color = Color.Green
Private DEFAULTfntScript As Font = New Font(FontFamily.GenericSansSerif, 11, FontStyle.Regular)
Private DEFAULTclrScript As Color = Color.Black
Private DEFAULTfntEditor As Font = New Font(FontFamily.GenericSansSerif, 10, FontStyle.Regular)
Private DEFAULTclrEditor As Color = Color.Black
Private DEFAULTiPreviewRows As Integer = 10
Private DEFAULTiMaxRows As Integer = 1000
Private DEFAULTstrComment As String = "code generated by the dialog"
Private DEFAULTstrGraphDisplayOption As String = "view_output_window"
Private DEFAULTbChangeDataFrame As Boolean = False
'TODO is this sensible?
Private DEFAULTstrLanguageCultureCode As String = Thread.CurrentThread.CurrentCulture.Name
Private DEFAULTstrWorkingDirectory As String = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
Private DEFAULTlstColourPalette As List(Of Color) = ({Color.Aqua, Color.Gray, Color.LightGreen, Color.AliceBlue, Color.Maroon, Color.Green, Color.LightPink, Color.LightSkyBlue, Color.Brown, Color.MediumPurple, Color.White}).ToList
Private DEFAULTiDigits As Integer = 4
Private DEFAULTbShowSignifStars As Boolean = False

Public Sub New(Optional bSetOptions As Boolean = True)
'TODO Is this sensible to do in constructor?
bIncludeRDefaultParameters = DEFAULTbIncludeRDefaultParameters
bCommandsinOutput = DEFAULTbCommandsinOutput
bIncludeCommentDefault = DEFAULTbIncludeCommentDefault
fntOutput = DEFAULTfntOutput
clrOutput = DEFAULTclrOutput
fntComment = DEFAULTfntComment
clrComment = DEFAULTclrComment
fntScript = DEFAULTfntScript
clrScript = DEFAULTclrScript
fntEditor = DEFAULTfntEditor
clrEditor = DEFAULTclrEditor
iPreviewRows = DEFAULTiPreviewRows
iMaxRows = DEFAULTiMaxRows
strComment = DEFAULTstrComment
strGraphDisplayOption = DEFAULTstrGraphDisplayOption
'TODO is this sensible?
strLanguageCultureCode = DEFAULTstrLanguageCultureCode
strWorkingDirectory = DEFAULTstrWorkingDirectory
SetColorPalette(DEFAULTlstColourPalette)
iDigits = DEFAULTiDigits
bShowSignifStars = DEFAULTbShowSignifStars
bIncludeRDefaultParameters = clsInstatOptionsDefaults.DEFAULTbIncludeRDefaultParameters
bCommandsinOutput = clsInstatOptionsDefaults.DEFAULTbCommandsinOutput
bIncludeCommentDefault = clsInstatOptionsDefaults.DEFAULTbIncludeCommentDefault
fntOutput = clsInstatOptionsDefaults.DEFAULTfntOutput
clrOutput = clsInstatOptionsDefaults.DEFAULTclrOutput
fntComment = clsInstatOptionsDefaults.DEFAULTfntComment
clrComment = clsInstatOptionsDefaults.DEFAULTclrComment
fntScript = clsInstatOptionsDefaults.DEFAULTfntScript
clrScript = clsInstatOptionsDefaults.DEFAULTclrScript
fntEditor = clsInstatOptionsDefaults.DEFAULTfntEditor
clrEditor = clsInstatOptionsDefaults.DEFAULTclrEditor
iPreviewRows = clsInstatOptionsDefaults.DEFAULTiPreviewRows
iMaxRows = clsInstatOptionsDefaults.DEFAULTiMaxRows
iMaxCols = clsInstatOptionsDefaults.DEFAULTiMaxCols
strComment = clsInstatOptionsDefaults.DEFAULTstrComment
strGraphDisplayOption = clsInstatOptionsDefaults.DEFAULTstrGraphDisplayOption
strLanguageCultureCode = clsInstatOptionsDefaults.DEFAULTstrLanguageCultureCode
strWorkingDirectory = clsInstatOptionsDefaults.DEFAULTstrWorkingDirectory
lstColourPalette = clsInstatOptionsDefaults.DEFAULTlstColourPalette
iDigits = clsInstatOptionsDefaults.DEFAULTiDigits
bShowSignifStars = clsInstatOptionsDefaults.DEFAULTbShowSignifStars
If bSetOptions Then
SetOptions()
End If
Expand All @@ -78,93 +71,124 @@ Imports RDotNet
If fntOutput IsNot Nothing AndAlso clrOutput <> Color.Empty Then
SetFormatOutput(fntOutput, clrOutput)
Else
SetFormatOutput(DEFAULTfntOutput, DEFAULTclrOutput)
SetFormatOutput(clsInstatOptionsDefaults.DEFAULTfntOutput, clsInstatOptionsDefaults.DEFAULTclrOutput)
End If

If fntComment IsNot Nothing AndAlso clrComment <> Color.Empty Then
SetFormatComment(fntComment, clrComment)
Else
SetFormatComment(DEFAULTfntComment, DEFAULTclrComment)
SetFormatComment(clsInstatOptionsDefaults.DEFAULTfntComment, clsInstatOptionsDefaults.DEFAULTclrComment)
End If

If fntScript IsNot Nothing AndAlso clrScript <> Color.Empty Then
SetFormatScript(fntScript, clrScript)
Else
SetFormatScript(DEFAULTfntScript, DEFAULTclrScript)
SetFormatScript(clsInstatOptionsDefaults.DEFAULTfntScript, clsInstatOptionsDefaults.DEFAULTclrScript)
End If

If fntEditor IsNot Nothing AndAlso clrEditor <> Color.Empty Then
SetFormatEditor(fntEditor, clrEditor)
Else
SetFormatEditor(DEFAULTfntEditor, DEFAULTclrEditor)
SetFormatEditor(clsInstatOptionsDefaults.DEFAULTfntEditor, clsInstatOptionsDefaults.DEFAULTclrEditor)
End If

If iPreviewRows.HasValue Then
SetPreviewRows(iPreviewRows)
Else
SetPreviewRows(DEFAULTiPreviewRows)
SetPreviewRows(clsInstatOptionsDefaults.DEFAULTiPreviewRows)
End If

If iMaxRows.HasValue Then
SetMaxRows(iMaxRows)
Else
SetMaxRows(DEFAULTiMaxRows)
SetMaxRows(clsInstatOptionsDefaults.DEFAULTiMaxRows)
End If

If iMaxCols.HasValue Then
SetMaxCols(iMaxCols)
Else
SetMaxCols(clsInstatOptionsDefaults.DEFAULTiMaxCols)
End If

If bCommandsinOutput.HasValue Then
SetCommandInOutpt(bCommandsinOutput)
Else
SetCommandInOutpt(DEFAULTbCommandsinOutput)
SetCommandInOutpt(clsInstatOptionsDefaults.DEFAULTbCommandsinOutput)
End If

If strComment IsNot Nothing Then
SetComment(strComment)
Else
SetComment(DEFAULTstrComment)
SetComment(clsInstatOptionsDefaults.DEFAULTstrComment)
End If

If strGraphDisplayOption IsNot Nothing Then
SetGraphDisplayOption(strGraphDisplayOption)
Else
SetGraphDisplayOption(DEFAULTstrGraphDisplayOption)
SetGraphDisplayOption(clsInstatOptionsDefaults.DEFAULTstrGraphDisplayOption)
End If

If strLanguageCultureCode IsNot Nothing Then
SetLanguageCultureCode(strLanguageCultureCode)
Else
SetLanguageCultureCode(DEFAULTstrLanguageCultureCode)
SetLanguageCultureCode(clsInstatOptionsDefaults.DEFAULTstrLanguageCultureCode)
End If

If strWorkingDirectory IsNot Nothing Then
SetWorkingDirectory(strWorkingDirectory)
Else
SetWorkingDirectory(DEFAULTstrWorkingDirectory)
SetWorkingDirectory(clsInstatOptionsDefaults.DEFAULTstrWorkingDirectory)
End If

If iDigits.HasValue Then
SetDigits(iDigits)
Else
SetDigits(DEFAULTiDigits)
SetDigits(clsInstatOptionsDefaults.DEFAULTiDigits)
End If

If bShowSignifStars.HasValue Then
SetSignifStars(bShowSignifStars)
Else
SetSignifStars(DEFAULTbShowSignifStars)
SetSignifStars(clsInstatOptionsDefaults.DEFAULTbShowSignifStars)
End If

If bChangeDataFrame.HasValue Then
SetChangeDataFrame(bChangeDataFrame)
Else
SetChangeDataFrame(DEFAULTbChangeDataFrame)
SetChangeDataFrame(clsInstatOptionsDefaults.DEFAULTbChangeDataFrame)
End If

If bIncludeCommentDefault.HasValue Then
SetIncludeCommentByDefault(bIncludeCommentDefault)
Else
SetIncludeCommentByDefault(clsInstatOptionsDefaults.DEFAULTbIncludeCommentDefault)
End If

If bIncludeRDefaultParameters.HasValue Then
SetIncludeRDefaultParameters(bIncludeRDefaultParameters)
Else
SetIncludeRDefaultParameters(clsInstatOptionsDefaults.DEFAULTbIncludeRDefaultParameters)
End If

If lstColourPalette IsNot Nothing Then
SetColorPalette(lstColourPalette)
Else
SetColorPalette(clsInstatOptionsDefaults.DEFAULTlstColourPalette)
End If
End Sub

Public Sub SetMaxRows(iRows As Integer)
If iRows <> iMaxRows Then
If (iMaxRows.HasValue AndAlso iRows <> iMaxRows) OrElse Not iMaxRows.HasValue Then
iMaxRows = iRows
frmMain.clsGrids.SetMaxRows(iMaxRows)
End If
End Sub

Public Sub SetMaxCols(iCols As Integer)
If (iMaxCols.HasValue AndAlso iCols <> iMaxCols) OrElse Not iMaxCols.HasValue Then
iMaxCols = iCols
frmMain.clsGrids.SetMaxCols(iMaxCols)
End If
End Sub

Public Sub SetFormatOutput(fntNew As Font, clrNew As Color)
Expand Down Expand Up @@ -193,7 +217,6 @@ Imports RDotNet

Public Sub SetPreviewRows(intlines As Integer)
iPreviewRows = intlines
dlgImportDataset.setLinesToRead(iPreviewRows)
End Sub

Public Sub SetComment(strText As String)
Expand Down Expand Up @@ -254,14 +277,16 @@ Imports RDotNet
Public Sub SetDigits(iNewDigits As Integer)
Dim clsOptionsFunction As New RFunction
Dim clsGetOptionFunction As New RFunction
Dim expCurrDigits As SymbolicExpression

If iNewDigits > 22 OrElse iNewDigits < 0 Then
MsgBox("Cannot set digits to: " & iNewDigits & ". Digits must be an integer between 0 and 22.", MsgBoxStyle.Critical, "Error setting digits")
Else
iDigits = iNewDigits
clsGetOptionFunction.SetRCommand("getOption")
clsGetOptionFunction.AddParameter("x", Chr(34) & "digits" & Chr(34))
If frmMain.clsRLink.RunInternalScriptGetValue(clsGetOptionFunction.ToScript()).AsInteger(0) <> iDigits Then
expCurrDigits = frmMain.clsRLink.RunInternalScriptGetValue(clsGetOptionFunction.ToScript(), bSilent:=True)
If (expCurrDigits IsNot Nothing AndAlso expCurrDigits.Type <> Internals.SymbolicExpressionType.Null AndAlso expCurrDigits.AsInteger(0) <> iDigits) OrElse expCurrDigits Is Nothing Then
clsOptionsFunction.SetRCommand("options")
clsOptionsFunction.AddParameter("digits", iDigits)
frmMain.clsRLink.RunScript(clsOptionsFunction.ToScript(), strComment:="Option: Number of digits to display")
Expand All @@ -272,12 +297,14 @@ Imports RDotNet
Public Sub SetSignifStars(bShowStars As Boolean)
Dim clsOptionsFunction As New RFunction
Dim clsGetOptionsFunction As New RFunction
Dim expCurrStars As SymbolicExpression

bShowSignifStars = bShowStars
clsGetOptionsFunction.SetRCommand("getOption")
clsGetOptionsFunction.AddParameter("x", Chr(34) & "show.signif.stars" & Chr(34))
clsOptionsFunction.SetRCommand("options")
If frmMain.clsRLink.RunInternalScriptGetValue(clsGetOptionsFunction.ToScript()).AsLogical(0) <> bShowSignifStars Then
expCurrStars = frmMain.clsRLink.RunInternalScriptGetValue(clsGetOptionsFunction.ToScript(), bSilent:=True)
If (expCurrStars IsNot Nothing AndAlso expCurrStars.Type <> Internals.SymbolicExpressionType.Null AndAlso expCurrStars.AsLogical(0) <> bShowSignifStars) OrElse expCurrStars Is Nothing Then
If bShowSignifStars Then
clsOptionsFunction.AddParameter("show.signif.stars", "TRUE")
Else
Expand All @@ -290,4 +317,12 @@ Imports RDotNet
Public Sub SetChangeDataFrame(bNewChange As Boolean)
bChangeDataFrame = bNewChange
End Sub

Public Sub SetIncludeCommentByDefault(bNewInclude As Boolean)
bIncludeCommentDefault = bNewInclude
End Sub

Public Sub SetIncludeRDefaultParameters(bNewInclude As Boolean)
bIncludeRDefaultParameters = bNewInclude
End Sub
End Class
Loading

0 comments on commit c2afba0

Please sign in to comment.