From 62d7e0146d471e7623e4ec384a928a828b8780e9 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Thu, 5 Oct 2023 23:22:43 -0300 Subject: content, data: experimental art tag sidebar --- src/data/composite/things/art-tag/index.js | 1 + .../things/art-tag/withAncestorArtTagBaobabTree.js | 46 ++++++++++++++++++++++ src/data/things/art-tag.js | 8 +++- src/data/things/language.js | 1 + 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 src/data/composite/things/art-tag/withAncestorArtTagBaobabTree.js (limited to 'src/data') diff --git a/src/data/composite/things/art-tag/index.js b/src/data/composite/things/art-tag/index.js index 0c365ce2..bbd38293 100644 --- a/src/data/composite/things/art-tag/index.js +++ b/src/data/composite/things/art-tag/index.js @@ -1 +1,2 @@ export {default as withAllDescendantArtTags} from './withAllDescendantArtTags.js'; +export {default as withAncestorArtTagBaobabTree} from './withAncestorArtTagBaobabTree.js'; diff --git a/src/data/composite/things/art-tag/withAncestorArtTagBaobabTree.js b/src/data/composite/things/art-tag/withAncestorArtTagBaobabTree.js new file mode 100644 index 00000000..d5caa99e --- /dev/null +++ b/src/data/composite/things/art-tag/withAncestorArtTagBaobabTree.js @@ -0,0 +1,46 @@ +// Gets all the art tags which are ancestors of this one as a "baobab tree" - +// what you'd typically think of as roots are all up in the air! Since this +// really is backwards from the way that the art tag tree is written in data, +// chances are pretty good that there will be many of the exact same "leaf" +// nodes - art tags which don't themselves have any ancestors. In the actual +// data structure, each node is a Map, with keys for each ancestor and values +// for each ancestor's own baobab (thus a branching structure, just like normal +// trees in this regard). + +import {input, templateCompositeFrom} from '#composite'; + +import {raiseOutputWithoutDependency} from '#composite/control-flow'; +import {withReverseReferenceList} from '#composite/wiki-data'; + +export default templateCompositeFrom({ + annotation: `withAncestorArtTagBaobabTree`, + + outputs: ['#ancestorArtTagBaobabTree'], + + steps: () => [ + withReverseReferenceList({ + data: 'artTagData', + list: input.value('directDescendantArtTags'), + }).outputs({ + ['#reverseReferenceList']: '#directAncestorArtTags', + }), + + raiseOutputWithoutDependency({ + dependency: '#directAncestorArtTags', + mode: input.value('empty'), + output: input.value({'#ancestorArtTagBaobabTree': {}}) + }), + + { + dependencies: ['#directAncestorArtTags'], + compute: (continuation, { + ['#directAncestorArtTags']: directAncestorArtTags, + }) => continuation({ + ['#ancestorArtTagBaobabTree']: + new Map( + directAncestorArtTags + .map(artTag => [artTag, artTag.ancestorArtTagBaobabTree])), + }), + }, + ], +}); diff --git a/src/data/things/art-tag.js b/src/data/things/art-tag.js index 707b3c93..a530ba8c 100644 --- a/src/data/things/art-tag.js +++ b/src/data/things/art-tag.js @@ -19,7 +19,8 @@ import { wikiData, } from '#composite/wiki-properties'; -import {withAllDescendantArtTags} from '#composite/things/art-tag'; +import {withAllDescendantArtTags, withAncestorArtTagBaobabTree} + from '#composite/things/art-tag'; import Thing from './thing.js'; @@ -110,5 +111,10 @@ export class ArtTag extends Thing { data: 'artTagData', list: input.value('directDescendantArtTags'), }), + + ancestorArtTagBaobabTree: [ + withAncestorArtTagBaobabTree(), + exposeDependency({dependency: '#ancestorArtTagBaobabTree'}), + ], }); } diff --git a/src/data/things/language.js b/src/data/things/language.js index fe74f7bf..cd719d0c 100644 --- a/src/data/things/language.js +++ b/src/data/things/language.js @@ -376,6 +376,7 @@ Object.assign(Language.prototype, { countAdditionalFiles: countHelper('additionalFiles', 'files'), countAlbums: countHelper('albums'), countArtworks: countHelper('artworks'), + countArtTags: countHelper('artTags', 'tags'), countFlashes: countHelper('flashes'), countCommentaryEntries: countHelper('commentaryEntries', 'entries'), countContributions: countHelper('contributions'), -- cgit 1.3.0-6-gf8a5