yuzutech / kroki

Creates diagrams from textual descriptions!
https://kroki.io
MIT License
2.78k stars 206 forks source link

Javascript encode not working #777

Closed scherersebastian closed 3 years ago

scherersebastian commented 3 years ago

Based on example: https://docs.kroki.io/kroki/setup/encode-diagram/#javascript

Trying to encode a simple graphviz graph in React, but I am getting "404 unable to decode the source".

import Pako from "pako";

textEncode(str) {
    var utf8 = unescape(encodeURIComponent(str));
    var result = new Uint8Array(utf8.length);
    for (var i = 0; i < utf8.length; i++) {
      result[i] = utf8.charCodeAt(i);
    }
    console.log("textEncode: ", result);

    return result;
  }

  test() {
    var diagramSource = "digraph D { asdf }";

    var data = this.textEncode(diagramSource);
    var compressed = Pako.deflate(data, { level: 9 });
    var result = btoa(compressed).replace(/\+/g, "-").replace(/\//g, "_");

    console.log(result);
  }

Then I add the result to "https://kroki.io/graphviz/svg/ + result". It seems that the example is not working - could you please provide some insigths.

Cool project - it's great to have all of the diffrent diagram types in one service.

ggrossetie commented 3 years ago

Hello @IyotakeTatanka

Are you using Pako version 2.x? If so, you can take a look at: https://github.com/yuzutech/kroki/issues/593

I haven't had time to update the documentation but I would gladly accept a pull request.

Let me know if it works, and thanks for your kind words 🤗

scherersebastian commented 3 years ago

Thanks for the quick reply. Am using version 2.0.3. I will investigate further and then report back.

scherersebastian commented 3 years ago

I will use mermaid.js. You can run it directly in the client and do not have to query/set up an server.

My use case has changed.