From b3feb85346676bbc1a46ef089a6f9c5d87d0e91c Mon Sep 17 00:00:00 2001 From: Justin Schell Date: Mon, 1 Jul 2024 22:43:40 +0000 Subject: [PATCH 01/11] can center labels using uniform mode as they'll get hidden if too big --- src/traces/pie/plot.js | 15 ++++++++++----- src/traces/sunburst/plot.js | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/traces/pie/plot.js b/src/traces/pie/plot.js index 450b8c4a09f..4ff86540226 100644 --- a/src/traces/pie/plot.js +++ b/src/traces/pie/plot.js @@ -167,7 +167,7 @@ function plot(gd, cdModule) { if(textPosition === 'outside') { transform = transformOutsideText(textBB, pt); } else { - transform = transformInsideText(textBB, pt, cd0); + transform = transformInsideText(textBB, pt, cd0, fullLayout); if(textPosition === 'auto' && transform.scale < 1) { var newFont = Lib.ensureUniformFontSize(gd, trace.outsidetextfont); @@ -635,7 +635,7 @@ function prerenderTitles(cdModule, gd) { } } -function transformInsideText(textBB, pt, cd0) { +function transformInsideText(textBB, pt, cd0, fullLayout) { var r = cd0.r || pt.rpx1; var rInscribed = pt.rInscribed; @@ -660,6 +660,7 @@ function transformInsideText(textBB, pt, cd0) { var isTangential = orientation === 'tangential'; var isRadial = orientation === 'radial'; var isAuto = orientation === 'auto'; + var isUniformModeHide = fullLayout.uniformtext.mode === 'hide'; var allTransforms = []; var newT; @@ -723,7 +724,7 @@ function transformInsideText(textBB, pt, cd0) { } if(isAuto || isRadial) { - newT = calcRadTransform(textBB, r, ring, halfAngle, midAngle); + newT = calcRadTransform(textBB, r, ring, halfAngle, midAngle, isUniformModeHide); newT.textPosAngle = (pt.startangle + pt.stopangle) / 2; allTransforms.push(newT); } @@ -760,7 +761,7 @@ function isCrossing(pt, angle) { ); } -function calcRadTransform(textBB, r, ring, halfAngle, midAngle) { +function calcRadTransform(textBB, r, ring, halfAngle, midAngle, isUniformModeHide) { r = Math.max(0, r - 2 * TEXTPAD); // max size if text is rotated radially @@ -768,7 +769,7 @@ function calcRadTransform(textBB, r, ring, halfAngle, midAngle) { var s = calcMaxHalfSize(a, halfAngle, r, ring); return { scale: s * 2 / textBB.height, - rCenter: calcRCenter(a, s / r), + rCenter: isUniformModeHide ? calcRingCenter(ring) : calcRCenter(a, s / r), rotate: calcRotate(midAngle) }; } @@ -790,6 +791,10 @@ function calcRCenter(a, b) { return Math.cos(b) - a * b; } +function calcRingCenter(ring) { + return 1 - ring / 2; +} + function calcRotate(t) { return (180 / Math.PI * t + 720) % 180 - 90; } diff --git a/src/traces/sunburst/plot.js b/src/traces/sunburst/plot.js index 386dc1bf4ce..e83478c346e 100644 --- a/src/traces/sunburst/plot.js +++ b/src/traces/sunburst/plot.js @@ -275,7 +275,7 @@ function plotOne(gd, cd, element, transitionOpts) { // position the text relative to the slice var textBB = Drawing.bBox(sliceText.node()); - pt.transform = transformInsideText(textBB, pt, cd0); + pt.transform = transformInsideText(textBB, pt, cd0, fullLayout); pt.transform.targetX = getTargetX(pt); pt.transform.targetY = getTargetY(pt); From be66ed6076ccebccf68be8e7283f9a889ca71a1c Mon Sep 17 00:00:00 2001 From: Justin Schell Date: Tue, 2 Jul 2024 22:40:55 +0000 Subject: [PATCH 02/11] build custom plotly github action --- .github/workflows/lint-and-build.yml | 17 +++++++++++++++++ .gitignore | 1 + 2 files changed, 18 insertions(+) create mode 100644 .github/workflows/lint-and-build.yml diff --git a/.github/workflows/lint-and-build.yml b/.github/workflows/lint-and-build.yml new file mode 100644 index 00000000000..560fe309cea --- /dev/null +++ b/.github/workflows/lint-and-build.yml @@ -0,0 +1,17 @@ +name: Lint & Build Custom Plotly.js +on: [push] +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: lts/* + - run: npm ci + - run: npm run lint + - run: npm run custom-bundle -- --traces pie,bar,sunburst --transforms none + - uses: actions/upload-artifact@v4 + with: + name: plotly-custom.min.js + path: dist/plotly-custom.min.js diff --git a/.gitignore b/.gitignore index 40e49228498..37e0a0bd2d4 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ tags !.npmignore !.eslintrc !.eslintignore +!.github \ No newline at end of file From 2356af1e510c5b5a7e40e37ad20c26ddeb138625 Mon Sep 17 00:00:00 2001 From: Justin Schell Date: Tue, 23 Jul 2024 17:49:17 +0000 Subject: [PATCH 03/11] can also center text snapped to horizontal in uniform hide mode --- src/traces/pie/plot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/traces/pie/plot.js b/src/traces/pie/plot.js index 4ff86540226..ae119487bfa 100644 --- a/src/traces/pie/plot.js +++ b/src/traces/pie/plot.js @@ -678,7 +678,7 @@ function transformInsideText(textBB, pt, cd0, fullLayout) { if(key === 'tan') { newT = calcTanTransform(textBB, r, ring, closestEdge, 0); } else { // case of 'rad' - newT = calcRadTransform(textBB, r, ring, closestEdge, Math.PI / 2); + newT = calcRadTransform(textBB, r, ring, closestEdge, Math.PI / 2, isUniformModeHide); } newT.textPosAngle = angle; From f475f2e91f4d20ff17a0ebdafecbd742c1316e8a Mon Sep 17 00:00:00 2001 From: Justin Schell Date: Tue, 23 Jul 2024 17:50:23 +0000 Subject: [PATCH 04/11] only prefer earlier for same scale; later larger scales look better --- src/traces/pie/plot.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/traces/pie/plot.js b/src/traces/pie/plot.js index ae119487bfa..4a8be486da8 100644 --- a/src/traces/pie/plot.js +++ b/src/traces/pie/plot.js @@ -739,15 +739,10 @@ function transformInsideText(textBB, pt, cd0, fullLayout) { var maxScale = 0; for(var k = 0; k < allTransforms.length; k++) { var s = allTransforms[k].scale; - if(maxScale < s) { + if(s - maxScale > 0.01) { maxScale = s; id = k; } - - if(!isAuto && maxScale >= 1) { - // respect test order for non-auto options - break; - } } return allTransforms[id]; } From 9579edeb3ea4b09243c429035b5b49318df01683 Mon Sep 17 00:00:00 2001 From: Justin Schell Date: Tue, 20 Aug 2024 21:33:40 +0000 Subject: [PATCH 05/11] add waterfall --- .github/workflows/lint-and-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint-and-build.yml b/.github/workflows/lint-and-build.yml index 560fe309cea..21c1cfec684 100644 --- a/.github/workflows/lint-and-build.yml +++ b/.github/workflows/lint-and-build.yml @@ -10,7 +10,7 @@ jobs: node-version: lts/* - run: npm ci - run: npm run lint - - run: npm run custom-bundle -- --traces pie,bar,sunburst --transforms none + - run: npm run custom-bundle -- --traces pie,bar,sunburst,waterfall --transforms none - uses: actions/upload-artifact@v4 with: name: plotly-custom.min.js From 6fd2c6c60273c4b592482951db6a2f3f7202f059 Mon Sep 17 00:00:00 2001 From: Justin Schell Date: Fri, 30 Aug 2024 14:51:03 +0000 Subject: [PATCH 06/11] generate artifact with version id to invalidate cache --- .github/workflows/lint-and-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint-and-build.yml b/.github/workflows/lint-and-build.yml index 21c1cfec684..b6df7af99d3 100644 --- a/.github/workflows/lint-and-build.yml +++ b/.github/workflows/lint-and-build.yml @@ -13,5 +13,5 @@ jobs: - run: npm run custom-bundle -- --traces pie,bar,sunburst,waterfall --transforms none - uses: actions/upload-artifact@v4 with: - name: plotly-custom.min.js + name: plotly-custom-{{ github.run_id }}-{{github.run_attempt}}.min.js path: dist/plotly-custom.min.js From 7036bc905d5d7f5dc3423c7362951e4eb83fa450 Mon Sep 17 00:00:00 2001 From: Justin Schell Date: Fri, 30 Aug 2024 14:55:48 +0000 Subject: [PATCH 07/11] fix variable reference --- .github/workflows/lint-and-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint-and-build.yml b/.github/workflows/lint-and-build.yml index b6df7af99d3..2712c9fa751 100644 --- a/.github/workflows/lint-and-build.yml +++ b/.github/workflows/lint-and-build.yml @@ -13,5 +13,5 @@ jobs: - run: npm run custom-bundle -- --traces pie,bar,sunburst,waterfall --transforms none - uses: actions/upload-artifact@v4 with: - name: plotly-custom-{{ github.run_id }}-{{github.run_attempt}}.min.js + name: plotly-custom-${{ github.run_id }}-${{ github.run_attempt }}.min.js path: dist/plotly-custom.min.js From 6a27a07a695e6e0f6fa25c1ba520ea907f1e9add Mon Sep 17 00:00:00 2001 From: Justin Schell Date: Fri, 30 Aug 2024 15:45:39 +0000 Subject: [PATCH 08/11] use short sha instead of action id, run number --- .github/workflows/lint-and-build.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lint-and-build.yml b/.github/workflows/lint-and-build.yml index 2712c9fa751..b9771ea24d8 100644 --- a/.github/workflows/lint-and-build.yml +++ b/.github/workflows/lint-and-build.yml @@ -11,7 +11,11 @@ jobs: - run: npm ci - run: npm run lint - run: npm run custom-bundle -- --traces pie,bar,sunburst,waterfall --transforms none + - id: get-short-sha + run: | + sha=$(echo ${{github.sha}} | cut -c-7) + echo "sha=$id" >> $GITHUB_OUTPUT - uses: actions/upload-artifact@v4 with: - name: plotly-custom-${{ github.run_id }}-${{ github.run_attempt }}.min.js + name: plotly-custom-${{steps.get-short-sha.outputs.sha}}.min.js path: dist/plotly-custom.min.js From 89c1682dd405f814631bd97dd7c1e09e48548326 Mon Sep 17 00:00:00 2001 From: Justin Schell Date: Fri, 30 Aug 2024 15:47:49 +0000 Subject: [PATCH 09/11] fpc --- .github/workflows/lint-and-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint-and-build.yml b/.github/workflows/lint-and-build.yml index b9771ea24d8..7cfebb6942f 100644 --- a/.github/workflows/lint-and-build.yml +++ b/.github/workflows/lint-and-build.yml @@ -14,7 +14,7 @@ jobs: - id: get-short-sha run: | sha=$(echo ${{github.sha}} | cut -c-7) - echo "sha=$id" >> $GITHUB_OUTPUT + echo "sha=$sha" >> $GITHUB_OUTPUT - uses: actions/upload-artifact@v4 with: name: plotly-custom-${{steps.get-short-sha.outputs.sha}}.min.js From 303bde8816bb7d88f111c969082cb6e24d86ac56 Mon Sep 17 00:00:00 2001 From: Justin Schell Date: Fri, 30 Aug 2024 15:52:45 +0000 Subject: [PATCH 10/11] use sha in filename itself --- .github/workflows/lint-and-build.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lint-and-build.yml b/.github/workflows/lint-and-build.yml index 7cfebb6942f..4d387cd64c9 100644 --- a/.github/workflows/lint-and-build.yml +++ b/.github/workflows/lint-and-build.yml @@ -15,7 +15,8 @@ jobs: run: | sha=$(echo ${{github.sha}} | cut -c-7) echo "sha=$sha" >> $GITHUB_OUTPUT + - run: mv dist/plotly-custom.min.js dist/plotly-custom-${{steps.get-short-sha.outputs.sha}}.min.js - uses: actions/upload-artifact@v4 with: name: plotly-custom-${{steps.get-short-sha.outputs.sha}}.min.js - path: dist/plotly-custom.min.js + path: dist/plotly-custom-${{steps.get-short-sha.outputs.sha}}.min.js From 32edc870e0f6afed1be6994b0350a0e0828852d1 Mon Sep 17 00:00:00 2001 From: Justin Schell Date: Thu, 17 Oct 2024 22:06:34 +0000 Subject: [PATCH 11/11] Override download image button title --- src/components/modebar/buttons.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/modebar/buttons.js b/src/components/modebar/buttons.js index 67bc00abf55..1e0300a8458 100644 --- a/src/components/modebar/buttons.js +++ b/src/components/modebar/buttons.js @@ -41,8 +41,10 @@ modeBarButtons.toImage = { var opts = gd._context.toImageButtonOptions || {}; var format = opts.format || 'png'; return format === 'png' ? - _(gd, 'Download plot as a png') : // legacy text - _(gd, 'Download plot'); // generic non-PNG text + // Overriding title; revert to "Download plot as a png" to support localization + _(gd, 'Download chart') : // legacy text + // Overriding title; revert to "Download plot" to support localization + _(gd, 'Download chart'); // generic non-PNG text }, icon: Icons.camera, click: function(gd) {