Commit 9244779d authored by Sascha Herzinger's avatar Sascha Herzinger
Browse files

just some documentation

parent 4f8c07f4
Pipeline #3276 passed with stages
in 3 minutes and 16 seconds
......@@ -14,6 +14,12 @@ export default class {
}
}
/**
* Attempts to set a chart based on a given name as a child of the given selector.
* @param chart: The name of the chart. Must be a name of a vue component within AVAILABLE_CHARTS.
* @param selector: A unique selector which will be the parent of the chart.
* @returns {Vue} The mounted vue component.
*/
setChart (chart, selector) {
if (!this.AVAILABLE_CHARTS.hasOwnProperty(chart)) {
throw new Error(`Chart '${chart} is not available. Must be one of: ${this.AVAILABLE_CHARTS}`)
......
import store from '../store/store'
export default class {
getChartElementForSelector (selector) {
/**
* For a given selector call back the given callback with the stateID whenever the state changes.
* In short, this can be used to get a unique identifier for the current state of a chart and to restore it later on.
* @param selector: Must identify a unique fjs-chart element.
* @param callback: An arbitrary callback with one argument (the state ID).
*/
chart2id (selector, callback) {
let chartElement = document.querySelectorAll(selector)
if (chartElement.length !== 1) {
throw new Error('The given selector must point to exactly one element. ' +
......@@ -12,11 +18,9 @@ export default class {
throw new Error('The given selector must point to a div element with class "fjs-chart". ' +
'This is the div that replaced the placeholder when creating the chart initially.')
}
return chartElement
}
chart2id (selector, callback) {
const chartElement = this.getChartElementForSelector(selector)
if (typeof chartElement.__vue__.$parent._setStateChangedCallback === 'undefined') {
throw new Error('Cannot generate an id for this chart. It does not permit state saving.')
}
chartElement.__vue__.$parent._setStateChangedCallback(async function (name, state) {
const rv = await store.getters.requestManager.saveState({chartName: name, chartState: state})
const stateID = rv.data.state_id
......@@ -24,6 +28,11 @@ export default class {
})
}
/**
* For a given state ID submit GET requests until state is available or until access is denied.
* @param stateID. The id given to the callback in chart2id()
* @returns {Promise}. Resolves with the requested state on success or rejects with an exception otherwise.
*/
async getState (stateID) {
function timeout (ms) {
return new Promise(resolve => setTimeout(resolve, ms))
......@@ -43,6 +52,12 @@ export default class {
}
}
/**
* For a given state id attempt to restore a chart as a child of the given selector element.
* @param selector: The parent of where the chart should be restored.
* @param stateID: The ID returned by chart2id()
* @returns {Promise}. Empty resolve on success or reject with exception otherwise.
*/
async id2chart (selector, stateID) {
const state = await this.getState(stateID)
const vm = store.getters.chartManager.setChart(state.chartName, selector)
......
......@@ -16,6 +16,11 @@ export default {
throw new Error('The dispatched value must be an instance of RequestManager.')
}
},
/**
* Commits ChartManager mutation that will overwrite the old value.
* @param context The context of the action.
* @param manager Instance of ChartManager
*/
setChartManager: (context, manager) => {
if (manager instanceof ChartManager) {
context.commit(types.SET_CHART_MANAGER, manager)
......@@ -23,6 +28,11 @@ export default {
throw new Error('The dispatched value must be an instance of ChartManager.')
}
},
/**
* Commits StateManager mutation that will overwrite the old value.
* @param context The context of the action.
* @param manager Instance of StateManager
*/
setStateManager: (context, manager) => {
if (manager instanceof StateManager) {
context.commit(types.SET_STATE_MANAGER, manager)
......
/**
* Tooltips for SVG!
* Refer to https://atomiks.github.io/tippyjs/ for documentation.
* Pass your own options like this v-tooltip='{...}'
*/
import tippy from 'tippy.js'
export default {
......
/**
* Provide a mixin that allows the component to register certain parts of their state to be saved.
* The only "public" method is registerDataToSave which takes a list strings (paths) representing
* paths in the component data.
*/
import objectPath from 'object-path'
export default {
......@@ -32,4 +38,4 @@ export default {
return state
}
}
}
\ No newline at end of file
}
/**
* Utility functions that you might or might not want to use within your chart.
*/
/**
* https://stackoverflow.com/questions/5723154/truncate-a-string-in-the-middle-with-javascript
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment