gitbrent / PptxGenJS

Create PowerPoint presentations with a powerful, concise JavaScript API.
https://gitbrent.github.io/PptxGenJS/
MIT License
2.84k stars 625 forks source link

[BUG] Faulty presentation with ScatterPlot #1245

Open artemkov79 opened 1 year ago

artemkov79 commented 1 year ago

We appreciate your feedback - to help the team understand your needs please complete the following template to ensure we have the details to help.

Submission Guidelines

Issue Category

Product Versions

Desired Behavior

Received faulty presentation with code below. The main feature is valAxisCrossesAt: 0,

Observed Behavior

Must be good file which can be opened in PP without repairing

Steps to Reproduce

My Code:

let arrDataScatter1 = [
            { name: "X-Axis", values: [0, 1, 2, 3, 4, 5] },
            { name: "Y-Value 1", values: [90, 80, 70, 85, 75, 92], labels: ["Jan", "Feb", "Mar", "Apr", "May", "Jun"] },
            { name: "Y-Value 2", values: [21, 32, 40, 49, 31, 29], labels: ["Jan", "Feb", "Mar", "Apr", "May", "Jun"] },
        ];

        let optsChartScat1 = {
            x: 0.5,
            y: 0.6,
            w: 4,
            h: 3,
            valAxisCrossesAt: 0,
            lineSize: 0,
            catAxisTitle: "Last 6 Months",
            catAxisTitleColor: "428442",
            catAxisTitleFontSize: 14,
            showCatAxisTitle: true,
            showLabel: true, // Must be set to true or labels will not be shown
            dataLabelPosition: "b", // Options: 't'|'b'|'l'|'r'|'ctr'
        };
        slide.addChart(pptx.charts.SCATTER, arrDataScatter1, optsChartScat1);

i think problem appears in function makeCatAxis(opts, axisId, valAxisId) in string:

    `strXml += " <c:".concat(typeof opts.valAxisCrossesAt === 'number' ? 'crossesAt' : 'crosses', " val=\"").concat(opts.valAxisCrossesAt || 'autoZero', "\"/>");`

The part "|| 'autoZero'" if opts.valAxisCrossesAt===0 at the end leads to faulty result file. I think this string can be refactored with

if (opts.valAxisCrossesAt!==undefined)
        strXml += " <c:".concat(typeof opts.valAxisCrossesAt === 'number' ? 'crossesAt' : 'crosses', " val=\"").concat(opts.valAxisCrossesAt,"\"/>");
    else
        strXml += " <c:crosses val=\"autoZero\"/>";