From 52c9b9f6ff93def17237361938d9028edd00d12c Mon Sep 17 00:00:00 2001 From: simon Date: Sat, 25 May 2019 13:44:21 -0400 Subject: [PATCH] Tag filters, different menu for tags/releases --- music_graph/src/MusicGraph.js | 45 ++-- music_graph/src/MusicGraphApi.js | 48 +++- music_graph/src/genres.js | 421 +++++++++++++++++++++++++++++++ 3 files changed, 489 insertions(+), 25 deletions(-) create mode 100644 music_graph/src/genres.js diff --git a/music_graph/src/MusicGraph.js b/music_graph/src/MusicGraph.js index 8fe6d5b..3272f45 100644 --- a/music_graph/src/MusicGraph.js +++ b/music_graph/src/MusicGraph.js @@ -78,8 +78,8 @@ export function MusicGraph(data) { this.container.append('g').attr('id', 'links') this.container.append('g').attr('id', 'nodes') - this.container.append('g').attr('id', 'labels') this.container.append('g').attr('id', 'menu') + this.container.append('g').attr('id', 'labels') this.dragStarted = (d) => { if (d.menu) { @@ -144,7 +144,7 @@ export function MusicGraph(data) { this.node.classed('hover', n => n.id === d.id) - if (d.type === 'Group' && d.type === 'Artist') { + if (d.type === 'Group' || d.type === 'Artist') { this._data.hoverArtist = d } } @@ -160,7 +160,7 @@ export function MusicGraph(data) { this.makeMenu = function (d) { let items = [] let i = 0 - if (!d.membersExpanded) { + if (d.type === 'Group' && !d.membersExpanded) { items.push({ idx: i++, icon: icons.guitar, @@ -174,15 +174,12 @@ export function MusicGraph(data) { } }) } - if (!d.relatedExpanded) { + if ((d.type === 'Group' || d.type === 'Artist') && !d.relatedExpanded) { items.push({ idx: i++, icon: icons.expand, title: 'Related', fn: (d) => { - if (d.relatedExpanded) { - return - } this.api.getRelatedByMbid(d.mbid) .then(data => { this.addNodes(data.newNodes, data.relations, d.id) @@ -192,15 +189,12 @@ export function MusicGraph(data) { } }) } - if (!d.releasesExpanded) { + if ((d.type === 'Artist' || d.type === 'Group') && !d.releasesExpanded) { items.push({ idx: i++, icon: icons.release, title: 'Releases', fn: (d) => { - if (d.releasesExpanded) { - return - } this.api.getArtistReleases(d.mbid, d.id) .then(data => { this.addNodes(data.newNodes, data.relations, d.id) @@ -209,21 +203,32 @@ export function MusicGraph(data) { } }) } - if (!d.tagsExpanded) { - items.push({ - idx: i++, - icon: icons.hash, - title: 'Tags', - fn: (d) => { - if (d.tagsExpanded) { - return - } + if ((d.type === 'Album' || d.type === 'EP' || d.type === 'Single' || d.type === 'Group' || d.type === 'Artist') && + !d.tagsExpanded) { + let fn + if (d.type === 'Group' || d.type === 'Artist') { + fn = (d) => { this.api.getArtistTags(d.mbid, d.id) .then(data => { this.addNodes(data.newNodes, data.relations, d.id) d.tagsExpanded = true }) } + } else if (d.type === 'Album' || d.type === 'EP' || d.type === 'Single') { + fn = (d) => { + this.api.getReleaseDetails(d.mbid, d.id) + .then(data => { + this.addNodes(data.newNodes, data.relations, d.id) + d.tagsExpanded = true + }) + } + } + + items.push({ + idx: i++, + icon: icons.hash, + title: 'Tags', + fn: fn }) } items.push({ diff --git a/music_graph/src/MusicGraphApi.js b/music_graph/src/MusicGraphApi.js index 8176327..209a47e 100644 --- a/music_graph/src/MusicGraphApi.js +++ b/music_graph/src/MusicGraphApi.js @@ -1,4 +1,8 @@ import * as d3 from 'd3' +import {genres} from './genres' + +const IGNORE_DATES_TAG = true +const ONLY_GENRE_TAGS = true const nodeUtils = { getNodeType: function (labels) { @@ -35,6 +39,7 @@ const nodeUtils = { return { id: data.id, name: data.name, + mbid: data.mbid, type: type, sourceLinks: new Set(), targetLinks: new Set(), @@ -116,15 +121,30 @@ export function MusicGraphApi() { }) } + this._filterTags = function (tags) { + if (ONLY_GENRE_TAGS) { + return tags.filter(tag => genres.has(tag.name)) + } else if (IGNORE_DATES_TAG) { + return tags.filter(tag => isNaN(tag.name) && isNaN(tag.name.slice(0, -1))) + } + return tags + } + + this._addTagLabel = function (objects) { + return objects.map(tag => { + tag.labels = ['Tag'] + return tag + }) + } + this.getArtistTags = function (mbid, originId) { return d3.json(this.url + '/artist/details/' + mbid) .then((r) => { + const tags = this._filterTags(r.tags) + return { - newNodes: r.tags.map(tag => { - tag.labels = ['Tag'] - return tag - }).map(nodeUtils.fromRawDict), - relations: r.tags.map(t => { + newNodes: this._addTagLabel(tags).map(nodeUtils.fromRawDict), + relations: tags.map(t => { return { source: originId, target: t.id, @@ -144,4 +164,22 @@ export function MusicGraphApi() { } }) } + + this.getReleaseDetails = function (mbid, originId) { + return d3.json(this.url + '/release/details/' + mbid) + .then((r) => { + const tags = this._filterTags(r.tags) + + return { + newNodes: this._addTagLabel(tags).map(nodeUtils.fromRawDict), + relations: tags.map(t => { + return { + source: originId, + target: t.id, + weight: t.weight + } + }) + } + }) + } } diff --git a/music_graph/src/genres.js b/music_graph/src/genres.js new file mode 100644 index 0000000..1412460 --- /dev/null +++ b/music_graph/src/genres.js @@ -0,0 +1,421 @@ +export const genres = new Set([ + 'acid house', + 'acid jazz', + 'acid techno', + 'acoustic blues', + 'acoustic rock', + 'afrobeat', + 'alternative country', + 'alternative dance', + 'alternative folk', + 'alternative hip hop', + 'alternative metal', + 'alternative pop', + 'alternative punk', + 'alternative rock', + 'ambient', + 'ambient house', + 'ambient techno', + 'americana', + 'anarcho-punk', + 'aor', + 'arena rock', + 'art rock', + 'atmospheric black metal', + 'audiobook', + 'avant-garde', + 'avant-garde jazz', + 'avant-garde metal', + 'avant-garde pop', + 'bachata', + 'ballad', + 'barbershop', + 'baroque', + 'bebop', + 'bhangra', + 'big band', + 'big beat', + 'black metal', + 'blackened death metal', + 'blackgaze', + 'blue-eyed soul', + 'bluegrass', + 'blues', + 'blues rock', + 'bolero', + 'bolero son', + 'boom bap', + 'bossa nova', + 'breakbeat', + 'breakcore', + 'breaks', + 'britpop', + 'broken beat', + 'brutal death metal', + 'bubblegum pop', + 'cajun', + 'calypso', + 'canterbury scene', + 'cantopop', + 'celtic', + 'celtic punk', + 'chamber pop', + 'champeta', + 'chanson', + 'chicago blues', + 'chillout', + 'chiptune', + 'christian rock', + 'christmas music', + 'city pop', + 'classic blues', + 'classic country', + 'classic jazz', + 'classic rock', + 'classical', + 'club', + 'comedy', + 'conscious hip hop', + 'contemporary christian', + 'contemporary classical', + 'contemporary folk', + 'contemporary gospel', + 'contemporary jazz', + 'contemporary r&b', + 'contra', + 'cool jazz', + 'country', + 'country blues', + 'country folk', + 'country pop', + 'country rock', + 'crossover prog', + 'crust punk', + 'cumbia', + 'd-beat', + 'dance', + 'dance-pop', + 'dance-punk', + 'dancehall', + 'dark ambient', + 'dark electro', + 'dark folk', + 'dark wave', + 'death metal', + 'death-doom metal', + 'deathcore', + 'deathgrind', + 'deathrock', + 'deep house', + 'delta blues', + 'desert rock', + 'digital hardcore', + 'disco', + 'doo-wop', + 'doom metal', + 'downtempo', + 'drill', + 'drone', + 'drum and bass', + 'dub', + 'dub techno', + 'dubstep', + 'dungeon synth', + 'east coast hip hop', + 'ebm', + 'electric blues', + 'electro', + 'electro house', + 'electro swing', + 'electro-funk', + 'electro-industrial', + 'electroclash', + 'electronic', + 'electronic rock', + 'electronica', + 'electronicore', + 'electropop', + 'electropunk', + 'emo', + 'emocore', + 'enka', + 'ethereal', + 'euro house', + 'eurodance', + 'europop', + 'experimental', + 'experimental rock', + 'fado', + 'filk', + 'flamenco', + 'folk', + 'folk metal', + 'folk pop', + 'folk punk', + 'folk rock', + 'freak folk', + 'free improvisation', + 'free jazz', + 'funk', + 'funk carioca', + 'funk metal', + 'funk rock', + 'funk soul', + 'funky house', + 'fusion', + 'future jazz', + 'futurepop', + 'g-funk', + 'gabber', + 'gangsta rap', + 'garage', + 'garage house', + 'garage punk', + 'garage rock', + 'glam', + 'glam metal', + 'glam rock', + 'glitch', + 'goa trance', + 'goregrind', + 'gospel', + 'gothic', + 'gothic metal', + 'gothic rock', + 'grebo', + 'grime', + 'grindcore', + 'groove metal', + 'grunge', + 'guaracha', + 'happy hardcore', + 'hard bop', + 'hard house', + 'hard rock', + 'hard trance', + 'hardcore punk', + 'hardcore techno', + 'hardstyle', + 'heavy metal', + 'hip hop', + 'honky tonk', + 'horror punk', + 'horrorcore', + 'house', + 'idm', + 'illbient', + 'indie', + 'indie folk', + 'indie pop', + 'indie rock', + 'indietronica', + 'indorock', + 'industrial', + 'industrial metal', + 'industrial rock', + 'instrumental', + 'instrumental jazz', + 'instrumental rock', + 'irish folk', + 'italo-disco', + 'j-pop', + 'j-rock', + 'jazz', + 'jazz blues', + 'jazz fusion', + 'jazz rap', + 'jazz rock', + 'jazz-funk', + 'jungle', + 'k-pop', + 'kayōkyoku', + 'kizomba', + 'klezmer', + 'krautrock', + 'latin', + 'latin jazz', + 'latin pop', + 'latin rock', + 'leftfield', + 'line dance', + 'lo-fi', + 'lounge', + 'lovers rock', + 'madchester', + 'mainstream rock', + 'mambo', + 'mandopop', + 'martial industrial', + 'math rock', + 'mathcore', + 'medieval', + 'melodic black metal', + 'melodic death metal', + 'melodic metalcore', + 'melodic rock', + 'melodic trance', + 'mento', + 'merengue', + 'metal', + 'metalcore', + 'microhouse', + 'milonga', + 'min\'yō', + 'mincecore', + 'minimal', + 'modern blues', + 'modern classical', + 'modern country', + 'motown', + 'mpb', + 'musical', + 'neo soul', + 'neo-progressive rock', + 'neo-rockabilly', + 'neofolk', + 'nerdcore', + 'new age', + 'new jack swing', + 'new romantic', + 'new wave', + 'no wave', + 'noise', + 'noise pop', + 'noisecore', + 'non-music', + 'norteño', + 'northern soul', + 'nu jazz', + 'nu metal', + 'occult rock', + 'oi', + 'old school death metal', + 'old-time', + 'opera', + 'orchestral', + 'outlaw country', + 'p-funk', + 'pachanga', + 'pop', + 'pop metal', + 'pop punk', + 'pop rap', + 'pop rock', + 'pop soul', + 'pornogrind', + 'post-bop', + 'post-classical', + 'post-grunge', + 'post-hardcore', + 'post-metal', + 'post-punk', + 'post-rock', + 'power electronics', + 'power metal', + 'power pop', + 'powerviolence', + 'production music', + 'progressive', + 'progressive folk', + 'progressive house', + 'progressive metal', + 'progressive rock', + 'progressive trance', + 'psy-trance', + 'psychedelic', + 'psychedelic folk', + 'psychedelic pop', + 'psychedelic rock', + 'psychobilly', + 'psytrance', + 'punk', + 'punk rock', + 'queercore', + 'r&b', + 'ragga', + 'ragga hip-hop', + 'ragga jungle', + 'ragtime', + 'raï', + 'ranchera', + 'rap rock', + 'rapcore', + 'rave', + 'reggae', + 'reggaeton', + 'rhythmic noise', + 'rock', + 'rock and roll', + 'rockabilly', + 'rocksteady', + 'roots reggae', + 'rumba', + 'salsa', + 'samba', + 'schlager', + 'screamo', + 'shibuya-kei', + 'shoegaze', + 'singer-songwriter', + 'ska', + 'ska punk', + 'skacore', + 'slow waltz', + 'sludge metal', + 'smooth jazz', + 'smooth soul', + 'soca', + 'soft rock', + 'son cubano', + 'son montuno', + 'soul', + 'soul jazz', + 'southern rock', + 'southern soul', + 'space rock', + 'speed garage', + 'speed metal', + 'spoken word', + 'stoner metal', + 'stoner rock', + 'street punk', + 'surf rock', + 'swing', + 'symphonic black metal', + 'symphonic metal', + 'symphonic prog', + 'symphonic rock', + 'symphony', + 'synth-pop', + 'synthwave', + 'tango', + 'tech house', + 'technical death metal', + 'techno', + 'teen pop', + 'thrash metal', + 'thrashcore', + 'timba', + 'traditional country', + 'trance', + 'trap', + 'trap edm', + 'tribal house', + 'trip hop', + 'turntablism', + 'uk drill', + 'uk garage', + 'underground hip hop', + 'vallenato', + 'vaporwave', + 'viking metal', + 'visual kei', + 'vocal house', + 'vocal jazz', + 'vocal trance', + 'west coast hip hop', + 'west coast swing', + 'yé-yé', + 'zamrock', + 'zydeco' +])