RowTitle.tsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import React from 'react'
  2. import { DimetionType, IChartStyles } from '../Widget'
  3. import { IDrawingData } from './Pivot'
  4. import { getPivotContentTextWidth, getPivotCellHeight, getPivot, getStyleConfig } from '../util'
  5. const styles = require('./Pivot.less')
  6. interface IRowTitleProps {
  7. rows: string[]
  8. rowKeys: string[][]
  9. chartStyles: IChartStyles
  10. drawingData: IDrawingData
  11. dimetionAxis: DimetionType
  12. }
  13. export function RowTitle (props: IRowTitleProps) {
  14. const { rows, rowKeys, chartStyles, dimetionAxis, drawingData } = props
  15. const { elementSize, unitMetricHeight } = drawingData
  16. const { color: fontColor } = getStyleConfig(chartStyles).pivot
  17. let tableHeight = 0
  18. if (dimetionAxis) {
  19. tableHeight = dimetionAxis === 'row'
  20. ? elementSize * rowKeys.length
  21. : elementSize * unitMetricHeight
  22. } else {
  23. tableHeight = rowKeys.length * getPivotCellHeight()
  24. }
  25. const content = rows.join(` / `)
  26. const contentLength = getPivotContentTextWidth(content)
  27. return (
  28. <div
  29. className={styles.rowTitle}
  30. style={{
  31. width: rowKeys.length && getPivotCellHeight(),
  32. height: tableHeight,
  33. color: fontColor
  34. }}
  35. >
  36. <p style={{transform: `translate(12px, ${contentLength / 2}px) rotate(-90deg)`}}>{content}</p>
  37. </div>
  38. )
  39. }
  40. export default RowTitle