Fix missing scope for chart function evaluation
This commit is contained in:
parent
316d917f6e
commit
399407b15a
@ -56,7 +56,7 @@ spec:
|
|||||||
- name: DATABASE_NAME
|
- name: DATABASE_NAME
|
||||||
value: mathy
|
value: mathy
|
||||||
ports:
|
ports:
|
||||||
- containerPort: 80
|
- containerPort: 8000
|
||||||
|
|
||||||
- name: redis
|
- name: redis
|
||||||
image: redis:latest
|
image: redis:latest
|
||||||
@ -73,7 +73,7 @@ spec:
|
|||||||
- name: http
|
- name: http
|
||||||
port: 80
|
port: 80
|
||||||
protocol: TCP
|
protocol: TCP
|
||||||
targetPort: 80
|
targetPort: 8000
|
||||||
selector:
|
selector:
|
||||||
name: mathy-api
|
name: mathy-api
|
||||||
---
|
---
|
||||||
|
@ -3,10 +3,11 @@ import * as math from 'mathjs'
|
|||||||
import { v4 as uuidv4 } from 'uuid'
|
import { v4 as uuidv4 } from 'uuid'
|
||||||
import { LineChart } from 'vue-chart-3'
|
import { LineChart } from 'vue-chart-3'
|
||||||
import { computed, ref } from 'vue'
|
import { computed, ref } from 'vue'
|
||||||
import { Chart, ChartData, ChartOptions, registerables } from 'chart.js'
|
import { Chart, ChartData, registerables } from 'chart.js'
|
||||||
import { MathStatement } from '../support/parse'
|
import { MathStatement } from '../support/parse'
|
||||||
import { ChartBox } from '../support/types'
|
import { ChartBox } from '../support/types'
|
||||||
import { stepX, stepY } from '../support/const'
|
import { stepX, stepY } from '../support/const'
|
||||||
|
import {MathPage} from '../support/page'
|
||||||
|
|
||||||
Chart.register(...registerables)
|
Chart.register(...registerables)
|
||||||
|
|
||||||
@ -17,6 +18,7 @@ const emit = defineEmits<{
|
|||||||
}>()
|
}>()
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
|
page: MathPage,
|
||||||
fn: MathStatement,
|
fn: MathStatement,
|
||||||
value: ChartBox,
|
value: ChartBox,
|
||||||
}>()
|
}>()
|
||||||
@ -69,27 +71,32 @@ const getChartData = (): ChartData<'line'> => {
|
|||||||
throw new TypeError('Cannot chart node that is not a function.')
|
throw new TypeError('Cannot chart node that is not a function.')
|
||||||
}
|
}
|
||||||
|
|
||||||
const node = props.fn.parse() as math.FunctionAssignmentNode
|
try {
|
||||||
const fn = node.compile().evaluate() // FIXME need dependencies in scope
|
const evaluationResult = props.page.evaluate()
|
||||||
|
const node = props.fn.parse() as math.FunctionAssignmentNode
|
||||||
|
const fn = node.compile().evaluate(evaluationResult.scope)
|
||||||
|
|
||||||
console.log('getChartData', {
|
return {
|
||||||
labels: range.map(x => `${x}`),
|
labels: range.map(x => `${x}`),
|
||||||
datasets: [
|
datasets: [{
|
||||||
{
|
|
||||||
label: node.name,
|
label: node.name,
|
||||||
data: range.map(n => fn(n)),
|
backgroundColor: '#553564',
|
||||||
},
|
borderColor: '#ccc',
|
||||||
],
|
data: range.map(x => fn(x)),
|
||||||
})
|
pointRadius: 5
|
||||||
return {
|
}],
|
||||||
labels: range.map(x => `${x}`),
|
}
|
||||||
datasets: [{
|
} catch (_) {
|
||||||
label: node.name,
|
return {
|
||||||
backgroundColor: '#553564',
|
labels: [],
|
||||||
borderColor: '#ccc',
|
datasets: [{
|
||||||
data: range.map(x => fn(x)),
|
label: '',
|
||||||
pointRadius: 5
|
backgroundColor: '#553564',
|
||||||
}],
|
borderColor: '#ccc',
|
||||||
|
data: [],
|
||||||
|
pointRadius: 5
|
||||||
|
}],
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -515,6 +515,7 @@ onMounted(() => {
|
|||||||
<q-page-container id="editor" style='padding: 0'>
|
<q-page-container id="editor" style='padding: 0'>
|
||||||
<span v-for="(chartBox, index) in chartBoxes" style="display: flex">
|
<span v-for="(chartBox, index) in chartBoxes" style="display: flex">
|
||||||
<RangeChart
|
<RangeChart
|
||||||
|
:page="math"
|
||||||
:fn="math.getFunctionByNameOrFail(chartBox.fnName)"
|
:fn="math.getFunctionByNameOrFail(chartBox.fnName)"
|
||||||
:key="chartBoxKey"
|
:key="chartBoxKey"
|
||||||
:value="chartBox"
|
:value="chartBox"
|
||||||
|
@ -197,6 +197,7 @@ export class MathPage {
|
|||||||
return {
|
return {
|
||||||
variables: nonFunctionalScope,
|
variables: nonFunctionalScope,
|
||||||
statements: evaluations,
|
statements: evaluations,
|
||||||
|
scope,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,6 +90,7 @@ export type EvaluatedValue = TypeTag<'@app.EvaluatedValue'> & string
|
|||||||
export interface EvaluationResult {
|
export interface EvaluationResult {
|
||||||
variables: Record<VariableName, any>
|
variables: Record<VariableName, any>
|
||||||
statements: Record<StatementID, any>
|
statements: Record<StatementID, any>
|
||||||
|
scope: Record<VariableName, any>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user