Comments (3)
Hi @AndreaMinato can you give me a code example for this?
from svg-gauge.
The framework
I'm using vueJs and I want tot wrap this library into a component, I don't want to use vue-gauge
since I need to keep the fewer dependencies I can.
Some details
In the mounted function (called as soon as my component is rendered) I create the gauge setting the values as some defaults, than I call LoadData that send a request to a server to get the data.
It would be Handy to have the chance to change the max property when I get the response from the server.
Workaround
Right know I just use the 100 max value, but it cause some graphics inconsistencies since if i had a cooking time of 600 the value itself (calculated like this return Math.round(this.timeElapsed / this.totaltime * 100);
) change once every 6 seconds.
The code
import Vue from "vue";
import Gauge from "svg-gauge";
import axios from "axios";
export default Vue.extend({
name: "Gauge",
data() {
return {
interval: null,
gauge: null,
totaltime: 0,
timeleft: 0,
status: "",
lidError: "",
UpperPlateTemperature: "",
BottomPlateTemperature: "",
recipe: ""
};
},
computed: {
timeElapsed() {
return this.totaltime - this.timeleft;
},
value() {
return Math.round(this.timeElapsed / this.totaltime * 100);
},
finished() {
if (this.timeleft <= 0) {
this.$emit("finished");
return true;
}
return false;
}
},
mounted() {
this.createGauge();
this.loadData();
},
methods: {
tickIt() {
this.interval = setInterval(() => {
this.timeleft--;
this.gauge.setValue(this.value);
}, 1000);
this.$on("finished", () => {
clearInterval(this.interval);
});
},
createGauge() {
this.gauge = Gauge(this.$refs.gauge, {
max: 100,
value: 0,
showValue: false,
dialRadius: 48,
gaugeClass: "gauge",
dialClass: "dial",
valueDialClass: "value",
valueTextClass: "value-text"
});
},
async loadData() {
clearInterval(this.interval);
try {
let res = await axios.get(`/gaugeValues`);
this.totaltime = res.data["CookingTime"];
this.timeleft = res.data["RunTime"];
} catch (error) {
console.log(error);
}
this.gauge.setValueAnimated(this.value, 1);
this.tickIt();
}
}
});
from svg-gauge.
Hi @AndreaMinato I'll take a look into this.
from svg-gauge.
Related Issues (20)
- Experiencing a ReferenceError: k is not defined (gauge.js) HOT 5
- Animations not working in React HOT 3
- Gauge label transform not working on Safari HOT 3
- CSS for value-text not working HOT 1
- Use in a vue component? HOT 6
- Is it possible to display decimals in labels HOT 1
- Error: <path> attribute d: Expected number, "β¦0 A 40 40 0 1 1 NaN NaN". HOT 5
- Color Text Value
- Add Min/Max labels? HOT 1
- Dynamic setMaxValue HOT 2
- In the old webview, the number display position is wrong HOT 2
- -
- Add TypeScript types HOT 5
- SetMaxValue does not update the label if "this.max" is used in the label HOT 2
- Floating Point Number HOT 1
- function getGauge(myHtmlElement) like. HOT 1
- Gauge is not defined HOT 4
- Changing the direction of animation HOT 4
- Ticks support
- Decimal places and ΒΊC symbol HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from svg-gauge.