default.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. /**
  20. * AUTO-GENERATED FILE. DO NOT MODIFY.
  21. */
  22. /*
  23. * Licensed to the Apache Software Foundation (ASF) under one
  24. * or more contributor license agreements. See the NOTICE file
  25. * distributed with this work for additional information
  26. * regarding copyright ownership. The ASF licenses this file
  27. * to you under the Apache License, Version 2.0 (the
  28. * "License"); you may not use this file except in compliance
  29. * with the License. You may obtain a copy of the License at
  30. *
  31. * http://www.apache.org/licenses/LICENSE-2.0
  32. *
  33. * Unless required by applicable law or agreed to in writing,
  34. * software distributed under the License is distributed on an
  35. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36. * KIND, either express or implied. See the License for the
  37. * specific language governing permissions and limitations
  38. * under the License.
  39. */
  40. import * as zrUtil from 'zrender/lib/core/util.js';
  41. import * as graphic from '../util/graphic.js';
  42. import tokens from '../visual/tokens.js';
  43. var PI = Math.PI;
  44. /**
  45. * @param {module:echarts/ExtensionAPI} api
  46. * @param {Object} [opts]
  47. * @param {string} [opts.text]
  48. * @param {string} [opts.color]
  49. * @param {string} [opts.textColor]
  50. * @return {module:zrender/Element}
  51. */
  52. export default function defaultLoading(api, opts) {
  53. opts = opts || {};
  54. zrUtil.defaults(opts, {
  55. text: 'loading',
  56. textColor: tokens.color.primary,
  57. fontSize: 12,
  58. fontWeight: 'normal',
  59. fontStyle: 'normal',
  60. fontFamily: 'sans-serif',
  61. maskColor: 'rgba(255,255,255,0.8)',
  62. showSpinner: true,
  63. color: tokens.color.theme[0],
  64. spinnerRadius: 10,
  65. lineWidth: 5,
  66. zlevel: 0
  67. });
  68. var group = new graphic.Group();
  69. var mask = new graphic.Rect({
  70. style: {
  71. fill: opts.maskColor
  72. },
  73. zlevel: opts.zlevel,
  74. z: 10000
  75. });
  76. group.add(mask);
  77. var textContent = new graphic.Text({
  78. style: {
  79. text: opts.text,
  80. fill: opts.textColor,
  81. fontSize: opts.fontSize,
  82. fontWeight: opts.fontWeight,
  83. fontStyle: opts.fontStyle,
  84. fontFamily: opts.fontFamily
  85. },
  86. zlevel: opts.zlevel,
  87. z: 10001
  88. });
  89. var labelRect = new graphic.Rect({
  90. style: {
  91. fill: 'none'
  92. },
  93. textContent: textContent,
  94. textConfig: {
  95. position: 'right',
  96. distance: 10
  97. },
  98. zlevel: opts.zlevel,
  99. z: 10001
  100. });
  101. group.add(labelRect);
  102. var arc;
  103. if (opts.showSpinner) {
  104. arc = new graphic.Arc({
  105. shape: {
  106. startAngle: -PI / 2,
  107. endAngle: -PI / 2 + 0.1,
  108. r: opts.spinnerRadius
  109. },
  110. style: {
  111. stroke: opts.color,
  112. lineCap: 'round',
  113. lineWidth: opts.lineWidth
  114. },
  115. zlevel: opts.zlevel,
  116. z: 10001
  117. });
  118. arc.animateShape(true).when(1000, {
  119. endAngle: PI * 3 / 2
  120. }).start('circularInOut');
  121. arc.animateShape(true).when(1000, {
  122. startAngle: PI * 3 / 2
  123. }).delay(300).start('circularInOut');
  124. group.add(arc);
  125. }
  126. // Inject resize
  127. group.resize = function () {
  128. var textWidth = textContent.getBoundingRect().width;
  129. var r = opts.showSpinner ? opts.spinnerRadius : 0;
  130. // cx = (containerWidth - arcDiameter - textDistance - textWidth) / 2
  131. // textDistance needs to be calculated when both animation and text exist
  132. var cx = (api.getWidth() - r * 2 - (opts.showSpinner && textWidth ? 10 : 0) - textWidth) / 2 - (opts.showSpinner && textWidth ? 0 : 5 + textWidth / 2)
  133. // only show the text
  134. + (opts.showSpinner ? 0 : textWidth / 2)
  135. // only show the spinner
  136. + (textWidth ? 0 : r);
  137. var cy = api.getHeight() / 2;
  138. opts.showSpinner && arc.setShape({
  139. cx: cx,
  140. cy: cy
  141. });
  142. labelRect.setShape({
  143. x: cx - r,
  144. y: cy - r,
  145. width: r * 2,
  146. height: r * 2
  147. });
  148. mask.setShape({
  149. x: 0,
  150. y: 0,
  151. width: api.getWidth(),
  152. height: api.getHeight()
  153. });
  154. };
  155. group.resize();
  156. return group;
  157. }