topologicpy 0.7.71__py3-none-any.whl → 0.7.73__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
topologicpy/Plotly.py CHANGED
@@ -278,21 +278,35 @@ class Plotly:
278
278
  sides: int = 8,
279
279
  angle: float = 0,
280
280
  vertexColor: str = "black",
281
+ vertexColorKey: str = None,
281
282
  vertexSize: float = 6,
283
+ vertexSizeKey: str = None,
282
284
  vertexLabelKey: str = None,
283
285
  vertexGroupKey: str = None,
284
286
  vertexGroups: list = [],
287
+ vertexMinGroup = None,
288
+ vertexMaxGroup = None,
285
289
  showVertices: bool = True,
286
- showVertexLabels: bool = False,
290
+ showVertexLabel: bool = False,
287
291
  showVertexLegend: bool = False,
292
+ vertexLegendLabel="Graph Vertices",
293
+ vertexLegendRank=4,
294
+ vertexLegendGroup=4,
288
295
  edgeColor: str = "black",
296
+ edgeColorKey: str = None,
289
297
  edgeWidth: float = 1,
298
+ edgeWidthKey: str = None,
290
299
  edgeLabelKey: str = None,
291
300
  edgeGroupKey: str = None,
292
301
  edgeGroups: list = [],
302
+ edgeMinGroup = None,
303
+ edgeMaxGroup = None,
293
304
  showEdges: bool = True,
294
- showEdgeLabels: bool = False,
305
+ showEdgeLabel: bool = False,
295
306
  showEdgeLegend: bool = False,
307
+ edgeLegendLabel="Graph Edges",
308
+ edgeLegendRank=2,
309
+ edgeLegendGroup=2,
296
310
  colorScale: str = "viridis",
297
311
  mantissa: int = 6,
298
312
  silent: bool = False):
@@ -318,6 +332,8 @@ class Plotly:
318
332
  - An hsv/hsva string (e.g. 'hsv(0,100%,100%)')
319
333
  - A named CSS color.
320
334
  The default is "black".
335
+ vertexColorKey : str , optional
336
+ The dictionary key under which to find the vertex color. The default is None.
321
337
  vertexSize : float , optional
322
338
  The desired size of the vertices. The default is 6.
323
339
  vertexLabelKey : str , optional
@@ -326,12 +342,22 @@ class Plotly:
326
342
  The dictionary key to use to display the vertex group. The default is None.
327
343
  vertexGroups : list , optional
328
344
  The list of vertex groups against which to index the color of the vertex. The default is [].
345
+ vertexMinGroup : int or float , optional
346
+ For numeric vertexGroups, vertexMinGroup is the desired minimum value for the scaling of colors. This should match the type of value associated with the vertexGroupKey. If set to None, it is set to the minimum value in vertexGroups. The default is None.
347
+ vertexMaxGroup : int or float , optional
348
+ For numeric vertexGroups, vertexMaxGroup is the desired maximum value for the scaling of colors. This should match the type of value associated with the vertexGroupKey. If set to None, it is set to the maximum value in vertexGroups. The default is None.
329
349
  showVertices : bool , optional
330
350
  If set to True the vertices will be drawn. Otherwise, they will not be drawn. The default is True.
331
351
  showVertexLabels : bool , optional
332
352
  If set to True, the vertex labels are shown permenantely on screen. Otherwise, they are not. The default is False.
333
353
  showVertexLegend : bool , optional
334
354
  If set to True the vertex legend will be drawn. Otherwise, it will not be drawn. The default is False.
355
+ vertexLegendLabel : str , optional
356
+ The legend label string used to identify vertices. The default is "Topology Vertices".
357
+ vertexLegendRank : int , optional
358
+ The legend rank order of the vertices of this topology. The default is 1.
359
+ vertexLegendGroup : int , optional
360
+ The number of the vertex legend group to which the vertices of this topology belong. The default is 1.
335
361
  edgeColor : str , optional
336
362
  The desired color of the output edges. This can be any plotly color string and may be specified as:
337
363
  - A hex string (e.g. '#ff0000')
@@ -340,8 +366,12 @@ class Plotly:
340
366
  - An hsv/hsva string (e.g. 'hsv(0,100%,100%)')
341
367
  - A named CSS color.
342
368
  The default is "black".
369
+ edgeColorKey : str , optional
370
+ The dictionary key under which to find the edge color. The default is None.
343
371
  edgeWidth : float , optional
344
372
  The desired thickness of the output edges. The default is 1.
373
+ edgeWidthKey : str , optional
374
+ The dictionary key under which to find the edge width. The default is None.
345
375
  edgeLabelKey : str , optional
346
376
  The dictionary key to use to display the edge label. The default is None.
347
377
  edgeGroupKey : str , optional
@@ -368,6 +398,7 @@ class Plotly:
368
398
  from topologicpy.Vertex import Vertex
369
399
  from topologicpy.Edge import Edge
370
400
  from topologicpy.Wire import Wire
401
+ from topologicpy.Cluster import Cluster
371
402
  from topologicpy.Dictionary import Dictionary
372
403
  from topologicpy.Topology import Topology
373
404
  from topologicpy.Graph import Graph
@@ -376,83 +407,40 @@ class Plotly:
376
407
 
377
408
  if not Topology.IsInstance(graph, "Graph"):
378
409
  return None
379
- v_labels = []
380
- v_groupList = []
381
410
  data = []
382
411
 
383
412
  if showVertices:
384
413
  vertices = Graph.Vertices(graph)
385
- if vertexLabelKey or vertexGroupKey:
386
- for v in vertices:
387
- Xn=[Vertex.X(v, mantissa=mantissa) for v in vertices] # x-coordinates of nodes
388
- Yn=[Vertex.Y(v, mantissa=mantissa) for v in vertices] # y-coordinates of nodes
389
- Zn=[Vertex.Z(v, mantissa=mantissa) for v in vertices] # x-coordinates of nodes
390
- v_label = ""
391
- v_group = ""
392
- d = Topology.Dictionary(v)
393
- if d:
394
- if vertexLabelKey:
395
- v_label = str(Dictionary.ValueAtKey(d, key=vertexLabelKey))
396
- if v_label == None:
397
- v_label = ""
398
- if vertexGroupKey:
399
- v_group = Dictionary.ValueAtKey(d, key=vertexGroupKey)
400
- if v_group == None:
401
- v_group = ""
402
- try:
403
- v_groupList.append(vertexGroups.index(v_group))
404
- except:
405
- v_groupList.append(len(vertexGroups))
406
- v_labels.append(v_label)
407
- else:
408
- for v in vertices:
409
- Xn=[Vertex.X(v, mantissa=mantissa) for v in vertices] # x-coordinates of nodes
410
- Yn=[Vertex.Y(v, mantissa=mantissa) for v in vertices] # y-coordinates of nodes
411
- Zn=[Vertex.Z(v, mantissa=mantissa) for v in vertices] # x-coordinates of nodes
412
- if len(v_labels) < 1:
413
- v_labels = ""
414
- if showVertexLabels == True:
415
- mode = "markers+text"
416
- else:
417
- mode = "markers"
418
- normalized_categories = vertexColor # Start with the default vertexColor
419
- if len(vertexGroups) > 0:
420
- # Normalize categories to a range between 0 and 1 for the color scale
421
- min_category = 0
422
- max_category = max(len(vertexGroups), 1)
423
- normalized_categories = [(cat - min_category) / (max_category - min_category) for cat in v_groupList]
424
- v_trace=go.Scatter3d(x=Xn,
425
- y=Yn,
426
- z=Zn,
427
- mode=mode,
428
- name='Graph Vertices',
429
- legendgroup=4,
430
- legendrank=4,
431
- showlegend=showVertexLegend,
432
- marker=dict(symbol='circle',
433
- size=vertexSize,
434
- color=normalized_categories,
435
- colorscale=Plotly.ColorScale(colorScale),
436
- cmin = 0,
437
- cmax=1,
438
- line=dict(color=edgeColor, width=0.5)
439
- ),
440
- text=v_labels,
441
- hoverinfo='text'
442
- )
443
- data.append(v_trace)
414
+ v_dictionaries = [Topology.Dictionary(v) for v in vertices]
415
+ e_cluster = Cluster.ByTopologies(vertices)
416
+ geo = Topology.Geometry(e_cluster, mantissa=mantissa)
417
+ vertices = geo['vertices']
418
+ v_data = Plotly.DataByTopology(e_cluster,
419
+ vertexColor=vertexColor,
420
+ vertexColorKey=vertexColorKey,
421
+ vertexSize=vertexSize,
422
+ vertexSizeKey=vertexSizeKey,
423
+ vertexLabelKey=vertexLabelKey,
424
+ showVertexLabel=showVertexLabel,
425
+ vertexGroupKey=vertexGroupKey,
426
+ vertexMinGroup=vertexMinGroup,
427
+ vertexMaxGroup=vertexMaxGroup,
428
+ vertexGroups=vertexGroups,
429
+ vertexLegendLabel=vertexLegendLabel,
430
+ vertexLegendGroup=vertexLegendGroup,
431
+ vertexLegendRank=vertexLegendRank,
432
+ colorScale=colorScale)
433
+
434
+ data += v_data
444
435
 
445
436
  if showEdges:
446
- Xe=[]
447
- Ye=[]
448
- Ze=[]
449
- e_labels = []
450
- e_groupList = []
437
+ e_dictionaries = []
451
438
  edges = Graph.Edges(graph)
452
439
  new_edges = []
453
- if sagitta > 0:
454
- for edge in edges:
455
- d = Topology.Dictionary(edge)
440
+ # if sagitta > 0:
441
+ for edge in edges:
442
+ d = Topology.Dictionary(edge)
443
+ if sagitta > 0:
456
444
  arc = Wire.ArcByEdge(edge, sagitta=sagitta, absolute=absolute, sides=sides, close=False, silent=silent)
457
445
  if Topology.IsInstance(arc, "Wire"):
458
446
  if not angle == 0:
@@ -462,98 +450,263 @@ class Plotly:
462
450
  for arc_edge in arc_edges:
463
451
  arc_edge = Topology.SetDictionary(arc_edge, d, silent=True)
464
452
  new_edges.append(arc_edge)
453
+ e_dictionaries.append(d)
465
454
  else:
466
455
  new_edges.append(edge)
456
+ e_dictionaries.append(d)
457
+
458
+ else:
459
+ new_edges = edges
460
+ e_dictionaries.append(d)
461
+
462
+ e_cluster = Cluster.ByTopologies(new_edges)
463
+ geo = Topology.Geometry(e_cluster, mantissa=mantissa)
464
+ vertices = geo['vertices']
465
+ edges = geo['edges']
466
+ data.extend(Plotly.edgeData(vertices, edges, dictionaries=e_dictionaries, color=edgeColor, colorKey=edgeColorKey, width=edgeWidth, widthKey=edgeWidthKey, labelKey=edgeLabelKey, showEdgeLabel=showEdgeLabel, groupKey=edgeGroupKey, minGroup=edgeMinGroup, maxGroup=edgeMaxGroup, groups=edgeGroups, legendLabel=edgeLegendLabel, legendGroup=edgeLegendGroup, legendRank=edgeLegendRank, showLegend=showEdgeLegend, colorScale=colorScale))
467
+ return data
468
+
469
+ @staticmethod
470
+ def vertexData(vertices, dictionaries=[], color="black", colorKey=None, size=1.1, sizeKey=None, labelKey=None, showVertexLabel = False, groupKey=None, minGroup=None, maxGroup=None, groups=[], legendLabel="Topology Vertices", legendGroup=1, legendRank=1, showLegend=True, colorScale="Viridis"):
471
+ from topologicpy.Dictionary import Dictionary
472
+ from topologicpy.Color import Color
473
+ x = []
474
+ y = []
475
+ z = []
476
+ sizeList = []
477
+ labels = []
478
+ groupList = []
479
+ label = ""
480
+ group = None
481
+ if colorKey or sizeKey or labelKey or groupKey:
482
+ if groups:
483
+ if len(groups) > 0:
484
+ if type(groups[0]) == int or type(groups[0]) == float:
485
+ if not minGroup:
486
+ minGroup = min(groups)
487
+ if not maxGroup:
488
+ maxGroup = max(groups)
489
+ else:
490
+ minGroup = 0
491
+ maxGroup = len(groups) - 1
467
492
  else:
468
- new_edges = edges
469
-
470
- if edgeLabelKey or edgeGroupKey:
471
- for e in new_edges:
472
- sv = Edge.StartVertex(e)
473
- ev = Edge.EndVertex(e)
474
- Xe+=[Vertex.X(sv, mantissa=mantissa), Vertex.X(ev, mantissa=mantissa), None] # x-coordinates of edge ends
475
- Ye+=[Vertex.Y(sv, mantissa=mantissa), Vertex.Y(ev, mantissa=mantissa), None] # y-coordinates of edge ends
476
- Ze+=[Vertex.Z(sv, mantissa=mantissa), Vertex.Z(ev, mantissa=mantissa), None] # z-coordinates of edge ends
477
- e_label = ""
478
- e_group = ""
479
- d = Topology.Dictionary(e)
493
+ minGroup = 0
494
+ maxGroup = 1
495
+ for m, v in enumerate(vertices):
496
+ x.append(v[0])
497
+ y.append(v[1])
498
+ z.append(v[2])
499
+ label = ""
500
+ group = None
501
+ if len(dictionaries) > 0:
502
+ d = dictionaries[m]
480
503
  if d:
481
- if not edgeLabelKey == None:
482
- e_label = str(Dictionary.ValueAtKey(d, key=edgeLabelKey))
483
- if e_label == None:
484
- e_label = ""
485
- if not edgeGroupKey == None:
486
- if edgeGroupKey:
487
- e_group = Dictionary.ValueAtKey(d, key=edgeGroupKey)
488
- if e_group == None:
489
- e_group = ""
504
+ if not colorKey == None:
505
+ d_color = Dictionary.ValueAtKey(d, key=colorKey) or color
506
+ color = Color.AnyToHex(d_color)
507
+ groupList.append(color)
508
+ if not labelKey == None:
509
+ label = str(Dictionary.ValueAtKey(d, key=labelKey)) or ""
510
+ if not sizeKey == None:
511
+ size = Dictionary.ValueAtKey(d, key=sizeKey) or size
512
+ if not groupKey == None:
513
+ group = Dictionary.ValueAtKey(d, key=groupKey) or ""
490
514
  try:
491
- e_groupList.append(edgeGroups.index(e_group))
515
+ if group == "":
516
+ #color = 'white'
517
+ #groupList.append(Color.AnyToHex(color))
518
+ pass
519
+ elif type(group) == int or type(group) == float:
520
+ if group < minGroup:
521
+ group = minGroup
522
+ if group > maxGroup:
523
+ group = maxGroup
524
+ color = Color.ByValueInRange(group, minValue=minGroup, maxValue=maxGroup, colorScale=colorScale)
525
+ color = Color.AnyToHEX(color)
526
+ groupList.append(Color.AnyToHex(color))
527
+
528
+ else:
529
+ color = Color.ByValueInRange(groups.index(group), minValue=minGroup, maxValue=maxGroup, colorScale=colorScale)
530
+ color = Color.AnyToHex(color)
531
+ groupList.append(Color.AnyToHex(color))
492
532
  except:
493
- e_groupList.append(len(edgeGroups))
494
- if not e_label == "" and not e_group == "":
495
- e_label = e_label+" ("+e_group+")"
496
- e_labels.append(e_label)
497
- else:
498
- for e in new_edges:
499
- sv = Edge.StartVertex(e)
500
- ev = Edge.EndVertex(e)
501
- Xe+=[Vertex.X(sv, mantissa=mantissa), Vertex.X(ev, mantissa=mantissa), None] # x-coordinates of edge ends
502
- Ye+=[Vertex.Y(sv, mantissa=mantissa), Vertex.Y(ev, mantissa=mantissa), None] # y-coordinates of edge ends
503
- Ze+=[Vertex.Z(sv, mantissa=mantissa), Vertex.Z(ev, mantissa=mantissa), None] # z-coordinates of edge ends
504
-
505
-
506
- if len(list(set(e_groupList))) < 2:
507
- e_groupList = edgeColor
508
- if len(e_labels) < 1:
509
- e_labels = ""
510
-
511
- if showEdgeLabels == True:
533
+ #groupList.append(Color.AnyToHex([0,0,0]))
534
+ pass
535
+ labels.append(label)
536
+ sizeList.append(size)
537
+ else:
538
+ for v in vertices:
539
+ x.append(v[0])
540
+ y.append(v[1])
541
+ z.append(v[2])
542
+
543
+ if len(list(set(groupList))) < 2:
544
+ groupList = Color.AnyToHex(color)
545
+ if len(labels) < 1:
546
+ labels = ""
547
+ if len(sizeList) < 1:
548
+ sizeList = size
549
+ if showVertexLabel == True:
550
+ mode = "markers+text"
551
+ else:
552
+ mode = "markers"
553
+ vData= go.Scatter3d(x=x,
554
+ y=y,
555
+ z=z,
556
+ name=legendLabel,
557
+ showlegend=showLegend,
558
+ marker=dict(color=groupList, size=sizeList, opacity=1),
559
+ mode=mode,
560
+ legendgroup=legendGroup,
561
+ legendrank=legendRank,
562
+ text=labels,
563
+ hoverinfo='text',
564
+ hovertext=labels
565
+ )
566
+ return vData
567
+
568
+ @staticmethod
569
+ def edgeData(vertices, edges, dictionaries=None, color="black", colorKey=None, width=1, widthKey=None, labelKey=None, showEdgeLabel = False, groupKey=None, minGroup=None, maxGroup=None, groups=[], legendLabel="Topology Edges", legendGroup=2, legendRank=2, showLegend=True, colorScale="Viridis"):
570
+
571
+ from topologicpy.Color import Color
572
+ from topologicpy.Dictionary import Dictionary
573
+ from topologicpy.Helper import Helper
574
+ traces = []
575
+ x = []
576
+ y = []
577
+ z = []
578
+ labels = []
579
+ groupList = []
580
+ label = ""
581
+ group = ""
582
+
583
+ if showEdgeLabel == True:
584
+ mode = "lines+text"
585
+ else:
586
+ mode = "lines"
587
+
588
+ if showEdgeLabel == True:
589
+ mode = "lines+text"
590
+ else:
591
+ mode = "lines"
592
+ if groups:
593
+ if len(groups) > 0:
594
+ if type(groups[0]) == int or type(groups[0]) == float:
595
+ if not minGroup:
596
+ minGroup = min(groups)
597
+ if not maxGroup:
598
+ maxGroup = max(groups)
599
+ else:
600
+ minGroup = 0
601
+ maxGroup = len(groups) - 1
602
+ else:
603
+ minGroup = 0
604
+ maxGroup = 1
605
+
606
+ if colorKey or widthKey or labelKey or groupKey:
607
+ keys = [x for x in [colorKey, widthKey, labelKey, groupKey] if not x == None]
608
+ temp_dict = Helper.ClusterByKeys(edges, dictionaries, keys, silent=False)
609
+ dict_clusters = temp_dict["dictionaries"]
610
+ elements_clusters = temp_dict['elements']
611
+ for j, elements_cluster in enumerate(elements_clusters):
612
+ d = dict_clusters[j][0] # All dicitonaries have same values in dictionaries, so take first one.
613
+ if d:
614
+ if not colorKey == None:
615
+ d_color = Dictionary.ValueAtKey(d, key=colorKey) or color
616
+ color = Color.AnyToHex(d_color)
617
+ if not labelKey == None:
618
+ label = str(Dictionary.ValueAtKey(d, key=labelKey)) or ""
619
+ if not widthKey == None:
620
+ width = Dictionary.ValueAtKey(d, key=widthKey) or width
621
+ if not groupKey == None:
622
+ group = Dictionary.ValueAtKey(d, key=groupKey)
623
+ if not group == None:
624
+ if type(group) == int or type(group) == float:
625
+ if group < minGroup:
626
+ group = minGroup
627
+ if group > maxGroup:
628
+ group = maxGroup
629
+ d_color = Color.ByValueInRange(group, minValue=minGroup, maxValue=maxGroup, colorScale=colorScale)
630
+ else:
631
+ d_color = Color.ByValueInRange(groups.index(group), minValue=minGroup, maxValue=maxGroup, colorScale=colorScale)
632
+ color = d_color
633
+ x = []
634
+ y = []
635
+ z = []
636
+ for e in elements_cluster:
637
+ sv = vertices[e[0]]
638
+ ev = vertices[e[1]]
639
+ x+=[sv[0], ev[0], None] # x-coordinates of edge ends
640
+ y+=[sv[1], ev[1], None] # y-coordinates of edge ends
641
+ z+=[sv[2], ev[2], None] # z-coordinates of edge ends
642
+ if showEdgeLabel == True:
643
+ mode = "lines+text"
644
+ else:
645
+ mode = "lines"
646
+ trace = go.Scatter3d(x=x,
647
+ y=y,
648
+ z=z,
649
+ name=label,
650
+ showlegend=showLegend,
651
+ marker_size=0,
652
+ mode=mode,
653
+ line=dict(color=color, width=width),
654
+ legendgroup=legendGroup,
655
+ legendrank=legendRank,
656
+ text=label,
657
+ hoverinfo='text')
658
+ traces.append(trace)
659
+ else:
660
+ x = []
661
+ y = []
662
+ z = []
663
+ for e in edges:
664
+ sv = vertices[e[0]]
665
+ ev = vertices[e[1]]
666
+ x+=[sv[0], ev[0], None] # x-coordinates of edge ends
667
+ y+=[sv[1], ev[1], None] # y-coordinates of edge ends
668
+ z+=[sv[2], ev[2], None] # z-coordinates of edge ends
669
+ if showEdgeLabel == True:
512
670
  mode = "lines+text"
513
671
  else:
514
672
  mode = "lines"
515
-
516
- final_categories = edgeColor # Start with the default edgeColor
517
- if len(edgeGroups) > 0:
518
- # Normalize categories to a range between 0 and 1 for the color scale
519
- min_category = 0
520
- max_category = max(len(edgeGroups), 1)
521
- normalized_categories = [(cat - min_category) / (max_category - min_category) for cat in e_groupList]
522
-
523
- final_categories = []
524
- for c in normalized_categories:
525
- color = Color.ByValueInRange(c, minValue=0, maxValue=1, colorScale=colorScale)
526
- color = "rgb("+str(color[0])+","+str(color[1])+","+str(color[2])+")"
527
- final_categories.append(color)
528
- e_trace=go.Scatter3d(x=Xe,
529
- y=Ye,
530
- z=Ze,
531
- mode=mode,
532
- name='Graph Edges',
533
- legendgroup=5,
534
- legendrank=5,
535
- showlegend=showEdgeLegend,
536
- line=dict(color=final_categories, colorscale=Plotly.ColorScale(colorScale), cmin=0, cmax=1, width=edgeWidth),
537
- text=e_labels,
538
- hoverinfo='text'
539
- )
540
- data.append(e_trace)
541
-
542
- return data
673
+ trace = go.Scatter3d(x=x,
674
+ y=y,
675
+ z=z,
676
+ name=label,
677
+ showlegend=showLegend,
678
+ marker_size=0,
679
+ mode=mode,
680
+ line=dict(color=color, width=width),
681
+ legendgroup=legendGroup,
682
+ legendrank=legendRank,
683
+ text=label,
684
+ hoverinfo='text')
685
+ traces.append(trace)
686
+ return traces
687
+
688
+
689
+
690
+
691
+
692
+
693
+
694
+
695
+
543
696
 
544
697
  @staticmethod
545
698
  def DataByTopology(topology,
546
- showVertices=True, vertexSize=1.1, vertexColor="black",
699
+ showVertices=True, vertexSize=1.1, vertexSizeKey=None, vertexColor="black", vertexColorKey=None,
547
700
  vertexLabelKey=None, showVertexLabel=False, vertexGroupKey=None, vertexGroups=[],
548
701
  vertexMinGroup=None, vertexMaxGroup=None,
549
702
  showVertexLegend=False, vertexLegendLabel="Topology Vertices", vertexLegendRank=1,
550
703
  vertexLegendGroup=1,
551
- showEdges=True, edgeWidth=1, edgeColor="black",
704
+ showEdges=True, edgeWidth=1, edgeWidthKey=None, edgeColor="black", edgeColorKey=None,
552
705
  edgeLabelKey=None, showEdgeLabel=False, edgeGroupKey=None, edgeGroups=[],
553
706
  edgeMinGroup=None, edgeMaxGroup=None,
554
707
  showEdgeLegend=False, edgeLegendLabel="Topology Edges", edgeLegendRank=2,
555
708
  edgeLegendGroup=2,
556
- showFaces=True, faceOpacity=0.5, faceColor="#FAFAFA",
709
+ showFaces=True, faceOpacity=0.5, faceOpacityKey=None, faceColor="#FAFAFA", faceColorKey=None,
557
710
  faceLabelKey=None, faceGroupKey=None, faceGroups=[],
558
711
  faceMinGroup=None, faceMaxGroup=None,
559
712
  showFaceLegend=False, faceLegendLabel="Topology Faces", faceLegendRank=3,
@@ -571,6 +724,8 @@ class Plotly:
571
724
  If set to True the vertices will be drawn. Otherwise, they will not be drawn. The default is True.
572
725
  vertexSize : float , optional
573
726
  The desired size of the vertices. The default is 1.1.
727
+ vertexSizeKey : str , optional
728
+ The dictionary key under which to find the vertex size.The default is None.
574
729
  vertexColor : str , optional
575
730
  The desired color of the output vertices. This can be any plotly color string and may be specified as:
576
731
  - A hex string (e.g. '#ff0000')
@@ -579,6 +734,8 @@ class Plotly:
579
734
  - An hsv/hsva string (e.g. 'hsv(0,100%,100%)')
580
735
  - A named CSS color.
581
736
  The default is "black".
737
+ vertexColorKey : str , optional
738
+ The dictionary key under which to find the vertex color.The default is None.
582
739
  vertexLabelKey : str , optional
583
740
  The dictionary key to use to display the vertex label. The default is None.
584
741
  vertexGroupKey : str , optional
@@ -602,6 +759,8 @@ class Plotly:
602
759
  If set to True the edges will be drawn. Otherwise, they will not be drawn. The default is True.
603
760
  edgeWidth : float , optional
604
761
  The desired thickness of the output edges. The default is 1.
762
+ edgeWidthKey : str , optional
763
+ The dictionary key under which to find the edge width.The default is None.
605
764
  edgeColor : str , optional
606
765
  The desired color of the output edges. This can be any plotly color string and may be specified as:
607
766
  - A hex string (e.g. '#ff0000')
@@ -610,6 +769,8 @@ class Plotly:
610
769
  - An hsv/hsva string (e.g. 'hsv(0,100%,100%)')
611
770
  - A named CSS color.
612
771
  The default is "black".
772
+ edgeColorKey : str , optional
773
+ The dictionary key under which to find the edge color.The default is None.
613
774
  edgeLabelKey : str , optional
614
775
  The dictionary key to use to display the edge label. The default is None.
615
776
  edgeGroupKey : str , optional
@@ -633,6 +794,8 @@ class Plotly:
633
794
  If set to True the faces will be drawn. Otherwise, they will not be drawn. The default is True.
634
795
  faceOpacity : float , optional
635
796
  The desired opacity of the output faces (0=transparent, 1=opaque). The default is 0.5.
797
+ faceOpacityKey : str , optional
798
+ The dictionary key under which to find the face opacity.The default is None.
636
799
  faceColor : str , optional
637
800
  The desired color of the output faces. This can be any plotly color string and may be specified as:
638
801
  - A hex string (e.g. '#ff0000')
@@ -641,6 +804,8 @@ class Plotly:
641
804
  - An hsv/hsva string (e.g. 'hsv(0,100%,100%)')
642
805
  - A named CSS color.
643
806
  The default is "#FAFAFA".
807
+ faceColorKey : str , optional
808
+ The dictionary key under which to find the face color.The default is None.
644
809
  faceLabelKey : str , optional
645
810
  The dictionary key to use to display the face label. The default is None.
646
811
  faceGroupKey : str , optional
@@ -682,176 +847,129 @@ class Plotly:
682
847
  from topologicpy.Topology import Topology
683
848
  from topologicpy.Dictionary import Dictionary
684
849
  from topologicpy.Color import Color
850
+ from topologicpy.Helper import Helper
685
851
  from time import time
686
852
 
687
853
  def closest_index(input_value, values):
688
854
  return int(min(range(len(values)), key=lambda i: abs(values[i] - input_value)))
689
855
 
690
- def vertexData(vertices, dictionaries=[], color="black", size=1.1, labelKey=None, showVertexLabel = False, groupKey=None, minGroup=None, maxGroup=None, groups=[], legendLabel="Topology Vertices", legendGroup=1, legendRank=1, showLegend=True, colorScale="Viridis"):
856
+ def edgeData_old(vertices, edges, dictionaries=None, color="black", colorKey=None, width=1, widthKey=None, labelKey=None, showEdgeLabel = False, groupKey=None, minGroup=None, maxGroup=None, groups=[], legendLabel="Topology Edges", legendGroup=2, legendRank=2, showLegend=True, colorScale="Viridis"):
857
+ traces = []
691
858
  x = []
692
859
  y = []
693
860
  z = []
694
861
  labels = []
695
862
  groupList = []
696
863
  label = ""
697
- group = None
698
- if labelKey or groupKey:
699
- if groups:
700
- if len(groups) > 0:
701
- if type(groups[0]) == int or type(groups[0]) == float:
702
- if not minGroup:
703
- minGroup = min(groups)
704
- if not maxGroup:
705
- maxGroup = max(groups)
706
- else:
707
- minGroup = 0
708
- maxGroup = len(groups) - 1
709
- else:
710
- minGroup = 0
711
- maxGroup = 1
712
- for m, v in enumerate(vertices):
713
- x.append(v[0])
714
- y.append(v[1])
715
- z.append(v[2])
716
- label = ""
717
- group = None
718
- if len(dictionaries) > 0:
719
- d = dictionaries[m]
720
- if d:
721
- if not labelKey == None:
722
- label = str(Dictionary.ValueAtKey(d, key=labelKey)) or ""
723
- if not groupKey == None:
724
- group = Dictionary.ValueAtKey(d, key=groupKey) or ""
725
- try:
726
- if group == "":
727
- color = 'white'
728
- elif type(group) == int or type(group) == float:
729
- if group < minGroup:
730
- group = minGroup
731
- if group > maxGroup:
732
- group = maxGroup
733
- color = Color.ByValueInRange(group, minValue=minGroup, maxValue=maxGroup, colorScale=colorScale)
734
- else:
735
- color = Color.ByValueInRange(groups.index(group), minValue=minGroup, maxValue=maxGroup, colorScale=colorScale)
736
- color = "rgb("+str(color[0])+","+str(color[1])+","+str(color[2])+")"
737
- groupList.append(color)
738
- except:
739
- groupList.append(len(groups))
740
- labels.append(label)
864
+ group = ""
865
+
866
+ if showEdgeLabel == True:
867
+ mode = "lines+text"
741
868
  else:
742
- for v in vertices:
743
- x.append(v[0])
744
- y.append(v[1])
745
- z.append(v[2])
869
+ mode = "lines"
746
870
 
747
- if len(list(set(groupList))) < 2:
748
- groupList = color
749
- if len(labels) < 1:
750
- labels = ""
751
- if showVertexLabel == True:
752
- mode = "markers+text"
871
+ if showEdgeLabel == True:
872
+ mode = "lines+text"
753
873
  else:
754
- mode = "markers"
755
- vData= go.Scatter3d(x=x,
756
- y=y,
757
- z=z,
758
- name=legendLabel,
759
- showlegend=showLegend,
760
- marker=dict(color=groupList, size=vertexSize),
761
- mode=mode,
762
- legendgroup=legendGroup,
763
- legendrank=legendRank,
764
- text=labels,
765
- hoverinfo='text',
766
- hovertext=labels
767
- )
768
- return vData
769
-
770
- def edgeData(vertices, edges, dictionaries=None, color="black", width=1, labelKey=None, showEdgeLabel = False, groupKey=None, minGroup=None, maxGroup=None, groups=[], legendLabel="Topology Edges", legendGroup=2, legendRank=2, showLegend=True, colorScale="Viridis"):
771
- x = []
772
- y = []
773
- z = []
774
- labels = []
775
- groupList = []
776
- label = ""
777
- group = ""
778
- if labelKey or groupKey:
779
- if groups:
780
- if len(groups) > 0:
781
- if type(groups[0]) == int or type(groups[0]) == float:
782
- if not minGroup:
783
- minGroup = min(groups)
784
- if not maxGroup:
785
- maxGroup = max(groups)
786
- else:
787
- minGroup = 0
788
- maxGroup = len(groups) - 1
789
- else:
790
- minGroup = 0
791
- maxGroup = 1
792
- for m, e in enumerate(edges):
793
- sv = vertices[e[0]]
794
- ev = vertices[e[1]]
795
- x+=[sv[0], ev[0], None] # x-coordinates of edge ends
796
- y+=[sv[1], ev[1], None] # y-coordinates of edge ends
797
- z+=[sv[2], ev[2], None] # z-coordinates of edge ends
798
- label = ""
799
- group = None
800
- if len(dictionaries) > 0:
801
- d = dictionaries[m]
802
- if d:
803
- if not labelKey == None:
804
- label = str(Dictionary.ValueAtKey(d, key=labelKey)) or ""
805
- if not groupKey == None:
806
- group = Dictionary.ValueAtKey(d, key=groupKey) or ""
807
- try:
808
- if group == "":
809
- color = 'white'
810
- if type(group) == int or type(group) == float:
811
- if group < minGroup:
812
- group = minGroup
813
- if group > maxGroup:
814
- group = maxGroup
815
- color = Color.ByValueInRange(group, minValue=minGroup, maxValue=maxGroup, colorScale=colorScale)
816
- else:
817
- color = Color.ByValueInRange(groups.index(group), minValue=minGroup, maxValue=maxGroup, colorScale=colorScale)
818
- color = "rgb("+str(color[0])+","+str(color[1])+","+str(color[2])+")"
819
- groupList.append(color)
820
- except:
821
- groupList.append(len(groups))
822
- labels.append(label)
874
+ mode = "lines"
875
+ if groups:
876
+ if len(groups) > 0:
877
+ if type(groups[0]) == int or type(groups[0]) == float:
878
+ if not minGroup:
879
+ minGroup = min(groups)
880
+ if not maxGroup:
881
+ maxGroup = max(groups)
882
+ else:
883
+ minGroup = 0
884
+ maxGroup = len(groups) - 1
885
+ else:
886
+ minGroup = 0
887
+ maxGroup = 1
888
+
889
+ if colorKey or widthKey or labelKey or groupKey:
890
+ keys = [x for x in [colorKey, widthKey, labelKey, groupKey] if not x == None]
891
+ temp_dict = Helper.ClusterByKeys(edges, dictionaries, keys, silent=False)
892
+ dict_clusters = temp_dict["dictionaries"]
893
+ elements_clusters = temp_dict['elements']
894
+ for j, elements_cluster in enumerate(elements_clusters):
895
+ d = dict_clusters[j][0] # All dicitonaries have same values in dictionaries, so take first one.
896
+ if d:
897
+ if not colorKey == None:
898
+ d_color = Dictionary.ValueAtKey(d, key=colorKey) or color
899
+ color = Color.AnyToHex(d_color)
900
+ if not labelKey == None:
901
+ label = str(Dictionary.ValueAtKey(d, key=labelKey)) or ""
902
+ if not widthKey == None:
903
+ width = Dictionary.ValueAtKey(d, key=edgeWidthKey) or width
904
+ if not groupKey == None:
905
+ group = Dictionary.ValueAtKey(d, key=groupKey)
906
+ if not group == None:
907
+ if type(group) == int or type(group) == float:
908
+ if group < minGroup:
909
+ group = minGroup
910
+ if group > maxGroup:
911
+ group = maxGroup
912
+ d_color = Color.ByValueInRange(group, minValue=minGroup, maxValue=maxGroup, colorScale=colorScale)
913
+ else:
914
+ d_color = Color.ByValueInRange(groups.index(group), minValue=minGroup, maxValue=maxGroup, colorScale=colorScale)
915
+ color = d_color
916
+ x = []
917
+ y = []
918
+ z = []
919
+ for e in elements_cluster:
920
+ sv = vertices[e[0]]
921
+ ev = vertices[e[1]]
922
+ x+=[sv[0], ev[0], None] # x-coordinates of edge ends
923
+ y+=[sv[1], ev[1], None] # y-coordinates of edge ends
924
+ z+=[sv[2], ev[2], None] # z-coordinates of edge ends
925
+ if showEdgeLabel == True:
926
+ mode = "lines+text"
927
+ else:
928
+ mode = "lines"
929
+ trace = go.Scatter3d(x=x,
930
+ y=y,
931
+ z=z,
932
+ name=label,
933
+ showlegend=showLegend,
934
+ marker_size=0,
935
+ mode=mode,
936
+ line=dict(color=color, width=width),
937
+ legendgroup=legendGroup,
938
+ legendrank=legendRank,
939
+ text=label,
940
+ hoverinfo='text')
941
+ traces.append(trace)
823
942
  else:
943
+ x = []
944
+ y = []
945
+ z = []
824
946
  for e in edges:
825
947
  sv = vertices[e[0]]
826
948
  ev = vertices[e[1]]
827
949
  x+=[sv[0], ev[0], None] # x-coordinates of edge ends
828
950
  y+=[sv[1], ev[1], None] # y-coordinates of edge ends
829
951
  z+=[sv[2], ev[2], None] # z-coordinates of edge ends
830
-
831
- if len(list(set(groupList))) < 2:
832
- groupList = color
833
- if len(labels) < 1:
834
- labels = ""
835
- if showEdgeLabel == True:
836
- mode = "lines+text"
837
- else:
838
- mode = "lines"
839
- eData = go.Scatter3d(x=x,
840
- y=y,
841
- z=z,
842
- name=legendLabel,
843
- showlegend=showLegend,
844
- marker_size=0,
845
- mode=mode,
846
- line=dict(color=groupList, width=edgeWidth),
847
- legendgroup=legendGroup,
848
- legendrank=legendRank,
849
- text=labels,
850
- hoverinfo='text')
851
- return eData
852
-
853
-
854
- def faceData(vertices, faces, dictionaries=None, color="#FAFAFA",
952
+ if showEdgeLabel == True:
953
+ mode = "lines+text"
954
+ else:
955
+ mode = "lines"
956
+ trace = go.Scatter3d(x=x,
957
+ y=y,
958
+ z=z,
959
+ name=label,
960
+ showlegend=showLegend,
961
+ marker_size=0,
962
+ mode=mode,
963
+ line=dict(color=color, width=width),
964
+ legendgroup=legendGroup,
965
+ legendrank=legendRank,
966
+ text=label,
967
+ hoverinfo='text')
968
+ traces.append(trace)
969
+
970
+ return traces
971
+
972
+ def faceData(vertices, faces, dictionaries=None, color="#FAFAFA", colorKey=None,
855
973
  opacity=0.5, labelKey=None, groupKey=None,
856
974
  minGroup=None, maxGroup=None, groups=[], legendLabel="Topology Faces",
857
975
  legendGroup=3, legendRank=3, showLegend=True, intensities=None, colorScale="viridis"):
@@ -867,9 +985,10 @@ class Plotly:
867
985
  k = []
868
986
  labels = []
869
987
  groupList = []
988
+ faceColorList = []
870
989
  label = ""
871
990
  group = ""
872
- if labelKey or groupKey:
991
+ if colorKey or labelKey or groupKey:
873
992
  if groups:
874
993
  if len(groups) > 0:
875
994
  if type(groups[0]) == int or type(groups[0]) == float:
@@ -888,7 +1007,7 @@ class Plotly:
888
1007
  j.append(f[1])
889
1008
  k.append(f[2])
890
1009
  label = ""
891
- group = ""
1010
+ group = None
892
1011
  if len(dictionaries) > 0:
893
1012
  d = dictionaries[m]
894
1013
  if d:
@@ -896,32 +1015,34 @@ class Plotly:
896
1015
  label = str(Dictionary.ValueAtKey(d, key=labelKey)) or ""
897
1016
  if not groupKey == None:
898
1017
  group = Dictionary.ValueAtKey(d, key=groupKey) or None
899
- try:
900
- if group == "":
901
- color = 'white'
902
- elif type(group) == int or type(group) == float:
903
- if group < minGroup:
904
- group = minGroup
905
- if group > maxGroup:
906
- group = maxGroup
907
- color = Color.ByValueInRange(group, minValue=minGroup, maxValue=maxGroup, colorScale=colorScale)
908
- else:
909
- color = Color.ByValueInRange(groups.index(group), minValue=minGroup, maxValue=maxGroup, colorScale=colorScale)
910
- color = "rgb("+str(color[0])+","+str(color[1])+","+str(color[2])+")"
911
- groupList.append(color)
912
- except:
913
- groupList.append(len(groups))
1018
+
1019
+ if group == None:
1020
+ f_color = Color.AnyToHex(color)
1021
+ groupList.append(f_color)
1022
+ elif type(group) == int or type(group) == float:
1023
+ if group < minGroup:
1024
+ group = minGroup
1025
+ if group > maxGroup:
1026
+ group = maxGroup
1027
+ f_color = Color.ByValueInRange(group, minValue=minGroup, maxValue=maxGroup, colorScale=colorScale)
1028
+ f_color = Color.AnyToHex(f_color)
1029
+ groupList.append(f_color)
1030
+ else:
1031
+ f_color = Color.ByValueInRange(groups.index(group), minValue=minGroup, maxValue=maxGroup, colorScale=colorScale)
1032
+ f_color = Color.AnyToHex(f_color)
1033
+ groupList.append(f_color)
914
1034
  labels.append(label)
915
1035
  else:
916
1036
  for f in faces:
917
1037
  i.append(f[0])
918
1038
  j.append(f[1])
919
1039
  k.append(f[2])
920
-
1040
+
921
1041
  if len(list(set(groupList))) < 2:
922
1042
  groupList = None
923
1043
  if len(labels) < 1:
924
1044
  labels = ""
1045
+ color = Color.AnyToHex(color)
925
1046
  fData = go.Mesh3d(
926
1047
  x = x,
927
1048
  y = y,
@@ -1009,11 +1130,11 @@ class Plotly:
1009
1130
  if showVertices:
1010
1131
  if len(vertices) == 0:
1011
1132
  for i, tp_v in enumerate(tp_vertices):
1012
- if vertexLabelKey or vertexGroupKey:
1133
+ if vertexColorKey or vertexSizeKey or vertexLabelKey or vertexGroupKey:
1013
1134
  d = Topology.Dictionary(tp_v)
1014
1135
  v_dictionaries.append(d)
1015
1136
  vertices.append([Vertex.X(tp_v, mantissa=mantissa), Vertex.Y(tp_v, mantissa=mantissa), Vertex.Z(tp_v, mantissa=mantissa)])
1016
- data.append(vertexData(vertices, dictionaries=v_dictionaries, color=vertexColor, size=vertexSize, labelKey=vertexLabelKey, showVertexLabel=showVertexLabel, groupKey=vertexGroupKey, minGroup=vertexMinGroup, maxGroup=vertexMaxGroup, groups=vertexGroups, legendLabel=vertexLegendLabel, legendGroup=vertexLegendGroup, legendRank=vertexLegendRank, showLegend=showVertexLegend, colorScale=colorScale))
1137
+ data.append(Plotly.vertexData(vertices, dictionaries=v_dictionaries, color=vertexColor, colorKey=vertexColorKey, size=vertexSize, sizeKey=vertexSizeKey, labelKey=vertexLabelKey, showVertexLabel=showVertexLabel, groupKey=vertexGroupKey, minGroup=vertexMinGroup, maxGroup=vertexMaxGroup, groups=vertexGroups, legendLabel=vertexLegendLabel, legendGroup=vertexLegendGroup, legendRank=vertexLegendRank, showLegend=showVertexLegend, colorScale=colorScale))
1017
1138
 
1018
1139
  if showEdges and Topology.Type(topology) > Topology.TypeID("Vertex"):
1019
1140
  if Topology.Type(topology) == Topology.TypeID("Edge"):
@@ -1022,16 +1143,24 @@ class Plotly:
1022
1143
  tp_edges = Topology.Edges(topology)
1023
1144
  if not (tp_edges == None or tp_edges == []):
1024
1145
  e_dictionaries = []
1025
- if edgeLabelKey or edgeGroupKey:
1146
+ if edgeColorKey or edgeWidthKey or edgeLabelKey or edgeGroupKey:
1026
1147
  for tp_edge in tp_edges:
1027
1148
  e_dictionaries.append(Topology.Dictionary(tp_edge))
1028
1149
  e_cluster = Cluster.ByTopologies(tp_edges)
1029
1150
  geo = Topology.Geometry(e_cluster, mantissa=mantissa)
1030
1151
  vertices = geo['vertices']
1031
1152
  edges = geo['edges']
1032
- data.append(edgeData(vertices, edges, dictionaries=e_dictionaries, color=edgeColor, width=edgeWidth, labelKey=edgeLabelKey, showEdgeLabel=showEdgeLabel, groupKey=edgeGroupKey, minGroup=edgeMinGroup, maxGroup=edgeMaxGroup, groups=edgeGroups, legendLabel=edgeLegendLabel, legendGroup=edgeLegendGroup, legendRank=edgeLegendRank, showLegend=showEdgeLegend, colorScale=colorScale))
1153
+ data.extend(Plotly.edgeData(vertices, edges, dictionaries=e_dictionaries, color=edgeColor, colorKey=edgeColorKey, width=edgeWidth, widthKey=edgeWidthKey, labelKey=edgeLabelKey, showEdgeLabel=showEdgeLabel, groupKey=edgeGroupKey, minGroup=edgeMinGroup, maxGroup=edgeMaxGroup, groups=edgeGroups, legendLabel=edgeLegendLabel, legendGroup=edgeLegendGroup, legendRank=edgeLegendRank, showLegend=showEdgeLegend, colorScale=colorScale))
1033
1154
 
1034
1155
  if showFaces and Topology.Type(topology) >= Topology.TypeID("Face"):
1156
+ if not faceColorKey == None:
1157
+ d = Topology.Dictionary(topology)
1158
+ faceColor = Dictionary.ValueAtKey(d, key=faceColorKey) or faceColor
1159
+ if not faceOpacityKey == None:
1160
+ d = Topology.Dictionary(topology)
1161
+ d_opacity = Dictionary.ValueAtKey(d, key=faceOpacityKey) or faceOpacity
1162
+ if 0 < d_opacity < 1:
1163
+ faceOpacity = d_opacity
1035
1164
  if Topology.IsInstance(topology, "Face"):
1036
1165
  tp_faces = [topology]
1037
1166
  else:
@@ -1043,18 +1172,18 @@ class Plotly:
1043
1172
  triangles = Face.Triangulate(tp_face, tolerance=tolerance)
1044
1173
  if isinstance(triangles, list):
1045
1174
  for tri in triangles:
1046
- if faceLabelKey or faceGroupKey:
1175
+ if faceColorKey or faceOpacityKey or faceLabelKey or faceGroupKey:
1047
1176
  d = Topology.Dictionary(tp_face)
1048
1177
  f_dictionaries.append(d)
1049
1178
  if d:
1050
- tri = Topology.SetDictionary(tri, d)
1179
+ tri = Topology.SetDictionary(tri, d, silent=True)
1051
1180
  all_triangles.append(tri)
1052
1181
  if len(all_triangles) > 0:
1053
1182
  f_cluster = Cluster.ByTopologies(all_triangles)
1054
1183
  geo = Topology.Geometry(f_cluster, mantissa=mantissa)
1055
1184
  vertices = geo['vertices']
1056
1185
  faces = geo['faces']
1057
- data.append(faceData(vertices, faces, dictionaries=f_dictionaries, color=faceColor, opacity=faceOpacity, labelKey=faceLabelKey, groupKey=faceGroupKey, minGroup=faceMinGroup, maxGroup=faceMaxGroup, groups=faceGroups, legendLabel=faceLegendLabel, legendGroup=faceLegendGroup, legendRank=faceLegendRank, showLegend=showFaceLegend, intensities=intensityList, colorScale=colorScale))
1186
+ data.append(faceData(vertices, faces, dictionaries=f_dictionaries, color=faceColor, colorKey=faceColorKey, opacity=faceOpacity, labelKey=faceLabelKey, groupKey=faceGroupKey, minGroup=faceMinGroup, maxGroup=faceMaxGroup, groups=faceGroups, legendLabel=faceLegendLabel, legendGroup=faceLegendGroup, legendRank=faceLegendRank, showLegend=showFaceLegend, intensities=intensityList, colorScale=colorScale))
1058
1187
  return data
1059
1188
 
1060
1189
  @staticmethod
@@ -1104,8 +1233,10 @@ class Plotly:
1104
1233
  The desired type of plotly color scales to use (e.g. "Viridis", "Plasma"). The default is "Viridis". For a full list of names, see https://plotly.com/python/builtin-colorscales/.
1105
1234
  colorSamples : int , optional
1106
1235
  The number of discrete color samples to use for displaying the data. The default is 10.
1107
- backgroundColor : str , optional
1108
- The desired background color. This can be any plotly color string and may be specified as:
1236
+ backgroundColor : list or str , optional
1237
+ The desired background color. This can be any color list or plotly color string and may be specified as:
1238
+ - An rgb list (e.g. [255,0,0])
1239
+ - A cmyk list (e.g. [0.5, 0, 0.25, 0.2])
1109
1240
  - A hex string (e.g. '#ff0000')
1110
1241
  - An rgb/rgba string (e.g. 'rgb(255,0,0)')
1111
1242
  - An hsl/hsla string (e.g. 'hsl(0,100%,50%)')
@@ -1126,6 +1257,8 @@ class Plotly:
1126
1257
  plotly.Figure
1127
1258
  The created plotly figure.
1128
1259
  """
1260
+ from topologicpy.Color import Color
1261
+
1129
1262
  try:
1130
1263
  import numpy as np
1131
1264
  except:
@@ -1155,7 +1288,7 @@ class Plotly:
1155
1288
  showScale=showScale,
1156
1289
  colorScale=Plotly.ColorScale(colorScale),
1157
1290
  colorSamples=colorSamples,
1158
- backgroundColor=backgroundColor,
1291
+ backgroundColor= Color.AnyToHex(backgroundColor),
1159
1292
  marginLeft=marginLeft,
1160
1293
  marginRight=marginRight,
1161
1294
  marginTop=marginTop,
@@ -1215,8 +1348,10 @@ class Plotly:
1215
1348
  The desired type of plotly color scales to use (e.g. "Viridis", "Plasma"). The default is "Viridis". For a full list of names, see https://plotly.com/python/builtin-colorscales/.
1216
1349
  colorSamples : int , optional
1217
1350
  The number of discrete color samples to use for displaying the data. The default is 10.
1218
- backgroundColor : str , optional
1219
- The desired background color. This can be any plotly color string and may be specified as:
1351
+ backgroundColor : list or str , optional
1352
+ The desired background color. This can be any color list or plotly color string and may be specified as:
1353
+ - An rgb list (e.g. [255,0,0])
1354
+ - A cmyk list (e.g. [0.5, 0, 0.25, 0.2])
1220
1355
  - A hex string (e.g. '#ff0000')
1221
1356
  - An rgb/rgba string (e.g. 'rgb(255,0,0)')
1222
1357
  - An hsl/hsla string (e.g. 'hsl(0,100%,50%)')
@@ -1238,6 +1373,7 @@ class Plotly:
1238
1373
  #import plotly.figure_factory as ff
1239
1374
  import plotly.graph_objects as go
1240
1375
  import plotly.express as px
1376
+ from topologicpy.Color import Color
1241
1377
 
1242
1378
  try:
1243
1379
  import numpy as np
@@ -1330,8 +1466,8 @@ class Plotly:
1330
1466
  "xaxis": {"title": xTitle},
1331
1467
  "yaxis": {"title": yTitle, "autorange": "reversed"},
1332
1468
  "annotations": annotations,
1333
- "paper_bgcolor": backgroundColor,
1334
- "plot_bgcolor": backgroundColor,
1469
+ "paper_bgcolor": Color.AnyToHex(backgroundColor),
1470
+ "plot_bgcolor": Color.AnyToHex(backgroundColor),
1335
1471
  "margin":dict(l=marginLeft, r=marginRight, t=marginTop, b=marginBottom)
1336
1472
  }
1337
1473
  fig = go.Figure(data=data, layout=layout)
@@ -1392,8 +1528,10 @@ class Plotly:
1392
1528
  The desired height of the figure. The default is 600.
1393
1529
  theme : str , optional
1394
1530
  The plotly color scheme to use. The options are "dark", "light", "default". The default is "default".
1395
- backgroundColor : str , optional
1396
- The desired background color. This can be any plotly color string and may be specified as:
1531
+ backgroundColor : list or str , optional
1532
+ The desired background color. This can be any color list or plotly color string and may be specified as:
1533
+ - An rgb list (e.g. [255,0,0])
1534
+ - A cmyk list (e.g. [0.5, 0, 0.25, 0.2])
1397
1535
  - A hex string (e.g. '#ff0000')
1398
1536
  - An rgb/rgba string (e.g. 'rgb(255,0,0)')
1399
1537
  - An hsl/hsla string (e.g. 'hsl(0,100%,50%)')
@@ -1420,6 +1558,8 @@ class Plotly:
1420
1558
  import plotly.graph_objs as go
1421
1559
  from sklearn.linear_model import LinearRegression
1422
1560
  import plotly.io as pio
1561
+ from topologicpy.Color import Color
1562
+
1423
1563
  actual_values = np.array(actual)
1424
1564
  predicted_values = np.array(predicted)
1425
1565
 
@@ -1481,8 +1621,8 @@ class Plotly:
1481
1621
  "xaxis": {"title": xTitle, "range":tick_range, "dtick":tick_step},
1482
1622
  "yaxis": {"title": yTitle, "range":tick_range, "dtick":tick_step},
1483
1623
  "showlegend": True,
1484
- "paper_bgcolor": backgroundColor,
1485
- "plot_bgcolor": backgroundColor,
1624
+ "paper_bgcolor": Color.AnyToHex(backgroundColor),
1625
+ "plot_bgcolor": Color.AnyToHex(backgroundColor),
1486
1626
  "margin":dict(l=marginLeft, r=marginRight, t=marginTop, b=marginBottom)
1487
1627
  }
1488
1628
 
@@ -1536,8 +1676,10 @@ class Plotly:
1536
1676
  If set to True, markers will be displayed. The default is False.
1537
1677
  chartType : str , optional
1538
1678
  The desired type of chart. The options are "Line", "Bar", or "Scatter". It is case insensitive. The default is "Line".
1539
- backgroundColor : str , optional
1540
- The desired background color. This can be any plotly color string and may be specified as:
1679
+ backgroundColor : list or str , optional
1680
+ The desired background color. This can be any color list or plotly color string and may be specified as:
1681
+ - An rgb list (e.g. [255,0,0])
1682
+ - A cmyk list (e.g. [0.5, 0, 0.25, 0.2])
1541
1683
  - A hex string (e.g. '#ff0000')
1542
1684
  - An rgb/rgba string (e.g. 'rgb(255,0,0)')
1543
1685
  - An hsl/hsla string (e.g. 'hsl(0,100%,50%)')
@@ -1567,6 +1709,7 @@ class Plotly:
1567
1709
 
1568
1710
  """
1569
1711
  import plotly.express as px
1712
+ from topologicpy.Color import Color
1570
1713
 
1571
1714
  if chartType.lower() == "line":
1572
1715
  figure = px.line(dataFrame, x=labels[0], y=labels[1:], title=title, markers=useMarkers)
@@ -1583,8 +1726,8 @@ class Plotly:
1583
1726
  "title": title,
1584
1727
  "xaxis": {"title": xTitle, "dtick": xSpacing, 'gridcolor': gridColor},
1585
1728
  "yaxis": {"title": yTitle, "dtick": ySpacing, 'gridcolor': gridColor},
1586
- "paper_bgcolor": backgroundColor,
1587
- "plot_bgcolor": backgroundColor,
1729
+ "paper_bgcolor": Color.AnyToHex(backgroundColor),
1730
+ "plot_bgcolor": Color.AnyToHex(backgroundColor),
1588
1731
  "margin":dict(l=marginLeft, r=marginRight, t=marginTop, b=marginBottom)
1589
1732
  }
1590
1733
  figure.update_layout(layout)
@@ -1617,14 +1760,16 @@ class Plotly:
1617
1760
  If set to True the z axis is drawn. Otherwise it is not drawn. The default is False.
1618
1761
  axisSize : float , optional
1619
1762
  The size of the X, Y, Z, axes. The default is 1.
1620
- backgroundColor : str , optional
1621
- The desired color of the background. This can be any plotly color string and may be specified as:
1763
+ backgroundColor : list or str , optional
1764
+ The desired background color. This can be any color list or plotly color string and may be specified as:
1765
+ - An rgb list (e.g. [255,0,0])
1766
+ - A cmyk list (e.g. [0.5, 0, 0.25, 0.2])
1622
1767
  - A hex string (e.g. '#ff0000')
1623
1768
  - An rgb/rgba string (e.g. 'rgb(255,0,0)')
1624
1769
  - An hsl/hsla string (e.g. 'hsl(0,100%,50%)')
1625
1770
  - An hsv/hsva string (e.g. 'hsv(0,100%,100%)')
1626
1771
  - A named CSS color.
1627
- The default is "rgba(0,0,0,0)".
1772
+ The default is 'rgba(0,0,0,0)' (transparent).
1628
1773
  marginLeft : int , optional
1629
1774
  The size in pixels of the left margin. The default value is 0.
1630
1775
  marginRight : int , optional
@@ -1644,7 +1789,7 @@ class Plotly:
1644
1789
  """
1645
1790
  from topologicpy.Vertex import Vertex
1646
1791
  from topologicpy.Edge import Edge
1647
- from topologicpy.Wire import Wire
1792
+ from topologicpy.Color import Color
1648
1793
  if not isinstance(data, list):
1649
1794
  return None
1650
1795
 
@@ -1677,8 +1822,8 @@ class Plotly:
1677
1822
  zaxis =dict(visible=False),
1678
1823
  ),
1679
1824
  scene_aspectmode='data',
1680
- paper_bgcolor=backgroundColor,
1681
- plot_bgcolor=backgroundColor,
1825
+ paper_bgcolor= Color.AnyToHex(backgroundColor),
1826
+ plot_bgcolor= Color.AnyToHex(backgroundColor),
1682
1827
  margin=dict(l=marginLeft, r=marginRight, t=marginTop, b=marginBottom),
1683
1828
  )
1684
1829
  figure.update_xaxes(showgrid=False, zeroline=False, visible=False)
@@ -1906,14 +2051,16 @@ class Plotly:
1906
2051
  If set to True the y axis is drawn. Otherwise it is not drawn. The default is False.
1907
2052
  zAxis : bool , optional
1908
2053
  If set to True the z axis is drawn. Otherwise it is not drawn. The default is False.
1909
- backgroundColor : str , optional
1910
- The desired color of the background. This can be any plotly color string and may be specified as:
2054
+ backgroundColor : list or str , optional
2055
+ The desired background color. This can be any color list or plotly color string and may be specified as:
2056
+ - An rgb list (e.g. [255,0,0])
2057
+ - A cmyk list (e.g. [0.5, 0, 0.25, 0.2])
1911
2058
  - A hex string (e.g. '#ff0000')
1912
2059
  - An rgb/rgba string (e.g. 'rgb(255,0,0)')
1913
2060
  - An hsl/hsla string (e.g. 'hsl(0,100%,50%)')
1914
2061
  - An hsv/hsva string (e.g. 'hsv(0,100%,100%)')
1915
2062
  - A named CSS color.
1916
- The default is "rgba(0,0,0,0)".
2063
+ The default is 'rgba(0,0,0,0)' (transparent).
1917
2064
  marginLeft : int , optional
1918
2065
  The size in pixels of the left margin. The default value is 0.
1919
2066
  marginRight : int , optional
@@ -1963,6 +2110,7 @@ class Plotly:
1963
2110
 
1964
2111
  """
1965
2112
  from topologicpy.Topology import Topology
2113
+ from topologicpy.Color import Color
1966
2114
 
1967
2115
  if not Topology.IsInstance(topology, "Topology"):
1968
2116
  print("Plotly.FigureByTopology - Error: the input topology is not a valid topology. Returning None.")
@@ -1986,7 +2134,7 @@ class Plotly:
1986
2134
  intensityKey=intensityKey, colorScale=colorScale, tolerance=tolerance)
1987
2135
  figure = Plotly.FigureByData(data=data, width=width, height=height,
1988
2136
  xAxis=xAxis, yAxis=yAxis, zAxis=zAxis, axisSize=axisSize,
1989
- backgroundColor=backgroundColor,
2137
+ backgroundColor=Color.AnyToHex(backgroundColor),
1990
2138
  marginLeft=marginLeft, marginRight=marginRight,
1991
2139
  marginTop=marginTop, marginBottom=marginBottom,
1992
2140
  tolerance=tolerance)
@@ -2243,6 +2391,7 @@ class Plotly:
2243
2391
  None
2244
2392
 
2245
2393
  """
2394
+
2246
2395
  if figure == None:
2247
2396
  print("Plotly.Show - Error: The input is NULL. Returning None.")
2248
2397
  return None
@@ -2254,9 +2403,21 @@ class Plotly:
2254
2403
  if not renderer.lower() in Plotly.Renderers():
2255
2404
  print("Plotly.Show - Error: The input renderer is not in the approved list of renderers. Returning None.")
2256
2405
  return None
2257
- if not camera == None and not center == None and not up == None:
2258
- figure = Plotly.SetCamera(figure, camera=camera, center=center, up=up, projection=projection)
2406
+ # Set up camera projection
2407
+ if "ortho" in projection.lower():
2408
+ camera_settings = dict(eye=dict(x=camera[0], y=camera[1], z=camera[2]),
2409
+ center=dict(x=center[0], y=center[1], z=center[2]),
2410
+ up=dict(x=up[0], y=up[1], z=up[2]),
2411
+ projection=dict(type="orthographic"))
2412
+ else:
2413
+ camera_settings = dict(eye=dict(x=camera[0], y=camera[1], z=camera[2]),
2414
+ center=dict(x=center[0], y=center[1], z=center[2]),
2415
+ up=dict(x=up[0], y=up[1], z=up[2]),
2416
+ projection=dict(type="perspective"))
2417
+
2259
2418
  figure.update_layout(
2419
+ scene_camera = camera_settings,
2420
+ scene=dict(aspectmode="data"),
2260
2421
  autosize=True,
2261
2422
  margin=dict(l=40, r=40, t=40, b=40)
2262
2423
  )