| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,8 +23,7 @@ import { | |||
| 23 | 23 | ChartLegendWrapper | |
| 24 | 24 | } from "../ChartLegend"; | |
| 25 | 25 | import { ChartCommonStyles, ChartThemeDefinition } from '../ChartTheme'; | |
| 26 | - import { getTheme } from '../ChartUtils'; | ||
| 27 | - import { getPaddingForSide } from '../ChartUtils/chart-padding'; | ||
| 26 | + import { getPaddingForSide, getTheme } from '../ChartUtils'; | ||
| 28 | 27 | ||
| 29 | 28 | /** | |
| 30 | 29 | * See https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/victory/index.d.ts | |
@@ -169,6 +168,8 @@ export interface ChartProps extends VictoryChartProps { | |||
| 169 | 168 | * Because Victory renders responsive containers, the width and height props do not determine the width and | |
| 170 | 169 | * height of the chart in number of pixels, but instead define an aspect ratio for the chart. The exact number of | |
| 171 | 170 | * pixels will depend on the size of the container the chart is rendered into. | |
| 171 | + * | ||
| 172 | + * Typically, the parent container is set to the same width in order to maintain the aspect ratio. | ||
| 172 | 173 | */ | |
| 173 | 174 | height?: number; | |
| 174 | 175 | /** | |
@@ -347,6 +348,8 @@ export interface ChartProps extends VictoryChartProps { | |||
| 347 | 348 | * Because Victory renders responsive containers, the width and height props do not determine the width and | |
| 348 | 349 | * height of the chart in number of pixels, but instead define an aspect ratio for the chart. The exact number of | |
| 349 | 350 | * pixels will depend on the size of the container the chart is rendered into. | |
| 351 | + * | ||
| 352 | + * Typically, the parent container is set to the same width in order to maintain the aspect ratio. | ||
| 350 | 353 | */ | |
| 351 | 354 | width?: number; | |
| 352 | 355 | } | |
@@ -372,7 +375,6 @@ export const Chart: React.FunctionComponent<ChartProps> = ({ | |||
| 372 | 375 | width = theme.chart.width, | |
| 373 | 376 | ...rest | |
| 374 | 377 | }: ChartProps) => { | |
| 375 | - | ||
| 376 | 378 | const defaultPadding = { | |
| 377 | 379 | bottom: getPaddingForSide('bottom', padding, theme.chart.padding), | |
| 378 | 380 | left: getPaddingForSide('left', padding, theme.chart.padding), | |
@@ -405,7 +407,7 @@ export const Chart: React.FunctionComponent<ChartProps> = ({ | |||
| 405 | 407 | return null; | |
| 406 | 408 | } | |
| 407 | 409 | let dx = 0; | |
| 408 | - let dy = defaultPadding.top || 0; | ||
| 410 | + let dy = defaultPadding.top; | ||
| 409 | 411 | if (legendPosition === ChartLegendPosition.bottom) { | |
| 410 | 412 | dy += ChartCommonStyles.legend.margin; | |
| 411 | 413 | } else if (legendPosition === ChartLegendPosition.bottomLeft) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,8 +16,7 @@ import { ChartContainer } from '../ChartContainer'; | |||
| 16 | 16 | import { ChartLabel } from '../ChartLabel'; | |
| 17 | 17 | import { ChartPie, ChartPieLegendPosition, ChartPieProps } from '../ChartPie'; | |
| 18 | 18 | import { ChartCommonStyles, ChartDonutStyles, ChartThemeDefinition } from '../ChartTheme'; | |
| 19 | - import { ChartTooltip } from '../ChartTooltip'; | ||
| 20 | - import { getLabelX, getLabelY } from "../ChartUtils"; | ||
| 19 | + import { getLabelX, getLabelY } from '../ChartUtils'; | ||
| 21 | 20 | ||
| 22 | 21 | export enum ChartDonutLabelPosition { | |
| 23 | 22 | centroid = 'centroid', | |
@@ -130,8 +129,7 @@ export interface ChartDonutProps extends ChartPieProps { | |||
| 130 | 129 | */ | |
| 131 | 130 | dataComponent?: React.ReactElement<any>; | |
| 132 | 131 | /** | |
| 133 | - * Specifies the height of the donut chart. This value should be given as a | ||
| 134 | - * number of pixels. | ||
| 132 | + * Specifies the height of the donut chart. This value should be given as a number of pixels. | ||
| 135 | 133 | * | |
| 136 | 134 | * Because Victory renders responsive containers, the width and height props do not determine the width and | |
| 137 | 135 | * height of the chart in number of pixels, but instead define an aspect ratio for the chart. The exact number of | |
@@ -144,7 +142,7 @@ export interface ChartDonutProps extends ChartPieProps { | |||
| 144 | 142 | * legends within the same SVG. However, donutHeight (not height) may need to be set in order to adjust the donut | |
| 145 | 143 | * height. | |
| 146 | 144 | * | |
| 147 | - * The innerRadius may also need to be set when changing the donut size. | ||
| 145 | + * Note: innerRadius may need to be set when using this property. | ||
| 148 | 146 | */ | |
| 149 | 147 | donutHeight?: number; | |
| 150 | 148 | /** | |
@@ -156,8 +154,7 @@ export interface ChartDonutProps extends ChartPieProps { | |||
| 156 | 154 | */ | |
| 157 | 155 | donutDy?: number; | |
| 158 | 156 | /** | |
| 159 | - * Specifies the width of the donut chart. This value should be given as a | ||
| 160 | - * number of pixels. | ||
| 157 | + * Specifies the width of the donut chart. This value should be given as a number of pixels. | ||
| 161 | 158 | * | |
| 162 | 159 | * Because Victory renders responsive containers, the width and height props do not determine the width and | |
| 163 | 160 | * height of the chart in number of pixels, but instead define an aspect ratio for the chart. The exact number of | |
@@ -169,7 +166,7 @@ export interface ChartDonutProps extends ChartPieProps { | |||
| 169 | 166 | * By default, donutWidth is the min. of either height or width. This covers most use cases in order to accommodate | |
| 170 | 167 | * legends within the same SVG. However, donutWidth (not width) may need to be set in order to adjust the donut width. | |
| 171 | 168 | * | |
| 172 | - * The innerRadius may also need to be set when changing the donut size. | ||
| 169 | + * Note: innerRadius may need to be set when using this property. | ||
| 173 | 170 | */ | |
| 174 | 171 | donutWidth?: number; | |
| 175 | 172 | /** | |
@@ -241,7 +238,13 @@ export interface ChartDonutProps extends ChartPieProps { | |||
| 241 | 238 | * height of the chart in number of pixels, but instead define an aspect ratio for the chart. The exact number of | |
| 242 | 239 | * pixels will depend on the size of the container the chart is rendered into. | |
| 243 | 240 | * | |
| 244 | - * Note: innerRadius may need to be set when using this property. | ||
| 241 | + * Note: When adding a legend, height (the overall SVG height) may need to be larger than donutHeight (the donut size) | ||
| 242 | + * in order to accommodate the extra legend. | ||
| 243 | + * | ||
| 244 | + * By default, donutHeight is the min. of either height or width. This covers most use cases in order to accommodate | ||
| 245 | + * legends within the same SVG. However, donutHeight (not height) may need to be set in order to adjust the donut height. | ||
| 246 | + * | ||
| 247 | + * Typically, the parent container is set to the same width in order to maintain the aspect ratio. | ||
| 245 | 248 | */ | |
| 246 | 249 | height?: number; | |
| 247 | 250 | /** | |
@@ -339,12 +342,13 @@ export interface ChartDonutProps extends ChartPieProps { | |||
| 339 | 342 | * the edge of the chart and any rendered child components. This prop can be given | |
| 340 | 343 | * as a number or as an object with padding specified for top, bottom, left | |
| 341 | 344 | * and right. | |
| 345 | + * | ||
| 346 | + * Note: innerRadius may need to be set when using this property. | ||
| 342 | 347 | */ | |
| 343 | 348 | padding?: PaddingProps; | |
| 344 | 349 | /** | |
| 345 | 350 | * Specifies the radius of the chart. If this property is not provided it is computed | |
| 346 | 351 | * from width, height, and padding props | |
| 347 | - * | ||
| 348 | 352 | */ | |
| 349 | 353 | radius?: number; | |
| 350 | 354 | /** | |
@@ -436,14 +440,19 @@ export interface ChartDonutProps extends ChartPieProps { | |||
| 436 | 440 | */ | |
| 437 | 441 | titleComponent?: React.ReactElement<any>; | |
| 438 | 442 | /** | |
| 439 | - * Specifies the width of the svg viewBox of the chart container. This value should be given as a | ||
| 440 | - * number of pixels. | ||
| 443 | + * Specifies the width of the svg viewBox of the chart container. This value should be given as a number of pixels. | ||
| 441 | 444 | * | |
| 442 | 445 | * Because Victory renders responsive containers, the width and height props do not determine the width and | |
| 443 | 446 | * height of the chart in number of pixels, but instead define an aspect ratio for the chart. The exact number of | |
| 444 | 447 | * pixels will depend on the size of the container the chart is rendered into. | |
| 445 | 448 | * | |
| 446 | - * Note: innerRadius may need to be set when using this property. | ||
| 449 | + * Note: When adding a legend, width (the overall SVG width) may need to be larger than donutWidth (the donut size) | ||
| 450 | + * in order to accommodate the extra legend. | ||
| 451 | + * | ||
| 452 | + * By default, donutWidth is the min. of either height or width. This covers most use cases in order to accommodate | ||
| 453 | + * legends within the same SVG. However, donutWidth (not width) may need to be set in order to adjust the donut width. | ||
| 454 | + * | ||
| 455 | + * Typically, the parent container is set to the same width in order to maintain the aspect ratio. | ||
| 447 | 456 | */ | |
| 448 | 457 | width?: number; | |
| 449 | 458 | /** | |
@@ -489,15 +498,15 @@ export const ChartDonut: React.FunctionComponent<ChartDonutProps> = ({ | |||
| 489 | 498 | ||
| 490 | 499 | // destructure last | |
| 491 | 500 | theme = getDonutTheme(themeColor, themeVariant), | |
| 492 | - | ||
| 493 | 501 | capHeight = 1.1, | |
| 494 | 502 | height = theme.pie.height, | |
| 495 | 503 | width = theme.pie.width, | |
| 496 | 504 | donutHeight = Math.min(height, width), | |
| 497 | - donutWidth = Math.min(height, width, donutHeight), | ||
| 505 | + donutWidth = Math.min(height, width), | ||
| 498 | 506 | innerRadius = (Math.min(donutHeight, donutWidth) - 34) / 2, | |
| 499 | 507 | ...rest | |
| 500 | 508 | }: ChartDonutProps) => { | |
| 509 | + const donutSize = Math.min(donutHeight, donutWidth); | ||
| 501 | 510 | ||
| 502 | 511 | // Returns subtitle | |
| 503 | 512 | const getSubTitle = () => { | |
@@ -511,14 +520,14 @@ export const ChartDonut: React.FunctionComponent<ChartDonutProps> = ({ | |||
| 511 | 520 | textAnchor: subTitlePosition === 'right' ? 'start' : 'middle', | |
| 512 | 521 | verticalAnchor: 'middle', | |
| 513 | 522 | x: getLabelX({ | |
| 514 | - chartWidth: donutWidth, | ||
| 523 | + chartWidth: donutSize, | ||
| 515 | 524 | dx: subTitleDx, | |
| 516 | 525 | labelPosition: subTitlePosition, | |
| 517 | 526 | legendPosition, | |
| 518 | 527 | svgWidth: width | |
| 519 | 528 | }), | |
| 520 | 529 | y: getLabelY({ | |
| 521 | - chartHeight: donutHeight, | ||
| 530 | + chartHeight: donutSize, | ||
| 522 | 531 | dy: subTitleDy, | |
| 523 | 532 | labelPosition: subTitlePosition | |
| 524 | 533 | }), | |
@@ -540,14 +549,14 @@ export const ChartDonut: React.FunctionComponent<ChartDonutProps> = ({ | |||
| 540 | 549 | textAnchor: 'middle', | |
| 541 | 550 | verticalAnchor: 'middle', | |
| 542 | 551 | x: getLabelX({ | |
| 543 | - chartWidth: donutWidth, | ||
| 552 | + chartWidth: donutSize, | ||
| 544 | 553 | dx: donutDx, | |
| 545 | 554 | labelPosition: 'center', | |
| 546 | 555 | legendPosition, | |
| 547 | 556 | svgWidth: width | |
| 548 | 557 | }), | |
| 549 | 558 | y: getLabelY({ | |
| 550 | - chartHeight: donutHeight, | ||
| 559 | + chartHeight: donutSize, | ||
| 551 | 560 | dy: donutDy, | |
| 552 | 561 | labelPosition: 'center' | |
| 553 | 562 | }), | |
@@ -559,12 +568,11 @@ export const ChartDonut: React.FunctionComponent<ChartDonutProps> = ({ | |||
| 559 | 568 | <ChartPie | |
| 560 | 569 | height={height} | |
| 561 | 570 | innerRadius={innerRadius > 0 ? innerRadius : 0} | |
| 562 | - labelComponent={<ChartTooltip theme={theme} />} | ||
| 563 | 571 | legendPosition={legendPosition} | |
| 564 | 572 | pieDx={donutDx} | |
| 565 | 573 | pieDy={donutDy} | |
| 566 | - pieHeight={donutHeight} | ||
| 567 | - pieWidth={donutWidth} | ||
| 574 | + pieHeight={donutSize} | ||
| 575 | + pieWidth={donutSize} | ||
| 568 | 576 | standalone={false} | |
| 569 | 577 | theme={theme} | |
| 570 | 578 | width={width} | |
| Back | FazBrowse Home | New Git URL |
0 commit comments