From 58e37d5efa982d85a323bdf1ad73d411b7376fb8 Mon Sep 17 00:00:00 2001 From: michaelbabyn Date: Fri, 5 Oct 2018 12:20:07 -0400 Subject: [PATCH 1/2] add makeTemplate and validateTemplate to plotly_js function reference. --- .../2016-06-03-plotly_js_function_ref.html | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/_posts/reference_pages/2016-06-03-plotly_js_function_ref.html b/_posts/reference_pages/2016-06-03-plotly_js_function_ref.html index f1bb36c44937..665e537be7b5 100644 --- a/_posts/reference_pages/2016-06-03-plotly_js_function_ref.html +++ b/_posts/reference_pages/2016-06-03-plotly_js_function_ref.html @@ -361,6 +361,77 @@

+

Plotly.makeTemplate

+ +Plotly.makeTemplate copies the style information from a figure. It does this by returning a template object which can be passed to the layout.template attribute of another figure. +

+
+Signature +
+
Plotly.makeTemplate(figure)
+
+
+
figure
+
a plot object, with {data, layout} members +
+
+
+
+

+ +

+var figure = {
+  data: [{
+    type: 'bar',
+    marker: {color: 'red'},
+    y: [2, 1, 3, 2],
+  }],
+  layout:{
+    title: 'Quarterly Earnings'
+  }
+};
+
+var template = Plotly.makeTemplate(figure);
+
+newData = [{
+  type:'bar',
+  y:[3,2,5,8]
+}]
+layoutTemplate = {template:template}
+
+Plotly.newPlot(graphDiv,newData,layoutTemplate)
+
+
+ +

Plotly.validateTemplate

+ +Plotly.validateTemplate allows users to Test for consistency between the given figure and a template, +either already included in the figure or given separately. Note that not every issue identified here is necessarily +a problem, it depends on what you're using the template for. +

+
+Signature +
+
Plotly.validateTemplate(figure, template)
+
+
+
figure
+
a plot object, with {data, layout} members +
template
+
the template, with its own {data, layout}, to test. + If omitted, we will look for a template already attached as + the plot's layout.template attribute. +
+
+
+
+

+ +

+var out = Plotly.validateTemplate(figure, template);
+console.log(out[0].msg)
+// "The template has 1 traces of type bar but there are none in the data."
+

Plotly.addTraces

This function has comparable performance to Plotly.react and is faster than redrawing the whole plot with Plotly.newPlot.

From 757583cf197712f08b4d0af38ece7277324a2563 Mon Sep 17 00:00:00 2001 From: michaelbabyn Date: Wed, 17 Oct 2018 15:17:17 -0400 Subject: [PATCH 2/2] add DOM to validateTemplate call sig. better variable name in makeTemplate example --- .../reference_pages/2016-06-03-plotly_js_function_ref.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/_posts/reference_pages/2016-06-03-plotly_js_function_ref.html b/_posts/reference_pages/2016-06-03-plotly_js_function_ref.html index 665e537be7b5..802303948742 100644 --- a/_posts/reference_pages/2016-06-03-plotly_js_function_ref.html +++ b/_posts/reference_pages/2016-06-03-plotly_js_function_ref.html @@ -397,7 +397,7 @@