From 7f75d58b58fee91a01ef1c97d56a48fd961747dc Mon Sep 17 00:00:00 2001 From: Mauricio Poppe Date: Sat, 2 Nov 2024 12:35:57 -0400 Subject: [PATCH] Refactor annotation API to use label to be consistent with axis --- jest.config.cjs | 3 +++ src/helpers/annotations.ts | 17 ++++++--------- src/types.ts | 11 +++++----- ...destroy-the-svg-node-on-destroy-1-snap.png | Bin 19991 -> 18863 bytes test/e2e/snippets.ts | 20 +++--------------- 5 files changed, 18 insertions(+), 33 deletions(-) diff --git a/jest.config.cjs b/jest.config.cjs index 93292d2..2476613 100644 --- a/jest.config.cjs +++ b/jest.config.cjs @@ -14,6 +14,9 @@ const config = { testMatch: ['**/__tests__/**/*.[jt]s?(x)', '/{src,test}/**/?(*.)+(spec|test).[jt]s?(x)'], transformIgnorePatterns: ['/node_modules/(?!d3-\\.*|internmap)'], testEnvironment: 'node', + globals: { + __COMMIT_HASH__: 'unknown' + }, extensionsToTreatAsEsm: ['.ts'] } diff --git a/src/helpers/annotations.ts b/src/helpers/annotations.ts index 88fb9c9..5bce502 100644 --- a/src/helpers/annotations.ts +++ b/src/helpers/annotations.ts @@ -54,30 +54,25 @@ export default function annotations(options: { owner: Chart }) { .merge(enter) .selectAll('text') .data(function (d) { - return [ - { - text: d.text || '', - hasX: 'x' in d - } - ] + return [{ text: d.label || '' }] }) text .enter() .append('text') .attr('y', function (d) { - return d.hasX ? 3 : 0 + return 'x' in d ? 3 : 0 }) .attr('x', function (d) { - return d.hasX ? 0 : 3 + return 'x' in d ? 0 : 3 }) .attr('dy', function (d) { - return d.hasX ? 5 : -5 + return 'x' in d ? 5 : -5 }) .attr('text-anchor', function (d) { - return d.hasX ? 'end' : '' + return 'x' in d ? 'end' : '' }) .attr('transform', function (d) { - return d.hasX ? 'rotate(-90)' : '' + return 'x' in d ? 'rotate(-90)' : '' }) .text(function (d) { return d.text diff --git a/src/types.ts b/src/types.ts index bff7efb..3ee1bec 100644 --- a/src/types.ts +++ b/src/types.ts @@ -151,14 +151,15 @@ export interface AbstractFunctionDatum { fnType?: 'linear' | 'parametric' | 'implicit' | 'polar' | 'points' | 'vector' /** - * The sampler to take samples from `range`, available values are `interval|builtIn` + * The sampler to take samples from `range`, available values are `builtIn|interval|asyncInterval` * * - **NOTE: `builtIn` should only be used when `graphType` is `polyline|scatter`** */ sampler?: 'interval' | 'builtIn' | 'asyncInterval' /** - * The number of values to be taken from `range` to evaluate the function, note that if interval-arithmetic is used the function + * The number of values to be taken from `range` to evaluate the function, + * note that if interval-arithmetic is used the function * will be evaluated with intervals instead of single values */ nSamples?: number @@ -316,7 +317,7 @@ export interface TextDatum { text: string /** - * An array of 2-number array for the position of the text when `fnType: 'text'` + * An array of 2-number array for the position of the text when `graphType: 'text'` */ location?: [number, number] } @@ -345,9 +346,9 @@ export interface FunctionPlotAnnotation { y?: number /** - * The text displayed next to the line + * The label displayed next to the line */ - text?: string + label?: string } export interface FunctionPlotOptions { diff --git a/test/e2e/__image_snapshots__/graphs-test-ts-function-plot-should-destroy-the-svg-node-on-destroy-1-snap.png b/test/e2e/__image_snapshots__/graphs-test-ts-function-plot-should-destroy-the-svg-node-on-destroy-1-snap.png index 7f035b81c0d77435741175d6783b8f6788dda66c..6a6b3455661fd0ac122986ac2248cc16571ab3e2 100644 GIT binary patch literal 18863 zcmeI4Pe@cz6o-$0P)D7Z5Mq*)w}@z|J1LAwrfeWYMWW?k8-pN1A={0vbdeaeNRen! zi#F0O5uyNZ)3-|JqBJBt9Pe+^HSs$vr&|ginlcOWDxp(EaNF;^)?Wy^V+P9r_Im(njRsTJ| z)qlD9YAtoNzrOZY&ExCGvlBJ;*Ve+qg=E=wBUw~(?a8X8FIh~#Yw@d6FdsZ<^0&%n zUdsMT%!_88>z+$)4VZZpo)gS7;W@#4DLf~b^IBd?)bctITS;n>iCzc*0U%TXijNNi zO10NP*g<$9*l&3q00e+g1vp~(FyKIzq(k5%fB+Bx;{Wd0JUOmCjI*G)`t{Gsi)ZHs|XAXs0bWJRRj*BAVI?bBsdYy00|$5Z(fRhWq&^X@~HR2 zMdw!}w7{6h5@B*pqkrh`EZtjL=!LfqT?%0J*|d|uM@^rm^k_nz~;=X=h1Z*?p_;;RkTiij^d8cB$F z3i?xBrB=54&KJ~|YbG%=D2Ep<4*f+odBf{5;;B2!=ZfrC%bs#&TV2tY+4PrtDSrJJv)+t7CP2)Ve|* zvzCtK+{OxVJFvr1N(c}YFbeePkU^HSf^*jR0!alK6zQUg1yb$bp(~ODr*?T3KOB4Hj&IBp_pQSW~O{!@q#;;I}$tOFckK0h;^=fT%SXtow6*wzk$!ExC z$Y(U!D7s