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

feat(dia.CellView)!: separate alias and calc expression evaluation fro… #2335

Closed

Conversation

kumilingus
Copy link
Contributor

@kumilingus kumilingus commented Sep 11, 2023

TBD

image

@kumilingus kumilingus force-pushed the separation-calc-attributes-eval branch from 878830d to 799faf7 Compare September 11, 2023 17:59
@kumilingus kumilingus force-pushed the separation-calc-attributes-eval branch from 799faf7 to d23c09e Compare September 11, 2023 18:02
@kumilingus kumilingus changed the title feat(dia.CellView)! separate alias and calc expression evaluation fro… feat(dia.CellView)!: separate alias and calc expression evaluation fro… Sep 12, 2023
@alexandernst
Copy link
Contributor

Is this related to #1421 ? 🤔

@kumilingus
Copy link
Contributor Author

Currently, it allows you to switch off the support for camel-case. But if we move the alias logic to Vectorizer.attr() it would solve #1421.

@kumilingus
Copy link
Contributor Author

The conversion of attribute names to kebab-case should be done efficiently. AFAIK there is no native API that uses camel-cased names as it is in the case of CSS properties e.g. `el.style.borderWidth = '5px'.

We can perhaps implement some caching like this:

const aliasMap = {
    xlinkHref: 'xlink:href',
    xlinkShow: 'xlink:show',
    xlinkRole: 'xlink:role',
    xlinkType: 'xlink:type',
    xlinkArcrole: 'xlink:arcrole',
    xlinkTitle: 'xlink:title',
    xlinkActuate: 'xlink:actuate',
    xmlSpace: 'xml:space',
    xmlLang: 'xml:lang',
    xmlBase: 'xml:base',
    preserveAspectRatio: 'preserveAspectRatio',
    requiredExtensions: 'requiredExtensions',
    requiredFeatures: 'requiredFeatures',
    systemLanguage: 'systemLanguage',
    externalResourcesRequired: 'externalResourcesRequired',
};

const aliases = new Proxy(aliasMap, {
    get(map, property) {
        if (property in map) {
            return map[property];
        } else {
            const alias = map[property] = util.toKebabCase(property);
            return alias;
        }
    }
});

Later, when using Vectorizer:

// get an alias
console.log(V.aliases.strokeWidh);

// setting attributes
V(el).attr('strokeWidth', 5);
V(el).attr({ strokeDashoffset': 100 });

// define custom / missing alias
V.aliases.myAlias = 'my:alias';

@kumilingus
Copy link
Contributor Author

At this point, I'm not sure if it's worth optimizing. See https://jsperf.app/disifi.

@alexandernst
Copy link
Contributor

🤔 it’s 11% slower on iPhone 12 mini, but indeed I don’t think it will really matter that much on desktop. Maybe on batch operations where multiple attrs of multiple cells will be modified?

@kumilingus
Copy link
Contributor Author

Using caching was slower in all browsers on Desktop for me. Yep, more testing is required.

@kumilingus
Copy link
Contributor Author

Obsolete now. See #2459.

@kumilingus kumilingus closed this Jan 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants