Skip to content

Accept JSON data provided directly (without an URL) #1

Description

@xtianpoli

When using MdmLayer in an ipywidget, the data isn't provided via a URL; instead, the JSON content is injected directly by the kernel. That's why we should be able to provide the data—for example, via a JSON property—like this: data: {json: SomeJsonContent}, just as we do with data: {url: 'yourDataFileHere.json'}. That's why I'm proposing this small change:

diff --git a/typescript/src/multiclass_layer/layer.ts b/typescript/src/multiclass_layer/layer.ts
index a6d3061..c4fcb28 100644
--- a/typescript/src/multiclass_layer/layer.ts
+++ b/typescript/src/multiclass_layer/layer.ts
@@ -39,9 +39,14 @@ const defaultProps = {
         transform: async (input: any) => {
             if (!input) throw Error("mdmSpecs must be provided");
             if (!input.specs) throw Error("mdmSpecs must have a 'specs' field");
+            if (!input.specs.data) throw Error("mdmSpecs.specs must have a 'data' field");
             const config = new Config(input.specs);
             const baseUrl = input.baseUrl || "";
+           if(input.specs.data.json){
+               await config.loadJson(input.specs.data.json);
+           } else {
                 await config.load(baseUrl, true, input.imageData);
+           }
             if (!config.validate())
             {
                 throw Error("config not validated");

Thanks in advance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions