Esempio n. 1
0
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            builder.OpenElement(0, "div");
            builder.AddAttribute(24, "class", "m-combined-input-container " + CssClass);

            builder.OpenComponent <InputDate <T> >(20);
            builder.AddAttribute(21, "Value", CurrentDateValue);
            builder.AddAttribute(22, "ValueChanged", RuntimeHelpers.CreateInferredEventCallback <T>(this, async __value =>
            {
                CurrentDateValue = __value;
                UpdateDateTimeValue();
            }, CurrentDateValue));
            builder.AddAttribute(23, "ValueExpression", Expression.Lambda <Func <T> >(Expression.Property(Expression.Constant(this), nameof(CurrentDateValue))));
            builder.AddAttribute(24, "class", "m-form-control m-combined-input");
            builder.AddAttribute(25, "style", "width: 66%;");
            builder.CloseComponent();

            builder.OpenComponent <InputTime <T> >(30);
            builder.AddAttribute(31, "Value", CurrentTimeValue);
            builder.AddAttribute(22, "ValueChanged", RuntimeHelpers.CreateInferredEventCallback <T>(this, async __value =>
            {
                CurrentTimeValue = __value;
                UpdateDateTimeValue();
            }, CurrentTimeValue));
            builder.AddAttribute(23, "ValueExpression", Expression.Lambda <Func <T> >(Expression.Property(Expression.Constant(this), nameof(CurrentTimeValue))));
            builder.AddAttribute(34, "class", "m-form-control m-combined-input");
            builder.AddAttribute(35, "style", "width: 34%;");
            builder.CloseComponent();

            builder.CloseElement(); //div
        }
Esempio n. 2
0
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            base.BuildRenderTree(builder);

            if (Points != null && Connections != null)
            {
                builder.OpenElement(1, "svg");
                builder.AddAttribute(2, "class", "flightplan-svg");
                builder.AddAttribute(3, "viewBox", "0 0 600 600");
                builder.AddAttribute(4, "preserveAspectRatio", "xMinYMin");

                builder.OpenElement(5, "g");
                builder.AddAttribute(6, "class", "flightplan");

                foreach (var conn in Connections)
                {
                    builder.OpenElement(7, "path");
                    builder.AddAttribute(8, "d", $"M {conn?.From?.X.ToString(CultureInfo.InvariantCulture)},{conn?.From?.Y.ToString(CultureInfo.InvariantCulture)} C {conn?.ControlPoints.pFromX.ToString(CultureInfo.InvariantCulture)},{conn?.ControlPoints.pFromY.ToString(CultureInfo.InvariantCulture)} {conn?.ControlPoints.pToX.ToString(CultureInfo.InvariantCulture)},{conn?.ControlPoints.pToY.ToString(CultureInfo.InvariantCulture)} {conn?.To?.X.ToString(CultureInfo.InvariantCulture)},{conn?.To?.Y.ToString(CultureInfo.InvariantCulture)}");
                    builder.AddAttribute(9, "class", (conn != null && conn.Active) ? "active" : "");
                    builder.CloseElement();
                }

                foreach (var point in Points)
                {
                    builder.OpenElement(10, "circle");
                    builder.AddAttribute(11, "r", 5);
                    builder.AddAttribute(12, "cx", point.X.ToString(CultureInfo.InvariantCulture));
                    builder.AddAttribute(13, "cy", point.Y.ToString(CultureInfo.InvariantCulture));
                    builder.AddAttribute(14, "class", "pulse-circle " + (point.Active ? "active" : "inactive"));
                    builder.CloseElement();

                    builder.OpenElement(15, "text");
                    builder.AddAttribute(16, "x", (point.X + 10).ToString(CultureInfo.InvariantCulture));
                    builder.AddAttribute(17, "y", (point.Y + 10).ToString(CultureInfo.InvariantCulture));
                    builder.AddContent(18, point?.Base?.Name);
                    builder.CloseElement();

                    builder.OpenElement(19, "circle");
                    builder.AddAttribute(20, "r", 5);
                    builder.AddAttribute(21, "fill", "white");
                    builder.AddAttribute(22, "cx", point?.X.ToString(CultureInfo.InvariantCulture));
                    builder.AddAttribute(23, "cy", point?.Y.ToString(CultureInfo.InvariantCulture));
                    builder.AddAttribute(24, "onmouseenter", EventCallback.Factory.Create <MouseEventArgs>(this, new Action(() => point?.SetActive())));
                    builder.AddAttribute(25, "onmouseleave", EventCallback.Factory.Create <MouseEventArgs>(this, new Action(() => point?.SetActive(false))));
                    builder.CloseElement();
                }

                builder.CloseElement();

                builder.CloseElement();
            }
        }
Esempio n. 3
0
    /// <summary>
    /// RenderTreeBuilder 扩展方法 通过 IEditorItem 与 model 创建 Display 组件
    /// </summary>
    /// <param name="builder"></param>
    /// <param name="item"></param>
    /// <param name="model"></param>
    public static void CreateDisplayByFieldType(this RenderTreeBuilder builder, IEditorItem item, object model)
    {
        var fieldType   = item.PropertyType;
        var fieldName   = item.GetFieldName();
        var displayName = item.GetDisplayName() ?? GetDisplayName(model, fieldName);
        var fieldValue  = GenerateValue(model, fieldName);
        var type        = (Nullable.GetUnderlyingType(fieldType) ?? fieldType);

        if (type == typeof(bool) || fieldValue?.GetType() == typeof(bool))
        {
            builder.OpenComponent <Switch>(0);
            builder.AddAttribute(1, nameof(Switch.Value), fieldValue);
            builder.AddAttribute(2, nameof(Switch.IsDisabled), true);
            builder.AddAttribute(3, nameof(Switch.DisplayText), displayName);
            builder.AddAttribute(4, nameof(Switch.ShowLabelTooltip), item.ShowLabelTooltip);
            builder.CloseComponent();
        }
        else if (item.ComponentType == typeof(Textarea))
        {
            builder.OpenComponent(0, typeof(Textarea));
            builder.AddAttribute(1, nameof(Textarea.DisplayText), displayName);
            builder.AddAttribute(2, nameof(Textarea.Value), fieldValue);
            builder.AddAttribute(3, nameof(Textarea.ShowLabelTooltip), item.ShowLabelTooltip);
            builder.AddAttribute(4, "readonly", true);
            if (item.Rows > 0)
            {
                builder.AddAttribute(5, "rows", item.Rows);
            }
            builder.CloseComponent();
        }
        else
        {
            builder.OpenComponent(0, typeof(Display <>).MakeGenericType(fieldType));
            builder.AddAttribute(1, nameof(Display <string> .DisplayText), displayName);
            builder.AddAttribute(2, nameof(Display <string> .Value), fieldValue);
            builder.AddAttribute(3, nameof(Display <string> .LookupServiceKey), item.LookupServiceKey);
            builder.AddAttribute(4, nameof(Display <string> .ShowLabelTooltip), item.ShowLabelTooltip);
            builder.CloseComponent();
        }
    }
        public static RenderTreeBuilder Data(this RenderTreeBuilder builder, string name, object value, [CallerLineNumber] int line = 0)
        {
            builder.AddAttribute(GetSequence(line), $"data-{name}", value);

            return(builder);
        }
        public static RenderTreeBuilder Id(this RenderTreeBuilder builder, object value, [CallerLineNumber] int line = 0)
        {
            builder.AddAttribute(GetSequence(line), "id", value);

            return(builder);
        }
Esempio n. 6
0
 protected override void AddAttributes(RenderTreeBuilder builder, ref int sequence)
 {
     base.AddAttributes(builder, ref sequence);
     builder.AddAttribute(sequence++, Attributes.Role, "status");
 }
Esempio n. 7
0
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            if (builder != null)
            {
                base.BuildRenderTree(builder);
                // According to Ant-Design 4.0, Fallback to 1 if level is invalid.

                builder.OpenElement(1, "span");
                builder.AddAttribute(2, "class", this.ClassMapper.Class);
                builder.AddAttribute(3, "style", Style);
                if (Mark)
                {
                    builder.OpenElement(4, "mark");
                }
                if (Delete)
                {
                    builder.OpenElement(5, "del");
                }
                if (Underline)
                {
                    builder.OpenElement(6, "u");
                }
                if (Code)
                {
                    builder.OpenElement(7, "code");
                }
                if (Keyboard)
                {
                    builder.OpenElement(8, "kbd");
                }
                if (Strong)
                {
                    builder.OpenElement(9, "strong");
                }
                builder.AddContent(10, ChildContent);
                if (Strong)
                {
                    builder.CloseElement();
                }
                if (Code)
                {
                    builder.CloseElement();
                }
                if (Keyboard)
                {
                    builder.CloseElement();
                }
                if (Underline)
                {
                    builder.CloseElement();
                }
                if (Delete)
                {
                    builder.CloseElement();
                }
                if (Mark)
                {
                    builder.CloseElement();
                }
                if (Copyable)
                {
                    builder.OpenElement(11, "a");
                    builder.AddAttribute(12, "onclick", (Action)(async() => await Copy()));
                    builder.OpenComponent <Icon>(13);
                    builder.AddAttribute(14, "Type", "copy");
                    builder.AddAttribute(15, "Theme", IconThemeType.Outline);
                    builder.CloseComponent();
                    builder.CloseElement();
                }
                builder.AddElementReferenceCapture(16, r => Ref = r);
                builder.CloseElement();
            }
        }
Esempio n. 8
0
        protected void BuildRenderInput_RenderRadioItem(RenderTreeBuilder builder, int index)
        {
            var item = itemsToRender[index];

            if (item != null)
            {
                bool selected = (index == selectedItemIndex);
                if (selected)
                {
                    chipValue = SelectorHelpers.GetText(TextSelectorImpl, item);
                }

                string inputId = GroupName + "_" + index.ToString();

                builder.OpenElement(100, "div");

                // TODO CoreCssClass
                builder.AddAttribute(101, "class", CssClassHelper.Combine("form-check", this.Inline ? "form-check-inline" : null));

                builder.OpenElement(200, "input");
                builder.AddAttribute(201, "class", "form-check-input");
                builder.AddAttribute(202, "type", "radio");
                builder.AddAttribute(203, "name", GroupName);
                builder.AddAttribute(204, "id", inputId);
                builder.AddAttribute(205, "value", index.ToString());
                builder.AddAttribute(206, "checked", selected);
                builder.AddAttribute(207, "disabled", !CascadeEnabledComponent.EnabledEffective(this));
                int j = index;
                builder.AddAttribute(208, "onclick", EventCallback.Factory.Create(this, () => HandleInputClick(j)));
                builder.AddEventStopPropagationAttribute(209, "onclick", true);
                builder.AddMultipleAttributes(250, this.AdditionalAttributes);
                builder.CloseElement();                 // input

                builder.OpenElement(300, "label");
                builder.AddAttribute(301, "class", "form-check-label");
                builder.AddAttribute(302, "for", inputId);
                if (ItemTemplateImpl != null)
                {
                    builder.AddContent(303, ItemTemplateImpl(item));
                }
                else
                {
                    builder.AddContent(304, SelectorHelpers.GetText(TextSelectorImpl, item));
                }
                builder.CloseElement();                 // label

                builder.CloseElement();                 // div
            }
        }
        /// <summary>
        /// Renders the component to the supplied <see cref="T:Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder" />.
        /// </summary>
        /// <param name="builder">A <see cref="T:Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder" /> that will receive the render output.</param>
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            if (DialogService.Modal != null)
            {
                builder.OpenComponent <Modal>(0);
                builder.AddAttribute(1, nameof(Modal.Size), Option?.Size);
                builder.AddAttribute(2, nameof(Modal.Actived), DialogService != null);
                builder.AddAttribute(3, nameof(Modal.Closable), false);
                builder.AddAttribute(4, nameof(Modal.Alignment), Option?.Alignment);
                if (!string.IsNullOrWhiteSpace(Option.Title))
                {
                    builder.AddAttribute(10, nameof(Modal.Header), (RenderFragment)(header =>
                    {
                        header.AddMarkupContent(0, Option.Title);
                    }));
                }

                builder.AddAttribute(12, nameof(Modal.Content), (RenderFragment)(content =>
                {
                    content.AddMarkupContent(0, Option.Message);

                    if (Option.Type == DialogType.Prompt)
                    {
                        content.OpenComponent <InputBox>(1);
                        content.AddAttribute(2, nameof(InputBox.ChildContent), (RenderFragment)(input => {
                            input.OpenElement(1, "input");
                            input.AddAttribute(2, "type", "text");
                            input.AddAttribute(3, "oninput", EventCallback.Factory.Create(input, TextChanged));
                            input.CloseElement();
                        }));
                        content.CloseComponent();
                    }
                }));

                builder.AddAttribute(13, nameof(Modal.Footer), (RenderFragment)(footer =>
                {
                    if (Option.Type == DialogType.Alert || Option.Type == DialogType.Confirm)
                    {
                        ConfirmedValue = true;
                    }
                    #region ConfirmButton
                    footer.OpenComponent <Button>(0);
                    footer.AddAttribute(1, nameof(Button.Color), Option.ConfirmColor);
                    footer.AddAttribute(2, Exntensions.EVENT_CLICK, EventCallback.Factory.Create(this, Confirm));
                    footer.AddAttribute(3, nameof(Button.Basic), Option.ConfirmOutline);
                    footer.AddAttribute(5, nameof(Button.ChildContent), (RenderFragment)(confirm =>
                    {
                        confirm.AddMarkupContent(1, Option.ConfirmText);
                    }));
                    footer.CloseComponent();
                    #endregion

                    #region CancelButton
                    if (Option.Type == DialogType.Confirm || Option.Type == DialogType.Prompt)
                    {
                        footer.OpenComponent <Button>(10);
                        footer.AddAttribute(11, nameof(Button.Color), Option.CancelColor);
                        footer.AddAttribute(12, Exntensions.EVENT_CLICK, EventCallback.Factory.Create(this, Cancel));
                        footer.AddAttribute(13, nameof(Button.Basic), Option.CancelOutline);
                        footer.AddAttribute(15, nameof(Button.ChildContent), (RenderFragment)(cancel =>
                        {
                            cancel.AddMarkupContent(1, Option.CancelText);
                        }));
                        footer.CloseComponent();
                    }
                    #endregion
                }));

                builder.CloseComponent();
            }
        }
Esempio n. 10
0
        /// <summary>
        /// 渲染组件方法
        /// </summary>
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            // 渲染正常按钮
            if (Columns != null)
            {
                var index = 0;
                foreach (var header in Columns.Columns)
                {
                    var fieldName   = header.GetFieldName();
                    var displayName = header.GetDisplayName();
                    builder.OpenElement(index++, "th");

                    // 移除 bind-Field
                    header.AdditionalAttributes?.Remove("FieldChanged");
                    builder.AddMultipleAttributes(index++, header.AdditionalAttributes);

                    // 如果允许排序
                    if (header.Sort)
                    {
                        builder.AddAttribute(index++, "onclick", EventCallback.Factory.Create(this, () =>
                        {
                            if (sortName != fieldName)
                            {
                                sortOrder = SortOrder.Asc;
                            }
                            else
                            {
                                sortOrder = sortOrder == SortOrder.Asc ? SortOrder.Desc : SortOrder.Asc;
                            }
                            sortName = fieldName;

                            // 通知 Table 组件刷新数据
                            Columns.OnSort?.Invoke(sortName, sortOrder);
                        }));
                        builder.AddAttribute(index++, "class", "sortable");
                    }
                    builder.OpenElement(index++, "div");
                    builder.AddAttribute(index++, "class", CssBuilder.Default("table-cell").AddClass("is-sort", header.Sort).Build());

                    builder.OpenElement(index++, "span");
                    builder.AddContent(index++, displayName);
                    builder.CloseElement(); // span

                    if (header.Sort)
                    {
                        builder.OpenElement(index++, "i");
                        var order = sortName == fieldName ? sortOrder : SortOrder.Unset;
                        var icon  = order switch
                        {
                            SortOrder.Asc => SortIconAsc,
                            SortOrder.Desc => SortIconDesc,
                            _ => SortDefault
                        };
                        builder.AddAttribute(index++, "class", icon);
                        builder.CloseElement(); // end i
                    }
                    builder.CloseElement();     // end div
                    builder.CloseElement();     // end th
                }
            }
        }
    }
 protected override void BuildRenderTree(RenderTreeBuilder __builder)
 {
     if (this.Settings == null)
     {
         return;
     }
     __builder.AddContent(0, "    ");
     __builder.OpenElement(1, "table");
     __builder.AddAttribute(2, "class", "table");
     __builder.AddMarkupContent(3, "\r\n        ");
     __builder.AddMarkupContent(4, "<tr>\r\n            <th>Key</th>\r\n            <th>Value</th>\r\n            <th>Description</th>\r\n            <th>Options</th>\r\n        </tr>\r\n");
     foreach (Setting setting1 in this.Settings)
     {
         Setting setting = setting1;
         __builder.AddContent(5, "            ");
         __builder.OpenElement(6, "tr");
         __builder.AddMarkupContent(7, "\r\n                ");
         __builder.OpenElement(8, "td");
         __builder.AddMarkupContent(9, "\r\n                   ");
         __builder.OpenElement(10, "input");
         __builder.AddAttribute(11, "class", "form-control");
         __builder.AddAttribute(12, "value", BindConverter.FormatValue(setting.Key));
         __builder.AddAttribute <ChangeEventArgs>(13, "onchange", EventCallback.Factory.CreateBinder((object)this, (Action <string>)(__value => setting.Key = __value), setting.Key));
         __builder.SetUpdatesAttributeName("value");
         __builder.CloseElement();
         __builder.AddMarkupContent(14, "\r\n                ");
         __builder.CloseElement();
         __builder.AddMarkupContent(15, "\r\n                ");
         __builder.OpenElement(16, "td");
         __builder.AddMarkupContent(17, "\r\n                   ");
         __builder.OpenElement(18, "input");
         __builder.AddAttribute(19, "class", "form-control");
         __builder.AddAttribute(20, "value", BindConverter.FormatValue(setting.Value));
         __builder.AddAttribute <ChangeEventArgs>(21, "onchange", EventCallback.Factory.CreateBinder((object)this, (Action <string>)(__value => setting.Value = __value), setting.Value));
         __builder.SetUpdatesAttributeName("value");
         __builder.CloseElement();
         __builder.AddMarkupContent(22, "\r\n                ");
         __builder.CloseElement();
         __builder.AddMarkupContent(23, "\r\n                ");
         __builder.OpenElement(24, "td");
         __builder.AddMarkupContent(25, "\r\n                    ");
         __builder.OpenElement(26, "input");
         __builder.AddAttribute(27, "class", "form-control");
         __builder.AddAttribute(28, "value", BindConverter.FormatValue(setting.Description));
         __builder.AddAttribute <ChangeEventArgs>(29, "onchange", EventCallback.Factory.CreateBinder((object)this, (Action <string>)(__value => setting.Description = __value), setting.Description));
         __builder.SetUpdatesAttributeName("value");
         __builder.CloseElement();
         __builder.AddMarkupContent(30, "\r\n                ");
         __builder.CloseElement();
         __builder.AddMarkupContent(31, "\r\n                ");
         __builder.OpenElement(32, "td");
         __builder.AddMarkupContent(33, "\r\n                    ");
         __builder.OpenElement(34, "button");
         __builder.AddAttribute(35, "class", "btn btn-success");
         __builder.AddAttribute <MouseEventArgs>(36, "onclick", EventCallback.Factory.Create <MouseEventArgs>((object)this, (Func <Task>)(() => this.UpdateSetting(setting))));
         __builder.AddContent(37, "Update");
         __builder.CloseElement();
         __builder.AddMarkupContent(38, "\r\n                ");
         __builder.CloseElement();
         __builder.AddMarkupContent(39, "\r\n            ");
         __builder.CloseElement();
         __builder.AddMarkupContent(40, "\r\n");
     }
     __builder.AddContent(41, "        ");
     __builder.OpenElement(42, "tr");
     __builder.AddMarkupContent(43, "\r\n            ");
     __builder.OpenElement(44, "td");
     __builder.OpenElement(45, "input");
     __builder.AddAttribute(46, "class", "form-control");
     __builder.AddAttribute(47, "value", BindConverter.FormatValue(this.NewSetting.Key));
     __builder.AddAttribute <ChangeEventArgs>(48, "onchange", EventCallback.Factory.CreateBinder((object)this, (Action <string>)(__value => this.NewSetting.Key = __value), this.NewSetting.Key));
     __builder.SetUpdatesAttributeName("value");
     __builder.CloseElement();
     __builder.CloseElement();
     __builder.AddMarkupContent(49, "\r\n            ");
     __builder.OpenElement(50, "td");
     __builder.OpenElement(51, "input");
     __builder.AddAttribute(52, "class", "form-control");
     __builder.AddAttribute(53, "value", BindConverter.FormatValue(this.NewSetting.Value));
     __builder.AddAttribute <ChangeEventArgs>(54, "onchange", EventCallback.Factory.CreateBinder((object)this, (Action <string>)(__value => this.NewSetting.Value = __value), this.NewSetting.Value));
     __builder.SetUpdatesAttributeName("value");
     __builder.CloseElement();
     __builder.CloseElement();
     __builder.AddMarkupContent(55, "\r\n            ");
     __builder.OpenElement(56, "td");
     __builder.OpenElement(57, "input");
     __builder.AddAttribute(58, "class", "form-control");
     __builder.AddAttribute(59, "value", BindConverter.FormatValue(this.NewSetting.Description));
     __builder.AddAttribute <ChangeEventArgs>(60, "onchange", EventCallback.Factory.CreateBinder((object)this, (Action <string>)(__value => this.NewSetting.Description = __value), this.NewSetting.Description));
     __builder.SetUpdatesAttributeName("value");
     __builder.CloseElement();
     __builder.CloseElement();
     __builder.AddMarkupContent(61, "\r\n            ");
     __builder.OpenElement(62, "td");
     __builder.OpenElement(63, "button");
     __builder.AddAttribute(64, "class", "btn btn-success");
     __builder.AddAttribute <MouseEventArgs>(65, "onclick", EventCallback.Factory.Create <MouseEventArgs>((object)this, (Func <Task>)(() => this.AddNewSetting())));
     __builder.AddContent(66, "Add setting");
     __builder.CloseElement();
     __builder.CloseElement();
     __builder.AddMarkupContent(67, "\r\n        ");
     __builder.CloseElement();
     __builder.AddMarkupContent(68, "\r\n    ");
     __builder.CloseElement();
     __builder.AddMarkupContent(69, "\r\n");
 }
Esempio n. 12
0
 protected override void BuildRenderTree(RenderTreeBuilder builder)
 {
     if (builder != null)
     {
         base.BuildRenderTree(builder);
         builder.OpenElement(0, "div");
         builder.AddAttribute(1, "class", this.ClassMapper.Class);
         builder.OpenElement(2, "span");
         if (Mark)
         {
             builder.OpenElement(3, "mark");
         }
         if (Delete)
         {
             builder.OpenElement(4, "del");
         }
         if (Underline)
         {
             builder.OpenElement(5, "u");
         }
         if (Code)
         {
             builder.OpenElement(6, "code");
         }
         if (Strong)
         {
             builder.OpenElement(7, "strong");
         }
         builder.AddContent(8, ChildContent);
         if (Strong)
         {
             builder.CloseElement();
         }
         if (Code)
         {
             builder.CloseElement();
         }
         if (Underline)
         {
             builder.CloseElement();
         }
         if (Delete)
         {
             builder.CloseElement();
         }
         if (Mark)
         {
             builder.CloseElement();
         }
         builder.CloseElement();
         if (Copyable)
         {
             builder.OpenElement(9, "a");
             builder.AddAttribute(10, "onclick", (Action)(async() => await Copy()));
             builder.OpenComponent <AntIcon>(10);
             builder.AddAttribute(11, "type", "copy");
             builder.AddAttribute(12, "theme", AntIconThemeType.Outline);
             builder.CloseComponent();
             builder.CloseElement();
         }
         builder.CloseElement();
     }
 }
Esempio n. 13
0
        public void RecognizesAttributesAdded()
        {
            // Arrange
            oldTree.OpenElement(0, "My element");
            oldTree.AddAttribute(1, "existing", "existing value");
            oldTree.CloseElement();
            newTree.OpenElement(0, "My element");
            newTree.AddAttribute(1, "existing", "existing value");
            newTree.AddAttribute(2, "added", "added value");
            newTree.CloseElement();

            // Act
            var(result, referenceFrames) = GetSingleUpdatedComponent();

            // Assert
            Assert.Collection(result.Edits,
                              entry =>
            {
                AssertEdit(entry, RenderTreeEditType.SetAttribute, 0);
                Assert.Equal(0, entry.ReferenceFrameIndex);
            });
            AssertFrame.Attribute(referenceFrames[0], "added", "added value");
        }
Esempio n. 14
0
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            var seq = 0;

            builder.OpenElement(seq, "figure");
            builder.OpenElement(++seq, "div");
            builder.AddAttribute(++seq, "class", "linechart-main");


            System.Diagnostics.Debug.WriteLine("ID" + InputData);

            string[] inputDataArrX = InputData.Split(new char[] { '[', ']' }, StringSplitOptions.RemoveEmptyEntries);
            int      numLines      = 0;

            System.Diagnostics.Debug.WriteLine("Start");
            foreach (string inputLine in inputDataArrX)
            {
                if (inputLine.IndexOfAny(new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }) >= 0)
                {
                    numLines++;
                }
            }
            System.Diagnostics.Debug.WriteLine("End");
            string[] inputDataArr = new string[numLines];
            int      lineCounter  = 0;

            foreach (string inputLine in inputDataArrX)
            {
                if (inputLine.IndexOfAny(new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }) >= 0)
                {
                    inputDataArr[lineCounter++] = inputLine;
                    System.Diagnostics.Debug.WriteLine("IL:" + inputLine);
                }
            }

            int[] inputData = { 30, 70, 42, 50, 3, 55, 35, 22 };
            int[] list1     = new int[8] {
                30, 70, 42, 50, 3, 55, 35, 22
            };
            int[] list2 = new int[8] {
                40, 50, 32, 70, 55, 15, 15, 12
            };
            int[] list3 = new int[8] {
                0, 10, 10, 10, 10, 20, 70, 70
            };
            int[][] lists = new int[][] { list1, list2, list3 };

            string[] colors = { "#ce4b99", "#27A844", "#377bbc" };
            string[] labels = { "App Store", "Website", "Partners" };

            SVG svg = new SVG()
            {
                { "width", "100%" }, { "height", "100%" }, { "viewBox", "0 0 100 100" }
            };
            Rectangle rect = new Rectangle()
            {
                { "width", "100%" }, { "height", "100%" }, { "fill", "white" }, { "stroke", "gray" }, { "stroke-width", "0.5" }
            };

            //Rectangle rect = new Rectangle() { { "width", "100%" }, { "height", "100%" }, { "fill", "cyan" }};
            svg.AddItems(rect);


            int    numHorizontalLines     = 10;
            int    numVerticalLines       = 10;
            double boundHeight            = 100.0;
            double boundWidth             = 100.0;
            double verticalStartSpace     = 10.0;
            double horizontalStartSpace   = 10.0;
            double verticalEndSpace       = 5.0;
            double horizontalEndSpace     = 5.0;
            double gridYUnits             = 10;
            double gridXUnits             = 10;
            bool   skipLastVerticalLine   = true;
            bool   skipLastHorizontalLine = true;

            double verticalSpace   = (boundHeight - verticalStartSpace - verticalEndSpace) / (numHorizontalLines - 1);
            double horizontalSpace = (boundWidth - horizontalStartSpace - horizontalEndSpace) / (numVerticalLines - 1);

            double totalGridWidth  = ((double)(numVerticalLines - 1)) * horizontalSpace;
            double totalGridHeight = ((double)(numHorizontalLines - 1)) * verticalSpace;

            System.Diagnostics.Debug.WriteLine("TotalGridHeight:" + totalGridHeight + ":" + verticalSpace);

            //Horizontal Lines
            double y          = verticalStartSpace;
            double startGridY = 0;

            for (int counter = 0; counter < numHorizontalLines; counter++)
            {
                if (counter == numHorizontalLines - 1 && skipLastHorizontalLine)
                {
                    continue;
                }

                Path path = new Path()
                {
                    { "fill", "none" }, { "stroke", "gray" }, { "stroke-width", "0.2" }, { "d", "M " + horizontalStartSpace.ToString() + " " + (boundHeight - y).ToString() + " L " + (boundWidth - horizontalEndSpace).ToString() + " " + (boundHeight - y).ToString() }
                };
                Text label = new Text()
                {
                    { "x", (horizontalStartSpace - 2).ToString() }, { "y", (boundHeight - y).ToString() }, { "font-size", "4px" }, { "text-anchor", "end" }, { "content", (startGridY).ToString() }
                };
                svg.AddItems(path, label);
                System.Diagnostics.Debug.WriteLine("Y:" + y);

                y          = y + verticalSpace;
                startGridY = startGridY + gridYUnits;
            }

            //Chart Line
            double gridx = 0, gridy = 0;

            gridx = horizontalStartSpace;
            gridy = boundHeight - verticalStartSpace;
            int colorcounter = 0;

            foreach (string iData in inputDataArr)
            {
                string chartLine  = "";
                double gridValueX = 0;
                double gridValueY = 0;
                bool   firstTime  = true;

                string[] inputLineArr = iData.Split(',');
                int[]    intAry       = new int[inputLineArr.Length];
                for (int i = 0; i < inputLineArr.Length; i++)
                {
                    intAry[i] = int.Parse(inputLineArr[i]);
                }

                foreach (int i in intAry)
                {
                    if (firstTime)
                    {
                        chartLine  = chartLine + "M ";
                        firstTime  = false;
                        gridValueX = horizontalStartSpace;
                        gridValueY = verticalStartSpace;
                        double gridValue = ((double)i) * verticalSpace / gridYUnits;
                        gridValueY = boundHeight - (gridValueY + gridValue);
                        chartLine  = chartLine + gridValueX.ToString() + " " + gridValueY.ToString();
                    }
                    else
                    {
                        chartLine  = chartLine + " L ";
                        gridValueX = gridValueX + horizontalSpace;
                        gridValueY = verticalStartSpace;
                        double gridValue = ((double)i) * verticalSpace / gridYUnits;
                        gridValueY = boundHeight - (gridValueY + gridValue);
                        chartLine  = chartLine + gridValueX.ToString() + " " + gridValueY.ToString();
                    }
                }
                //System.Diagnostics.Debug.WriteLine("CL:" + chartLine);
                Path linepath = new Path()
                {
                    { "fill", "none" }, { "stroke", colors[colorcounter++] }, { "stroke-width", "1.0" }, { "d", chartLine }
                };
                svg.AddItems(linepath);
            }

            //Vertical Lines
            double x          = horizontalStartSpace;
            double startGridX = 0;

            for (int counter = 0; counter < numVerticalLines; counter++)
            {
                if (counter == numVerticalLines - 1 && skipLastVerticalLine)
                {
                    continue;
                }

                Path path = new Path()
                {
                    { "fill", "none" }, { "stroke", "gray" }, { "stroke-width", "0.2" }, { "d", "M " + x.ToString() + " " + (boundHeight - verticalStartSpace).ToString() + " L " + x.ToString() + " " + (verticalEndSpace).ToString() }
                };
                Text label = new Text()
                {
                    { "x", x.ToString() }, { "y", (boundHeight - verticalStartSpace + 5).ToString() }, { "font-size", "4px" }, { "text-anchor", "middle" }, { "content", (startGridX).ToString() }
                };
                startGridX = startGridX + gridXUnits;

                svg.AddItems(path, label);
                x = x + horizontalSpace;
            }



            BlazorRenderer blazorRenderer = new BlazorRenderer();

            blazorRenderer.Draw(seq, builder, svg);

            builder.OpenElement(++seq, "figcaption");
            builder.AddAttribute(++seq, "class", "linechart-key");
            builder.OpenElement(++seq, "ul");
            builder.AddAttribute(++seq, "class", "linechart-key-list");
            builder.AddAttribute(++seq, "aria-hidden", "true");
            builder.AddAttribute(++seq, "style", "list-style-type: none;");

            colorcounter = 0;
            foreach (string iData in inputDataArr)
            {
                //int data = int.Parse(dataStr);
                builder.OpenElement(++seq, "li");
                builder.OpenElement(++seq, "span");
                builder.AddAttribute(++seq, "class", "round-dot");
                builder.AddAttribute(++seq, "style", "background-color:" + colors[colorcounter]);

                builder.CloseElement();
                builder.AddContent(++seq, labels[colorcounter++]);
                builder.CloseElement();
            }

            builder.CloseElement();
            builder.CloseElement();


            /*
             *             <path d="M 30 250 L 130 120
             * L 230 150 L 330 80 L 430 200"
             *    fill="none" stroke="#27A844" stroke-width="2.5" />
             *
             *
             *           <path d="M 25 50 L 450 50"
             *    fill="none" stroke="gray" stroke-width="0.3" />
             *
             * builder.OpenElement(++seq, "figcaption");
             * builder.AddAttribute(++seq, "class", "linechart-key");
             * builder.OpenElement(++seq, "ul");
             * builder.AddAttribute(++seq, "class", "linechart-key-list");
             * builder.AddAttribute(++seq, "aria-hidden", "true");
             * builder.AddAttribute(++seq, "style", "list-style-type: none;");
             *
             * int counter = 0;
             * foreach (string dataStr in inputDataArr)
             * {
             *  int data = int.Parse(dataStr);
             *  builder.OpenElement(++seq, "li");
             *  builder.OpenElement(++seq, "span");
             *  builder.AddAttribute(++seq, "class", "round-dot");
             *  builder.AddAttribute(++seq, "style", "background-color:" + colors[counter]);
             *
             *  builder.CloseElement();
             *  builder.AddContent(++seq, labels[counter++] + " " + "(" + data.ToString() + ")");
             *  builder.CloseElement();
             * }
             *
             * builder.CloseElement();
             * builder.CloseElement();
             */
            builder.CloseElement();
            builder.CloseElement();
        }
Esempio n. 15
0
        protected virtual void AddContent(RenderTreeBuilder builder, string buttonClassName)
        {
            if (this.Href == null)
            {
                builder.OpenElement(21, "button");
            }
            else
            {
                builder.OpenElement(21, "a");
                //builder.AddElementReferenceCapture(3, (elementRef) => { RootElementReference = elementRef; });
                builder.AddAttribute(22, "href", this.Href);
            }

            builder.AddAttribute(23, "class", $"ms-Button {buttonClassName} {this.ClassName} mediumFont {(Disabled ? "is-disabled" : "")} {(isChecked ? "is-checked" : "")}");
            builder.AddAttribute(24, "onclick", EventCallback.Factory.Create <MouseEventArgs>(this, this.ClickHandler));
            builder.AddAttribute(25, "disabled", this.Disabled && !this.AllowDisabledFocus);
            builder.AddAttribute(26, "data-is-focusable", this.Disabled || this.Split ? false : true);
            builder.AddAttribute(27, "style", this.Style);

            builder.AddElementReferenceCapture(28, (elementRef) => { RootElementReference = elementRef; });

            //if (MenuContent != null) // menu!
            //{
            //    builder.OpenElement(7, "div");
            //    builder.AddAttribute(8, "style", "display: inline-block;");

            //    builder.CloseElement();
            //}
            //skipping KeytipData component
            builder.OpenElement(29, "div");
            builder.AddAttribute(30, "class", "ms-Button-flexContainer");

            if (this.IconName != null)
            {
                builder.OpenComponent <BlazorFabric.Icon>(11);
                builder.AddAttribute(41, "ClassName", "ms-Button-icon");
                builder.AddAttribute(42, "IconName", this.IconName);
                builder.CloseComponent();
            }
            if (this.Text != null)
            {
                builder.OpenElement(51, "div");
                builder.AddAttribute(52, "class", "ms-Button-textContainer");
                builder.OpenElement(53, "div");
                builder.AddAttribute(54, "class", "ms-Button-label");
                builder.AddContent(55, this.Text);
                builder.CloseElement();
                if (this.SecondaryText != null)
                {
                    builder.OpenElement(61, "div");
                    builder.AddAttribute(62, "class", "ms-Button-description");
                    builder.AddContent(63, this.SecondaryText);
                    builder.CloseElement();
                }
                builder.CloseElement();
            }
            if (this.AriaDescripton != null)
            {
                builder.OpenElement(71, "span");
                builder.AddAttribute(72, "class", "ms-Button-screenReaderText");
                builder.AddContent(73, this.AriaDescripton);
                builder.CloseElement();
            }
            if (this.Text == null && this.ChildContent != null)
            {
                builder.AddContent(81, this.ChildContent);
            }
            if (!this.Split && this.MenuItems != null && !this.HideChevron)
            {
                builder.OpenComponent <BlazorFabric.Icon>(26);
                builder.AddAttribute(91, "IconName", "ChevronDown");
                builder.AddAttribute(92, "ClassName", "ms-Button-menuIcon");
                builder.CloseComponent();
            }
            //menu here!
            //if (MenuItems != null && contextMenuShown)
            //{
            //    //builder.OpenElement(0, "div");
            //    //builder.AddAttribute(1, "style", "display:inline-block;");
            //    //AddContent(builder, buttonClassName);
            //    ////builder.AddContent(50, ;
            //    //builder.AddAttribute(51, "ChildContent", MenuContent);
            //    //builder.CloseComponent();
            //}
            if (MenuItems != null && contextMenuShown)
            {
                builder.OpenComponent <ContextualMenu>(29);
                builder.AddAttribute(101, "FabricComponentTarget", this);
                builder.AddAttribute(102, "OnDismiss", EventCallback.Factory.Create <bool>(this, (isDismissed) => { contextMenuShown = false; }));
                builder.AddAttribute(103, "Items", MenuItems);
                builder.CloseComponent();
            }



            builder.CloseElement();

            //if (false)
            //{
            //    //render Menu, donotlayer,  not yet made
            //}
            //if (false) // menu causes inline-block div
            //{
            //    builder.CloseElement();
            //}

            builder.CloseElement();
        }
        public void Cmd_Render(int k, RenderTreeBuilder builder)
        {
            builder.OpenElement(k++, "g");
            builder.AddAttribute(k++, "style", "font-family:Georgia;font-size=14px");
            builder.AddAttribute(k++, "fill", "saddlebrown");

            foreach (var item in texts_list)
            {
                builder.OpenElement(k++, "text");
                builder.AddAttribute(k++, "x", item.x);
                builder.AddAttribute(k++, "y", item.y);
                if (!string.IsNullOrEmpty(item.text_anchor))
                {
                    builder.AddAttribute(k++, "text-anchor", item.text_anchor);
                }
                if (!string.IsNullOrEmpty(item.dominant_baseline))
                {
                    builder.AddAttribute(k++, "dominant-baseline", item.dominant_baseline);
                }
                builder.AddContent(k++, item.content);
                builder.CloseElement();
            }


            foreach (var item in rects_list)
            {
                builder.OpenElement(k++, "rect");
                builder.AddAttribute(k++, "x", item.x);
                builder.AddAttribute(k++, "y", item.y);
                builder.AddAttribute(k++, "width", item.width);
                builder.AddAttribute(k++, "height", item.height);
                if (!string.IsNullOrEmpty(item.fill))
                {
                    builder.AddAttribute(k++, "fill", item.fill);
                }
                if (!string.IsNullOrEmpty(item.stroke))
                {
                    builder.AddAttribute(k++, "stroke", item.stroke);
                }
                if (!double.IsNaN(item.stroke_width))
                {
                    builder.AddAttribute(k++, "stroke-width", item.stroke_width);
                }

                builder.CloseElement();
            }


            builder.CloseElement();
        }
Esempio n. 17
0
        /// <inheritdoc />
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            if (_refreshException != null)
            {
                var oldRefreshException = _refreshException;
                _refreshException = null;

                throw oldRefreshException;
            }

            builder.OpenElement(0, "div");
            builder.AddAttribute(1, "style", GetSpacerStyle(_itemsBefore));
            builder.AddElementReferenceCapture(2, elementReference => _spacerBefore = elementReference);
            builder.CloseElement();

            var lastItemIndex           = Math.Min(_itemsBefore + _visibleItemCapacity, _itemCount);
            var renderIndex             = _itemsBefore;
            var placeholdersBeforeCount = Math.Min(_loadedItemsStartIndex, lastItemIndex);

            builder.OpenRegion(3);

            // Render placeholders before the loaded items.
            for (; renderIndex < placeholdersBeforeCount; renderIndex++)
            {
                // This is a rare case where it's valid for the sequence number to be programmatically incremented.
                // This is only true because we know for certain that no other content will be alongside it.
                builder.AddContent(renderIndex, _placeholder, new PlaceholderContext(renderIndex, _itemSize));
            }

            builder.CloseRegion();

            _lastRenderedItemCount = 0;

            // Render the loaded items.
            if (_loadedItems != null && _itemTemplate != null)
            {
                var itemsToShow = _loadedItems
                                  .Skip(_itemsBefore - _loadedItemsStartIndex)
                                  .Take(lastItemIndex - _loadedItemsStartIndex);

                builder.OpenRegion(4);

                foreach (var item in itemsToShow)
                {
                    _itemTemplate(item)(builder);
                    _lastRenderedItemCount++;
                }

                renderIndex += _lastRenderedItemCount;

                builder.CloseRegion();
            }

            _lastRenderedPlaceholderCount = Math.Max(0, lastItemIndex - _itemsBefore - _lastRenderedItemCount);

            builder.OpenRegion(5);

            // Render the placeholders after the loaded items.
            for (; renderIndex < lastItemIndex; renderIndex++)
            {
                builder.AddContent(renderIndex, _placeholder, new PlaceholderContext(renderIndex, _itemSize));
            }

            builder.CloseRegion();

            var itemsAfter = Math.Max(0, _itemCount - _visibleItemCapacity - _itemsBefore);

            builder.OpenElement(6, "div");
            builder.AddAttribute(7, "style", GetSpacerStyle(itemsAfter));
            builder.AddElementReferenceCapture(8, elementReference => _spacerAfter = elementReference);

            builder.CloseElement();
        }
Esempio n. 18
0
        /// <inheritdoc />
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            if (HasLabel)
            {
                // <label>
                builder.OpenElement(0, Html.LABEL);
                builder.AddAttribute(1, "for", Id);
                builder.AddContent(2, Label);
                builder.CloseElement();
                // </label>
            }

            if (HasInputGroup)
            {
                // <div>
                builder.OpenElement(3, Html.DIV);
                builder.AddAttribute(4, Html.CLASS, Bootstrap.INPUT_GROUP);
            }

            if (HasPrepend)
            {
                // Div
                builder.OpenElement(5, Html.DIV);
                builder.AddAttribute(6, Html.CLASS, Bootstrap.INPUT_GROUP_PREPEND);

                // Span
                builder.OpenElement(7, Html.SPAN);
                builder.AddAttribute(8, Html.CLASS, Bootstrap.INPUT_GROUP_TEXT);
                builder.AddContent(9, Prepend);
                builder.CloseElement();

                builder.CloseElement();
            }

            // Select
            builder.OpenElement(10, "select");
            builder.AddMultipleAttributes(11, Attributes);
            builder.AddAttribute(12, Html.VALUE, BindConverter.FormatValue(CurrentValueAsString));
            builder.AddAttribute(13, Html.ONCHANGE, EventCallback.Factory.CreateBinder <string>(this, __value => CurrentValueAsString = __value, CurrentValueAsString));

            // Disabled?
            if (Disabled ?? false)
            {
                builder.AddAttribute(20, Html.DISABLED, string.Empty);
            }

            // Help
            if (HasHelp)
            {
                builder.AddAttribute(21, Html.ARIA_DESCRIBEDBY, $"{Id}-help");
            }

            // Content
            builder.AddContent(22, ChildContent);

            builder.CloseElement();

            if (HasAppend)
            {
                // Div
                builder.OpenElement(23, Html.DIV);
                builder.AddAttribute(24, Html.CLASS, "input-group-append");

                // Span
                builder.OpenElement(25, Html.SPAN);
                builder.AddAttribute(26, Html.CLASS, Bootstrap.INPUT_GROUP_TEXT);
                builder.AddContent(27, Append);
                builder.CloseElement();

                builder.CloseElement();
            }

            if (HasInputGroup)
            {
                builder.CloseElement();
            }

            // Help
            BuildRenderTreeHelp(builder);
        }
Esempio n. 19
0
        /// <summary>
        /// Builds the title.
        /// </summary>
        /// <param name="tr">The tr.</param>
        private void BuildTitle(RenderTreeBuilder tr)
        {
            tr.OpenComponent <TableHeader>(0);

            switch (ViewMode)
            {
            case CalendarViewMode.Year:
                tr.AddAttribute(1, "colspan", 5);
                break;

            case CalendarViewMode.Month:
                tr.AddAttribute(1, "colspan", 3);
                break;

            case CalendarViewMode.Date:
                tr.AddAttribute(1, "colspan", DAYS_IN_WEEK);
                break;

            case CalendarViewMode.Time:
                break;

            case CalendarViewMode.DateTime:
                break;

            default:
                break;
            }
            tr.AddAttribute(10, nameof(TableHeader.ChildContent), (RenderFragment)(th =>
            {
                th.OpenElement(0, "span");
                th.AddAttribute(1, "class", "link");

                var content = string.Empty;
                switch (ViewMode)
                {
                case CalendarViewMode.Year:
                    (var min, var max) = GetYearRange();
                    content = $"{min} - {max}";
                    break;

                case CalendarViewMode.Month:
                    content = CurrentYear.ToString();
                    break;

                case CalendarViewMode.Date:
                    content = $"{CurrentYear} - {CurrentMonth}";
                    break;

                case CalendarViewMode.Time:
                    break;

                case CalendarViewMode.DateTime:
                    break;

                default:
                    break;
                }

                th.AddContent(10, content);
                th.CloseElement();

                BuildPrevAndNext(th, true);
                BuildPrevAndNext(th, false, 25);
            }));
            tr.CloseComponent();
        }
Esempio n. 20
0
 protected override void BuildInputRenderTree(RenderTreeBuilder builder, int sequence)
 {
     builder.AddAttribute(sequence, "type", "date");
 }
        public static RenderTreeBuilder TabIndex(this RenderTreeBuilder builder, int?value, [CallerLineNumber] int line = 0)
        {
            builder.AddAttribute(GetSequence(line), $"tabindex", value);

            return(builder);
        }
Esempio n. 22
0
 protected override void BuildValueBindingAttribute(RenderTreeBuilder builder, int sequence)
 => builder.AddAttribute(sequence++, "value", BindConverter.FormatValue(CurrentValueAsString));
        public static RenderTreeBuilder OnClick(this RenderTreeBuilder builder, object receiver, EventCallback callback, [CallerLineNumber] int line = 0)
        {
            builder.AddAttribute(GetSequence(line), "onclick", EventCallback.Factory.Create <Microsoft.AspNetCore.Components.Web.MouseEventArgs>(receiver, callback));

            return(builder);
        }
Esempio n. 24
0
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            var seq = 0;

            builder.OpenElement(seq, "figure");
            builder.AddAttribute(++seq, "class", "line-chart");
            builder.OpenElement(++seq, "div");
            builder.AddAttribute(++seq, "class", "main");


            System.Diagnostics.Debug.WriteLine("ID" + InputData);

            string[] inputDataArrX  = InputData.Split(new char[] { '[', ']' }, StringSplitOptions.RemoveEmptyEntries);
            string[] inputLabelsArr = InputLabels.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            int numLines = 0;

            System.Diagnostics.Debug.WriteLine("Start");
            foreach (string inputLine in inputDataArrX)
            {
                if (inputLine.IndexOfAny(new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }) >= 0)
                {
                    numLines++;
                }
            }
            System.Diagnostics.Debug.WriteLine("End");
            string[] inputDataArr = new string[numLines];
            int      lineCounter  = 0;

            foreach (string inputLine in inputDataArrX)
            {
                if (inputLine.IndexOfAny(new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }) >= 0)
                {
                    inputDataArr[lineCounter++] = inputLine;
                    System.Diagnostics.Debug.WriteLine("IL:" + inputLine);
                }
            }

            string[] colors = { "#ce4b99", "#27A844", "#377bbc" };
            string[] labels = { "App Store", "Website", "Partners" };

            double boundHeight = 150.0;
            double boundWidth  = 150.0;

            SVG svg = new SVG()
            {
                { "width", "100%" }, { "height", "100%" }, { "viewBox", "0 0 150 150" }
            };
            //Rectangle rect = new Rectangle() { { "class", "background-rect" }, { "width", "100%" }, { "height", "100%" }, { "fill", "white" }, { "stroke", "gray" }, {"stroke-width", "0.5" } };
            //Rectangle rect = new Rectangle() { { "width", "100%" }, { "height", "100%" }, { "fill", "cyan" }};
            Rectangle rect = new Rectangle()
            {
                { "class", "background-rect" }
            };

            svg.AddItems(rect);


            int    numHorizontalLines   = 10;
            int    numVerticalLines     = 10;
            double verticalStartSpace   = 25.0;
            double horizontalStartSpace = 25.0;
            double verticalEndSpace     = 25.0;
            double horizontalEndSpace   = 25.0;
            double gridYUnits           = 10;
            double gridXUnits           = 10;
            //bool skipLastVerticalLine = true;
            //bool skipLastHorizontalLine = true;

            double verticalSpace   = (boundHeight - verticalStartSpace - verticalEndSpace) / (numHorizontalLines);
            double horizontalSpace = (boundWidth - horizontalStartSpace - horizontalEndSpace) / (numVerticalLines);

            double totalGridWidth  = ((double)(numVerticalLines - 1)) * horizontalSpace;
            double totalGridHeight = ((double)(numHorizontalLines - 1)) * verticalSpace;

            System.Diagnostics.Debug.WriteLine("TotalGridHeight:" + totalGridHeight + ":" + verticalSpace);

            //Horizontal Lines
            double y          = verticalStartSpace;
            double startGridY = 0;

            for (int counter = 0; counter <= numHorizontalLines; counter++)
            {
                //if (counter == numHorizontalLines - 1 && skipLastHorizontalLine)
                //    continue;

                Path path = new Path()
                {
                    { "class", "horizontal-grid-lines" }, { "d", "M " + horizontalStartSpace.ToString() + " " + (boundHeight - y).ToString() + " L " + (boundWidth - horizontalEndSpace).ToString() + " " + (boundHeight - y).ToString() }
                };
                Text label = new Text()
                {
                    { "class", "y-axis-labels" }, { "x", (horizontalStartSpace - 2).ToString() }, { "y", (boundHeight - y).ToString() }, { "content", (startGridY).ToString() }
                };
                svg.AddItems(path, label);
                System.Diagnostics.Debug.WriteLine("Y:" + y);

                y          = y + verticalSpace;
                startGridY = startGridY + gridYUnits;
            }

            //Chart Line
            double gridx = 0, gridy = 0;

            gridx = horizontalStartSpace;
            gridy = boundHeight - verticalStartSpace;
            int colorcounter = 0;

            foreach (string iData in inputDataArr)
            {
                string chartLine  = "";
                double gridValueX = 0;
                double gridValueY = 0;
                bool   firstTime  = true;

                string[] inputLineArr = iData.Split(',');
                int[]    intAry       = new int[inputLineArr.Length];
                for (int i = 0; i < inputLineArr.Length; i++)
                {
                    intAry[i] = int.Parse(inputLineArr[i]);
                }

                foreach (int i in intAry)
                {
                    if (firstTime)
                    {
                        chartLine  = chartLine + "M ";
                        firstTime  = false;
                        gridValueX = horizontalStartSpace;
                        gridValueY = verticalStartSpace;
                        double gridValue = ((double)i) * verticalSpace / gridYUnits;
                        gridValueY = boundHeight - (gridValueY + gridValue);
                        chartLine  = chartLine + gridValueX.ToString() + " " + gridValueY.ToString();
                    }
                    else
                    {
                        chartLine  = chartLine + " L ";
                        gridValueX = gridValueX + horizontalSpace;
                        gridValueY = verticalStartSpace;
                        double gridValue = ((double)i) * verticalSpace / gridYUnits;
                        gridValueY = boundHeight - (gridValueY + gridValue);
                        chartLine  = chartLine + gridValueX.ToString() + " " + gridValueY.ToString();
                    }
                }
                //System.Diagnostics.Debug.WriteLine("CL:" + chartLine);
                // Path linepath = new Path() { { "fill", "none" }, { "stroke", colors[colorcounter++] }, { "stroke-width", "1.0" }, { "d", chartLine } };
                Path linepath = new Path()
                {
                    { "class", "line-" + (colorcounter + 1).ToString() }, { "d", chartLine }
                };
                colorcounter++;
                svg.AddItems(linepath);
            }

            //Vertical Lines
            double x          = horizontalStartSpace;
            double startGridX = 0;

            for (int counter = 0; counter <= numVerticalLines; counter++)
            {
                //if (counter == numVerticalLines - 1 && skipLastVerticalLine)
                //    continue;

                Path path = new Path()
                {
                    { "class", "vertical-grid-lines" }, { "d", "M " + x.ToString() + " " + (boundHeight - verticalStartSpace).ToString() + " L " + x.ToString() + " " + (verticalEndSpace).ToString() }
                };
                Text label = new Text()
                {
                    { "class", "x-axis-labels" }, { "x", x.ToString() }, { "y", (boundHeight - verticalStartSpace + 5).ToString() }, { "content", (startGridX).ToString() }
                };
                startGridX = startGridX + gridXUnits;

                svg.AddItems(path, label);
                x = x + horizontalSpace;
            }

            BlazorRenderer blazorRenderer = new BlazorRenderer();

            blazorRenderer.Draw(seq, builder, svg);

            builder.OpenElement(++seq, "figcaption");
            builder.AddAttribute(++seq, "class", "key");
            builder.OpenElement(++seq, "ul");
            builder.AddAttribute(++seq, "class", "key-list");
            //builder.AddAttribute(++seq, "aria-hidden", "true");
            //builder.AddAttribute(++seq, "style", "list-style-type: none;");

            colorcounter = 0;
            foreach (string iData in inputDataArr)
            {
                //int data = int.Parse(dataStr);
                builder.OpenElement(++seq, "li");
                builder.OpenElement(++seq, "span");
                builder.AddAttribute(++seq, "class", "legend-" + (colorcounter + 1).ToString());
                //builder.AddAttribute(++seq, "style", "background-color:" + colors[colorcounter]);

                builder.CloseElement();

                string label = "";
                if (colorcounter < inputLabelsArr.Length)
                {
                    label = inputLabelsArr[colorcounter];
                }

                builder.AddContent(++seq, label);
                builder.CloseElement();
                colorcounter++;
            }

            builder.CloseElement();
            builder.CloseElement();


            builder.CloseElement();
            builder.CloseElement();
        }
        public static RenderTreeBuilder Fill(this RenderTreeBuilder builder, string value, [CallerLineNumber] int line = 0)
        {
            builder.AddAttribute(GetSequence(line), "fill", value);

            return(builder);
        }
Esempio n. 26
0
        protected void Process(RenderTreeBuilder builder2, IGrouping <int, IMField> groupResult)
        {
            if (groupResult.Key != 0 && !IsInTableRow)
            {
                builder2.OpenElement(10, "div");
                builder2.AddAttribute(11, "class", "m-form-row" + (groupResult.Count() > 1 ? " multiple-forms-in-row" : string.Empty));
            }

            foreach (var field in groupResult)
            {
                if (field is IMPropertyField propField)
                {
                    var propertyInfo = GetPropertyInfo(propField);

                    if (propertyInfo.GetCustomAttribute(typeof(HiddenAttribute)) != null)
                    {
                        continue;
                    }

                    if (field.Attributes != null)
                    {
                        propertyInfo.SetAttributes(field.Attributes);
                    }

                    var inpId = Guid.NewGuid();

                    if (IsInTableRow)
                    {
                        builder2.OpenElement(16, "td");
                        //       builder2.AddMultipleAttributes(17, field.AdditionalAttributes);
                        // update 13.07.2020, add AdditionalAttributes to Input

                        if (field.AdditionalAttributes != null && field.AdditionalAttributes.TryGetValue(Extensions.MFORM_IN_TABLE_ROW_TD_STYLE_ATTRIBUTE, out object value))
                        {
                            builder2.AddAttribute(247, "style", value);
                        }

                        if (propertyInfo.PropertyType != null)
                        {
                            AddInput(builder2, field, propertyInfo, inpId);
                        }

                        builder2.CloseElement();
                        continue;
                    }

                    if (groupResult.Key == 0)
                    {
                        builder2.OpenElement(10, "div");
                        builder2.AddAttribute(11, "class", "m-form-row");
                    }

                    //  <div class="form-group">
                    builder2.OpenElement(10, "div");

                    string cssClass = "form-group col-"; //TODO we use bootstrap here - good idea or bad?

                    if (groupResult.Key == 0)
                    {
                        cssClass += "12";
                    }
                    else
                    {
                        cssClass += 12 / groupResult.Count();
                    }

                    builder2.AddAttribute(11, "class", cssClass);

                    //  <label for="@inpId">@property.Name</label>
                    builder2.OpenElement(13, "label");
                    builder2.AddAttribute(14, "for", inpId);
                    builder2.AddAttribute(14, "class", "col-sm-12 col-form-label"); //TODO we use bootstrap here - good idea or bad?

                    var displayAttribute = propertyInfo.GetCustomAttribute(typeof(DisplayAttribute)) as DisplayAttribute;
                    if (displayAttribute != null)
                    {
                        builder2.AddContent(280, displayAttribute.Name);
                    }
                    else
                    {
                        builder2.AddContent(284, propertyInfo.Name);
                    }

                    builder2.CloseElement();

                    builder2.OpenElement(16, "div");
                    builder2.AddAttribute(17, "class", "col-sm-12");  //TODO we use bootstrap here - good idea or bad?

                    AddInput(builder2, field, propertyInfo, inpId);

                    builder2.CloseElement(); // </div>


                    builder2.CloseElement(); // </div>

                    if (groupResult.Key == 0)
                    {
                        builder2.CloseElement(); // </div>
                    }
                }
                else if (field is IMFieldGenerator fieldGenerator)
                {
                    MFieldGeneratorContext context = new MFieldGeneratorContext()
                    {
                        Form = this
                    };

                    if (IsInTableRow)
                    {
                        builder2.OpenElement(16, "td");
                    }

                    builder2.AddContent(42, fieldGenerator.Template?.Invoke(context));

                    if (IsInTableRow)
                    {
                        builder2.CloseElement();
                    }
                }
            }

            if (groupResult.Key != 0 && !IsInTableRow)
            {
                builder2.CloseElement();
            }
        }
Esempio n. 27
0
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            if (builder != null)
            {
                base.BuildRenderTree(builder);

                string container = "input";

                if (AddOnBefore != null || AddOnAfter != null)
                {
                    container = "groupWrapper";
                    builder.OpenElement(1, "span");
                    builder.AddAttribute(2, "class", GroupWrapperClass);
                    builder.AddAttribute(3, "style", Style);
                    builder.OpenElement(4, "span");
                    builder.AddAttribute(5, "class", $"{PrefixCls}-wrapper {PrefixCls}-group");
                }

                if (AddOnBefore != null)
                {
                    // addOnBefore
                    builder.OpenElement(11, "span");
                    builder.AddAttribute(12, "class", $"{PrefixCls}-group-addon");
                    builder.AddContent(13, AddOnBefore);
                    builder.CloseElement();
                }

                if (Prefix != null || Suffix != null)
                {
                    builder.OpenElement(21, "span");
                    builder.AddAttribute(22, "class", AffixWrapperClass);
                    if (container == "input")
                    {
                        container = "affixWrapper";
                        builder.AddAttribute(23, "style", Style);
                    }
                }

                if (Prefix != null)
                {
                    // prefix
                    builder.OpenElement(31, "span");
                    builder.AddAttribute(32, "class", $"{PrefixCls}-prefix");
                    builder.AddContent(33, Prefix);
                    builder.CloseElement();
                }

                // input
                builder.OpenElement(41, "input");
                builder.AddAttribute(42, "class", ClassMapper.Class);
                if (container == "input")
                {
                    builder.AddAttribute(43, "style", Style);
                }

                if (Attributes != null)
                {
                    builder.AddMultipleAttributes(44, Attributes);
                }

                if (AdditionalAttributes != null)
                {
                    builder.AddMultipleAttributes(45, AdditionalAttributes);
                }

                builder.AddAttribute(50, "Id", Id);
                builder.AddAttribute(51, "type", Type);
                builder.AddAttribute(60, "placeholder", Placeholder);
                builder.AddAttribute(61, "value", CurrentValue);

                // onchange 和 onblur 事件会导致点击 OnSearch 按钮时不触发 Click 事件,暂时取消这两个事件
                if (!IgnoreOnChangeAndBlur)
                {
                    builder.AddAttribute(62, "onchange", CallbackFactory.Create(this, OnChangeAsync));
                    builder.AddAttribute(65, "onblur", CallbackFactory.Create(this, OnBlurAsync));
                }

                builder.AddAttribute(63, "onkeypress", CallbackFactory.Create(this, OnKeyPressAsync));
                builder.AddAttribute(63, "onkeydown", CallbackFactory.Create(this, OnkeyDownAsync));
                builder.AddAttribute(63, "onkeyup", CallbackFactory.Create(this, OnKeyUpAsync));
                builder.AddAttribute(64, "oninput", CallbackFactory.Create(this, OnInputAsync));
                builder.AddAttribute(66, "onfocus", CallbackFactory.Create(this, OnFocusAsync));
                builder.AddAttribute(67, "onmouseup", CallbackFactory.Create(this, OnMouseUpAsync));
                builder.AddElementReferenceCapture(68, r => Ref = r);
                builder.CloseElement();

                if (Suffix != null)
                {
                    // suffix
                    builder.OpenElement(71, "span");
                    builder.AddAttribute(72, "class", $"{PrefixCls}-suffix");
                    builder.AddContent(73, Suffix);
                    builder.CloseElement();
                }

                if (Prefix != null || Suffix != null)
                {
                    builder.CloseElement();
                }

                if (AddOnAfter != null)
                {
                    // addOnAfter
                    builder.OpenElement(81, "span");
                    builder.AddAttribute(82, "class", $"{PrefixCls}-group-addon");
                    builder.AddContent(83, AddOnAfter);
                    builder.CloseElement();
                }

                if (AddOnBefore != null || AddOnAfter != null)
                {
                    builder.CloseElement();
                    builder.CloseElement();
                }
            }
        }
Esempio n. 28
0
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            base.BuildRenderTree(builder);

            // If _fixedEditContext changes, tear down and recreate all descendants.
            // This is so we can safely use the IsFixed optimization on Cascadi ngValue,
            // optimizing for the common case where _fixedEditContext never changes.
            builder.OpenRegion(mEditContext.GetHashCode());

            if (!IsInTableRow)
            {
                builder.OpenElement(0, "form");
                builder.AddMultipleAttributes(1, AdditionalAttributes);
                builder.AddAttribute(2, "onsubmit", EventCallback.Factory.Create(this, NotifyContainer));

                if (EnableValidation)
                {
                    builder.AddAttribute(11, "class", "m-form-validation");
                }
            }


            if (Fields != null)
            {
                RenderFragment child3() =>
                (builder2) =>
                {
                    builder2.AddMarkupContent(1, "\r\n");
                    builder2.AddContent(2, this.Fields);
                    builder2.AddMarkupContent(3, "\r\n");
                };

                builder.OpenComponent <CascadingValue <MForm <T> > >(4);
                builder.AddAttribute(5, "Value", this);
                builder.AddAttribute(6, "ChildContent", child3());
                builder.CloseComponent();
            }

            RenderFragment child(EditContext context) =>
            (builder2) =>
            {
                if (EnableValidation)
                {
                    builder2.OpenComponent <DataAnnotationsValidator>(0);
                    builder2.CloseComponent();
                }

                if (!IsInTableRow)
                {
                    builder2.OpenComponent <ValidationSummary>(1);
                    builder2.CloseComponent();
                }

                if (FieldList.Any())
                {
                    foreach (var groupResult in GroupByRow(FieldList))
                    {
                        Process(builder2, groupResult);
                    }
                }
                else
                {
                    foreach (var groupResult in GroupByRow(ReflectionHelper.GetProperties(Model).Select(pi => GetField(pi))))
                    {
                        //    Console.WriteLine(property.PropertyType.FullName);

                        Process(builder2, groupResult);
                    }
                }

                if (!IsInTableRow)
                {
                    builder2.AddMarkupContent(27, "<button type=\"submit\" style=\"display: none;\">Submit</button>\r\n");
                }
            };

            builder.OpenComponent <CascadingValue <EditContext> >(3);
            builder.AddAttribute(4, "IsFixed", true);
            builder.AddAttribute(5, "Value", mEditContext);
            builder.AddAttribute(6, "ChildContent", child(mEditContext));
            builder.CloseComponent();

            if (!IsInTableRow)
            {
                builder.CloseElement();
            }

            builder.CloseRegion();
        }
Esempio n. 29
0
    /// <summary>
    /// RenderTreeBuilder 扩展方法 通过指定模型与属性生成编辑组件
    /// </summary>
    /// <param name="builder"></param>
    /// <param name="model"></param>
    /// <param name="component"></param>
    /// <param name="item"></param>
    /// <param name="changedType"></param>
    /// <param name="isSearch"></param>
    /// <param name="lookUpService"></param>
    public static void CreateComponentByFieldType(this RenderTreeBuilder builder, ComponentBase component, IEditorItem item, object model, ItemChangedType changedType = ItemChangedType.Update, bool isSearch = false, ILookupService?lookUpService = null)
    {
        var fieldType   = item.PropertyType;
        var fieldName   = item.GetFieldName();
        var displayName = item.GetDisplayName() ?? GetDisplayName(model, fieldName);

        var fieldValue        = GenerateValue(model, fieldName);
        var fieldValueChanged = GenerateValueChanged(component, model, fieldName, fieldType);
        var valueExpression   = GenerateValueExpression(model, fieldName, fieldType);
        var lookup            = item.Lookup ?? lookUpService?.GetItemsByKey(item.LookupServiceKey);
        var componentType     = item.ComponentType ?? GenerateComponentType(fieldType, item.Rows != 0, lookup);

        builder.OpenComponent(0, componentType);
        if (componentType.IsSubclassOf(typeof(ValidateBase <>).MakeGenericType(fieldType)))
        {
            builder.AddAttribute(1, nameof(ValidateBase <string> .DisplayText), displayName);
            builder.AddAttribute(2, nameof(ValidateBase <string> .Value), fieldValue);
            builder.AddAttribute(3, nameof(ValidateBase <string> .ValueChanged), fieldValueChanged);
            builder.AddAttribute(4, nameof(ValidateBase <string> .ValueExpression), valueExpression);

            if (!item.CanWrite(model.GetType(), changedType, isSearch))
            {
                builder.AddAttribute(5, nameof(ValidateBase <string> .IsDisabled), true);
            }

            if (item.ValidateRules != null)
            {
                builder.AddAttribute(6, nameof(ValidateBase <string> .ValidateRules), item.ValidateRules);
            }

            if (item.ShowLabelTooltip != null)
            {
                builder.AddAttribute(7, nameof(ValidateBase <string> .ShowLabelTooltip), item.ShowLabelTooltip);
            }
        }

        if (componentType == typeof(NullSwitch) && TryGetProperty(model.GetType(), fieldName, out var propertyInfo))
        {
            // 读取默认值
            var defaultValueAttr = propertyInfo.GetCustomAttribute <DefaultValueAttribute>();
            if (defaultValueAttr != null)
            {
                var dv = defaultValueAttr.Value is bool v && v;
                builder.AddAttribute(8, nameof(NullSwitch.DefaultValueWhenNull), dv);
            }
        }

        if (IsCheckboxList(fieldType, componentType) && item.Items != null)
        {
            builder.AddAttribute(9, nameof(CheckboxList <IEnumerable <string> > .Items), item.Items.Clone());
        }

        // Nullabl<bool?>
        if (item.ComponentType == typeof(Select <bool?>) && fieldType == typeof(bool?) && lookup == null && item.Items == null)
        {
            builder.AddAttribute(10, nameof(Select <bool?> .Items), GetNullableBoolItems(model, fieldName));
        }

        // Lookup
        if (lookup != null && item.Items == null)
        {
            builder.AddAttribute(11, nameof(Select <SelectedItem> .Items), lookup.Clone());
            builder.AddAttribute(12, nameof(Select <SelectedItem> .StringComparison), item.LookupStringComparison);
        }

        // 增加非枚举类,手动设定 ComponentType 为 Select 并且 Data 有值 自动生成下拉框
        if (item.Items != null && item.ComponentType == typeof(Select <>).MakeGenericType(fieldType))
        {
            builder.AddAttribute(13, nameof(Select <SelectedItem> .Items), item.Items.Clone());
        }

        // 设置 SkipValidate 参数
        if (IsValidatableComponent(componentType))
        {
            builder.AddAttribute(14, nameof(IEditorItem.SkipValidate), item.SkipValidate);
        }

        builder.AddMultipleAttributes(15, CreateMultipleAttributes(fieldType, model, fieldName, item));

        if (item.ComponentParameters != null)
        {
            builder.AddMultipleAttributes(16, item.ComponentParameters);
        }
        builder.CloseComponent();
    }
Esempio n. 30
0
        protected override void AddContent(RenderTreeBuilder builder, string buttonClassName)
        {
            builder.OpenElement(21, "button");

            builder.AddAttribute(23, "class", $"mediumFont ms-Button {buttonClassName} {(Disabled ? "is-disabled" : "")} {(isChecked ? "is-checked" : "")} {this.ClassName}");
            builder.AddAttribute(24, "onclick", EventCallback.Factory.Create <MouseEventArgs>(this, this.ClickHandler));
            builder.AddAttribute(25, "disabled", this.Disabled && !this.AllowDisabledFocus);
            builder.AddAttribute(26, "data-is-focusable", this.Disabled || this.Split ? false : true);
            builder.AddAttribute(27, "style", this.Style);

            builder.AddAttribute(28, "aria-selected", this.AriaSelected);
            builder.AddAttribute(29, "aria-label", this.AriaLabel);

            builder.AddElementReferenceCapture(30, (elementRef) => { RootElementReference = elementRef; });

            //skipping KeytipData component
            builder.OpenElement(40, "div");
            builder.AddAttribute(41, "class", "ms-Button-flexContainer");

            if (this.Text != null)
            {
                builder.OpenElement(51, "div");
                builder.AddAttribute(52, "class", "ms-Button-textContainer");
                builder.OpenElement(53, "div");
                builder.AddAttribute(54, "class", "ms-Button-label");
                builder.AddContent(55, this.Text);
                builder.CloseElement();
                builder.CloseElement();
            }
            if (this.AriaDescripton != null)
            {
                builder.OpenElement(71, "span");
                builder.AddAttribute(72, "class", "ms-Button-screenReaderText");
                builder.AddContent(73, this.AriaDescripton);
                builder.CloseElement();
            }
            //if (this.Text == null && this.ChildContent != null)
            //{
            //    builder.AddContent(81, this.ChildContent);
            //}

            builder.CloseElement();
            builder.CloseElement();
        }