default.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. var PI = Math.PI;
  43. /**
  44. * @param {module:echarts/ExtensionAPI} api
  45. * @param {Object} [opts]
  46. * @param {string} [opts.text]
  47. * @param {string} [opts.color]
  48. * @param {string} [opts.textColor]
  49. * @return {module:zrender/Element}
  50. */
  51. export default function defaultLoading(api, opts) {
  52. opts = opts || {};
  53. zrUtil.defaults(opts, {
  54. text: 'loading',
  55. textColor: '#000',
  56. fontSize: 12,
  57. fontWeight: 'normal',
  58. fontStyle: 'normal',
  59. fontFamily: 'sans-serif',
  60. maskColor: 'rgba(255, 255, 255, 0.8)',
  61. showSpinner: true,
  62. color: '#5470c6',
  63. spinnerRadius: 10,
  64. lineWidth: 5,
  65. zlevel: 0
  66. });
  67. var group = new graphic.Group();
  68. var mask = new graphic.Rect({
  69. style: {
  70. fill: opts.maskColor
  71. },
  72. zlevel: opts.zlevel,
  73. z: 10000
  74. });
  75. group.add(mask);
  76. var textContent = new graphic.Text({
  77. style: {
  78. text: opts.text,
  79. fill: opts.textColor,
  80. fontSize: opts.fontSize,
  81. fontWeight: opts.fontWeight,
  82. fontStyle: opts.fontStyle,
  83. fontFamily: opts.fontFamily
  84. },
  85. zlevel: opts.zlevel,
  86. z: 10001
  87. });
  88. var labelRect = new graphic.Rect({
  89. style: {
  90. fill: 'none'
  91. },
  92. textContent: textContent,
  93. textConfig: {
  94. position: 'right',
  95. distance: 10
  96. },
  97. zlevel: opts.zlevel,
  98. z: 10001
  99. });
  100. group.add(labelRect);
  101. var arc;
  102. if (opts.showSpinner) {
  103. arc = new graphic.Arc({
  104. shape: {
  105. startAngle: -PI / 2,
  106. endAngle: -PI / 2 + 0.1,
  107. r: opts.spinnerRadius
  108. },
  109. style: {
  110. stroke: opts.color,
  111. lineCap: 'round',
  112. lineWidth: opts.lineWidth
  113. },
  114. zlevel: opts.zlevel,
  115. z: 10001
  116. });
  117. arc.animateShape(true).when(1000, {
  118. endAngle: PI * 3 / 2
  119. }).start('circularInOut');
  120. arc.animateShape(true).when(1000, {
  121. startAngle: PI * 3 / 2
  122. }).delay(300).start('circularInOut');
  123. group.add(arc);
  124. } // Inject resize
  125. group.resize = function () {
  126. var textWidth = textContent.getBoundingRect().width;
  127. var r = opts.showSpinner ? opts.spinnerRadius : 0; // cx = (containerWidth - arcDiameter - textDistance - textWidth) / 2
  128. // textDistance needs to be calculated when both animation and text exist
  129. var cx = (api.getWidth() - r * 2 - (opts.showSpinner && textWidth ? 10 : 0) - textWidth) / 2 - (opts.showSpinner && textWidth ? 0 : 5 + textWidth / 2) // only show the text
  130. + (opts.showSpinner ? 0 : textWidth / 2) // only show the spinner
  131. + (textWidth ? 0 : r);
  132. var cy = api.getHeight() / 2;
  133. opts.showSpinner && arc.setShape({
  134. cx: cx,
  135. cy: cy
  136. });
  137. labelRect.setShape({
  138. x: cx - r,
  139. y: cy - r,
  140. width: r * 2,
  141. height: r * 2
  142. });
  143. mask.setShape({
  144. x: 0,
  145. y: 0,
  146. width: api.getWidth(),
  147. height: api.getHeight()
  148. });
  149. };
  150. group.resize();
  151. return group;
  152. }