mirror of https://github.com/sveltejs/svelte
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
348 B
21 lines
348 B
8 years ago
|
<p>{{scale(x)}}</p>
|
||
|
|
||
|
<script>
|
||
|
export default {
|
||
|
data: () => ({
|
||
|
x: 5,
|
||
|
domain: [ 0, 10 ],
|
||
|
range: [ 0, 100 ]
|
||
|
}),
|
||
|
|
||
|
computed: {
|
||
|
scale: ( domain, range ) => {
|
||
|
return num => {
|
||
|
const t = domain[0] + ( num - domain[0] ) / ( domain[1] - domain[0] );
|
||
|
return range[0] + t * ( range[1] - range[0] );
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
</script>
|