Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Figmagic gradients appear different from Figma #108

Open
tjmusser opened this issue Jun 18, 2021 · 2 comments
Open

Figmagic gradients appear different from Figma #108

tjmusser opened this issue Jun 18, 2021 · 2 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@tjmusser
Copy link

Describe the bug
There's difference in the gradient that Figma outputs and the one that figmagic returns. Both in the angle of the gradient, and in the color stops.

You can see an example of this in the code pen I created.

https://codepen.io/tmusser-illumina/pen/jOBJdGb

Figma value linear-gradient(61.68deg, #0045E6 -4.27%, #FDDD33 116.09%)

Figmagic value linear-gradient(8.62deg, rgba(0, 69, 230, 1) 10%, rgba(253, 221, 51, 1) 100%)

To Reproduce
Steps to reproduce the behavior:

  1. Have a gradient color on the colors page
  2. Run figmagic
  3. Check output and compare to figma inspector

Expected behavior
I would expect the same gradient settings between Figma and Figmagic

Screenshots

Figma File Code Pen Example
Screen Shot 2021-06-18 at 3 33 26 PM Screen Shot 2021-06-18 at 3 34 33 PM

Gradient angle in Figma

Screen Shot 2021-06-18 at 3 38 17 PM

Additional context
RGBA colors/values are fine.

Json from Files API for gradient in question

{
  "id": "3279:0",
  "name": "TJFINDME",
  "type": "RECTANGLE",
  "blendMode": "PASS_THROUGH",
  "absoluteBoundingBox": {
    "x": -2372.0,
    "y": -1033.0,
    "width": 120.0,
    "height": 120.0
  },
  "preserveRatio": true,
  "constraints": {
    "vertical": "TOP",
    "horizontal": "LEFT"
  },
  "fills": [
    {
      "blendMode": "NORMAL",
      "type": "GRADIENT_LINEAR",
      "gradientHandlePositions": [
        {
          "x": 0.028397589928173650,
          "y": 1.5776396405568802
        },
        {
          "x": 0.48260872530965471,
          "y": -1.4196428150293696
        },
        {
          "x": 1.9517800440212534,
          "y": 5.1467014794766746
        }
      ],
      "gradientStops": [
        {
          "color": {
            "r": 0.0,
            "g": 0.27150836586952209,
            "b": 0.90196079015731812,
            "a": 1.0
          },
          "position": 0.10496804118156433
        },
        {
          "color": {
            "r": 0.99215686321258545,
            "g": 0.86516082286834717,
            "b": 0.19843137264251709,
            "a": 1.0
          },
          "position": 1.0
        }
      ]
    }
  ],
  "strokes": [],
  "strokeWeight": 1.0,
  "strokeAlign": "INSIDE",
  "effects": [],
  "cornerRadius": 4.0,
  "rectangleCornerRadii": [
    4.0,
    4.0,
    4.0,
    4.0
  ]
}

My FIgmagic settings

{
  "debugMode": false,
  "figmaData": "figma.json",
  "fontUnit": "rem",
  "letterSpacingUnit": "em",
  "outputFolderGraphics": "./dist/graphics",
  "outputFolderTokens": "./dist/tokens",
  "outputFormatCss": "ts",
  "outputFormatDesc": "md",
  "outputFormatGraphics": "svg",
  "outputScaleGraphics": 1,
  "outputFormatTokens": "js",
  "syncElements": false,
  "skipFileGeneration": {
    "forceUpdate": true,
    "skipCss": false,
    "skipDescription": false,
    "skipReact": true,
    "skipStorybook": true,
    "skipStyled": true
  },
  "remSize": 16,
  "syncTokens": true,
  "spacingUnit": "px",
}
@mikaelvesavuori
Copy link
Owner

mikaelvesavuori commented Jun 30, 2021

Hi and thanks for the reproducible example. I looked at this when you first posted it, but my work did not fully cover a solution at the time.

This will have to be on hold from my side until I get more time to look into this.

@mikaelvesavuori mikaelvesavuori added bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed labels Jul 1, 2021
@mikaelvesavuori mikaelvesavuori added hacktoberfest Hacktoberfest and removed good first issue Good for newcomers labels Oct 9, 2021
@mikaelvesavuori mikaelvesavuori removed the hacktoberfest Hacktoberfest label Nov 8, 2021
@mikaelvesavuori
Copy link
Owner

mikaelvesavuori commented Sep 24, 2023

I've worked on this, to and from, a couple of times since this issue originally popped up. Most recently I also used ChatGPT as well as finding more recent discussions around the gradient handle positions and gradients overall, out on the internet. Even with intense prompting and chaining, I can't get ChatGPT to figure out what's going on, either.

Some things seem pretty simple to understand, such as how color positions work in strictly straight lines (0, 90 degrees etc.) but I can't seem to figure out the math when the handles are originating from outside a frame or having angles similar to what you've shown in your demo use case.

There is no obvious way that the Figma-provided output (in the Dev Mode, for example) is calculated, at least to my degree of competence.

With all that said, it seems the angle calculation is improved in this recent commit a97db33

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants