Skip to content
Open
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
bb5366f
ok
selvalt7 Aug 6, 2024
fc89200
Add editor
selvalt7 Aug 7, 2024
12f4c86
Fix
selvalt7 Aug 7, 2024
0d9c7d5
Improved visual editor
selvalt7 Aug 8, 2024
984ffae
Update naming
selvalt7 Aug 9, 2024
8834ab0
Added color selector
selvalt7 Aug 9, 2024
9f5ace9
Add visual editor
selvalt7 Aug 9, 2024
e7276f6
Fix
selvalt7 Aug 9, 2024
f43e017
Fix: color conversion functions
selvalt7 Aug 9, 2024
4224e50
Added support for color array
selvalt7 Aug 9, 2024
765fa0a
Added color thresholds editor
selvalt7 Aug 10, 2024
61c3f6f
Set default show values
selvalt7 Aug 11, 2024
00d2c09
Removed use color thresholds option
selvalt7 Aug 12, 2024
05b81a5
Added state map editor
selvalt7 Aug 13, 2024
f7fb286
Made subpage link focusable
selvalt7 Aug 14, 2024
83a7661
Removed color conversion functions
selvalt7 Aug 14, 2024
1ff2815
Merge branch 'dev' of https://github.com/selvalt7/mini-graph-card int…
selvalt7 Aug 14, 2024
56f324b
Merge branch 'dev' into editor
selvalt7 Aug 14, 2024
e210a83
ok
selvalt7 Aug 14, 2024
0a0f90f
fix: missing "resolved" and "integrity" field in "package-lock.json" …
selvalt7 Aug 20, 2024
78369e0
fix: visual glitch in "select" selector
selvalt7 Aug 20, 2024
b689ee5
feat: entity can be removed with button inside the selector
selvalt7 Aug 20, 2024
aa10d65
fix: unset show properties were treated as undefined
selvalt7 Aug 20, 2024
cbc8880
feat: display entity_id under entity selector
selvalt7 Aug 22, 2024
e16f430
Merge branch 'dev' into editor
selvalt7 Sep 16, 2024
87d963b
Added `ha-form-mgc-list` for use in `ha-form` schema
selvalt7 Sep 20, 2024
5f82f5f
add German translation
tr05t Oct 23, 2024
1fcae0f
add German translation
tr05t Oct 23, 2024
86cb9d8
Merge branch 'editor' of github.com:tr05t/mini-graph-card into editor
tr05t Oct 24, 2024
a69556c
add German translation
tr05t Oct 24, 2024
138875d
Merge branch 'editor' of github.com:tr05t/mini-graph-card into editor
tr05t Oct 25, 2024
86f544d
add German translation
selvalt7 Oct 25, 2024
100dd42
Added value localization
selvalt7 Nov 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified .babelrc
100755 → 100644
Empty file.
1 change: 1 addition & 0 deletions .eslintrc.yaml
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ globals:
window: true
Event: true
customElements: true
document: true
Empty file modified .gitignore
100755 → 100644
Empty file.
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"license": "MIT",
"dependencies": {
"@kalkih/lz-string": "^1.4.5",
"@mdi/js": "^7.4.47",
"custom-card-helpers": "^1.6.6",
"d3-interpolate": "^3.0.1",
"lit-element": "^2.2.1",
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default {
plugins: [
commonjs(),
json({
include: 'package.json',
include: ['package.json', 'src/localize/languages/*'],
preferConst: true,
}),
resolve(),
Expand Down
Empty file modified scripts/update_readme.sh
100755 → 100644
Empty file.
127 changes: 127 additions & 0 deletions src/editor/components/colorSelector.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import { mdiClose } from '@mdi/js';
import { fireEvent } from 'custom-card-helpers';
import { css, html, LitElement } from 'lit-element';

export const colorSelector = {
hex_color: {},
};

export class CustomColorSelector extends LitElement {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason not to use the color picker provided by hass itself?

If it is the "clearable" feature, it could be handled in the usual hass way by having an enable/disable toggle in front of the color picker.

If it is the hex format, could it be converted "output-only" in the main valueChanged function? I am not familiar enough with the way these things work...

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mainly it was the hex format. I've tried to do the convertion on output but this resulted in warnings in console about supplied color value to hass color picker but the selecter was rendering just fine.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see... I'd guess, we'd have to convert back and forth to not loose colours on each startup of the editor... At least in setConfig, configChanged and entitiesChanged... Then use [r,g,b] internally in the editor and hex outside...

Another idea: How about we allow [r,g,b] as a new colour input format for the mini-graph-card itself? Better suited for a follow-up PR then, maybe... We'd still loose non-hex colours on first startup of the editor, I assume...

I shall test, if losing colours is actually an issue...

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a test, and yes, loosing colours is an issue. Try this:

  • Edit card
  • Switch to YAML
  • Set colour to "yellow" on an entity
  • Switch to UI mode and edit entity
  • Observe the colour to be black now.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've addressed this issue in the latest commit

static get properties() {
return {
hass: { attribute: false },
selector: { attribute: false },
value: {},
label: {},
};
}

render() {
return html`
<div class="color-container">
<label id="hex" for="color-input">
<span class="label">${this.label}</span>
<span class="input-wrapper">
<div class="overflow">
<input class=${this.value ? '' : 'empty'}
id="color-input"
@input=${this.valueChanged}
type="color"
.value=${this.value ? this.value : '#000000'}>
</div>
</span>
</label>
${this.selector.hex_color.clearable ? html`
<ha-icon-button
class="clear-button"
.label=${this.hass.localize('ui.common.clear')}
.path=${mdiClose}
@click=${this.clearValue}
><ha-icon-button>
` : html``}
</div>
`;
}

valueChanged(ev) {
const value = (ev.target).value || '#000000';
fireEvent(this, 'value-changed', { value });
}

clearValue() {
fireEvent(this, 'value-changed', { undefined });
}

static get styles() {
return css`
#hex {
display: flex;
align-items: center;
margin: 4px 0px;
flex: 1;
}

.input-wrapper {
width: 48px;
height: 48px;
box-sizing: border-box;
border: 1px solid var(--outline-color);
position: relative;
border-radius: 50%;
}

#hex:hover .input-wrapper {
border: 2px solid var(--outline-color);
}

.label {
font-family: var(--mdc-typography-body2-font-family, var(--mdc-typography-font-family, Roboto, sans-serif));
color: var(--mdc-theme-text-primary-on-background, rgba(0, 0, 0, .87));
font-size: 1em;
line-height: var(--mdc-typography-body2-line-height, 1.25rem);
font-weight: var(--mdc-typography-body2-font-weight, 400);
flex-grow: 1;
padding-inline-start: 4px;
}

.overflow {
width: 100%;
height: 100%;
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;
border-radius: inherit;
}

#hex input {
min-width: 200%;
min-height: 200%;
}

#hex .empty::before {
background:
repeating-conic-gradient(
var(--secondary-background-color) 0 90deg,
var(--disabled-text-color) 0 180deg)
0 0/40px 40px round;
content: '';
min-width: 200%;
min-height: 200%;
display: block;
}

.color-container {
display: flex;
align-items: center;
}

.clear-button {
--mdc-icon-size: 20px;
color: var(--input-dropdown-icon-color);
}
`;
}
}

customElements.define('ha-selector-hex_color', CustomColorSelector);
159 changes: 159 additions & 0 deletions src/editor/components/colorThresholdsEditor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
import { css, html, LitElement } from 'lit-element';
import { mdiClose } from '@mdi/js';
import { fireEvent } from 'custom-card-helpers';
import { localize } from '../../localize/localize';
import './colorSelector';
import './subPageHeader';

const SCHEMA = [
{
name: '',
type: 'grid',
schema: [
{
name: 'value',
selector: { number: { step: 0.1 } },
},
{
name: 'color',
selector: { hex_color: {} },
},
],
},
];

class ColorThresholdsEditor extends LitElement {
static get properties() {
return {
hass: { attribute: false },
config: { attribute: false },
};
}

computeLabel(schema) {
return localize(`editor.form.color_thresholds.${schema.name}`, this.hass);
}

render() {
if (!this.hass) {
return html``;
}

if (!this.config) {
return html`
<mini-graph-card-subpage-header
adding=true
.name=${localize('editor.edit_color_thresholds', this.hass)}
@go-back=${this.goBack}
@add-row=${this.addRow}
></mini-graph-card-subpage-header>
`;
}

return html`
<mini-graph-card-subpage-header
adding=true
.name=${localize('editor.edit_color_thresholds', this.hass)}
@go-back=${this.goBack}
@add-row=${this.addRow}
></mini-graph-card-subpage-header>
<div class="thresholds">
${this.config.map((threshold, index) => html`
<div class="threshold">
<ha-expansion-panel outlined>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this expansion panel? It is a bit clumsy to have to open the individual panels for changing colors. It is also inconsistent to the state map editor.

<span slot="header"><span class="circle-color" style="background-color: ${threshold.color}"></span>${threshold.value}</span>
<ha-form
.hass=${this.hass}
.schema=${SCHEMA}
.data=${threshold}
.index=${index}
.computeLabel=${this.computeLabel}
@value-changed=${this.valueChanged}
></ha-form>
</ha-expansion-panel>
<ha-icon-button
.label=${this.hass.localize('ui.components.entity.entity-picker.clear')}
.path=${mdiClose}
.index=${index}
@click=${this.removeRow}
></ha-icon-button>
</div>
`)}
</div>
`;
}

goBack() {
fireEvent(this, 'go-back');
}

removeRow(ev) {
ev.stopPropagation();
if (!this.config || !this.hass) {
return;
}
const index = (ev.currentTarget).index || '';
const newColorThresholds = this.config.concat();

newColorThresholds.splice(index, 1);

fireEvent(this, 'config-changed', newColorThresholds);
}

addRow(ev) {
ev.stopPropagation();
const value = { value: 0, color: '#000000' };
if (!this.config) {
fireEvent(this, 'config-changed', [value]);
return;
}
fireEvent(this, 'config-changed', [...this.config, value]);
}

valueChanged(ev) {
if (!this.config || !this.hass) {
return;
}
const value = ev.detail.value || '';
const index = (ev.target).index || 0;
const newColorThresholds = this.config.concat();

newColorThresholds[index] = value;

fireEvent(this, 'config-changed', newColorThresholds);
}

static get styles() {
return css`
.threshold-header {
display: flex;
gap: 10px;
}

.threshold {
display: flex;
align-items: center;
margin-bottom: 8px;
}

ha-expansion-panel > span {
display: flex;
gap: 1rem;
}

.threshold > ha-expansion-panel {
flex-grow: 1;
}

.circle-color {
display: block;
background-color: #ffffff;
border-radius: 10px;
width: 20px;
height: 20px;
}
`;
}
}

customElements.define('color-thresholds-editor', ColorThresholdsEditor);
Loading