Possible to add clickable elements to the Feature Details panel? #4986
-
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
I am imagining there is the code for the select box in the GFF3 file encoded as HTML in column 9 :) Unforunately jbrowse doesn't allow this anymore! It is somewhat insecure to allow such things (creates opportunity for cross site scripting) However, we try to allow plugins to do these operations I tried making a similar thing with a plugin here. This is a no-build plugin, so it doesn't require compiling or anything, it can just be dropped into your folder and then adding to config. It specifically adds this extra feature panel to the track with trackId 'Genes' in this case // esm_plugin.js
export default class Plugin {
name = 'MyLittlePlugin'
version = '1.0'
install(pluginManager) {
const React = pluginManager.jbrequire('react')
function ExtraFeaturePanel({ feature }) {
// if you wanted to get data off the feature, use the feature object param
const options = ['ctgA:1-5,000', 'ctgA:2,000-20,000', 'ctgB'] // hardcoded options
const [value, setValue] = React.useState('EDEN')
return React.createElement('div', null, [
React.createElement(
'label',
{ htmlFor: 'selectbox' },
'Select location: ',
),
React.createElement(
'select',
{
value,
id: 'selectbox',
onChange: async event => {
setValue(event.target.value)
pluginManager.rootModel.session.addView('LinearGenomeView', {
type: 'LinearGenomeView',
init: {
// note: this "init" field is a new feature of jbrowse since last couple releases. It let's you provide a simple JSON object with location and tracks array and assembly. possibly has less error checking than the approach you had, but it is a simple syntax
loc: event.target.value,
tracks: ['Genes'],
assembly: 'volvox',
},
})
},
},
options.map(option => React.createElement('option', { key: option }, option)),
),
])
}
pluginManager.addToExtensionPoint(
'Core-extraFeaturePanel',
(DefaultFeatureExtra, { model }) => {
return model.trackId === 'Genes'
? { name: 'Pangenome navigator', Component: ExtraFeaturePanel }
: DefaultFeatureExtra
},
)
}
configure() {}
} config {
"tracks": [],
"assemblies": [],
"plugins": [
{
"name": "UMDLocPlugin",
"esmLoc": {
"uri": "esm_plugin.js"
}
}
]
}
extra note: the same thing written with e.g. the jbrowse-plugin-template, which allows JSX, would look like this import React from 'react'
function ExtraFeaturePanel({ feature }) {
// if you wanted to get data off the feature, use the feature object param
const options = ["ctgA:1-5,000", "ctgA:2,000-20,000", "ctgB"]; // hardcoded options
const [value, setValue] = React.useState("EDEN");
return (
<div>
<label htmlFor="selectbox">Select location</label>
<select
id="selectbox"
value={value}
onChange={async (event) => {
setValue(event.target.value);
pluginManager.rootModel.session.addView("LinearGenomeView", {
type: "LinearGenomeView",
init: {
// note: this "init" field is a new feature of jbrowse since last couple releases. It let's you provide a simple JSON object with location and tracks array and assembly. possibly has less error checking than the approach you had, but it is a simple syntax
loc: event.target.value,
tracks: ["Genes"],
assembly: "volvox",
},
});
}}
>
{options.map((option) =>
React.createElement("option", { key: option }, option),
)}
</select>
</div>
);
}
export default class Plugin {
name = 'MyLittlePlugin'
version = '1.0'
install(pluginManager) {
const React = pluginManager.jbrequire('react')
pluginManager.addToExtensionPoint(
'Core-extraFeaturePanel',
(DefaultFeatureExtra, { model }) => {
return model.trackId === 'Genes'
? { name: 'Pangenome navigator', Component: ExtraFeaturePanel }
: DefaultFeatureExtra
},
)
}
configure() {}
} |
Beta Was this translation helpful? Give feedback.
I am imagining there is the code for the select box in the GFF3 file encoded as HTML in column 9 :)
Unforunately jbrowse doesn't allow this anymore! It is somewhat insecure to allow such things (creates opportunity for cross site scripting)
However, we try to allow plugins to do these operations
I tried making a similar thing with a plugin here. This is a no-build plugin, so it doesn't require compiling or anything, it can just be dropped into your folder and then adding to config.
It specifically adds this extra feature panel to the track with trackId 'Genes' in this case
Screenshot