d33ab4b16389695233c100cf321291af6491c9d47a15ffe0c47b78a707c4d4d1ca64280f5bf3176f0d6a2f8cef333e4ff5fe4653672106bf838b04a89d15de 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { doUpdate } from '../class/updater.class'
  2. import { deepClone } from '@jiaminghi/c-render/lib/plugin/util'
  3. import { titleConfig } from '../config'
  4. import { deepMerge } from '../util'
  5. export function title (chart, option = {}) {
  6. let title = []
  7. if (option.title) {
  8. title[0] = deepMerge(deepClone(titleConfig, true), option.title)
  9. }
  10. doUpdate({
  11. chart,
  12. series: title,
  13. key: 'title',
  14. getGraphConfig: getTitleConfig
  15. })
  16. }
  17. function getTitleConfig (titleItem, updater) {
  18. const { animationCurve, animationFrame, rLevel } = titleConfig
  19. const shape = getTitleShape(titleItem, updater)
  20. const style = getTitleStyle(titleItem)
  21. return [{
  22. name: 'text',
  23. index: rLevel,
  24. visible: titleItem.show,
  25. animationCurve,
  26. animationFrame,
  27. shape,
  28. style
  29. }]
  30. }
  31. function getTitleShape (titleItem, updater) {
  32. const { offset, text } = titleItem
  33. const { x, y, w } = updater.chart.gridArea
  34. const [ox, oy] = offset
  35. return {
  36. content: text,
  37. position: [x + (w / 2) + ox, y + oy]
  38. }
  39. }
  40. function getTitleStyle (titleItem) {
  41. const { style } = titleItem
  42. return style
  43. }