mermaid icon indicating copy to clipboard operation
mermaid copied to clipboard

Pie chart colors don't match with pie1 pie2 theme colors

Open Judp0m opened this issue 1 year ago • 1 comments

Description

Here is an example, the colors do not match. For some reason, the labels get sorted from largest to smallest. I actually would prefer that sorting/re-ordering does not happen or be optional via the config. The doc leads me to thing this should not be re-sorted by value: Pie slices will be ordered clockwise in the same order as the labels. cf https://mermaid.js.org/syntax/pie.html#syntax

config:
    themeVariables:
        pie1: "red"
        pie2: "green"
        pie3: "blue"
        pie4: "yellow"
pie 
    title Key elements in Product X
    "Pie1-red" : 30
    "pie2-green" : 50
    "pie3-blue" : 19
    "pie4-yellow" :  1

May be related to https://github.com/mermaid-js/mermaid/pull/4774

Steps to reproduce

Plot the provided pie chart and observe the mismatch in label/colors.

Screenshots

image

Code Sample

---
config:
    themeVariables:
        pie1: "red"
        pie2: "green"
        pie3: "blue"
        pie4: "yellow"
---
pie 
    title Key elements in Product X
    "Pie1-red" : 30
    "pie2-green" : 50
    "pie3-blue" : 19
    "pie4-yellow" :  1

Setup

No response

Suggested Solutions

Make the pie1 pie2 etc match the order of the config. Additionally, Don't reorder, or make it optional.

Additional Context

No response

Judp0m avatar Feb 24 '24 20:02 Judp0m

Has this been fixed? It's really annoying me that the colors don't match the specified difficulty that I have, instead it makes orders them from highest to lowest and puts the colors in that order.

TheRealH0u avatar Apr 26 '24 13:04 TheRealH0u

+1

kilogold avatar Aug 04 '24 19:08 kilogold

I also came across this error in version 10.9.1 . My solution is to remove the sorting by value in "createPieArcs" . Maybe the following diff helps:

--- ./dev/js/mermaid.js	2024-08-20 16:53:11.436105506 +0200
+++ ./dev/js/mermaid/mermaid.js	2024-08-20 17:13:20.106787643 +0200
@@ -52951,8 +52951,6 @@
         label: element2[0],
         value: element2[1]
       };
-    }).sort((a, b) => {
-      return b.value - a.value;
     });
     const pie2 = d3pie().value(
       (d3Section) => d3Section.value

arcturionSF avatar Aug 20 '24 15:08 arcturionSF