JavaScript中 动态仪表插件 JustGage

  • 源码大小:1.06MB
  • 所需积分:1积分
  • 源码编号:19JP-3273
  • 浏览次数:803次
  • 最后更新:2023年05月25日
  • 所属栏目:动画
我要下载
加入收藏
本站默认解压密码:19jp.com 或 19jp_com

简介

JustGage是一个JavaScript插件,用于生成漂亮干净的仪表并设置其动画。

它基于用于矢量绘制的Raphaâl库,因此它完全独立于分辨率并可自我调整。

参见:

  • jQuery和纯JavaScript/CSS中的10个最佳仪表插件

如何使用它:

1.安装和下载。

  1. # NPM
  2. $ npm i justgage --save

2.在文档中加载必要的Raphaél库和JustGage插件。

  1. <script src="/path/to/cdn/raphael.min.js"></script>
  2. <script src="/path/to/dist/justgage.js"></script>

3.创建一个容器来容纳仪表。

  1. <div id="gauge"></div>

4.创建一个新的仪表实例。

  1. var gauge = new JustGage({
  2. id: "gauge", // required
  3. // more options here
  4. });

5.用于自定义仪表的所有默认配置。

  1. // id : string
  2. // this is container element id
  3. id: config.id,
  4.  
  5. // value : float
  6. // value gauge is showing
  7. value: kvLookup('value', config, dataset, 0, 'float'),
  8.  
  9. // defaults : bool
  10. // defaults parameter to use
  11. defaults: kvLookup('defaults', config, dataset, 0, false),
  12.  
  13. // parentNode : node object
  14. // this is container element
  15. parentNode: kvLookup('parentNode', config, dataset, null),
  16.  
  17. // width : int
  18. // gauge width
  19. width: kvLookup('width', config, dataset, null),
  20.  
  21. // height : int
  22. // gauge height
  23. height: kvLookup('height', config, dataset, null),
  24.  
  25. // valueFontColor : string
  26. // color of label showing current value
  27. valueFontColor: kvLookup('valueFontColor', config, dataset, "#010101"),
  28.  
  29. // valueFontFamily : string
  30. // color of label showing current value
  31. valueFontFamily: kvLookup('valueFontFamily', config, dataset, "Arial"),
  32.  
  33. // symbol : string
  34. // special symbol to show next to value
  35. symbol: kvLookup('symbol', config, dataset, ''),
  36.  
  37. // min : float
  38. // min value
  39. min: kvLookup('min', config, dataset, 0, 'float'),
  40.  
  41. // minTxt : string
  42. // min value text
  43. minTxt: kvLookup('minTxt', config, dataset, false),
  44.  
  45. // max : float
  46. // max value
  47. max: kvLookup('max', config, dataset, 100, 'float'),
  48.  
  49. // maxTxt : string
  50. // max value text
  51. maxTxt: kvLookup('maxTxt', config, dataset, false),
  52.  
  53. // reverse : bool
  54. // reverse min and max
  55. reverse: kvLookup('reverse', config, dataset, false),
  56.  
  57. // humanFriendlyDecimal : int
  58. // number of decimal places for our human friendly number to contain
  59. humanFriendlyDecimal: kvLookup('humanFriendlyDecimal', config, dataset, 0),
  60.  
  61.  
  62. // textRenderer: func
  63. // function applied before rendering text
  64. textRenderer: kvLookup('textRenderer', config, dataset, null),
  65.  
  66. // onAnimationEnd: func
  67. // function applied after animation is done
  68. onAnimationEnd: kvLookup('onAnimationEnd', config, dataset, null),
  69.  
  70. // gaugeWidthScale : float
  71. // width of the gauge element
  72. gaugeWidthScale: kvLookup('gaugeWidthScale', config, dataset, 1.0),
  73.  
  74. // gaugeColor : string
  75. // background color of gauge element
  76. gaugeColor: kvLookup('gaugeColor', config, dataset, "#edebeb"),
  77.  
  78. // label : string
  79. // text to show below value
  80. label: kvLookup('label', config, dataset, ''),
  81.  
  82. // labelFontColor : string
  83. // color of label showing label under value
  84. labelFontColor: kvLookup('labelFontColor', config, dataset, "#b3b3b3"),
  85.  
  86. // valueFontFamily : string
  87. // font-family for label as well as min/max value
  88. labelFontFamily: kvLookup('labelFontFamily', config, dataset, "Arial"),
  89.  
  90. // shadowOpacity : int
  91. // 0 ~ 1
  92. shadowOpacity: kvLookup('shadowOpacity', config, dataset, 0.2),
  93.  
  94. // shadowSize: int
  95. // inner shadow size
  96. shadowSize: kvLookup('shadowSize', config, dataset, 5),
  97.  
  98. // shadowVerticalOffset : int
  99. // how much shadow is offset from top
  100. shadowVerticalOffset: kvLookup('shadowVerticalOffset', config, dataset, 3),
  101.  
  102. // levelColors : string[]
  103. // colors of indicator, from lower to upper, in RGB format
  104. levelColors: kvLookup('levelColors', config, dataset, ["#a9d70b", "#f9c802", "#ff0000"], 'array', ','),
  105.  
  106. // startAnimationTime : int
  107. // length of initial animation
  108. startAnimationTime: kvLookup('startAnimationTime', config, dataset, 700),
  109.  
  110. // startAnimationType : string
  111. // type of initial animation (linear, >, <, <>, bounce)
  112. startAnimationType: kvLookup('startAnimationType', config, dataset, '>'),
  113.  
  114. // refreshAnimationTime : int
  115. // length of refresh animation
  116. refreshAnimationTime: kvLookup('refreshAnimationTime', config, dataset, 700),
  117.  
  118. // refreshAnimationType : string
  119. // type of refresh animation (linear, >, <, <>, bounce)
  120. refreshAnimationType: kvLookup('refreshAnimationType', config, dataset, '>'),
  121.  
  122. // donutStartAngle : int
  123. // angle to start from when in donut mode
  124. donutStartAngle: kvLookup('donutStartAngle', config, dataset, 90),
  125.  
  126. // valueMinFontSize : int
  127. // absolute minimum font size for the value
  128. valueMinFontSize: kvLookup('valueMinFontSize', config, dataset, 16),
  129.  
  130. // labelMinFontSize
  131. // absolute minimum font size for the label
  132. labelMinFontSize: kvLookup('labelMinFontSize', config, dataset, 10),
  133.  
  134. // minLabelMinFontSize
  135. // absolute minimum font size for the minimum label
  136. minLabelMinFontSize: kvLookup('minLabelMinFontSize', config, dataset, 10),
  137.  
  138. // maxLabelMinFontSize
  139. // absolute minimum font size for the maximum label
  140. maxLabelMinFontSize: kvLookup('maxLabelMinFontSize', config, dataset, 10),
  141.  
  142. // hideValue : bool
  143. // hide value text
  144. hideValue: kvLookup('hideValue', config, dataset, false),
  145.  
  146. // hideMinMax : bool
  147. // hide min and max values
  148. hideMinMax: kvLookup('hideMinMax', config, dataset, false),
  149.  
  150. // showInnerShadow : bool
  151. // show inner shadow
  152. showInnerShadow: kvLookup('showInnerShadow', config, dataset, false),
  153.  
  154. // humanFriendly : bool
  155. // convert large numbers for min, max, value to human friendly (e.g. 1234567 -> 1.23M)
  156. humanFriendly: kvLookup('humanFriendly', config, dataset, false),
  157.  
  158. // noGradient : bool
  159. // whether to use gradual color change for value, or sector-based
  160. noGradient: kvLookup('noGradient', config, dataset, false),
  161.  
  162. // donut : bool
  163. // show full donut gauge
  164. donut: kvLookup('donut', config, dataset, false),
  165.  
  166. // relativeGaugeSize : bool
  167. // whether gauge size should follow changes in container element size
  168. relativeGaugeSize: kvLookup('relativeGaugeSize', config, dataset, false),
  169.  
  170. // counter : bool
  171. // animate level number change
  172. counter: kvLookup('counter', config, dataset, false),
  173.  
  174. // decimals : int
  175. // number of digits after floating point
  176. decimals: kvLookup('decimals', config, dataset, 0),
  177.  
  178. // customSectors : object
  179. // custom sectors colors. Expects an object with props
  180. // percents : bool hi/lo are percents values
  181. // ranges : array of objects : {hi, lo, color}
  182. customSectors: kvLookup('customSectors', config, dataset, {}),
  183.  
  184. // formatNumber: boolean
  185. // formats numbers with commas where appropriate
  186. formatNumber: kvLookup('formatNumber', config, dataset, false),
  187.  
  188. // pointer : bool
  189. // show value pointer
  190. pointer: kvLookup('pointer', config, dataset, false),
  191.  
  192. // min must = -max and pointer will be at top when = 0
  193. differential: true,
  194.  
  195. // pointerOptions : object
  196. // define pointer look
  197. pointerOptions: kvLookup('pointerOptions', config, dataset, {}),
  198.  
  199. // displayRemaining: boolean
  200. // replace display number with the number remaining to reach max
  201. displayRemaining: kvLookup('displayRemaining', config, dataset, false)

6.API方法。

  1. // refresh the gauge value
  2. guage.refresh(val, max, min, label);
  3.  
  4. // update options
  5. gauge.update({
  6. // new options
  7. });
  8.  
  9. // destroy the instance
  10. guage.destroy();

更新日志:

v1.6.1 (2022-12-02)

  • 修复:使差速器在所有间隔内工作

v1.6.0 (2022-12-01)

  • 专长:差动仪表

v1.5.1 (2021-12-11)

  • 家务:从1.0.6到1.0.7的凹凸路径解析
  • 修复:使用“parentNode”方法创建的多个仪表的样式冲突

v1.4.3/1.5.0 (2021-06-11)

  • 专长:当textRenderer返回false时使用自定义格式

第1.4.2节(2021-02-16)

  • 修复:使用最小值/最大值0刷新

v1.4.1 (2021-02-10)

  • 添加labelFont族道具

v1.4.0 (2020-08-05)

  • 使现代化

预览截图