/// <summary> /// Serialize conditional formatting, classification rules /// </summary> /// <returns></returns> public string SerializeRules() { CondFormatRules rules = CondFormatRulesCtl.GetRules(); string serializedForm = rules.Serialize(); return(serializedForm); }
/// <summary> /// See if valid basic calculated field /// </summary> /// <returns></returns> private bool IsValidBasicCalcField() { for (int cfcci = 0; cfcci < CfColCtls.Count; cfcci++) { CalcFieldColumnControl cfcc = CfColCtls[cfcci]; bool validate = false; // decide if we should validate this field if (cfcci == 0) { validate = true; // always validate 1st field } else if (cfcci == 1 && !Lex.StartsWith(Operation.Text, "none")) { validate = true; // validate 2nd field if operator is not "none" } else if (cfcc.FieldSelectorControl.MetaColumn != null) { validate = true; } if (validate && !ValidateField(cfcc)) { return(false); } } if (!CondFormatRulesCtl.AreValid()) // are any rules valid { Tabs.SelectedTabPageIndex = 1; return(false); } CondFormatRules rules = CondFormatRulesCtl.GetRules(); if (CalcField.SourceColumnType == MetaColumnType.Structure && rules.Count == 0) { Tabs.SelectedTabPageIndex = 1; MessageBoxMx.Show( "Calculated fields on chemical structures must use classification\r\n" + "for the calculated field value", UmlautMobius.String); return(false); } if (rules.Count > 0) // must have at least one rule { foreach (CondFormatRule rule in rules) // must have name for each rule { if (String.IsNullOrEmpty(rule.Name)) { Tabs.SelectedTabPageIndex = 1; MessageBoxMx.Show("A name must be defined for each rule if using rule names the as calculated value", UmlautMobius.String); return(false); } } } return(true); }
/// <summary> /// GetDataDisplayColumnsFormValue /// </summary> /// <param name="rules"></param> /// <returns></returns> List <ColorCodingItemMsx> GetColorCodingColumnsFormValues( TrellisCardBarChartControl cc) { CondFormatRules rules = cc.GetCondFormatRulesFromDataTable(); List <ColorCodingItemMsx> ccl = ConvertCondFormatRulesToColorCodingItems(rules); return(ccl); }
/// <summary> /// Setup the rules control /// </summary> /// <param name="columnType"></param> /// <param name="rules"></param> public void Setup( SpotfireViewProps svp, CondFormatRules rules) { SetupDataTableAndGrid(svp, rules); LoadDataTableFromCondFormatRules(rules); return; }
/// <summary> /// Setup color set conditional formatting rules for column /// </summary> /// <param name="setName"></param> /// <returns></returns> private CondFormatRules InitializeColorSetCondFormatRules(string setName) { CondFormatRule rule = null; CondFormatRules rules = GetCondFormatRulesFromDataTable(); bool compatible = (rules.ColoringStyle == CondFormatStyle.ColorSet || rules.ColoringStyle == CondFormatStyle.IconSet); bool setExists = (Bitmaps.ColorSetImageColors.ContainsKey(setName)); if (!compatible || !setExists) // need new rules set? { if (!setExists || Lex.Eq(setName, CondFormat.DefaultColorSet)) { CondFormat cf = CondFormat.BuildDefaultConditionalFormatting(); rules = cf.Rules; return(rules); } rules = new CondFormatRules(CondFormatStyle.ColorSet); } rules.ColoringStyle = CondFormatStyle.ColorSet; Color[] colors = Bitmaps.ColorSetImageColors[setName]; for (int ri = 0; ri < colors.Length; ri++) { if (ri < rules.Count) { rule = rules[ri]; } else { rule = new CondFormatRule(); rule.Name = "Rule " + (ri + 1); rule.Op = "<="; rule.OpCode = CondFormatRule.ConvertOpNameToCode(rule.Op); rules.Add(rule); } rule.BackColor1 = colors[ri]; } return(rules); }
/// <summary> /// Reset form for change in source column type if needed /// </summary> /// <param name="sourceColumnType"></param> public void SetSourceColumnType( int sourceColumnTypeInt) { MetaColumnType sourceColumnType = (MetaColumnType)sourceColumnTypeInt; SetupFormForColumnType(sourceColumnType); // setup form CalcField.SourceColumnType = sourceColumnType; CalcField.SetDerivedValues(); CondFormatRules rules = new CondFormatRules(); CondFormatRulesCtl.SetupControl(CalcField.PreclassificationlResultType, rules.ColoringStyle); rules.Add(new CondFormatRule()); // include initial rule CondFormatRulesCtl.SetupControl(CalcField.PreclassificationlResultType, rules); return; }
/// <summary> /// Setup the rules control /// </summary> /// <param name="columnType"></param> /// <param name="rules"></param> public void Setup( SpotfireViewProps svp, CondFormatRules rules, EventHandler editValueChangedEventHandler) { InSetup = true; SetupDataTableAndGrid(svp, rules); LoadDataTableFromCondFormatRules(rules); EditValueChangedEventHandler = editValueChangedEventHandler; InSetup = false; return; }
/// <summary> /// Setup ColorSet rules and grid /// </summary> /// <param name="setName"></param> private void InitializeColorSetCondFormatRulesAndGrid( string setName) { if (InSetup) { return; } SetColumnVisibilityForColoringStyle(CondFormatStyle.ColorSet); CondFormatRules rules = InitializeColorSetCondFormatRules(setName); Setup(SVP, rules); EditValueChanged(); return; }
/// <summary> /// Setup the conditional formatting control for marker colors /// </summary> public void SetupColorSchemeGrid( QueryColumn qc, ViewManager view) { return; // todo if (qc == null || qc.CondFormat == null) { CondFormatRules rules = new CondFormatRules(); SetupControl(MetaColumnType.Unknown, rules); } else // column assigned to color rules { ResultsField rfld = view.ResultsFormat.GetResultsField(qc); if (rfld != null) { SetupControl(rfld, qc.CondFormat.Rules); // setup existing rules } } return; }
void SetupCondFormatRulesFromColorCodingItems( TrellisCardBarChartControl cc, List <ColorCodingItemMsx> ccl, CondFormatStyle cfStyle) { CondFormatRules rules = new CondFormatRules(cfStyle); foreach (ColorCodingItemMsx i in ccl) { CondFormatRule r = new CondFormatRule(); r.Name = i.ColumnName; string suffix = ""; if (cfStyle == CondFormatStyle.ColorSet) { r.BackColor1 = i.BackColor; } else // Gradient { int ruleCnt = i.SubRules.Count; List <string> subruleText = new List <string>(); foreach (ColorCodingSubRuleMsx ccr in i.SubRules) { string txt = ccr.Value; if (ccr.CalcType != ValueCalcTypeEnumMsx.Value) { txt += " (" + ccr.CalcType + ")"; } subruleText.Add(txt); } List <Color> colors = new List <Color>(); if (ruleCnt > 0) { r.Value = subruleText[0]; colors.Add(i.SubRules[0].Color); } if (ruleCnt > 2) { r.Value2 = subruleText[2]; // max rule text colors.Add(i.SubRules[1].Color); // avg color colors.Add(i.SubRules[2].Color); // max color } else if (ruleCnt > 1) { r.Value2 = subruleText[1]; colors.Add(i.SubRules[1].Color); } string scaleName = Bitmaps.GetColorScaleNameFromColorset(colors.ToArray()); if (Lex.IsUndefined(scaleName)) { scaleName = CondFormat.DefaultColorScale; } r.ImageName = scaleName; } rules.Add(r); } cc.Setup(SVP, rules, EditValueChanged); return; }
/// <summary> /// Get other values from calc field form checking for errors /// </summary> /// <returns></returns> bool GetCalcFieldForm() { List <MetaColumn> mcList; CalcField cf = CalcField; CalcFieldColumn cfc = null; if (cf.CalcType == CalcTypeEnum.Basic) // basic CF { cf.Operation = Operation.Text; cf.CfCols.Clear(); // update foreach (CalcFieldColumnControl cfcc in CfColCtls) { if (cfcc.FieldSelectorControl.MetaColumn == null) { continue; } cfc = new CalcFieldColumn(); cfc.MetaColumn = cfcc.FieldSelectorControl.MetaColumn; cfc.Function = cfcc.Function.Text; cfc.Constant = cfcc.Constant.Text; cf.CfCols.Add(cfc); } } else // advanced CF { cf.AdvancedExpr = ParseAdvancedExpr(AdvancedExpr.Text, out mcList); // Get preclassification result type string txt = ResultDataType.Text; if (Lex.IsDefined(txt)) { cf.PreclassificationlResultType = MetaColumn.ParseMetaColumnTypeString(txt); } else { cf.PreclassificationlResultType = MetaColumnType.Number; } // Get anchor table for joins cf.CfCols.Clear(); foreach (MetaColumn mc0 in mcList) { cfc = new CalcFieldColumn(); cfc.MetaColumn = mc0; cf.CfCols.Add(cfc); } cf.OuterJoinRoot = ""; txt = JoinAnchorComboBox.Text; if (Lex.Eq(txt, "(None)")) { txt = ""; } if (Lex.IsDefined(txt)) { for (int ci = 0; ci < cf.CfCols.Count; ci++) { cfc = cf.CfCols[ci]; if (Lex.Eq(txt, cfc.MetaColumn.MetaTable.Label)) { cf.OuterJoinRoot = cfc.MetaColumn.MetaTable.Name; break; } } } } cf.Description = Description.Text; CondFormatRules rules = CondFormatRulesCtl.GetRules(); if (rules.Count == 0) { cf.Classification = null; } else { cf.Classification = new CondFormat(); cf.Classification.Rules = rules; } try { cf.SetDerivedValuesWithException(); } // set derived values checking for errors catch (Exception ex) { MessageBoxMx.ShowError(ex.Message); return(false); } return(true); }
/// <summary> /// Set contents of calculated field form /// </summary> /// <param name="cf"></param> void SetupForm() { InSetup = true; CalcField cf = CalcField; CalcFieldColumn cfc; CalcFieldColumnControl cfcc; CondFormatRules rules; int ci, cci; MetaColumnType mcType = MetaColumnType.Number; // be sure source column type is set MetaColumn cfMc = null; Tabs.SelectedTabPageIndex = 0; // be sure first tab is selected SetupControlVisibility(); foreach (CalcFieldColumnControl cfc0 in CfColCtls) // clear field selector controls on form { cfc0.FieldSelectorControl.Query = QueriesControl.Instance.CurrentQuery; // cfc0.CfCol.Query = QueriesControl.Instance.CurrentQuery; cfc0.FieldSelectorControl.MetaColumn = null; } AdvancedExpr.Text = ""; FormatAdvancedExpr(cf.AdvancedExpr, out AdvancedEditorPseudoQuery); // setup advanced field menu if (cf.CalcType == CalcTypeEnum.Basic) { cfMc = cf.MetaColumn1; BasicOptionButton.Checked = true; if (cf.Operation != "") { Operation.Text = cf.Operation; } else { Operation.Text = "/ (Division)"; } cf.SetDerivedValues(); } else // advanced type { AdvancedOptionButton.Checked = true; AdvancedExpr.Text = FormatAdvancedExpr(cf.AdvancedExpr, out AdvancedEditorPseudoQuery); List <MetaColumn> mcList = cf.GetInputMetaColumnList(); if (mcList.Count > 0) { cfMc = mcList[0]; } // Setup result type if (cf.PreclassificationlResultType == MetaColumnType.Unknown) { cf.PreclassificationlResultType = MetaColumnType.Number; } string txt = cf.PreclassificationlResultType.ToString(); if (Lex.Eq(txt, "String")) { txt = "Text"; // fixup } ResultDataType.Text = txt; // Setup outer join table JoinAnchorComboBox.Text = ""; if (Lex.IsDefined(cf.OuterJoinRoot)) { for (ci = 0; ci < cf.CfCols.Count; ci++) { cfc = cf.CfCols[ci]; if (cfc.MetaColumn == null) { continue; } MetaTable mt = cfc.MetaColumn.MetaTable; if (Lex.Eq(cf.OuterJoinRoot, cfc.MetaColumn.MetaTable.Name)) { JoinAnchorComboBox.Text = cfc.MetaColumn.MetaTable.Label; break; } } } } // Setup column controls for source column type if (cfMc != null) { cf.SourceColumnType = cfMc.DataType; } else { cf.SourceColumnType = MetaColumnType.Number; } SetupFormForColumnType(cf.SourceColumnType); // Add column controls MetaColumn references and function info cci = -1; // col control index for (ci = 0; ci < cf.CfCols.Count; ci++) { cfc = cf.CfCols[ci]; cci++; if (cci >= CfColCtls.Count) { throw new Exception("Number of calculated field columns exceeds limit of: " + CfColCtls.Count); } cfcc = CfColCtls[cci]; cfcc.FieldSelectorControl.MetaColumn = cfc.MetaColumn; if (Lex.IsDefined(cfc.Function)) { cfcc.Function.Text = cfc.Function; } else { cfcc.Function.Text = "None"; } cfcc.Constant.Text = cfc.Constant; cfcc.Constant.Enabled = Lex.Contains(cfc.Function, "constant"); } CalcField.ColumnLabel = FieldColumnName.Text; Description.Text = cf.Description; if (cf.Operation != "") { Operation.SelectedItem = cf.Operation; } if (cf.Classification != null) { rules = cf.Classification.Rules; } else { rules = new CondFormatRules(); } if (rules.Count == 0) { rules.Add(new CondFormatRule()); // include initial rule } CondFormatRulesCtl.SetupControl(CalcField.PreclassificationlResultType, rules.ColoringStyle); CondFormatRulesCtl.SetupControl(CalcField.PreclassificationlResultType, rules); InSetup = false; return; }
/// <summary> /// Get the rules from the form /// </summary> /// <returns></returns> public CondFormatRules GetCondFormatRulesFromDataTable() { CondFormatRules rules = new CondFormatRules(); CondFormatRule rule = null; rules.ColoringStyle = ColoringStyle; for (int r = 0; r < DataTable.Rows.Count; r++) { string nameText = GetCellText(r, LabelCol); string opText = GetCellText(r, OpCol); CondFormatOpCode opCode = CondFormatRule.ConvertOpNameToCode(opText); string valText = GetCellText(r, ValCol); string val2Text = GetCellText(r, ValCol2); if (Lex.IsUndefined(nameText)) { continue; } bool valueRequired = (ColoringStyle == CondFormatStyle.ColorScale); if (valueRequired && Lex.IsUndefined(valText)) // skip if no value && a value is needed { continue; } rule = new CondFormatRule(); rules.Add(rule); rule.Name = nameText; rule.Op = opText; rule.OpCode = opCode; rule.Value = valText; if (!String.IsNullOrEmpty(rule.Value)) { double.TryParse(rule.Value, out rule.ValueNumber); } rule.Value2 = val2Text; if (!String.IsNullOrEmpty(rule.Value2)) { double.TryParse(rule.Value2, out rule.Value2Number); } rule.BackColor1 = GetCellColor(r, BackColorCol1); int ii = GetCellInt(r, IconImageCol); if (ii >= 0) { rule.ImageName = Bitmaps.GetImageNameFromIndex(ColumnImageCollection, ii); } else { rule.ImageName = ""; } } return(rules); }
/// <summary> /// Add to the content of the rules control /// </summary> /// <param name="rules"></param> public void LoadDataTableFromCondFormatRules( CondFormatRules rules) { DataTable dt = DataTable; DataRow dr; InSetup = true; //bool saveEnabled = dt.EnableDataChangedEventHandlers(false); // turn off change events while filling // Setup for CF coloring style CondFormatStyle colorStyle = rules.ColoringStyle; if (colorStyle == CondFormatStyle.ColorScale) { //ColorStyleDropDown.Text = "Continuous Colors"; ColumnImageCollection = Bitmaps.I.ColorScaleImages; } else if (colorStyle == CondFormatStyle.DataBar) { //ColorStyleDropDown.Text = "Data Bars"; ColumnImageCollection = Bitmaps.I.DataBarsImages; } else if (colorStyle == CondFormatStyle.IconSet) { //ColorStyleDropDown.Text = "Icon Set"; ColumnImageCollection = Bitmaps.I.IconSetImages; } else { //ColorStyleDropDown.Text = "Discrete Colors"; ColumnImageCollection = null; } // Setup rules for color style if (rules == null) { InSetup = false; return; } for (int ri = 0; ri < rules.Count; ri++) // fill in the grid { CondFormatRule r = rules[ri]; dr = dt.NewRow(); dt.Rows.InsertAt(dr, ri); dr[LabelCol] = r.Name; dr[OpCol] = r.Op; dr[ValCol] = r.Value; dr[ValCol2] = r.Value2; dr[BackColorCol1] = r.BackColor1; if (Lex.IsDefined(r.ImageName)) { dr[IconImageCol] = Bitmaps.GetImageIndexFromName(ColumnImageCollection, r.ImageName); } else { dr[IconImageCol] = DBNull.Value; } } RulesGrid.DataSource = dt; // make the data visible //RulesGrid.AddNewRowAsNeeded(); //dt.EnableDataChangedEventHandlers(saveEnabled); InSetup = false; return; }
/// <summary> /// Setup the control for the specified column and format style /// (Doesn't set the list of specific rules) /// </summary> /// <param name="columnType">MetaColumnType for column</param> public void SetupDataTableAndGrid( SpotfireViewProps svp, CondFormatRules rules) { SVP = svp; Rules = rules; ColoringStyle = rules.ColoringStyle; CondFormatStyle cfStyle = rules.ColoringStyle; DataTable dt = new DataTable(); DataTable = dt; // save ref to table dt.Columns.Add("RuleName", typeof(string)); // column id dt.Columns.Add("Operator", typeof(string)); dt.Columns.Add("Value", typeof(string)); dt.Columns.Add("Value2", typeof(string)); V.Columns[OpCol].Visible = false; // hide operator V.Columns[ValCol].Caption = "Comparison Value"; V.Columns[ValCol].FieldName = "Value"; // restore name V.Columns[ValCol].UnboundType = UnboundColumnType.Bound; // column is bound V.Columns[ValCol2].Visible = true; // show high val V.Columns[ValCol].Width = ValColWidth; V.Columns[ValCol2].Width = ValCol2Width; EnableCfStyleOptions(colorSets: true, colorScales: false, dataBars: false, iconSets: true); // don't allow non-discrete styles string ops = "Equal to|" + "Between|" + ">|" + "<|" + ">=|" + "<=|" + "Not Equal to|" + "Not Between|" + "Any other value|" + "Missing"; if (cfStyle == CondFormatStyle.ColorScale) { ops = "Between"; // only allow between rule V.Columns[ValCol].Caption = "Bottom Color Data Value"; V.Columns[ValCol2].Caption = "Top Color Data Value"; } else // single color (cfStyle == CondFormatStyle.ColorSet { V.Columns[ValCol].Visible = false; V.Columns[ValCol2].Visible = false; } string[] list = ops.Split('|'); RepositoryItemComboBox cb = V.Columns[OpCol].ColumnEdit as RepositoryItemComboBox; if (cb != null) { cb.Items.Clear(); cb.Items.AddRange(list); } dt.Columns.Add("BackColor1", typeof(Color)); dt.Columns.Add("IconImageIdx", typeof(int)); SetColumnVisibilityForColoringStyle(cfStyle); dt.RowChanged += new DataRowChangeEventHandler(DataRowChangeEventHandler); dt.RowDeleted += new DataRowChangeEventHandler(DataRowDeletedEventHandler); return; }
List <ColorCodingItemMsx> ConvertCondFormatRulesToColorCodingItems( CondFormatRules rules) { List <ColorCodingItemMsx> ccl = new List <ColorCodingItemMsx>(); double v1, v2; foreach (CondFormatRule r in rules) { ColorCodingItemMsx i = new ColorCodingItemMsx(); i.ColumnName = r.Name; if (rules.ColoringStyle == CondFormatStyle.ColorSet) { i.BackColor = r.BackColor1; } else // Gradient { //i.ImageName = r.ImageName; Color[] colors = Bitmaps.GetColorSetByName(Bitmaps.ColorScaleImageColors, r.ImageName); if (colors == null) { Bitmaps.GetColorSetByName(Bitmaps.ColorScaleImageColors, CondFormat.DefaultColorScale); } if (colors == null) { colors = new Color[] { Color.LightGray, Color.DarkGray } } ; int cl = colors.Length; if (cl > 0) { i.SubRules.Add(BuildSubrule(r.Value, colors[0])); } if (cl == 3) { i.SubRules.Add(BuildSubrule("Average", colors[1])); i.SubRules.Add(BuildSubrule(r.Value2, colors[2])); } else if (cl == 2) { i.SubRules.Add(BuildSubrule(r.Value2, colors[1])); } } ccl.Add(i); } return(ccl); } ColorCodingSubRuleMsx BuildSubrule( string value, Color color) { ColorCodingSubRuleMsx sr = new ColorCodingSubRuleMsx(); if (Lex.Contains(value, "min")) { sr.CalcType = ValueCalcTypeEnumMsx.Min; } else if (Lex.Contains(value, "avg")) { sr.CalcType = ValueCalcTypeEnumMsx.Average; } else if (Lex.Contains(value, "max")) { sr.CalcType = ValueCalcTypeEnumMsx.Max; } else { sr.CalcType = ValueCalcTypeEnumMsx.Value; sr.Value = value; } sr.Color = color; return(sr); } }
/// <summary> /// Initialize coloring rules for newly selected QueryColumn /// </summary> #if false internal CondFormatRules InitializeRulesBasedOnDataValues() { CondFormatRule r; Color[] colors = GetColors(); CondFormatRules rules = new CondFormatRules(); if (ResultsField == null) { return(rules); } QueryColumn qc = ResultsField.QueryColumn; ColumnStatistics stats = ResultsField.GetStats(); if (qc.MetaColumn.DataType == MetaColumnType.Structure) { // setup substructure search rules if structures for (int i1 = 0; i1 < stats.DistinctValueList.Count; i1++) { MobiusDataType mdt = stats.DistinctValueList[i1]; r = new CondFormatRule(); r.Op = "SSS"; r.OpCode = CondFormatOpCode.SSS; ChemicalStructureMx cs = mdt as ChemicalStructureMx; if (cs != null) { r.Value = cs.ChimeString; } r.BackColor1 = colors[i1 % colors.Length]; rules.Add(r); } } else // setup equality rules for other types { for (int i1 = 0; i1 < stats.DistinctValueList.Count; i1++) { MobiusDataType mdt = stats.DistinctValueList[i1]; r = new CondFormatRule(); r.Op = "Equal to"; r.OpCode = CondFormatOpCode.Eq; r.Value = mdt.FormattedText; r.BackColor1 = colors[i1 % colors.Length]; rules.Add(r); // if (i1 + 1 >= 25) break; // limit number of items } } if (stats.NullsExist) { r = new CondFormatRule(); r.Name = "Missing Data"; r.Op = "Missing"; r.OpCode = CondFormatOpCode.NotExists; r.BackColor1 = CondFormatMatcher.DefaultMissingValueColor; rules.Add(r); } SetRules(ResultsField, rules); // put into the grid return(rules); }