-
Notifications
You must be signed in to change notification settings - Fork 30
added files for selector #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
musiciancodes
wants to merge
1
commit into
new-codelabs
Choose a base branch
from
filter-codelab
base: new-codelabs
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| select { | ||
| width: 100%; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| const dscc = require("@google/dscc"); | ||
|
|
||
| // a global to keep track of state | ||
| const state = { | ||
| data: undefined, | ||
| height: undefined, | ||
| width: undefined, | ||
| selected: undefined | ||
| }; | ||
|
|
||
| // removes the selector if it already exists | ||
| const removeSelect = () => { | ||
| let selector = document.getElementsByTagName("select"); | ||
musiciancodes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (selector.length > 0) { | ||
| document.body.removeChild(selector[0]); | ||
| } | ||
| }; | ||
|
|
||
| // what to do when user makes a selection | ||
| const click = (d, data) => { | ||
musiciancodes marked this conversation as resolved.
Show resolved
Hide resolved
musiciancodes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const FILTER = dscc.InteractionType.FILTER; | ||
| const actionId = "onClick"; | ||
| const dimId = data.fields.dimensions[0].id; | ||
|
|
||
| const filterData = { | ||
| concepts: [dimId], | ||
| values: [[d]] | ||
| }; | ||
| dscc.sendInteraction(actionId, FILTER, filterData); | ||
| }; | ||
|
|
||
| // check what is difference in the message | ||
musiciancodes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const whatChanged = data => { | ||
musiciancodes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const changed = { | ||
| data: false, | ||
| size: false | ||
| }; | ||
| const vals = data.tables.DEFAULT.rows.map(d => d[0]); | ||
| if (JSON.stringify(vals) !== JSON.stringify(state.data)) { | ||
musiciancodes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| changed.data = true; | ||
| } | ||
| if (dscc.getHeight() !== state.height || dscc.getWidth() !== state.width) { | ||
musiciancodes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| changed.size = true; | ||
| } | ||
| return changed; | ||
| }; | ||
|
|
||
| // make the selector | ||
| const makeSelect = data => { | ||
| var vals = data.tables.DEFAULT.rows.map(d => d[0]); | ||
| let selector = document.createElement("select"); | ||
| for (let dimVal of vals) { | ||
musiciancodes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const option = document.createElement("option"); | ||
| option.setAttribute("value", dimVal); | ||
| const optionText = document.createTextNode(dimVal); | ||
| option.appendChild(optionText); | ||
| selector.appendChild(option); | ||
| } | ||
| selector.addEventListener("change", function() { | ||
| click(this.value, data); | ||
musiciancodes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| document.body.appendChild(selector); | ||
| state.data = vals; | ||
| state.width = dscc.getWidth(); | ||
| state.height = dscc.getHeight(); | ||
| }; | ||
|
|
||
| // run every time a new message is sent | ||
| const drawViz = data => { | ||
| let changed = whatChanged(data); | ||
|
|
||
| // if data or height changed, redraw the selector | ||
| if (changed.data || changed.size) { | ||
| removeSelect(); | ||
| makeSelect(data); | ||
| } | ||
| }; | ||
|
|
||
| dscc.subscribeToData(drawViz, { transform: dscc.tableTransform }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| { | ||
| "data": [ | ||
| { | ||
| "id": "concepts", | ||
| "label": "Concepts", | ||
| "elements": [ | ||
| { | ||
| "id": "dimensions", | ||
| "label": "Dimensions", | ||
| "type": "DIMENSION", | ||
| "options": { | ||
| "min": 1, | ||
| "max": 1 | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| ], | ||
| "style": [ ], | ||
| "interactions": [ | ||
| { | ||
| "id": "onClick", | ||
| "supportedActions": ["FILTER"] | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| { | ||
| "name": "My Visualizations", | ||
| "organization": "MyOrg", | ||
| "description": "My first visualization package.", | ||
| "logoUrl": "https://logo", | ||
| "organizationUrl": "https://url", | ||
| "supportUrl": "https://url", | ||
| "privacyPolicyUrl": "https://url", | ||
| "termsOfServiceUrl": "https://url", | ||
| "packageUrl": "https://url", | ||
| "devMode": "DEVMODE_BOOL", | ||
| "components": [ | ||
| { | ||
| "name": "table", | ||
| "description": "Simple JavaScript Table", | ||
| "iconUrl": "https://url", | ||
| "resource": { | ||
| "js": "YOUR_GCS_BUCKET/index.js", | ||
| "config": "YOUR_GCS_BUCKET/index.json", | ||
| "css": "YOUR_GCS_BUCKET/index.css" | ||
| } | ||
| } | ||
| ] | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.