diff --git a/src/server/sparql/FacetResults.js b/src/server/sparql/FacetResults.js index 423d81ecaed6dfa170338e852387763d2ac4096f..5847a27fb27cf59ffc3e06801ab1c604fb219aaa 100644 --- a/src/server/sparql/FacetResults.js +++ b/src/server/sparql/FacetResults.js @@ -106,7 +106,7 @@ export const getAllResults = ({ } else { ({ endpoint, defaultConstraint, langTag, langTagSecondary } = config) } - const { filterTarget, resultMapper, postprocess = null } = config + const { filterTarget, resultMapper, resultMapperConfig, postprocess = null } = config let { q } = config if (constraints == null && defaultConstraint == null) { q = q.replace(/<FILTER>/g, '# no filters') @@ -153,6 +153,7 @@ export const getAllResults = ({ endpoint: endpoint.url, useAuth: endpoint.useAuth, resultMapper, + resultMapperConfig, postprocess, resultFormat }) diff --git a/src/server/sparql/Mappers.js b/src/server/sparql/Mappers.js index a4fa0682e813d3f88d54ef4260e160f02adeb402..01e66fba74377d7bd742b7303f276b3593b565a1 100644 --- a/src/server/sparql/Mappers.js +++ b/src/server/sparql/Mappers.js @@ -81,20 +81,7 @@ export const mapNameSampoResults = sparqlBindings => { return results } -export const mapLineChart = sparqlBindings => { - const seriesData = [] - const categoriesData = [] - sparqlBindings.map(b => { - seriesData.push(b.count.value) - categoriesData.push(b.category.value) - }) - return { - seriesData, - categoriesData - } -} - -export const mapLineChartFillEmptyValues = sparqlBindings => { +export const mapLineChart = ({ sparqlBindings, config }) => { const seriesData = [] const categoriesData = [] const sparqlBindingsLength = sparqlBindings.length @@ -102,15 +89,23 @@ export const mapLineChartFillEmptyValues = sparqlBindings => { const currentCategory = parseInt(b.category.value) const currentValue = parseInt(b.count.value) seriesData.push(currentValue) - categoriesData.push(currentCategory) - if (index + 1 < sparqlBindingsLength) { + categoriesData.push( + config && config.xAxisConverter + ? config.xAxisConverter(currentCategory) + : currentCategory + ) + if (config && config.fillEmptyValues && index + 1 < sparqlBindingsLength) { let categoryIter = currentCategory const nextNonZeroCategory = parseInt(bindings[index + 1].category.value) // add zeros until we reach the next category with a non zero value while (categoryIter < nextNonZeroCategory - 1) { categoryIter += 1 seriesData.push(0) - categoriesData.push(categoryIter) + categoriesData.push( + config && config.xAxisConverter + ? config.xAxisConverter(categoryIter) + : categoryIter + ) } } }) diff --git a/src/server/sparql/SparqlApi.js b/src/server/sparql/SparqlApi.js index 1a9534698f75845d6058b219ed46eb5a092241b7..d4a0aec9336bb1ef7aed2c3b1910b3b57ce24606 100644 --- a/src/server/sparql/SparqlApi.js +++ b/src/server/sparql/SparqlApi.js @@ -5,6 +5,7 @@ export const runSelectQuery = async ({ query, endpoint, resultMapper, + resultMapperConfig = null, postprocess = null, previousSelections = null, // not in use resultFormat, @@ -29,7 +30,12 @@ export const runSelectQuery = async ({ data: q }) if (resultFormat === 'json') { - const mappedResults = resultMapper(response.data.results.bindings, previousSelections) + if (resultMapper) { + + } + const mappedResults = resultMapperConfig + ? resultMapper({ sparqlBindings: response.data.results.bindings, config: resultMapperConfig }) + : resultMapper(response.data.results.bindings) if (postprocess) { postprocess.func({ data: mappedResults, config: postprocess.config }) } diff --git a/src/server/sparql/sampo/BackendSearchConfig.js b/src/server/sparql/sampo/BackendSearchConfig.js index aa7141f2d97f26c7013757759dd6343fc54b7b80..52b4180ccc6179bbd17c2be7d77ab3b7f39ce8bb 100644 --- a/src/server/sparql/sampo/BackendSearchConfig.js +++ b/src/server/sparql/sampo/BackendSearchConfig.js @@ -175,7 +175,10 @@ export const backendSearchConfig = { perspectiveID: 'perspective1', q: productionsByDecadeQuery, filterTarget: 'instance', - resultMapper: mapLineChart + resultMapper: mapLineChart, + resultMapperConfig: { + fillEmptyValues: false + } }, eventLineChart: { perspectiveID: 'perspective1',