Corner.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import React from 'react'
  2. import classnames from 'classnames'
  3. import { DimetionType, IChartStyles } from '../Widget'
  4. import { getPivotCellWidth, getPivotCellHeight, getPivot, getStyleConfig } from '../util'
  5. const styles = require('./Pivot.less')
  6. interface ICornerProps {
  7. cols: string[]
  8. rows: string[]
  9. rowWidths: number[]
  10. chartStyles: IChartStyles
  11. dimetionAxis: DimetionType
  12. }
  13. export function Corner (props: ICornerProps) {
  14. const { cols, rows, rowWidths, chartStyles, dimetionAxis } = props
  15. const {
  16. color: fontColor,
  17. fontSize,
  18. fontFamily,
  19. lineColor,
  20. lineStyle,
  21. headerBackgroundColor
  22. } = getStyleConfig(chartStyles).pivot
  23. let width
  24. let height
  25. let marginTop = cols.length && 27
  26. let marginLeft = rows.length && 27
  27. if (dimetionAxis) {
  28. if (dimetionAxis === 'col') {
  29. width = rowWidths.reduce((sum, rw) => sum + getPivotCellWidth(rw), 0) + 64
  30. height = Math.max(0, cols.length - 1) * getPivotCellHeight()
  31. } else {
  32. width = rowWidths.slice(0, rowWidths.length - 1).reduce((sum, rw) => sum + getPivotCellWidth(rw), 0) + 64
  33. height = cols.length * getPivotCellHeight()
  34. }
  35. } else {
  36. width = rowWidths.reduce((sum, rw) => sum + getPivotCellWidth(rw), 0)
  37. height = cols.length * getPivotCellHeight()
  38. marginTop += 1
  39. marginLeft += 1
  40. }
  41. const cornerClass = classnames({
  42. [styles.corner]: true,
  43. [styles.raw]: !dimetionAxis && cols.length && rows.length
  44. })
  45. return (
  46. <div
  47. className={cornerClass}
  48. style={{
  49. width,
  50. height,
  51. marginTop,
  52. marginLeft,
  53. ...(cols.length || rows.length) && {
  54. ...!dimetionAxis && {backgroundColor: headerBackgroundColor},
  55. color: fontColor,
  56. fontSize: Number(fontSize),
  57. fontFamily,
  58. borderColor: lineColor,
  59. borderStyle: lineStyle
  60. }
  61. }}
  62. />
  63. )
  64. }
  65. export default Corner