(host: GraphHost, palette: Palette)
| 510 | } |
| 511 | |
| 512 | function drawHorizontalBar(host: GraphHost, palette: Palette): GraphDrawFn { |
| 513 | return (spreadsheet, range, gview, gtype, helpflag) => { |
| 514 | if (helpflag || !range) { |
| 515 | const hideHelp = host.SocialCalc.Constants['s_loc_hide_help'] ?? 'Hide Help'; |
| 516 | gview.innerHTML = `<input type="button" value="${hideHelp}" onclick="DoGraph(false,false);"><br><br>Horizontal bar help.`; |
| 517 | return; |
| 518 | } |
| 519 | const { values, labels } = collectValues(host, spreadsheet, range); |
| 520 | gview.innerHTML = '<canvas id="myBarCanvas" width="500px" height="400px" style="border:1px solid black;"></canvas>'; |
| 521 | const canv = host.doc.getElementById('myBarCanvas') as HTMLCanvasElement | null; |
| 522 | if (!canv) return; |
| 523 | const ctx = canv.getContext('2d') as CanvasRenderingContext2D | null; |
| 524 | if (!ctx) return; |
| 525 | ctx.font = '10pt bold Arial'; |
| 526 | palette.reset(); |
| 527 | const each = Math.floor(canv.height / (values.length || 1)) - 4 || 1; |
| 528 | let max = 0; |
| 529 | for (const v of values) if (v > max) max = v; |
| 530 | for (let i = 0; i < values.length; i++) { |
| 531 | ctx.fillStyle = '#' + palette.getBarColor(); |
| 532 | ctx.fillRect(0, i * each, (values[i]! / (max || 1)) * (canv.width - 50), each); |
| 533 | ctx.fillStyle = '#000'; |
| 534 | // Labels pushed 1:1 with values — `?? ''` is defensive-only. |
| 535 | ctx.fillText(/* istanbul ignore next */ labels[i] ?? '', 4, i * each + each / 2); |
| 536 | } |
| 537 | }; |
| 538 | } |
| 539 | |
| 540 | function drawPieChart(host: GraphHost, palette: Palette): GraphDrawFn { |
| 541 | return (spreadsheet, range, gview) => { |
no test coverage detected