Example #1
0
        public void ComplexNamedObject()
        {
            var json = new JsonBuilder()
                .WriteObject( j => j
                    .WriteObject("object1", obj1 => obj1
                        .WriteProperty("property1", 1)
                    )
                )
                .ToString();

            Assert.AreEqual("{object1:{property1:1}}", json);
        }
Example #2
0
        public void MultipleNamedObjects()
        {
            var json = new JsonBuilder()
                .WriteObject( root => root
                    .WriteObject("object1", obj1 => { })
                    .WriteObject("object2", obj2 => { })
                ).ToString();

            Assert.AreEqual(
                "{object1:{},object2:{}}",
                json
            );
        }
Example #3
0
 internal void ToJson(JsonBuilder json)
 {
     // lines, points, bars: {
     //    show: boolean
     //    lineWidth: number
     //    fill: boolean or number
     //    fillColor: null or color/gradient
     //  }
     json.WriteObject("lines", lines => lines
                      .WritePropertyIf("show", GetField(Field.Show), GetField(Field.Show) != null)
                      .WritePropertyIf("lineWidth", GetField(Field.LineWidth), GetField(Field.LineWidth) != null)
                      .WritePropertyIf("fill", GetField(Field.Fill), GetField(Field.Fill) != null)
                      .WritePropertyIf("fillColor", GetField(Field.FillColor), GetField(Field.FillColor) != null)
                      );
 }
Example #4
0
 internal void ToJson(JsonBuilder json)
 {
     // lines, points, bars: {
     //    show: boolean
     //    lineWidth: number
     //    fill: boolean or number
     //    fillColor: null or color/gradient
     //  }
     json.WriteObject("lines", lines => lines
         .WritePropertyIf("show", GetField(Field.Show), GetField(Field.Show) != null)
         .WritePropertyIf("lineWidth", GetField(Field.LineWidth), GetField(Field.LineWidth) != null)
         .WritePropertyIf("fill", GetField(Field.Fill), GetField(Field.Fill) != null)
         .WritePropertyIf("fillColor", GetField(Field.FillColor), GetField(Field.FillColor) != null)
     );
 }
Example #5
0
 internal void ToJson(JsonBuilder json)
 {
     // lines, points, bars: {
     //    show: boolean
     //    lineWidth: number
     //    fill: boolean or number
     //    fillColor: null or color/gradient
     //  }
     json.WriteObject("bars", bars=>bars
         .WritePropertyIf("show", _fields[Field.Show], _fields[Field.Show] != null)
         .WritePropertyIf("lineWidth", _fields[Field.LineWidth], _fields[Field.LineWidth] != null)
         .WritePropertyIf("fill", _fields[Field.Fill], _fields[Field.Fill] != null)
         .WritePropertyIf("fillColor", _fields[Field.FillColor], _fields[Field.FillColor] != null)
     );
 }
Example #6
0
 internal void ToJson(JsonBuilder json)
 {
     // lines, points, bars: {
     //    show: boolean
     //    lineWidth: number
     //    fill: boolean or number
     //    fillColor: null or color/gradient
     //  }
     json.WriteObject("points", points => points
                      .WritePropertyIf("show", _fields[Field.Show], _fields[Field.Show] != null)
                      .WritePropertyIf("lineWidth", _fields[Field.LineWidth], _fields[Field.LineWidth] != null)
                      .WritePropertyIf("fill", _fields[Field.Fill], _fields[Field.Fill] != null)
                      .WritePropertyIf("fillColor", _fields[Field.FillColor], _fields[Field.FillColor] != null)
                      .WritePropertyIf("radius", _fields[Field.Radius], _fields[Field.Radius] != null)
                      );
 }
Example #7
0
        internal void ToJson(JsonBuilder json)
        {
            //legend: {
            //  show: boolean
            //  labelFormatter: null or (fn: string, series object -> string)
            //  labelBoxBorderColor: color
            //  noColumns: number
            //  position: "ne" or "nw" or "se" or "sw"
            //  margin: number of pixels or [x margin, y margin]
            //  backgroundColor: null or color
            //  backgroundOpacity: number between 0 and 1
            //  container: null or jQuery object/DOM element/jQuery expression
            //}

            json.WriteObject("legend", legend => legend
                .WritePropertyIf("show", GetValue(Field.Show), GetValue(Field.Show) != null)
                .WritePropertyIf("position",GetValue(Field.Position), GetValue(Field.Position) != null )
            );
        }
Example #8
0
        internal void ToJson(JsonBuilder json)
        {
            //legend: {
            //  show: boolean
            //  labelFormatter: null or (fn: string, series object -> string)
            //  labelBoxBorderColor: color
            //  noColumns: number
            //  position: "ne" or "nw" or "se" or "sw"
            //  margin: number of pixels or [x margin, y margin]
            //  backgroundColor: null or color
            //  backgroundOpacity: number between 0 and 1
            //  container: null or jQuery object/DOM element/jQuery expression
            //}

            json.WriteObject("legend", legend => legend
                             .WritePropertyIf("show", GetValue(Field.Show), GetValue(Field.Show) != null)
                             .WritePropertyIf("position", GetValue(Field.Position), GetValue(Field.Position) != null)
                             );
        }
Example #9
0
        public void MultipleNamedComplexObjects()
        {
            var json = new JsonBuilder()
                .WriteObject(root => root
                    .WriteObject("object1", obj1 => obj1
                        .WriteProperty("prop1", 1)
                        .WriteProperty("prop2", 2)
                    )
                    .WriteObject("object2", obj2 => obj2
                        .WriteProperty("prop1", 1)
                        .WriteProperty("prop2", 2)
                    )
                ).ToString();

            Assert.AreEqual(
                "{object1:{prop1:1,prop2:2},object2:{prop1:1,prop2:2}}",
                json
            );
        }
Example #10
0
 internal void ToJson(JsonBuilder json)
 {
     json
         .WriteObject("xaxis", xaxis => xaxis
             .WritePropertyIf("mode", GetValue(Field.Mode), GetValue(Field.Mode) != null)
             .WritePropertyIf("timeformat", GetValue(Field.TimeFormat), GetValue(Field.TimeFormat) != null)
             .WritePropertyIf("min", GetValue(Field.Min), GetValue(Field.Min) != null)
             .WritePropertyIf("max", GetValue(Field.Max), GetValue(Field.Max) != null)
         );
 }
Example #11
0
 public string ToJson()
 {
     var json = new JsonBuilder();
     ToJson(json);
     return json.ToString();
 }
Example #12
0
        internal void ToJson(JsonBuilder json)
        {
            json
            //.BeginObject()
            .WritePropertyIf(
                "color",
                _fields.ContainsKey(Field.Color)
                                                        ? _fields[Field.Color]
                                                        : null,
                _fields.ContainsKey(Field.Color)
                )
            .WritePropertyIf(
                "label",
                _fields.ContainsKey(Field.Label)
                                                        ? _fields[Field.Label]
                                                        : null,
                _fields.ContainsKey(Field.Label)
                )
            .WritePropertyIf(
                "xaxis",
                _fields.ContainsKey(Field.XAxis)
                                                        ? _fields[Field.XAxis]
                                                        : null,
                _fields.ContainsKey(Field.XAxis)
                )
            .WritePropertyIf(
                "yaxis",
                _fields.ContainsKey(Field.YAxis)
                                                        ? _fields[Field.YAxis]
                                                        : null,
                _fields.ContainsKey(Field.YAxis)
                )
            .WritePropertyIf(
                "clickable",
                _fields.ContainsKey(Field.Clickable)
                                                        ? _fields[Field.Clickable]
                                                        : null,
                _fields.ContainsKey(Field.Clickable)
                )
            .WritePropertyIf(
                "hoverable",
                _fields.ContainsKey(Field.Hoverable)
                                                        ? _fields[Field.Hoverable]
                                                        : null,
                _fields.ContainsKey(Field.Hoverable)
                )
            .WritePropertyIf(
                "shadowSize",
                _fields.ContainsKey(Field.ShadowSize)
                                                        ? _fields[Field.ShadowSize]
                                                        : null,
                _fields.ContainsKey(Field.ShadowSize)
                );

            if (_lineOptions != null)
            {
                _lineOptions.ToJson(json);
            }

            if (_barOptions != null)
            {
                _barOptions.ToJson(json);
            }

            if (_pointOptions != null)
            {
                _pointOptions.ToJson(json);
            }
        }
Example #13
0
        public void SimpleNamedObject()
        {
            var json = new JsonBuilder()
                .WriteObject( m => m
                    .WriteObject("object1", j => { } )
                )
                .ToString();

            Assert.AreEqual("{object1:{}}", json);
        }
Example #14
0
        internal void ToJson(JsonBuilder json)
        {
            json
                //.BeginObject()
                    .WritePropertyIf(
                        "color",
                        _fields.ContainsKey(Field.Color)
                            ? _fields[Field.Color]
                            : null,
                        _fields.ContainsKey(Field.Color)
                    )
                    .WritePropertyIf(
                        "label",
                        _fields.ContainsKey(Field.Label)
                            ? _fields[Field.Label]
                            : null,
                        _fields.ContainsKey(Field.Label)
                    )
                    .WritePropertyIf(
                        "xaxis",
                        _fields.ContainsKey(Field.XAxis)
                            ? _fields[Field.XAxis]
                            : null,
                        _fields.ContainsKey(Field.XAxis)
                    )
                    .WritePropertyIf(
                        "yaxis",
                        _fields.ContainsKey(Field.YAxis)
                            ? _fields[Field.YAxis]
                            : null,
                        _fields.ContainsKey(Field.YAxis)
                    )
                    .WritePropertyIf(
                        "clickable",
                        _fields.ContainsKey(Field.Clickable)
                            ? _fields[Field.Clickable]
                            : null,
                        _fields.ContainsKey(Field.Clickable)
                    )
                    .WritePropertyIf(
                        "hoverable",
                        _fields.ContainsKey(Field.Hoverable)
                            ? _fields[Field.Hoverable]
                            : null,
                        _fields.ContainsKey(Field.Hoverable)
                    )
                    .WritePropertyIf(
                        "shadowSize",
                        _fields.ContainsKey(Field.ShadowSize)
                            ? _fields[Field.ShadowSize]
                            : null,
                        _fields.ContainsKey(Field.ShadowSize)
                    );

            if (_lineOptions != null)
                _lineOptions.ToJson(json);

            if (_barOptions != null)
                _barOptions.ToJson(json);

            if (_pointOptions != null)
                _pointOptions.ToJson(json);
        }
Example #15
0
        public void NestedNamedObjects()
        {
            var json = new JsonBuilder()
                .WriteObject(root => root
                    .WriteObject("object1", m=>m
                        .WriteProperty("property1", 1)
                        .WriteObject("object1-1",n=>n
                            .WriteProperty("property2",2)
                        )
                    )
                )
                .ToString();

            Assert.AreEqual(
                "{object1:{property1:1,object1-1:{property2:2}}}",
                json
            );
        }
Example #16
0
        public void MultiplePropertiesTest()
        {
            var json = new JsonBuilder()
                .WriteObject( json2 => json2
                    .WriteProperty("property1", 1)
                    .WriteProperty("property2", 2)
                )
                .ToString();

            Assert.AreEqual("{property1:1,property2:2}", json);
        }
Example #17
0
 public void CanCreate()
 {
     var json = new JsonBuilder();
     Assert.IsNotNull(json);
 }
Example #18
0
 public void EmptyBuilder()
 {
     var json = new JsonBuilder().ToString();
     Assert.AreEqual("", json);
 }