config.ts 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. import { ChartInternal } from './core'
  2. import { isDefined } from './util'
  3. ChartInternal.prototype.getDefaultConfig = function() {
  4. var config = {
  5. bindto: '#chart',
  6. svg_classname: undefined,
  7. size_width: undefined,
  8. size_height: undefined,
  9. padding_left: undefined,
  10. padding_right: undefined,
  11. padding_top: undefined,
  12. padding_bottom: undefined,
  13. resize_auto: true,
  14. zoom_enabled: false,
  15. zoom_initialRange: undefined,
  16. zoom_type: 'scroll',
  17. zoom_disableDefaultBehavior: false,
  18. zoom_privileged: false,
  19. zoom_rescale: false,
  20. zoom_onzoom: function() {},
  21. zoom_onzoomstart: function() {},
  22. zoom_onzoomend: function() {},
  23. zoom_x_min: undefined,
  24. zoom_x_max: undefined,
  25. interaction_brighten: true,
  26. interaction_enabled: true,
  27. onmouseover: function() {},
  28. onmouseout: function() {},
  29. onresize: function() {},
  30. onresized: function() {},
  31. oninit: function() {},
  32. onrendered: function() {},
  33. transition_duration: 350,
  34. data_epochs: 'epochs',
  35. data_x: undefined,
  36. data_xs: {},
  37. data_xFormat: '%Y-%m-%d',
  38. data_xLocaltime: true,
  39. data_xSort: true,
  40. data_idConverter: function(id) {
  41. return id
  42. },
  43. data_names: {},
  44. data_classes: {},
  45. data_groups: [],
  46. data_axes: {},
  47. data_type: undefined,
  48. data_types: {},
  49. data_labels: {},
  50. data_order: 'desc',
  51. data_regions: {},
  52. data_color: undefined,
  53. data_colors: {},
  54. data_hide: false,
  55. data_filter: undefined,
  56. data_selection_enabled: false,
  57. data_selection_grouped: false,
  58. data_selection_isselectable: function() {
  59. return true
  60. },
  61. data_selection_multiple: true,
  62. data_selection_draggable: false,
  63. data_stack_normalize: false,
  64. data_onclick: function() {},
  65. data_onmouseover: function() {},
  66. data_onmouseout: function() {},
  67. data_onselected: function() {},
  68. data_onunselected: function() {},
  69. data_url: undefined,
  70. data_headers: undefined,
  71. data_json: undefined,
  72. data_rows: undefined,
  73. data_columns: undefined,
  74. data_mimeType: undefined,
  75. data_keys: undefined,
  76. // configuration for no plot-able data supplied.
  77. data_empty_label_text: '',
  78. // subchart
  79. subchart_show: false,
  80. subchart_size_height: 60,
  81. subchart_axis_x_show: true,
  82. subchart_onbrush: function() {},
  83. // color
  84. color_pattern: [],
  85. color_threshold: {},
  86. // legend
  87. legend_show: true,
  88. legend_hide: false,
  89. legend_position: 'bottom',
  90. legend_inset_anchor: 'top-left',
  91. legend_inset_x: 10,
  92. legend_inset_y: 0,
  93. legend_inset_step: undefined,
  94. legend_item_onclick: undefined,
  95. legend_item_onmouseover: undefined,
  96. legend_item_onmouseout: undefined,
  97. legend_equally: false,
  98. legend_padding: 0,
  99. legend_item_tile_width: 10,
  100. legend_item_tile_height: 10,
  101. // axis
  102. axis_rotated: false,
  103. axis_x_show: true,
  104. axis_x_type: 'indexed',
  105. axis_x_localtime: true,
  106. axis_x_categories: [],
  107. axis_x_tick_centered: false,
  108. axis_x_tick_format: undefined,
  109. axis_x_tick_culling: {},
  110. axis_x_tick_culling_max: 10,
  111. axis_x_tick_count: undefined,
  112. axis_x_tick_fit: true,
  113. axis_x_tick_values: null,
  114. axis_x_tick_rotate: 0,
  115. axis_x_tick_outer: true,
  116. axis_x_tick_multiline: true,
  117. axis_x_tick_multilineMax: 0,
  118. axis_x_tick_width: null,
  119. axis_x_max: undefined,
  120. axis_x_min: undefined,
  121. axis_x_padding: {},
  122. axis_x_height: undefined,
  123. axis_x_selection: undefined,
  124. axis_x_label: {},
  125. axis_x_inner: undefined,
  126. axis_y_show: true,
  127. axis_y_type: 'linear',
  128. axis_y_max: undefined,
  129. axis_y_min: undefined,
  130. axis_y_inverted: false,
  131. axis_y_center: undefined,
  132. axis_y_inner: undefined,
  133. axis_y_label: {},
  134. axis_y_tick_format: undefined,
  135. axis_y_tick_outer: true,
  136. axis_y_tick_values: null,
  137. axis_y_tick_rotate: 0,
  138. axis_y_tick_count: undefined,
  139. axis_y_tick_time_type: undefined,
  140. axis_y_tick_time_interval: undefined,
  141. axis_y_padding: {},
  142. axis_y_default: undefined,
  143. axis_y2_show: false,
  144. axis_y2_type: 'linear',
  145. axis_y2_max: undefined,
  146. axis_y2_min: undefined,
  147. axis_y2_inverted: false,
  148. axis_y2_center: undefined,
  149. axis_y2_inner: undefined,
  150. axis_y2_label: {},
  151. axis_y2_tick_format: undefined,
  152. axis_y2_tick_outer: true,
  153. axis_y2_tick_values: null,
  154. axis_y2_tick_count: undefined,
  155. axis_y2_padding: {},
  156. axis_y2_default: undefined,
  157. // grid
  158. grid_x_show: false,
  159. grid_x_type: 'tick',
  160. grid_x_lines: [],
  161. grid_y_show: false,
  162. // not used
  163. // grid_y_type: 'tick',
  164. grid_y_lines: [],
  165. grid_y_ticks: 10,
  166. grid_focus_show: true,
  167. grid_lines_front: true,
  168. // point - point of each data
  169. point_show: true,
  170. point_r: 2.5,
  171. point_sensitivity: 10,
  172. point_focus_expand_enabled: true,
  173. point_focus_expand_r: undefined,
  174. point_select_r: undefined,
  175. // line
  176. line_connectNull: false,
  177. line_step_type: 'step',
  178. // bar
  179. bar_width: undefined,
  180. bar_width_ratio: 0.6,
  181. bar_width_max: undefined,
  182. bar_zerobased: true,
  183. bar_space: 0,
  184. // area
  185. area_zerobased: true,
  186. area_above: false,
  187. // pie
  188. pie_label_show: true,
  189. pie_label_format: undefined,
  190. pie_label_threshold: 0.05,
  191. pie_label_ratio: undefined,
  192. pie_expand: {},
  193. pie_expand_duration: 50,
  194. pie_padAngle: 0,
  195. // gauge
  196. gauge_fullCircle: false,
  197. gauge_label_show: true,
  198. gauge_labelLine_show: true,
  199. gauge_label_format: undefined,
  200. gauge_min: 0,
  201. gauge_max: 100,
  202. gauge_startingAngle: (-1 * Math.PI) / 2,
  203. gauge_label_extents: undefined,
  204. gauge_units: undefined,
  205. gauge_width: undefined,
  206. gauge_arcs_minWidth: 5,
  207. gauge_expand: {},
  208. gauge_expand_duration: 50,
  209. // donut
  210. donut_label_show: true,
  211. donut_label_format: undefined,
  212. donut_label_threshold: 0.05,
  213. donut_label_ratio: undefined,
  214. donut_width: undefined,
  215. donut_title: '',
  216. donut_expand: {},
  217. donut_expand_duration: 50,
  218. donut_padAngle: 0,
  219. // spline
  220. spline_interpolation_type: 'cardinal',
  221. // stanford
  222. stanford_lines: [],
  223. stanford_regions: [],
  224. stanford_texts: [],
  225. stanford_scaleMin: undefined,
  226. stanford_scaleMax: undefined,
  227. stanford_scaleWidth: undefined,
  228. stanford_scaleFormat: undefined,
  229. stanford_scaleValues: undefined,
  230. stanford_colors: undefined,
  231. stanford_padding: {
  232. top: 0,
  233. right: 0,
  234. bottom: 0,
  235. left: 0
  236. },
  237. // region - region to change style
  238. regions: [],
  239. // tooltip - show when mouseover on each data
  240. tooltip_show: true,
  241. tooltip_grouped: true,
  242. tooltip_order: undefined,
  243. tooltip_format_title: undefined,
  244. tooltip_format_name: undefined,
  245. tooltip_format_value: undefined,
  246. tooltip_horizontal: undefined,
  247. tooltip_position: undefined,
  248. tooltip_contents: function(
  249. d,
  250. defaultTitleFormat,
  251. defaultValueFormat,
  252. color
  253. ) {
  254. return this.getTooltipContent
  255. ? this.getTooltipContent(
  256. d,
  257. defaultTitleFormat,
  258. defaultValueFormat,
  259. color
  260. )
  261. : ''
  262. },
  263. tooltip_init_show: false,
  264. tooltip_init_x: 0,
  265. tooltip_init_position: { top: '0px', left: '50px' },
  266. tooltip_onshow: function() {},
  267. tooltip_onhide: function() {},
  268. // title
  269. title_text: undefined,
  270. title_padding: {
  271. top: 0,
  272. right: 0,
  273. bottom: 0,
  274. left: 0
  275. },
  276. title_position: 'top-center'
  277. }
  278. Object.keys(this.additionalConfig).forEach(function(key) {
  279. config[key] = this.additionalConfig[key]
  280. }, this)
  281. return config
  282. }
  283. ChartInternal.prototype.additionalConfig = {}
  284. ChartInternal.prototype.loadConfig = function(config) {
  285. var this_config = this.config,
  286. target,
  287. keys,
  288. read
  289. function find() {
  290. var key = keys.shift()
  291. // console.log("key =>", key, ", target =>", target);
  292. if (key && target && typeof target === 'object' && key in target) {
  293. target = target[key]
  294. return find()
  295. } else if (!key) {
  296. return target
  297. } else {
  298. return undefined
  299. }
  300. }
  301. Object.keys(this_config).forEach(function(key) {
  302. target = config
  303. keys = key.split('_')
  304. read = find()
  305. // console.log("CONFIG : ", key, read);
  306. if (isDefined(read)) {
  307. this_config[key] = read
  308. }
  309. })
  310. }