針型のポインタ

デフォルトでは、Wijmoのラジアルゲージは、ゲージの現在の値を示すために色付きの扇形とテキスト要素を使用します。 これにより、きれいで読みやすい外観になります。

より伝統的な針スタイルのポインタを好む場合は、コントロールに追加のSVG形状を追加し、ゲージ値が変化したときにそれを移動するために変換を適用することができます。

import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; import * as wijmo from '@grapecity/wijmo'; import * as gauge from '@grapecity/wijmo.gauge'; // document.readyState === 'complete' ? init() : window.onload = init; // function init() { // create the gauge // regular gauges new gauge.RadialGauge('#theGauge1', { min: 0, max: 100, value: 25, isReadOnly: false }); new gauge.RadialGauge('#theGauge2', { min: 0, max: 100, value: 25, startAngle: -45, sweepAngle: 270, isReadOnly: false }); new gauge.RadialGauge('#theGauge3', { min: 0, max: 500, value: 100, startAngle: -45, sweepAngle: -270, isReadOnly: false }); // // rounded needle pointer new gauge.RadialGauge('#theGaugeR1', { min: 0, max: 100, value: 25, showTicks: true, tickSpacing: 10, thickness: 0.1, showText: 'MinMax', isReadOnly: false, refreshed: updateNeedleRounded, valueChanged: updateNeedleRounded }); new gauge.RadialGauge('#theGaugeR2', { min: 0, max: 100, value: 25, startAngle: -45, sweepAngle: 270, showTicks: true, tickSpacing: 10, thickness: 0.1, showText: 'MinMax', isReadOnly: false, refreshed: updateNeedleRounded, valueChanged: updateNeedleRounded }); new gauge.RadialGauge('#theGaugeR3', { min: 0, max: 500, value: 100, startAngle: -45, sweepAngle: -270, showTicks: true, tickSpacing: 25, thickness: 0.1, showText: 'MinMax', isReadOnly: false, refreshed: updateNeedleRounded, valueChanged: updateNeedleRounded }); // // pointed needle pointer new gauge.RadialGauge('#theGaugeP1', { min: 0, max: 100, value: 25, showTicks: true, tickSpacing: 10, thickness: 0.1, showText: 'MinMax', isReadOnly: false, refreshed: updateNeedlePointed, valueChanged: updateNeedlePointed }); new gauge.RadialGauge('#theGaugeP2', { min: 0, max: 100, value: 25, startAngle: -45, sweepAngle: 270, showTicks: true, tickSpacing: 10, thickness: 0.1, showText: 'MinMax', isReadOnly: false, refreshed: updateNeedlePointed, valueChanged: updateNeedlePointed }); new gauge.RadialGauge('#theGaugeP3', { min: 0, max: 500, value: 100, startAngle: -45, sweepAngle: -270, showTicks: true, tickSpacing: 25, thickness: 0.1, showText: 'MinMax', isReadOnly: false, refreshed: updateNeedlePointed, valueChanged: updateNeedlePointed }); // // update needle element when gauge size or value change // pointed (diamond-shaped) needle function updateNeedlePointed(g) { // add needle element if necessary let needle = g.hostElement.querySelector('.needle'); if (!needle) { let svg = g.hostElement.querySelector('svg'); needle = document.createElementNS('http://www.w3.org/2000/svg', 'path'); wijmo.addClass(needle, 'needle'); svg.appendChild(needle); } // // update needle parameters let args = getArgs(g); needle.setAttribute('d', wijmo.format('M {lft} {y} L {x} {bot} L {rgt} {y} L {x} {top} Z', args)); needle.setAttribute('transform', wijmo.format('rotate({angle} {x} {y})', args)); } // // update needle element when gauge size or value change // rounded (drop-shaped) needle function updateNeedleRounded(g) { // add needle element if necessary let needle = g.hostElement.querySelector('.needle'); if (!needle) { let svg = g.hostElement.querySelector('svg'); needle = document.createElementNS('http://www.w3.org/2000/svg', 'path'); wijmo.addClass(needle, 'needle'); svg.appendChild(needle); } // // update needle parameters let args = getArgs(g); needle.setAttribute('d', wijmo.format('M {lft} {y} A {wid} {wid} 0 0 0 {rgt} {y} L {x} {top} Z', args)); needle.setAttribute('transform', wijmo.format('rotate({angle} {x} {y})', args)); } // // utilities function getArgs(g) { let rc = g.faceBounds, cx = rc.width / 2, cy = rc.height / 2, r = Math.min(rc.width, rc.height) / 2, wid = r / 10, pct = (g.max > g.min) ? (g.value - g.min) / (g.max - g.min) : 0, angle = g.startAngle + g.sweepAngle * wijmo.clamp(pct, 0, 1) - 90; // return { angle: angle, x: cx.toFixed(4), y: cy.toFixed(4), wid: wid.toFixed(4), lft: (cx - wid).toFixed(4), rgt: (cx + wid).toFixed(4), top: (cy - r).toFixed(4), bot: (cy + wid).toFixed(4) }; } } <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Radial Gauges with Needle Pointers</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app'); </script> </head> <body> <div class="container-fluid"> <div class="row"> <div class="col-xs-4"> <div id="theGauge1"></div> </div> <div class="col-xs-4"> <div id="theGauge2"></div> </div> <div class="col-xs-4"> <div id="theGauge3"></div> </div> </div> <p> より伝統的な針型のポインタを使用する場合は、追加のSVGシェイプをコントロールに追加し、変形を適用して針を移動させることができます。ドロップ型の針ポインタを追加する例を次に示します。 </p> <div class="row"> <div class="col-xs-4"> <div id="theGaugeR1"></div> </div> <div class="col-xs-4"> <div id="theGaugeR2"></div> </div> <div class="col-xs-4"> <div id="theGaugeR3"></div> </div> </div> <p> ポインタは単なるSVGパスなので、パスパラメータや針要素に関連付けられたCSSを変更することで、ポインタを非常に簡単にカスタマイズできます。 </p> <div class="row"> <div class="col-xs-4"> <div id="theGaugeP1"></div> </div> <div class="col-xs-4"> <div id="theGaugeP2"></div> </div> <div class="col-xs-4"> <div id="theGaugeP3"></div> </div> </div> </div> </body> </html> .wj-radialgauge { height: 250px; padding: 24pt; margin: auto auto; } .wj-radialgauge .needle { fill: orange; stroke: black; stroke-width: 1px; transition: transform 400ms; } body { margin-bottom: 24pt; } import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; // import * as wijmo from '@grapecity/wijmo'; import * as gauge from '@grapecity/wijmo.gauge'; // import { Component, enableProdMode, NgModule } from '@angular/core'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { BrowserModule } from '@angular/platform-browser'; import { WjInputModule } from '@grapecity/wijmo.angular2.input'; import { WjGaugeModule } from '@grapecity/wijmo.angular2.gauge'; // @Component({ selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent { initializeNeedleRounded(g: gauge.RadialGauge) { g.refreshed.addHandler((g: gauge.RadialGauge) => { this.updateNeedleRounded(g); }); } // initializeNeedlePointed(g: gauge.RadialGauge) { g.refreshed.addHandler((g: gauge.RadialGauge) => { this.updateNeedlePointed(g); }); } // // update needle element when gauge size or value change // pointed (diamond-shaped) needle updateNeedlePointed(g: gauge.RadialGauge) { if (!g.clientSize) { return; } // // add needle element if necessary let needle = g.hostElement.querySelector('.needle'); if (!needle) { let svg = g.hostElement.querySelector('svg'); needle = document.createElementNS('http://www.w3.org/2000/svg', 'path'); wijmo.addClass(needle, 'needle'); svg.appendChild(needle); } // // update needle parameters let args = this.getArgs(g); needle.setAttribute('d', wijmo.format('M {lft} {y} L {x} {bot} L {rgt} {y} L {x} {top} Z', args)); needle.setAttribute('transform', wijmo.format('rotate({angle} {x} {y})', args)); } // // update needle element when gauge size or value change // rounded (drop-shaped) needle updateNeedleRounded(g: gauge.RadialGauge) { if (!g.clientSize) { return; } // // add needle element if necessary let needle = g.hostElement.querySelector('.needle'); if (!needle) { let svg = g.hostElement.querySelector('svg'); needle = document.createElementNS('http://www.w3.org/2000/svg', 'path'); wijmo.addClass(needle, 'needle'); svg.appendChild(needle); } // // update needle parameters let args = this.getArgs(g); needle.setAttribute('d', wijmo.format('M {lft} {y} A {wid} {wid} 0 0 0 {rgt} {y} L {x} {top} Z', args)); needle.setAttribute('transform', wijmo.format('rotate({angle} {x} {y})', args)); } // // utilities private getArgs(g: gauge.RadialGauge) { let rc = g.faceBounds, cx = rc.width / 2, cy = rc.height / 2, r = Math.min(rc.width, rc.height) / 2, wid = r / 10, pct = (g.max > g.min) ? (g.value - g.min) / (g.max - g.min) : 0, angle = g.startAngle + g.sweepAngle * wijmo.clamp(pct, 0, 1) - 90; // return { angle: angle, x: cx.toFixed(4), y: cy.toFixed(4), wid: wid.toFixed(4), lft: (cx - wid).toFixed(4), rgt: (cx + wid).toFixed(4), top: (cy - r).toFixed(4), bot: (cy + wid).toFixed(4) }; } } // @NgModule({ imports: [WjGaugeModule, WjInputModule, BrowserModule], declarations: [AppComponent], bootstrap: [AppComponent] }) export class AppModule { } // enableProdMode(); // Bootstrap application with hash style navigation and global services. platformBrowserDynamic().bootstrapModule(AppModule); <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Radial Gauges with Needle Pointers</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Polyfills --> <script src="node_modules/core-js/client/shim.min.js"></script> <script src="node_modules/zone.js/dist/zone.min.js"></script> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.js"></script> <script src="systemjs.config.js"></script> <script> // workaround to load 'rxjs/operators' from the rxjs bundle System.import('rxjs').then(function (m) { System.set(SystemJS.resolveSync('rxjs/operators'), System.newModule(m.operators)); System.import('./src/app.component'); }); </script> </head> <body> <app-component></app-component> </body> </html> <div class="container-fluid"> <div class="row"> <div class="col-xs-4"> <wj-radial-gauge [min]="0" [max]="100" [value]="25" [isReadOnly]="false"> </wj-radial-gauge> </div> <div class="col-xs-4"> <wj-radial-gauge [min]="0" [max]="100" [value]="25" [startAngle]="-45" [sweepAngle]="270" [isReadOnly]="false"> </wj-radial-gauge> </div> <div class="col-xs-4"> <wj-radial-gauge [min]="0" [max]="500" [value]="100" [startAngle]="-45" [sweepAngle]="-270" [isReadOnly]="false"> </wj-radial-gauge> </div> </div> <p> より伝統的な針型のポインタを使用する場合は、追加のSVGシェイプをコントロールに追加し、変形を適用して針を移動させることができます。ドロップ型の針ポインタを追加する例を次に示します。 </p> <div class="row"> <div class="col-xs-4"> <wj-radial-gauge #theGaugeR1 [min]="0" [max]="100" [value]="25" [showTicks]="true" [tickSpacing]="10" [thickness]="0.1" [showText]="'MinMax'" [isReadOnly]="false" (initialized)="initializeNeedleRounded(theGaugeR1)" (valueChanged)="updateNeedleRounded(theGaugeR1)"> </wj-radial-gauge> </div> <div class="col-xs-4"> <wj-radial-gauge #theGaugeR2 [min]="0" [max]="100" [value]="25" [startAngle]="-45" [sweepAngle]="270" [showTicks]="true" [tickSpacing]="10" [thickness]="0.1" [showText]="'MinMax'" [isReadOnly]="false" (initialized)="initializeNeedleRounded(theGaugeR2)" (valueChanged)="updateNeedleRounded(theGaugeR2)"> </wj-radial-gauge> </div> <div class="col-xs-4"> <wj-radial-gauge #theGaugeR3 [min]="0" [max]="500" [value]="100" [startAngle]="-45" [sweepAngle]="-270" [showTicks]="true" [tickSpacing]="25" [thickness]="0.1" [showText]="'MinMax'" [isReadOnly]="false" (initialized)="initializeNeedleRounded(theGaugeR3)" (valueChanged)="updateNeedleRounded(theGaugeR3)"> </wj-radial-gauge> </div> </div> <p> ポインタは単なるSVGパスなので、パスパラメータや針要素に関連付けられたCSSを変更することで、ポインタを非常に簡単にカスタマイズできます。 </p> <div class="row"> <div class="col-xs-4"> <wj-radial-gauge #theGaugeP1 [min]="0" [max]="100" [value]="25" [showTicks]="true" [tickSpacing]="10" [thickness]="0.1" [showText]="'MinMax'" [isReadOnly]="false" (initialized)="initializeNeedlePointed(theGaugeP1)" (valueChanged)="updateNeedlePointed(theGaugeP1)"> </wj-radial-gauge> </div> <div class="col-xs-4"> <wj-radial-gauge #theGaugeP2 [min]="0" [max]="100" [value]="25" [startAngle]="45" [sweepAngle]="270" [showTicks]="true" [tickSpacing]="10" [thickness]="0.1" [showText]="'MinMax'" [isReadOnly]="false" (initialized)="initializeNeedlePointed(theGaugeP2)" (valueChanged)="updateNeedlePointed(theGaugeP2)"> </wj-radial-gauge> </div> <div class="col-xs-4"> <wj-radial-gauge #theGaugeP3 [min]="0" [max]="500" [value]="100" [startAngle]="-45" [sweepAngle]="-270" [showTicks]="true" [tickSpacing]="25" [thickness]="0.1" [showText]="'MinMax'" [isReadOnly]="false" (initialized)="initializeNeedlePointed(theGaugeP3)" (valueChanged)="updateNeedlePointed(theGaugeP3)"> </wj-radial-gauge> </div> </div> </div> .wj-radialgauge { height: 250px; padding: 24pt; margin: auto auto; } .wj-radialgauge .needle { fill: orange; stroke: black; stroke-width: 1px; transition: transform 400ms; } body { margin-bottom: 24pt; } import './app.css'; import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import * as React from 'react'; import * as ReactDOM from 'react-dom'; import * as wijmo from '@grapecity/wijmo'; import * as wjGauge from '@grapecity/wijmo.react.gauge'; class App extends React.Component { render() { return (<div className="container-fluid"> <div className="row"> <div className="col-xs-4"> <wjGauge.RadialGauge min={0} max={100} value={25} isReadOnly={false}> </wjGauge.RadialGauge> </div> <div className="col-xs-4"> <wjGauge.RadialGauge min={0} max={100} value={25} startAngle={-45} sweepAngle={270} isReadOnly={false}> </wjGauge.RadialGauge> </div> <div className="col-xs-4"> <wjGauge.RadialGauge min={0} max={500} value={100} startAngle={-45} sweepAngle={-270} isReadOnly={false}> </wjGauge.RadialGauge> </div> </div> <p> より伝統的な針型のポインタを使用する場合は、追加のSVGシェイプをコントロールに追加し、変形を適用して針を移動させることができます。ドロップ型の針ポインタを追加する例を次に示します。 </p> <div className="row"> <div className="col-xs-4"> <wjGauge.RadialGauge min={0} max={100} value={25} showTicks={true} tickSpacing={10} thickness={0.1} showText="MinMax" isReadOnly={false} initialized={this._initializeNeedleRounded.bind(this)} valueChanged={this._updateNeedleRounded.bind(this)}> </wjGauge.RadialGauge> </div> <div className="col-xs-4"> <wjGauge.RadialGauge min={0} max={100} value={25} startAngle={-45} sweepAngle={270} showTicks={true} tickSpacing={10} thickness={0.1} showText="MinMax" isReadOnly={false} initialized={this._initializeNeedleRounded.bind(this)} valueChanged={this._updateNeedleRounded.bind(this)}> </wjGauge.RadialGauge> </div> <div className="col-xs-4"> <wjGauge.RadialGauge min={0} max={500} value={100} startAngle={-45} sweepAngle={-270} showTicks={true} tickSpacing={25} thickness={0.1} showText="MinMax" isReadOnly={false} initialized={this._initializeNeedleRounded.bind(this)} valueChanged={this._updateNeedleRounded.bind(this)}> </wjGauge.RadialGauge> </div> </div> <p> ポインタは単なるSVGパスなので、パスパラメータや針要素に関連付けられたCSSを変更することで、ポインタを非常に簡単にカスタマイズできます。 </p> <div className="row"> <div className="col-xs-4"> <wjGauge.RadialGauge min={0} max={100} value={25} showTicks={true} tickSpacing={10} thickness={0.1} showText="MinMax" isReadOnly={false} initialized={this._initializeNeedlePointed.bind(this)} valueChanged={this._updateNeedlePointed.bind(this)}> </wjGauge.RadialGauge> </div> <div className="col-xs-4"> <wjGauge.RadialGauge min={0} max={100} value={25} startAngle={45} sweepAngle={270} showTicks={true} tickSpacing={10} thickness={0.1} showText="MinMax" isReadOnly={false} initialized={this._initializeNeedlePointed.bind(this)} valueChanged={this._updateNeedlePointed.bind(this)}> </wjGauge.RadialGauge> </div> <div className="col-xs-4"> <wjGauge.RadialGauge min={0} max={500} value={100} startAngle={-45} sweepAngle={-270} showTicks={true} tickSpacing={25} thickness={0.1} showText="MinMax" isReadOnly={false} initialized={this._initializeNeedlePointed.bind(this)} valueChanged={this._updateNeedlePointed.bind(this)}> </wjGauge.RadialGauge> </div> </div> </div>); } _initializeNeedleRounded(s) { s.refreshed.addHandler((s) => this._updateNeedleRounded(s)); } _initializeNeedlePointed(s) { s.refreshed.addHandler((s) => this._updateNeedlePointed(s)); } _updateNeedleRounded(s) { if (!s.clientSize) { return; } // add needle element if necessary let needle = s.hostElement.querySelector('.needle'); if (!needle) { let svg = s.hostElement.querySelector('svg'); needle = document.createElementNS('http://www.w3.org/2000/svg', 'path'); wijmo.addClass(needle, 'needle'); svg.appendChild(needle); } // update needle parameters let args = this._getArgs(s); needle.setAttribute('d', wijmo.format('M {lft} {y} A {wid} {wid} 0 0 0 {rgt} {y} L {x} {top} Z', args)); needle.setAttribute('transform', wijmo.format('rotate({angle} {x} {y})', args)); } _updateNeedlePointed(s) { if (!s.clientSize) { return; } // add needle element if necessary let needle = s.hostElement.querySelector('.needle'); if (!needle) { let svg = s.hostElement.querySelector('svg'); needle = document.createElementNS('http://www.w3.org/2000/svg', 'path'); wijmo.addClass(needle, 'needle'); svg.appendChild(needle); } // update needle parameters let args = this._getArgs(s); needle.setAttribute('d', wijmo.format('M {lft} {y} L {x} {bot} L {rgt} {y} L {x} {top} Z', args)); needle.setAttribute('transform', wijmo.format('rotate({angle} {x} {y})', args)); } _getArgs(g) { let rc = g.faceBounds, cx = rc.width / 2, cy = rc.height / 2, r = Math.min(rc.width, rc.height) / 2, wid = r / 10, pct = (g.max > g.min) ? (g.value - g.min) / (g.max - g.min) : 0, angle = g.startAngle + g.sweepAngle * wijmo.clamp(pct, 0, 1) - 90; return { angle: angle, x: cx.toFixed(4), y: cy.toFixed(4), wid: wid.toFixed(4), lft: (cx - wid).toFixed(4), rgt: (cx + wid).toFixed(4), top: (cy - r).toFixed(4), bot: (cy + wid).toFixed(4) }; } } ReactDOM.render(<App />, document.getElementById('app')); <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Radial Gauges with Needle Pointers</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app'); </script> </head> <body> <div id="app"></div> </body> </html> .container-fluid .wj-radialgauge { height: 250px; padding: 24pt; margin: auto auto; } .container-fluid .wj-radialgauge .needle { fill: orange; stroke: black; stroke-width: 1px; transition: transform 400ms; } body { margin-bottom: 24pt; } <template> <div class="container-fluid"> <div class="row"> <div class="col-xs-4"> <wj-radial-gauge :min=0 :max=100 :value=25 :isReadOnly=false> </wj-radial-gauge> </div> <div class="col-xs-4"> <wj-radial-gauge :min=0 :max=100 :value=25 :startAngle=-45 :sweepAngle=270 :isReadOnly=false> </wj-radial-gauge> </div> <div class="col-xs-4"> <wj-radial-gauge :min=0 :max=500 :value=100 :startAngle=-45 :sweepAngle=-270 :isReadOnly=false> </wj-radial-gauge> </div> </div> <p> より伝統的な針型のポインタを使用する場合は、追加のSVGシェイプをコントロールに追加し、変形を適用して針を移動させることができます。ドロップ型の針ポインタを追加する例を次に示します。 </p> <div class="row"> <div class="col-xs-4"> <wj-radial-gauge :min=0 :max=100 :value=25 :showTicks=true :tickSpacing=10 :thickness=0.1 showText="MinMax" :isReadOnly=false :initialized="initializeNeedleRounded" :valueChanged="updateNeedleRounded"> </wj-radial-gauge> </div> <div class="col-xs-4"> <wj-radial-gauge :min=0 :max=100 :value=25 :startAngle=-45 :sweepAngle=270 :showTicks=true :tickSpacing=10 :thickness=0.1 showText="MinMax" :isReadOnly=false :initialized="initializeNeedleRounded" :valueChanged="updateNeedleRounded"> </wj-radial-gauge> </div> <div class="col-xs-4"> <wj-radial-gauge :min=0 :max=500 :value=100 :startAngle=-45 :sweepAngle=-270 :showTicks=true :tickSpacing=25 :thickness=0.1 showText="MinMax" :isReadOnly=false :initialized="initializeNeedleRounded" :valueChanged="updateNeedleRounded"> </wj-radial-gauge> </div> </div> <p> ポインタは単なるSVGパスなので、パスパラメータや針要素に関連付けられたCSSを変更することで、ポインタを非常に簡単にカスタマイズできます。 </p> <div class="row"> <div class="col-xs-4"> <wj-radial-gauge :min=0 :max=100 :value=25 :showTicks=true :tickSpacing=10 :thickness=0.1 showText="MinMax" :isReadOnly=false :initialized="initializeNeedlePointed" :valueChanged="updateNeedlePointed"> </wj-radial-gauge> </div> <div class="col-xs-4"> <wj-radial-gauge :min=0 :max=100 :value=25 :startAngle=45 :sweepAngle=270 :showTicks=true :tickSpacing=10 :thickness=0.1 showText="MinMax" :isReadOnly=false :initialized="initializeNeedlePointed" :valueChanged="updateNeedlePointed"> </wj-radial-gauge> </div> <div class="col-xs-4"> <wj-radial-gauge :min=0 :max=500 :value=100 :startAngle=-45 :sweepAngle=-270 :showTicks=true :tickSpacing=25 :thickness=0.1 showText="MinMax" :isReadOnly=false :initialized="initializeNeedlePointed" :valueChanged="updateNeedlePointed"> </wj-radial-gauge> </div> </div> </div> </template> <script> import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import Vue from 'vue'; import '@grapecity/wijmo.vue2.gauge'; let App = Vue.extend({ name: 'app', data: function(){ return { theGauge: { pointer: { color: '#000000', thickness: 1 } } } }, methods: { onInputValueChanged: function(s,e) { this.theGauge.pointer[s.hostElement.id] = s.value; }, initializeNeedleRounded: function(s,e){ s.refreshed.addHandler((s) => { this.updateNeedleRounded(s); }); }, updateNeedleRounded: function(s,e){ if (!s.clientSize) { return; } // // add needle element if necessary let needle = s.hostElement.querySelector('.needle'); if (!needle) { let svg = s.hostElement.querySelector('svg'); needle = document.createElementNS('http://www.w3.org/2000/svg', 'path'); wijmo.addClass(needle, 'needle'); svg.appendChild(needle); } // // update needle parameters let args = this.getArgs(s); needle.setAttribute('d', wijmo.format('M {lft} {y} A {wid} {wid} 0 0 0 {rgt} {y} L {x} {top} Z', args)); needle.setAttribute('transform', wijmo.format('rotate({angle} {x} {y})', args)); }, initializeNeedlePointed: function(s,e){ s.refreshed.addHandler((s) => { this.updateNeedlePointed(s); }); }, updateNeedlePointed: function(s,e){ if (!s.clientSize) { return; } // // add needle element if necessary let needle = s.hostElement.querySelector('.needle'); if (!needle) { let svg = s.hostElement.querySelector('svg'); needle = document.createElementNS('http://www.w3.org/2000/svg', 'path'); wijmo.addClass(needle, 'needle'); svg.appendChild(needle); } // // update needle parameters let args = this.getArgs(s); needle.setAttribute('d', wijmo.format('M {lft} {y} L {x} {bot} L {rgt} {y} L {x} {top} Z', args)); needle.setAttribute('transform', wijmo.format('rotate({angle} {x} {y})', args)); }, getArgs: function(g){ let rc = g.faceBounds, cx = rc.width / 2, cy = rc.height / 2, r = Math.min(rc.width, rc.height) / 2, wid = r / 10, pct = (g.max > g.min) ? (g.value - g.min) / (g.max - g.min) : 0, angle = g.startAngle + g.sweepAngle * wijmo.clamp(pct, 0, 1) - 90; // return { angle: angle, x: cx.toFixed(4), y: cy.toFixed(4), wid: wid.toFixed(4), lft: (cx - wid).toFixed(4), rgt: (cx + wid).toFixed(4), top: (cy - r).toFixed(4), bot: (cy + wid).toFixed(4) }; } } }) new Vue({ render: h => h(App) }).$mount('#app'); </script> <style> .container-fluid .wj-radialgauge { height: 250px; padding: 24pt; margin: auto auto; } .container-fluid .wj-radialgauge .needle { fill: orange; stroke: black; stroke-width: 1px; transition: transform 400ms; } body { margin-bottom: 24pt; } </style> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Radial Gauges with Needle Pointers</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app.vue'); </script> </head> <body> <div id="app"> </div> </body> </html>