Skip to content

Commit 81e2550

Browse files
Update bullet chart
1 parent 130777a commit 81e2550

4 files changed

Lines changed: 26 additions & 19 deletions

File tree

‎package-lock.json‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@undp/data-viz",
3-
"version": "2.0.5",
3+
"version": "2.0.6",
44
"main": "./dist/index.cjs",
55
"module": "./dist/index.js",
66
"browser": "./dist/index.umd.js",

‎src/Components/Graphs/BulletChart/Graph.tsx‎

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ interface Props {
7373
customLayers: CustomLayerDataType[];
7474
naLabel: string;
7575
rtl: boolean;
76+
targetLineThickness: number;
7677
}
7778

7879
export function VerticalGraph(props: Props) {
@@ -118,6 +119,7 @@ export function VerticalGraph(props: Props) {
118119
precision,
119120
customLayers,
120121
naLabel,
122+
targetLineThickness,
121123
} = props;
122124
const svgRef = useRef(null);
123125
const isInView = useInView(svgRef, {
@@ -376,21 +378,21 @@ export function VerticalGraph(props: Props) {
376378
<motion.rect
377379
x={0}
378380
width={x.bandwidth()}
379-
style={{
380-
fill: targetColor,
381-
}}
382381
exit={{
383382
height: 0,
384383
y: y(0),
384+
fill: targetColor,
385385
transition: { duration: animate.duration },
386386
}}
387387
variants={{
388388
initial: {
389389
height: 0,
390+
fill: targetColor,
390391
y: y(0),
391392
},
392393
whileInView: {
393394
height: Math.abs(y(d.target) - y(0)),
395+
fill: targetColor,
394396
y: d.target > 0 ? y(d.target) : y(0),
395397
transition: { duration: animate.duration },
396398
},
@@ -430,28 +432,28 @@ export function VerticalGraph(props: Props) {
430432
<motion.rect
431433
x={0}
432434
width={x.bandwidth()}
433-
style={{
434-
fill: targetColor,
435-
}}
436435
exit={{
437436
y: y(0),
438437
opacity: 0,
438+
fill: targetColor,
439439
transition: { duration: animate.duration },
440440
}}
441441
variants={{
442442
initial: {
443443
y: y(0),
444444
opacity: 0,
445+
fill: targetColor,
445446
},
446447
whileInView: {
447-
y: y(d.target) - 1,
448+
y: y(d.target) - targetLineThickness / 2,
448449
opacity: 1,
450+
fill: targetColor,
449451
transition: { duration: animate.duration },
450452
},
451453
}}
452454
initial='initial'
453455
animate={isInView ? 'whileInView' : 'initial'}
454-
height={2}
456+
height={targetLineThickness}
455457
/>
456458
) : null}
457459
{showLabels ? (
@@ -609,6 +611,7 @@ export function HorizontalGraph(props: Props) {
609611
precision,
610612
customLayers,
611613
naLabel,
614+
targetLineThickness,
612615
} = props;
613616
const svgRef = useRef(null);
614617
const isInView = useInView(svgRef, {
@@ -839,21 +842,21 @@ export function HorizontalGraph(props: Props) {
839842
y={0}
840843
x={d.target >= 0 ? x(0) : x(d.target)}
841844
height={y.bandwidth()}
842-
style={{
843-
fill: targetColor,
844-
}}
845845
exit={{
846846
width: 0,
847847
x: x(0),
848+
fill: targetColor,
848849
transition: { duration: animate.duration },
849850
}}
850851
variants={{
851852
initial: {
852853
x: x(0),
854+
fill: targetColor,
853855
width: 0,
854856
},
855857
whileInView: {
856858
x: d.target >= 0 ? x(0) : x(d.target),
859+
fill: targetColor,
857860
width: d.target >= 0 ? x(d.target) - x(0) : x(0) - x(d.target),
858861
transition: { duration: animate.duration },
859862
},
@@ -893,23 +896,23 @@ export function HorizontalGraph(props: Props) {
893896
<motion.rect
894897
y={0}
895898
height={y.bandwidth()}
896-
style={{
897-
fill: targetColor,
898-
}}
899-
width={2}
899+
width={targetLineThickness}
900900
exit={{
901901
opacity: 0,
902902
x: x(0),
903+
fill: targetColor,
903904
transition: { duration: animate.duration },
904905
}}
905906
variants={{
906907
initial: {
907908
x: x(0),
908909
opacity: 0,
910+
fill: targetColor,
909911
},
910912
whileInView: {
911-
x: x(d.target) - 1,
913+
x: x(d.target) - targetLineThickness / 2,
912914
opacity: 1,
915+
fill: targetColor,
913916
transition: { duration: animate.duration },
914917
},
915918
}}

‎src/Components/Graphs/BulletChart/index.tsx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ interface Props {
112112
targetStyle?: 'background' | 'line';
113113
/** Defines the color of the target bar */
114114
targetColor?: string;
115+
/** Defines the thickness if the target is of style line */
116+
targetLineThickness?: number;
115117
/** Defines the width of the measure bar in relation with available width */
116118
measureBarWidthFactor?: number;
117119
/** Custom order for labels */
@@ -232,6 +234,7 @@ export function BulletChart(props: Props) {
232234
detailsOnClick,
233235
barAxisTitle,
234236
noOfTicks = 5,
237+
targetLineThickness = 2,
235238
} = props;
236239

237240
const [svgWidth, setSvgWidth] = useState(0);
@@ -370,6 +373,7 @@ export function BulletChart(props: Props) {
370373
precision={precision}
371374
customLayers={customLayers}
372375
naLabel={naLabel}
376+
targetLineThickness={targetLineThickness}
373377
rtl={language === 'ar' || language === 'he'}
374378
/>
375379
) : null}

0 commit comments

Comments
 (0)