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

Fix multi lvl categories in embedded .xlsx #1330

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix multi lvl categories in embedded .xlsx
  • Loading branch information
MariusOpeepl committed Apr 9, 2024
commit 03ac4e3a0671f69d64e68dad07eeee33fbd19ee2
29 changes: 20 additions & 9 deletions src/gen-charts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ export async function createExcelWorksheet (chartObject: ISlideRelChart, zip: JS
)
}

// dictionary of shared strings mapped to indexes
const sharedStrings: Record<string, number> = {}

// sharedStrings.xml
{
// A: Start XML
Expand All @@ -148,6 +151,7 @@ export async function createExcelWorksheet (chartObject: ISlideRelChart, zip: JS
data[0].labels.forEach(arrLabel => (totCount += arrLabel.filter(label => label && label !== '').length))
strSharedStrings += `<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="${totCount}" uniqueCount="${totCount}">`
strSharedStrings += '<si><t/></si>'
sharedStrings[''] = 0
} else {
// series names + all labels of one series + number of label groups (data.labels.length) of one series (i.e. how many times the blank string is used)
const totCount = data.length + data[0].labels.length * data[0].labels[0].length + data[0].labels.length
Expand All @@ -157,20 +161,29 @@ export async function createExcelWorksheet (chartObject: ISlideRelChart, zip: JS
strSharedStrings += `<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="${totCount}" uniqueCount="${unqCount}">`
// B: Add 'blank' for A1, B1, ..., of every label group inside data[n].labels
strSharedStrings += '<si><t xml:space="preserve"></t></si>'
sharedStrings[''] = 0
}

// C: Add `name`/Series
if (chartObject.opts._type === CHART_TYPE.BUBBLE || chartObject.opts._type === CHART_TYPE.BUBBLE3D) {
data.forEach((objData, idx) => {
if (idx === 0) strSharedStrings += '<si><t>X-Axis</t></si>'
else {
strSharedStrings += `<si><t>${encodeXmlEntities(objData.name || `Y-Axis${idx}`)}</t></si>`
strSharedStrings += `<si><t>${encodeXmlEntities(`Size${idx}`)}</t></si>`
if (idx === 0) {
const xAxisSharedString = 'X-Axis'
strSharedStrings += `<si><t>${xAxisSharedString}</t></si>`
} else {
const yAxisSharedString = encodeXmlEntities(objData.name || `Y-Axis${idx}`)
strSharedStrings += `<si><t>${yAxisSharedString}</t></si>`
sharedStrings[yAxisSharedString] = Object.keys(yAxisSharedString).length
const sizeSharedString = encodeXmlEntities(`Size${idx}`)
strSharedStrings += `<si><t>${sizeSharedString}</t></si>`
sharedStrings[sizeSharedString] = Object.keys(sizeSharedString).length
}
})
} else {
data.forEach(objData => {
strSharedStrings += `<si><t>${encodeXmlEntities((objData.name || ' ').replace('X-Axis', 'X-Values'))}</t></si>`
const sharedString = encodeXmlEntities((objData.name || ' ').replace('X-Axis', 'X-Values'))
strSharedStrings += `<si><t>${sharedString}</t></si>`
sharedStrings[sharedString] = Object.keys(sharedStrings).length
})
}

Expand All @@ -185,6 +198,7 @@ export async function createExcelWorksheet (chartObject: ISlideRelChart, zip: JS
.filter(label => label && label !== '')
.forEach(label => {
strSharedStrings += `<si><t>${encodeXmlEntities(label)}</t></si>`
sharedStrings[encodeXmlEntities(label)] = Object.keys(sharedStrings).length
})
})
}
Expand Down Expand Up @@ -460,7 +474,6 @@ export async function createExcelWorksheet (chartObject: ISlideRelChart, zip: JS

// WIP: FIXME:
// B: add a col for each label/cat
let totLabels = TOT_SER
const revLabelGroups = data[0].labels.slice().reverse()
revLabelGroups.forEach((labelsGroup, idy) => {
/**
Expand All @@ -471,9 +484,7 @@ export async function createExcelWorksheet (chartObject: ISlideRelChart, zip: JS
*/
const colLabel = labelsGroup[idx]
if (colLabel) {
const totGrpLbls = idy === 0 ? 1 : revLabelGroups[idy - 1].filter(label => label && label !== '').length // get unique label so we can add to get proper shared-string #
totLabels += totGrpLbls
strSheetXml += `<c r="${getExcelColName(idx + 1 + idy)}${idx + 2}" t="s"><v>${totLabels}</v></c>`
strSheetXml += `<c r="${getExcelColName(1 + idy)}${idx + 2}" t="s"><v>${sharedStrings[colLabel]}</v></c>`
}
})

Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy