MCPcopy Create free account
hub / github.com/plotly/plotly.py / _merge_2_templates

Method _merge_2_templates

plotly/io/_templates.py:225–264  ·  view source on GitHub ↗

Helper function for merge_templates that merges exactly two templates Parameters ---------- template1: Template template2: Template Returns ------- Template: merged template

(self, template1, template2)

Source from the content-addressed store, hash-verified

223 return Template()
224
225 def _merge_2_templates(self, template1, template2):
226 """
227 Helper function for merge_templates that merges exactly two templates
228
229 Parameters
230 ----------
231 template1: Template
232 template2: Template
233
234 Returns
235 -------
236 Template:
237 merged template
238 """
239 # Validate/copy input templates
240 result = self._validate(template1)
241 other = self._validate(template2)
242
243 # Cycle traces
244 for trace_type in result.data:
245 result_traces = result.data[trace_type]
246 other_traces = other.data[trace_type]
247
248 if result_traces and other_traces:
249 lcm = (
250 len(result_traces)
251 * len(other_traces)
252 // gcd(len(result_traces), len(other_traces))
253 )
254
255 # Cycle result traces
256 result.data[trace_type] = result_traces * (lcm // len(result_traces))
257
258 # Cycle other traces
259 other.data[trace_type] = other_traces * (lcm // len(other_traces))
260
261 # Perform update
262 result.update(other)
263
264 return result
265
266
267# Make config a singleton object

Callers

nothing calls this directly

Calls 2

_validateMethod · 0.95
updateMethod · 0.45

Tested by

no test coverage detected