1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
//! Mesh plot

use plotly_derive::FieldSetter;
use serde::Serialize;

use crate::common::{
    color::Color, Calendar, ColorBar, ColorScale, Dim, HoverInfo, Label, LegendGroupTitle,
    PlotType, Visible,
};
use crate::private::{NumOrString, NumOrStringCollection};
use crate::Trace;

#[derive(Serialize, Clone, Debug)]
#[serde(rename_all = "lowercase")]
pub enum IntensityMode {
    Vertex,
    Cell,
}

#[derive(Serialize, Clone, Debug)]
#[serde(rename_all = "lowercase")]
pub enum DelaunayAxis {
    X,
    Y,
    Z,
}

#[serde_with::skip_serializing_none]
#[derive(Serialize, Clone, Debug, FieldSetter)]
pub struct Contour {
    /// Sets the color of the contour lines.
    color: Option<Box<dyn Color>>,
    /// Sets whether or not dynamic contours are shown on hover.
    show: Option<bool>,
    /// Sets the width of the contour lines.
    width: Option<usize>,
}

impl Contour {
    pub fn new() -> Self {
        Default::default()
    }
}

#[serde_with::skip_serializing_none]
#[derive(Serialize, Clone, Debug, FieldSetter)]
pub struct Lighting {
    /// Ambient light increases overall color visibility but can wash out the
    /// image.
    ambient: Option<f64>,
    /// Represents the extent that incident rays are reflected in a range of
    /// angles.
    diffuse: Option<f64>,
    #[serde(rename = "facenormalsepsilon")]
    /// Epsilon for face normals calculation avoids math issues arising from
    /// degenerate geometry.
    face_normals_epsilon: Option<f64>,
    /// Represents the reflectance as a dependency of the viewing angle; e.g.
    /// paper is reflective when viewing it from the edge of the paper
    /// (almost 90 degrees), causing shine.
    fresnel: Option<f64>,
    /// Alters specular reflection; the rougher the surface, the wider and less
    /// contrasty the shine.
    roughness: Option<f64>,
    /// Represents the level that incident rays are reflected in a single
    /// direction, causing shine.
    specular: Option<f64>,
    /// Epsilon for vertex normals calculation avoids math issues arising from
    /// degenerate geometry.
    #[serde(rename = "vertexnormalsepsilon")]
    vertex_normals_epsilon: Option<f64>,
}

impl Lighting {
    pub fn new() -> Self {
        Default::default()
    }
}

#[serde_with::skip_serializing_none]
#[derive(Serialize, Clone, Debug, FieldSetter)]
pub struct LightPosition {
    /// Numeric vector, representing the X coordinate for each vertex.
    x: Option<Vec<f64>>,
    /// Numeric vector, representing the Y coordinate for each vertex.
    y: Option<Vec<f64>>,
    /// Numeric vector, representing the Z coordinate for each vertex.
    z: Option<Vec<f64>>,
}

impl LightPosition {
    pub fn new() -> Self {
        Default::default()
    }
}

#[serde_with::skip_serializing_none]
#[derive(Serialize, Clone, Debug, FieldSetter)]
#[field_setter(box_self, kind = "trace")]
pub struct Mesh3D<X, Y, Z>
where
    X: Serialize + Clone,
    Y: Serialize + Clone,
    Z: Serialize + Clone,
{
    #[field_setter(default = "PlotType::Mesh3D")]
    r#type: PlotType,
    /// Sets the trace name. The trace name appear as the legend item and on
    /// hover.
    name: Option<String>,
    /// Determines whether or not this trace is visible. If
    /// `Visible::LegendOnly`, the trace is not drawn, but can appear as a
    /// legend item (provided that the legend itself is visible).
    visible: Option<Visible>,

    /// Determines whether or not an item corresponding to this trace is shown
    /// in the legend.
    #[serde(rename = "showlegend")]
    show_legend: Option<bool>,
    /// Sets the legend rank for this trace. Items and groups with smaller ranks
    /// are presented on top/left side while with `"reversed"
    /// `legend.trace_order` they are on bottom/right side. The default
    /// legendrank is 1000, so that you can use ranks less than 1000 to
    /// place certain items before all unranked items, and ranks greater
    /// than 1000 to go after all unranked items.
    #[serde(rename = "legendrank")]
    legend_rank: Option<usize>,
    /// Sets the legend group for this trace. Traces part of the same legend
    /// group hide/show at the same time when toggling legend items.
    #[serde(rename = "legendgroup")]
    legend_group: Option<String>,
    /// Set and style the title to appear for the legend group
    #[serde(rename = "legendgrouptitle")]
    legend_group_title: Option<LegendGroupTitle>,

    /// Sets the opacity of the trace.
    opacity: Option<f64>,

    /// Assigns id labels to each datum. These ids for object constancy of data
    /// points during animation. Should be an array of strings, not numbers
    /// or any other type.
    ids: Option<Vec<String>>,

    x: Option<Vec<X>>,
    y: Option<Vec<Y>>,
    z: Option<Vec<Z>>,

    i: Option<Vec<usize>>,
    j: Option<Vec<usize>>,
    k: Option<Vec<usize>>,

    /// Sets the color of each face. Overrides "color" and "vertexcolor".
    #[serde(rename = "facecolor")]
    face_color: Option<Vec<Box<dyn Color>>>,
    /// Sets the intensity values for vertices or cells as defined by
    /// `IntensityMode`. It can be used for plotting fields on meshes.
    intensity: Option<Vec<f64>>,
    #[serde(rename = "intensitymode")]
    /// Determines the source of `intensity` values.
    intensity_mode: Option<IntensityMode>,
    /// Sets the color of each vertex Overrides "color". While Red, green and
    /// blue colors are in the range of 0 and 255; in the case of having
    /// vertex color data in RGBA format, the alpha color should be normalized
    /// to be between 0 and 1.
    #[serde(rename = "vertexcolor")]
    vertex_color: Option<Vec<Box<dyn Color>>>,

    /// Sets text elements associated with each (x,y) pair. If a single string,
    /// the same string appears over all the data points. If an array of
    /// strings, the items are mapped in order to the this trace's (x,y)
    /// coordinates. If the trace `HoverInfo` contains a "text" flag and
    /// `hover_text` is not set, these elements will be seen in the hover
    /// labels.
    text: Option<Dim<String>>,
    /// Sets hover text elements associated with each (x,y) pair. If a single
    /// string, the same string appears over all the data points. If an
    /// array of strings, the items are mapped in order to the this trace's
    /// (x,y) coordinates. To be seen, trace `HoverInfo` must contain a
    /// "Text" flag.
    #[serde(rename = "hovertext")]
    hover_text: Option<Dim<String>>,
    /// Determines which trace information appear on hover. If `HoverInfo::None`
    /// or `HoverInfo::Skip` are set, no information is displayed upon
    /// hovering. But, if `HoverInfo::None` is set, click and hover events
    /// are still fired.
    #[serde(rename = "hoverinfo")]
    hover_info: Option<HoverInfo>,
    /// Template string used for rendering the information that appear on hover
    /// box. Note that this will override `HoverInfo`. Variables are
    /// inserted using %{variable}, for example "y: %{y}". Numbers are
    /// formatted using d3-format's syntax %{variable:d3-format}, for example
    /// "Price: %{y:$.2f}".
    /// https://github.com/d3/d3-3.x-api-reference/blob/master/Formatting.md#d3_format for details
    /// on the formatting syntax. Dates are formatted using d3-time-format's
    /// syntax %{variable|d3-time-format}, for example "Day:
    /// %{2019-01-01|%A}". https://github.com/d3/d3-3.x-api-reference/blob/master/Time-Formatting.md#format for details
    /// on the date formatting syntax. The variables available in
    /// `hovertemplate` are the ones emitted as event data described at this link https://plotly.com/javascript/plotlyjs-events/#event-data.
    /// Additionally, every attributes that can be specified per-point (the ones
    /// that are `arrayOk: true`) are available. Anything contained in tag
    /// `<extra>` is displayed in the secondary box, for example
    /// "<extra>{fullData.name}</extra>". To hide the secondary box
    /// completely, use an empty tag `<extra></extra>`.
    #[serde(rename = "hovertemplate")]
    hover_template: Option<Dim<String>>,
    /// Sets the hover text formatting rulefor `x` using d3 formatting
    /// mini-languages which are very similar to those in Python. For numbers, see: https://github.com/d3/d3-format/tree/v1.4.5#d3-format. And for dates
    /// see: https://github.com/d3/d3-time-format/tree/v2.2.3#locale_format. We add two items to d3's date
    /// formatter: "%h" for half of the year as a decimal number as well as
    /// "%{n}f" for fractional seconds with n digits. For example,
    /// "2016-10-13 09:15:23.456" with tickformat "%H~%M~%S.%2f" would display
    /// "09~15~23.46"By default the values are formatted using
    /// `xaxis.hoverformat`.
    #[serde(rename = "xhoverformat")]
    x_hover_format: Option<String>,
    /// Sets the hover text formatting rulefor `y` using d3 formatting
    /// mini-languages which are very similar to those in Python. For numbers, see: https://github.com/d3/d3-format/tree/v1.4.5#d3-format. And for dates
    /// see: https://github.com/d3/d3-time-format/tree/v2.2.3#locale_format. We add two items to d3's date
    /// formatter: "%h" for half of the year as a decimal number as well as
    /// "%{n}f" for fractional seconds with n digits. For example,
    /// "2016-10-13 09:15:23.456" with tickformat "%H~%M~%S.%2f" would display
    /// "09~15~23.46"By default the values are formatted using
    /// `yaxis.hoverformat`.
    #[serde(rename = "yhoverformat")]
    y_hover_format: Option<String>,

    /// Assigns extra meta information associated with this trace that can be
    /// used in various text attributes. Attributes such as trace `name`,
    /// graph, axis and colorbar `title.text`, annotation `text`
    /// `rangeselector`, `updatemenues` and `sliders` `label` text all support
    /// `meta`. To access the trace `meta` values in an attribute in the same
    /// trace, simply use `%{meta[i]}` where `i` is the index or key of the
    /// `meta` item in question. To access trace `meta` in layout
    /// attributes, use `%{data[n[.meta[i]}` where `i` is the index or key of
    /// the `meta` and `n` is the trace index.
    meta: Option<NumOrString>,
    /// Assigns extra data each datum. This may be useful when listening to
    /// hover, click and selection events. Note that, "scatter" traces also
    /// appends customdata items in the markers DOM elements.
    #[serde(rename = "customdata")]
    custom_data: Option<NumOrStringCollection>,

    /// Sets a reference between this trace's 3D coordinate system and a 3D
    /// scene. If "scene" (the default value), the (x,y,z) coordinates refer
    /// to `layout.scene`. If "scene2", the (x, y, z) coordinates refer to
    /// `layout.scene2`, and so on.
    scene: Option<String>,
    /// Sets a reference to a shared color axis. References to these shared
    /// color axes are "coloraxis", "coloraxis2", "coloraxis3", etc.
    /// Settings for these shared color axes are set in the layout, under
    /// `layout.coloraxis`, `layout.coloraxis2`, etc. Note that multiple color
    /// scales can be linked to the same color axis.
    #[serde(rename = "coloraxis")]
    color_axis: Option<String>,
    /// Sets the color of the whole mesh.
    color: Option<Box<dyn Color>>,

    #[serde(rename = "colorbar")]
    color_bar: Option<ColorBar>,

    /// Determines whether the colorscale is a default palette (`autocolorscale:
    /// True`) or the palette determined by `colorscale`. In case
    /// `colorscale` is unspecified or `autocolorscale` is True, the default
    /// palette will be chosen according to whether numbers in the `color`
    /// array are all positive, all negative or mixed.
    #[serde(rename = "autocolorscale")]
    auto_color_scale: Option<bool>,
    /// Sets the colorscale. The colorscale must be an array containing arrays
    /// mapping a normalized value to an rgb, rgba, hex, hsl, hsv, or named
    /// color string. At minimum, a mapping for the lowest (0) and highest (1)
    /// values are required. For example, `[[0, 'rgb(0,0,255)'], [1,
    /// 'rgb(255,0,0)']]`. To control the bounds of the colorscale in color
    /// space, use `cmin` and `cmax`. Alternatively, `colorscale` may be a
    /// palette name string of the following list:
    /// Blackbody,Bluered,Blues,Cividis,Earth,Electric,Greens,Greys,Hot,Jet,
    /// Picnic, Portland,Rainbow,RdBu,Reds,Viridis,YlGnBu,YlOrRd.
    #[serde(rename = "colorscale")]
    color_scale: Option<ColorScale>,
    /// Determines whether or not a colorbar is displayed for this trace.
    #[serde(rename = "showscale")]
    show_scale: Option<bool>,
    /// Reverses the color mapping if True. If True, `cmin` will correspond to
    /// the last color in the array and `cmax` will correspond to the first
    /// color.
    #[serde(rename = "reversescale")]
    reverse_scale: Option<bool>,

    /// Sets the hover text formatting rulefor `z` using d3 formatting
    /// mini-languages which are very similar to those in Python. For numbers, see: https://github.com/d3/d3-format/tree/v1.4.5#d3-format. And for dates
    /// see: https://github.com/d3/d3-time-format/tree/v2.2.3#locale_format. We add two items to d3's date
    /// formatter: "%h" for half of the year as a decimal number as well as
    /// "%{n}f" for fractional seconds with n digits. For example,
    /// "2016-10-13 09:15:23.456" with tickformat "%H~%M~%S.%2f" would display
    /// "09~15~23.46". By default the values are formatted using
    /// `zaxis.hoverformat`.
    #[serde(rename = "zhoverformat")]
    z_hover_format: Option<String>,

    /// Determines whether or not the color domain is computed with respect to
    /// the input data (here `intensity`) or the bounds set in `cmin` and
    /// `cmax` Defaults to `False` when `cmin` and `cmax` are set by the user.
    #[serde(rename = "cauto")]
    c_auto: Option<bool>,
    /// Sets the upper bound of the color domain. Value should have the same
    /// units as `intensity` and if set, `cmin` must be set as well.
    #[serde(rename = "cmax")]
    c_max: Option<f64>,
    /// Sets the mid-point of the color domain by scaling `cmin` and/or `cmax`
    /// to be equidistant to this point. Value should have the same units as
    /// `intensity`. Has no effect when `cauto` is `False`.
    #[serde(rename = "cmid")]
    c_mid: Option<f64>,
    /// Sets the lower bound of the color domain. Value should have the same
    /// units as `intensity` and if set, `cmax` must be set as well.
    #[serde(rename = "cmin")]
    c_min: Option<f64>,
    /// Determines how the mesh surface triangles are derived from the set of
    /// vertices (points) represented by the `x`, `y` and `z` arrays, if the
    /// `i`, `j`, `k` arrays are not supplied. For general use of `mesh3d` it is
    /// preferred that `i`, `j`, `k` are supplied. If "-1", Delaunay
    /// triangulation is used, which is mainly suitable if the mesh is a
    /// single, more or less layer surface that is perpendicular to
    /// `delaunayaxis`. In case the `delaunayaxis` intersects the mesh
    /// surface at more than one point it will result triangles that
    /// are very long in the dimension of `delaunayaxis`. If ">0", the
    /// alpha-shape algorithm is used. In this case, the positive
    /// `alphahull` value signals the use of the alpha-shape algorithm, _and_
    /// its value acts as the parameter for the mesh fitting. If "0", the
    /// convex-hull algorithm is used. It is suitable for convex
    /// bodies or if the intention is to enclose the `x`, `y` and `z` point set
    /// into a convex hull.
    #[serde(rename = "alphahull")]
    alpha_hull: Option<f64>,
    /// Sets the Delaunay axis, which is the axis that is perpendicular to the
    /// surface of the Delaunay triangulation. It has an effect if `i`, `j`,
    /// `k` are not provided and `alphahull` is set to indicate
    /// Delaunay triangulation.
    #[serde(rename = "delaunayaxis")]
    delaunay_axis: Option<DelaunayAxis>,
    contour: Option<Contour>,

    /// Determines whether or not normal smoothing is applied to the meshes,
    /// creating meshes with an angular, low-poly look via flat reflections.
    #[serde(rename = "flatshading")]
    flat_shading: Option<bool>,

    /// Properties of label displayed on mouse hover.
    #[serde(rename = "hoverlabel")]
    hover_label: Option<Label>,

    lighting: Option<Lighting>,
    #[serde(rename = "lightposition")]
    light_position: Option<LightPosition>,

    /// Sets the calendar system to use with `x` date data.
    #[serde(rename = "xcalendar")]
    x_calendar: Option<Calendar>,
    /// Sets the calendar system to use with `y` date data.
    #[serde(rename = "ycalendar")]
    y_calendar: Option<Calendar>,
    /// Sets the calendar system to use with `z` date data.
    #[serde(rename = "zcalendar")]
    z_calendar: Option<Calendar>,

    /// Controls persistence of some user-driven changes to the trace:
    /// `constraintrange` in `parcoords` traces, as well as some `editable:
    /// True` modifications such as `name` and `colorbar.title`. Defaults to
    /// `layout.uirevision`. Note that other user-driven trace attribute changes
    /// are controlled by `layout` attributes: `trace.visible` is controlled
    /// by `layout.legend.uirevision`, `selectedpoints` is controlled
    /// by `layout.selectionrevision`, and `colorbar.(x|y)` (accessible with
    /// `config: {editable: True}`) is controlled by `layout.editrevision`.
    /// Trace changes are tracked by `uid`, which only falls back on trace
    /// index if no `uid` is provided. So if your app can add/remove traces
    /// before the end of the `data` array, such that the same trace has a
    /// different index, you can still preserve user-driven changes if you give
    /// each trace a `uid` that stays with it as it moves.
    #[serde(rename = "uirevision")]
    ui_revision: Option<NumOrString>,
}

impl<X, Y, Z> Mesh3D<X, Y, Z>
where
    X: Serialize + Default + Clone,
    Y: Serialize + Default + Clone,
    Z: Serialize + Default + Clone,
{
    pub fn new(
        x: Vec<X>,
        y: Vec<Y>,
        z: Vec<Z>,
        i: Vec<usize>,
        j: Vec<usize>,
        k: Vec<usize>,
    ) -> Box<Self> {
        Box::new(Self {
            x: Some(x),
            y: Some(y),
            z: Some(z),
            i: Some(i),
            j: Some(j),
            k: Some(k),
            ..Default::default()
        })
    }
}

impl<X, Y, Z> Trace for Mesh3D<X, Y, Z>
where
    X: Serialize + Clone,
    Y: Serialize + Clone,
    Z: Serialize + Clone,
{
    fn to_json(&self) -> String {
        serde_json::to_string(&self).unwrap()
    }
}

#[cfg(test)]
mod tests {
    use serde_json::{json, to_value};

    use super::*;
    use crate::common::ColorScalePalette;

    #[test]
    fn test_serialize_intensity_mode() {
        assert_eq!(to_value(IntensityMode::Vertex).unwrap(), json!("vertex"));
        assert_eq!(to_value(IntensityMode::Cell).unwrap(), json!("cell"));
    }

    #[test]
    fn test_serialize_delaunay_axis() {
        assert_eq!(to_value(DelaunayAxis::X).unwrap(), json!("x"));
        assert_eq!(to_value(DelaunayAxis::Y).unwrap(), json!("y"));
        assert_eq!(to_value(DelaunayAxis::Z).unwrap(), json!("z"));
    }

    #[test]
    fn test_serialize_contour() {
        let contour = Contour::new().color("#123456").show(true).width(6);
        let expected = json!({"color": "#123456", "show": true, "width": 6});

        assert_eq!(to_value(contour).unwrap(), expected);
    }

    #[test]
    fn test_serialize_lighting() {
        let lighting = Lighting::new()
            .ambient(0.1)
            .diffuse(0.2)
            .face_normals_epsilon(0.3)
            .fresnel(0.4)
            .roughness(0.5)
            .specular(0.6)
            .vertex_normals_epsilon(0.7);
        let expected = json!({
            "ambient": 0.1,
            "diffuse": 0.2,
            "facenormalsepsilon": 0.3,
            "fresnel": 0.4,
            "roughness": 0.5,
            "specular": 0.6,
            "vertexnormalsepsilon": 0.7,
        });

        assert_eq!(to_value(lighting).unwrap(), expected);
    }

    #[test]
    fn test_serialize_light_position() {
        let light_position = LightPosition::new()
            .x(vec![10.0])
            .y(vec![20.0])
            .z(vec![30.0]);
        let expected = json!({"x": [10.0], "y": [20.0], "z": [30.0]});

        assert_eq!(to_value(light_position).unwrap(), expected);
    }

    #[test]
    fn test_serialize_mesh3d() {
        let mesh3d = Mesh3D::new(
            vec![0.0, 1.0, 2.0],
            vec![3.0, 4.0, 5.0],
            vec![6.0, 7.0, 8.0],
            vec![0],
            vec![1],
            vec![2],
        )
        .name("trace_name")
        .visible(Visible::True)
        .show_legend(true)
        .legend_rank(1000)
        .legend_group("legend_group")
        .legend_group_title(LegendGroupTitle::new("Legend Group Title"))
        .opacity(0.5)
        .ids(vec!["one"])
        .face_color(vec!["#ff00ff"])
        .intensity(vec![1.0])
        .intensity_mode(IntensityMode::Vertex)
        .vertex_color(vec!["#ff0000", "#00ff00", "#0000ff"])
        .text("text")
        .text_array(vec!["text"])
        .hover_text("hover_text")
        .hover_text_array(vec!["hover_text"])
        .hover_info(HoverInfo::XAndYAndZ)
        .hover_template("hover_template")
        .hover_template_array(vec!["hover_template"])
        .x_hover_format("x_hover_format")
        .y_hover_format("y_hover_format")
        .meta("meta")
        .custom_data(vec!["custom_data"])
        .scene("scene2")
        .color_axis("coloraxis2")
        .color("#cccccc")
        .color_bar(ColorBar::new())
        .auto_color_scale(false)
        .color_scale(ColorScale::Palette(ColorScalePalette::Rainbow))
        .show_scale(true)
        .reverse_scale(true)
        .z_hover_format("z_hover_format")
        .c_auto(false)
        .c_max(1.0)
        .c_min(0.0)
        .c_mid(0.2)
        .alpha_hull(7.5)
        .delaunay_axis(DelaunayAxis::Y)
        .contour(Contour::new())
        .flat_shading(true)
        .hover_label(Label::new())
        .lighting(Lighting::new())
        .light_position(LightPosition::new())
        .x_calendar(Calendar::Chinese)
        .y_calendar(Calendar::Coptic)
        .z_calendar(Calendar::Ummalqura)
        .ui_revision(2.5);

        let expected = json!({
            "type": "mesh3d",
            "x": [0.0, 1.0, 2.0],
            "y": [3.0, 4.0, 5.0],
            "z": [6.0, 7.0, 8.0],
            "i": [0],
            "j": [1],
            "k": [2],
            "name": "trace_name",
            "visible": true,
            "showlegend": true,
            "legendrank": 1000,
            "legendgroup": "legend_group",
            "legendgrouptitle": {"text": "Legend Group Title"},
            "opacity": 0.5,
            "ids": ["one"],
            "facecolor": ["#ff00ff"],
            "intensity": [1.0],
            "intensitymode": "vertex",
            "vertexcolor": ["#ff0000", "#00ff00", "#0000ff"],
            "text": ["text"],
            "hovertext": ["hover_text"],
            "hoverinfo": "x+y+z",
            "hovertemplate": ["hover_template"],
            "xhoverformat": "x_hover_format",
            "yhoverformat": "y_hover_format",
            "meta": "meta",
            "customdata": ["custom_data"],
            "scene": "scene2",
            "coloraxis": "coloraxis2",
            "color": "#cccccc",
            "colorbar": {
            },
            "autocolorscale": false,
            "colorscale": "Rainbow",
            "showscale": true,
            "reversescale": true,
            "zhoverformat": "z_hover_format",
            "cauto": false,
            "cmax": 1.0,
            "cmin": 0.0,
            "cmid": 0.2,
            "alphahull": 7.5,
            "delaunayaxis": "y",
            "contour": {},
            "flatshading": true,
            "hoverlabel": {},
            "lighting": {},
            "lightposition": {},
            "xcalendar": "chinese",
            "ycalendar": "coptic",
            "zcalendar": "ummalqura",
            "uirevision": 2.5
        });

        assert_eq!(to_value(mesh3d).unwrap(), expected);
    }
}