protected override void loadData()
        {
            var itemGroups = Enumerable.Range(1, 2)
                             .Select(
                group => ColumnPrimaryItemGroup.Create(
                    "Group {0}".FormatWith(group).ToComponents(),
                    groupActions:
                    new ButtonSetup(
                        "Action 1",
                        behavior: new PostBackBehavior(
                            postBack: PostBack.CreateIntermediate(
                                null,
                                id: PostBack.GetCompositeId(group.ToString(), "action1"),
                                firstModificationMethod: () => AddStatusMessage(StatusMessageType.Info, "Action 1")))).Append(
                        new ButtonSetup(
                            "Action 2",
                            behavior: new PostBackBehavior(
                                postBack: PostBack.CreateIntermediate(
                                    null,
                                    id: PostBack.GetCompositeId(group.ToString(), "action2"),
                                    firstModificationMethod: () => AddStatusMessage(StatusMessageType.Info, "Action 2")))))
                    .Materialize(),
                    selectedItemActions: group == 1
                                                                             ? SelectedItemAction.CreateWithIntermediatePostBackBehavior <int>(
                        "Echo group IDs",
                        null,
                        ids => AddStatusMessage(
                            StatusMessageType.Info,
                            StringTools.GetEnglishListPhrase(ids.Select(i => i.ToString()), true)))
                    .ToCollection()
                                                                             : Enumerable.Empty <SelectedItemAction <int> >().Materialize(),
                    items: Enumerable.Range(1, 5)
                    .Select(
                        i => EwfTableItem.Create(
                            EwfTableItemSetup.Create(
                                activationBehavior: ElementActivationBehavior.CreateRedirectScript(ActionControls.GetInfo()),
                                id: new SpecifiedValue <int>(group * 10 + i)),
                            i.ToString().ToCell(),
                            ((i * 2) + Environment.NewLine + "extra stuff").ToCell()))))
                             .Materialize();

            place.AddControlsReturnThis(
                ColumnPrimaryTable.Create(
                    caption: "My table",
                    subCaption: "A new table implementation",
                    allowExportToExcel: true,
                    tableActions: new ButtonSetup(
                        "Action",
                        behavior: new PostBackBehavior(
                            postBack: PostBack.CreateIntermediate(
                                null,
                                id: "action",
                                firstModificationMethod: () => AddStatusMessage(StatusMessageType.Info, "You clicked action.")))).ToCollection(),
                    selectedItemActions: SelectedItemAction
                    .CreateWithIntermediatePostBackBehavior <int>(
                        "Echo IDs",
                        null,
                        ids => AddStatusMessage(StatusMessageType.Info, StringTools.GetEnglishListPhrase(ids.Select(i => i.ToString()), true)))
                    .Append(
                        SelectedItemAction.CreateWithIntermediatePostBackBehavior <int>(
                            "With confirmation",
                            null,
                            ids => AddStatusMessage(StatusMessageType.Info, StringTools.GetEnglishListPhrase(ids.Select(i => i.ToString()), true)),
                            confirmationDialogContent: "Are you sure?".ToComponents()))
                    .Materialize(),
                    fields: new[] { new EwfTableField(size: 1.ToPercentage()), new EwfTableField(size: 2.ToPercentage()) })
                .AddItemGroups(itemGroups)
                .ToCollection()
                .GetControls());
        }
예제 #2
0
        void ControlTreeDataLoader.LoadData()
        {
            CssClass = CssClass.ConcatenateWithSpace(CssElementCreator.CssClass);

            var rand         = new Random();
            var actualColors = (colors ?? getDefaultColors()).Take(seriesCollection.Count())
                               .Pad(seriesCollection.Count(), () => Color.FromArgb(rand.Next(256), rand.Next(256), rand.Next(256)));

            Func <DataSeries, Color, BaseDataset> datasetSelector;
            OptionsBase options;

            switch (setup.ChartType)
            {
            case ChartType.Line:
                datasetSelector = (series, color) => new Dataset(color, series.Values.TakeLast(setup.MaxXValues));
                options         = new LineOptions {
                    bezierCurve = false
                };
                break;

            case ChartType.Bar:
                datasetSelector = (series, color) => new BaseDataset(color, series.Values.TakeLast(setup.MaxXValues));
                // ReSharper disable once RedundantEmptyObjectOrCollectionInitializer
                options = new BarOptions {
                };
                break;

            default:
                throw new UnexpectedValueException(setup.ChartType);
            }

            var chartData = new ChartData(
                setup.Labels.TakeLast(setup.MaxXValues),
                seriesCollection.Zip(actualColors, (series, color) => datasetSelector(series, color)).ToArray());

            var canvas = new HtmlGenericControl("canvas");

            switch (setup.ChartType)
            {
            case ChartType.Line:
            case ChartType.Bar:
                canvas.Attributes.Add("height", "400");
                break;

            default:
                throw new UnexpectedValueException(setup.ChartType);
            }
            Controls.Add(canvas);

            if (seriesCollection.Count() > 1)
            {
                Controls.Add(
                    new Box(
                        "Key",
                        new ControlLine(
                            chartData.datasets.Select(
                                (dataset, i) =>
                                new Literal
                {
                    Text =
                        @"<div style='display: inline-block; vertical-align: middle; width: 20px; height: 20px; background-color: {0}; border: 1px solid {1};'>&nbsp;</div> {2}"
                        .FormatWith(dataset.fillColor, dataset.strokeColor, seriesCollection.ElementAt(i).Name)
                } as Control).ToArray()).ToSingleElementArray()));
            }

            // Remove this when ColumnPrimaryTable supports Excel export.
            var headers   = setup.XAxisTitle.ToSingleElementArray().Concat(seriesCollection.Select(v => v.Name));
            var tableData = new List <IEnumerable <object> >(seriesCollection.First().Values.Count());

            for (var i = 0; i < tableData.Capacity; i++)
            {
                var i1 = i;
                tableData.Add(setup.Labels.ElementAt(i1).ToSingleElementArray().Concat(seriesCollection.Select(v => v.Values.ElementAt(i1).ToString())));
            }
            Controls.Add(getExportButton(headers, tableData));

            var table = new ColumnPrimaryTable(
                firstDataFieldIndex: 1,
                items:
                new EwfTableItem(from i in setup.XAxisTitle.ToSingleElementArray().Concat(setup.Labels) select i.ToCell()).ToSingleElementArray()
                .Concat(
                    from series in seriesCollection
                    select new EwfTableItem(series.Name.ToCell().ToSingleElementArray().Concat(from i in series.Values select i.ToString().ToCell()))));

            Controls.Add(table);

            using (var writer = new StringWriter()) {
                writer.WriteLine("var canvas = document.getElementById( '{0}' );".FormatWith(canvas.ClientID));
                writer.WriteLine("canvas.width = $( canvas ).parent().width();");
                writer.WriteLine("new Chart( canvas.getContext( '2d' ) ).{0}( {1}, {2} );".FormatWith(setup.ChartType, chartData.ToJson(), options.ToJson()));
                jsInitStatements = writer.ToString();
            }
        }